foc_simple/foc/
mod.rs

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