converted southbridge -> northbridge to length-data
also divided the pwm clock by ten to align with microseconds
This commit is contained in:
parent
a9573dc8bc
commit
1c268bba12
1 changed files with 27 additions and 28 deletions
|
|
@ -9,7 +9,6 @@ use embassy_rp::{bind_interrupts, block::ImageDef, gpio::{Level, Output}, periph
|
|||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
|
||||
use embassy_time::{with_deadline, with_timeout, Duration, Instant, Timer};
|
||||
use embedded_io_async::{BufRead, Read, Write};
|
||||
use framed::{bytes, FRAME_END_SYMBOL};
|
||||
use log::{error, info, trace, warn};
|
||||
use nalgebra::clamp;
|
||||
use portable_atomic::AtomicBool;
|
||||
|
|
@ -51,10 +50,10 @@ async fn main(spawner: Spawner) {
|
|||
spawner.spawn(logger_task(driver)).unwrap();
|
||||
|
||||
let mut drive_conf: pwm::Config = Default::default();
|
||||
drive_conf.divider = 15.into();
|
||||
drive_conf.top = 50000; // 5ms
|
||||
drive_conf.compare_b = 15000; // 1.5ms
|
||||
drive_conf.compare_a = 15000; // 1.5ms
|
||||
drive_conf.divider = 150.into();
|
||||
drive_conf.top = 20000; // 5ms
|
||||
drive_conf.compare_b = 1000; // 1.5ms
|
||||
drive_conf.compare_a = 1500; // 1.5ms
|
||||
let stopped = drive_conf.clone();
|
||||
let mut drive_pwm = Pwm::new_output_ab(p.PWM_SLICE0, p.PIN_16, p.PIN_17, stopped.clone());
|
||||
|
||||
|
|
@ -152,9 +151,6 @@ async fn decoder(mut rx: BufferedUartRx<'static, UART1>) {
|
|||
/// Receive data from channel and send it over UART
|
||||
#[embassy_executor::task]
|
||||
async fn telemetry(mut tx: BufferedUartTx<'static, UART1>, enabled: &'static AtomicBool) {
|
||||
info!("Reading...");
|
||||
let mut codec = framed::bytes::Config::default().to_codec();
|
||||
|
||||
loop {
|
||||
let data = with_timeout(Duration::from_millis(20), SENSOR_DATA.receive()).await.ok();
|
||||
|
||||
|
|
@ -169,13 +165,11 @@ async fn telemetry(mut tx: BufferedUartTx<'static, UART1>, enabled: &'static Ato
|
|||
continue;
|
||||
};
|
||||
|
||||
let mut buf = [0u8; 1024];
|
||||
let Ok(len) = codec.encode_to_slice(&serialized, &mut buf) else {
|
||||
error!("encoding error");
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Err(e) = tx.write_all(&buf[..len]).await {
|
||||
let len = u32::to_be_bytes(serialized.len() as u32);
|
||||
if let Err(e) = tx.write_all(&len).await {
|
||||
error!("transport error {e:?}");
|
||||
}
|
||||
if let Err(e) = tx.write_all(&serialized).await {
|
||||
error!("transport error {e:?}");
|
||||
}
|
||||
tx.flush().await.unwrap();
|
||||
|
|
@ -184,7 +178,7 @@ async fn telemetry(mut tx: BufferedUartTx<'static, UART1>, enabled: &'static Ato
|
|||
|
||||
/// -1 to 1
|
||||
fn calc_speed(speed: f32) -> u16 {
|
||||
const COUNTS_PER_MS: f32 = 10000.;
|
||||
const COUNTS_PER_MS: f32 = 1000.;
|
||||
let speed = speed.clamp(-1., 1.);
|
||||
|
||||
let ms = (speed/2.0)+1.5;
|
||||
|
|
|
|||
Loading…
Reference in a new issue