tuned servo pwm parameters
This commit is contained in:
parent
23a014c024
commit
022e4317f2
1 changed files with 5 additions and 3 deletions
|
@ -2,8 +2,10 @@ use arduino_hal::pac::tc1::OCR1B;
|
||||||
use arduino_hal::pac::tc1::OCR1A;
|
use arduino_hal::pac::tc1::OCR1A;
|
||||||
use arduino_hal::pac::TC1;
|
use arduino_hal::pac::TC1;
|
||||||
|
|
||||||
const MIN: u16 = 100; // *4us = .4ms
|
const CENTER: u16 = 375;
|
||||||
const MAX: u16 = 700; // *4us = 2.8ms
|
const RADIUS: u16 = 185;
|
||||||
|
const MIN: u16 = CENTER-RADIUS; // *4us
|
||||||
|
const MAX: u16 = CENTER+RADIUS; // *4us
|
||||||
const RANGE: u16 = MAX-MIN;
|
const RANGE: u16 = MAX-MIN;
|
||||||
|
|
||||||
pub(crate) trait Servo {
|
pub(crate) trait Servo {
|
||||||
|
@ -17,7 +19,7 @@ pub(crate) trait Servo {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// -1.0 full reverse, 1.0 full forward
|
/// -1.0 full reverse, 1.0 full forward
|
||||||
fn calculate_duty(speed: f32) -> u16 {
|
pub fn calculate_duty(speed: f32) -> u16 {
|
||||||
let speed = speed / 2.0 + 0.5;
|
let speed = speed / 2.0 + 0.5;
|
||||||
let duty = speed * RANGE as f32 + MIN as f32;
|
let duty = speed * RANGE as f32 + MIN as f32;
|
||||||
duty as u16
|
duty as u16
|
||||||
|
|
Loading…
Reference in a new issue