Compare commits
2 commits
7a8ecc5277
...
3ef9bbdcec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ef9bbdcec | ||
|
|
b5ad03c29e |
3 changed files with 36 additions and 1 deletions
34
spinnyboy_rust/src/bin/dc_driver/afroesc.rs
Normal file
34
spinnyboy_rust/src/bin/dc_driver/afroesc.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use esp_hal::aes::Operation;
|
||||||
|
use esp_hal::mcpwm::PwmPeripheral;
|
||||||
|
use esp_hal::mcpwm::operator::PwmPin;
|
||||||
|
use esp_hal::mcpwm::operator::Operator;
|
||||||
|
use esp_hal::mcpwm::McPwm;
|
||||||
|
use esp_hal::peripherals::MCPWM0;
|
||||||
|
|
||||||
|
pub struct AfroEsc<'a>{
|
||||||
|
pub pwm_pin: &'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>
|
||||||
|
|
||||||
|
}
|
||||||
|
const MIN_THROTTLE:u16 = 1121;
|
||||||
|
const MAX_THROTTLE:u16 = 1421;
|
||||||
|
const GAP:u16 = (MAX_THROTTLE - MIN_THROTTLE)/100;
|
||||||
|
|
||||||
|
impl AfroEsc<'_>{
|
||||||
|
pub fn new<'a>(pwm_pin:&'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>)-> AfroEsc<'a> {
|
||||||
|
AfroEsc{pwm_pin:pwm_pin}
|
||||||
|
}
|
||||||
|
pub fn set_timestamp(&mut self,value:u16){
|
||||||
|
&self.pwm_pin.set_timestamp(value);
|
||||||
|
}
|
||||||
|
//range is from 1121 till 1421
|
||||||
|
pub fn set_duty_percent(&mut self,value:u16){
|
||||||
|
if value > 100 {
|
||||||
|
// failsafe!
|
||||||
|
&self.pwm_pin.set_timestamp(1055);
|
||||||
|
}
|
||||||
|
let new_timestamp = MIN_THROTTLE+value*GAP;
|
||||||
|
&self.pwm_pin.set_timestamp(new_timestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
spinnyboy_rust/src/bin/dc_driver/mod.rs
Normal file
1
spinnyboy_rust/src/bin/dc_driver/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod afroesc;
|
||||||
|
|
@ -53,7 +53,7 @@ fn main() -> ! {
|
||||||
let mut esc = AfroEsc::new(&mut pwm_pin);
|
let mut esc = AfroEsc::new(&mut pwm_pin);
|
||||||
esc.set_timestamp(1000);
|
esc.set_timestamp(1000);
|
||||||
delay.delay_millis(3000);
|
delay.delay_millis(3000);
|
||||||
esc.set_timestamp(1121);
|
esc.set_duty_percent(10);
|
||||||
delay.delay_millis(3000);
|
delay.delay_millis(3000);
|
||||||
//1421 is I think the best, makes calculating the throttle easier
|
//1421 is I think the best, makes calculating the throttle easier
|
||||||
esc.set_timestamp(1055);
|
esc.set_timestamp(1055);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue