thingy drives
added deadzone to gamepad controller mended drive polarity wait to start telem until awakened by northbridge (linux doesn't boot in 300 cycles)
This commit is contained in:
parent
1c268bba12
commit
17553cf2a3
1 changed files with 36 additions and 24 deletions
|
|
@ -6,7 +6,7 @@ use core::{panic::PanicInfo, sync::atomic::Ordering};
|
|||
use common::{Command, Response, SensorData, BAUDRATE};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::{bind_interrupts, block::ImageDef, gpio::{Level, Output}, peripherals::{UART0, UART1, USB}, pwm::{self, Pwm}, uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, BufferedUartTx, Config}, usb::Driver};
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel, once_lock::OnceLock};
|
||||
use embassy_time::{with_deadline, with_timeout, Duration, Instant, Timer};
|
||||
use embedded_io_async::{BufRead, Read, Write};
|
||||
use log::{error, info, trace, warn};
|
||||
|
|
@ -51,8 +51,8 @@ async fn main(spawner: Spawner) {
|
|||
|
||||
let mut drive_conf: pwm::Config = Default::default();
|
||||
drive_conf.divider = 150.into();
|
||||
drive_conf.top = 20000; // 5ms
|
||||
drive_conf.compare_b = 1000; // 1.5ms
|
||||
drive_conf.top = 20000; // 20ms
|
||||
drive_conf.compare_b = 1500; // 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());
|
||||
|
|
@ -73,8 +73,10 @@ async fn main(spawner: Spawner) {
|
|||
|
||||
spawner.spawn(decoder(rx)).unwrap();
|
||||
|
||||
static STARTUP: OnceLock<()> = OnceLock::new();
|
||||
|
||||
static ENABLED: AtomicBool = AtomicBool::new(false);
|
||||
spawner.spawn(telemetry(tx, &ENABLED)).unwrap();
|
||||
spawner.spawn(telemetry(tx, &ENABLED, &STARTUP)).unwrap();
|
||||
|
||||
let enabled = &ENABLED;
|
||||
let mut enable_watchdog = Instant::now();
|
||||
|
|
@ -97,10 +99,12 @@ async fn main(spawner: Spawner) {
|
|||
COMMANDS.receive().await
|
||||
};
|
||||
|
||||
STARTUP.get_or_init(||());
|
||||
|
||||
match command {
|
||||
Command::Twist(forward, right) => {
|
||||
drive_conf.compare_a = calc_speed(forward - right);
|
||||
drive_conf.compare_b = calc_speed(forward + right);
|
||||
drive_conf.compare_a = calc_speed(-forward - right);
|
||||
drive_conf.compare_b = calc_speed(forward - right);
|
||||
drive_pwm.set_config(&drive_conf);
|
||||
},
|
||||
Command::Stop => {
|
||||
|
|
@ -150,7 +154,10 @@ 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) {
|
||||
async fn telemetry(mut tx: BufferedUartTx<'static, UART1>, enabled: &'static AtomicBool, startup: &'static OnceLock<()>) {
|
||||
info!("Telemetry waiting...");
|
||||
startup.get().await;
|
||||
info!("Telemetry started...");
|
||||
loop {
|
||||
let data = with_timeout(Duration::from_millis(20), SENSOR_DATA.receive()).await.ok();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue