adds arming sequence for the AfroESC

This commit is contained in:
Robert Schauklies 2025-12-28 18:37:49 +01:00
parent 07e6e6ec4b
commit 266f09c4b1

View file

@ -6,11 +6,12 @@ use esp_hal::mcpwm::operator::PwmPin;
use esp_hal::mcpwm::operator::Operator; use esp_hal::mcpwm::operator::Operator;
use esp_hal::mcpwm::McPwm; use esp_hal::mcpwm::McPwm;
use esp_hal::peripherals::MCPWM0; use esp_hal::peripherals::MCPWM0;
use esp_hal::delay::Delay;
pub struct AfroEsc<'a>{ pub struct AfroEsc<'a>{
pub pwm_pin: &'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true> pub pwm_pin: &'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>
} }
const ARMING_SEQUENCE:u16 = 1055;
const MIN_THROTTLE:u16 = 1121; const MIN_THROTTLE:u16 = 1121;
const MAX_THROTTLE:u16 = 1421; const MAX_THROTTLE:u16 = 1421;
const GAP:u16 = (MAX_THROTTLE - MIN_THROTTLE)/100; const GAP:u16 = (MAX_THROTTLE - MIN_THROTTLE)/100;
@ -18,7 +19,11 @@ const GAP:u16 = (MAX_THROTTLE - MIN_THROTTLE)/100;
impl AfroEsc<'_>{ impl AfroEsc<'_>{
//this is a little hacky tbh //this is a little hacky tbh
pub fn new<'a>(pwm_pin:&'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>)-> AfroEsc<'a> { pub fn new<'a>(pwm_pin:&'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>)-> AfroEsc<'a> {
AfroEsc{pwm_pin:pwm_pin} let mut esc = AfroEsc{pwm_pin:pwm_pin};
let delay = Delay::new();
esc.set_arming_sequence();
delay.delay_millis(3000);
esc
} }
pub fn set_timestamp(&mut self,value:u16){ pub fn set_timestamp(&mut self,value:u16){
&self.pwm_pin.set_timestamp(value); &self.pwm_pin.set_timestamp(value);
@ -32,4 +37,8 @@ impl AfroEsc<'_>{
let new_timestamp = MIN_THROTTLE+value*GAP; let new_timestamp = MIN_THROTTLE+value*GAP;
&self.pwm_pin.set_timestamp(new_timestamp); &self.pwm_pin.set_timestamp(new_timestamp);
} }
pub fn set_arming_sequence(&mut self){
&self.set_timestamp(1055);
}
} }