foc_simple/foc/
mod.rs

1pub mod foc_hall_sensor;
2pub mod foc_pwm;
3pub mod foc_simple;
4
5#[cfg(feature = "embassy")]
6pub mod foc_embassy;
7#[cfg(feature = "rtic")]
8pub mod foc_rtic;
9
10pub const MAX_MOTOR_NR: usize = 2;
11pub const COMMAND_CHANNEL_SIZE: usize = 25;
12
13use fixed::types::I16F16;
14
15use crate::{EFocSimpleError, FocParam, Result};
16
17#[derive(Clone, Debug, Copy)]
18pub enum EModulation {
19  /// Generate PWM values based on a sinusoidal waveform.
20  ///
21  /// While this method is very simple (and fast) it is less efficient than SpaceVector
22  /// as it does not utilise the bus voltage as well.
23  Sinusoidal,
24  /// Generate PWM values based on a trapezoidal wave.
25  ///
26  /// Note that for this method to work properly, when the output is 0 the
27  /// resective channel should be disabled/set as high impedance.
28  Trapezoidal,
29  /// Generate PWM values based on a square wave.
30  Square,
31  SpaceVector,
32}
33
34pub trait PwmDriver {
35  /// set the pwm duty cycles for A B and C.
36  fn set_pwm(&mut self, duty_cycles: [u16; 3]) -> Result<()>;
37}
38
39#[derive(Clone, Debug, Copy, PartialEq)]
40pub enum EDir {
41  Stopped,
42  Cw,
43  Ccw,
44}
45
46#[derive(Clone, Debug, Copy, PartialEq)]
47pub struct CalParams {
48  dir: EDir,
49  zero: I16F16,
50}
51impl CalParams {
52  pub fn new(dir: EDir, zero: I16F16) -> Self {
53    CalParams { dir, zero }
54  }
55}
56
57#[derive(Clone, Debug, Copy, PartialEq)]
58pub enum EFocMode {
59  Idle,
60  Calibration(Option<CalParams>),
61  Velocity(FocParam),
62  Angle(FocParam),
63  Torque(FocParam),
64  Error(EFocSimpleError),
65}