embedded_flight_motors/matrix/
motor.rs

1use nalgebra::Vector3;
2use num_traits::{Float, FromPrimitive};
3
4pub struct Motor<E, T> {
5    pub esc: E,
6    pub factor: Vector3<T>,
7    pub throttle_factor: T,
8    pub thrust_rpyt_out: T,
9}
10
11impl<E, T> Motor<E, T>
12where
13    T: Float,
14{
15    pub fn new(esc: E, factor: Vector3<T>, throttle_factor: T) -> Self {
16        Self {
17            esc,
18            factor,
19            throttle_factor,
20            thrust_rpyt_out: T::zero(),
21        }
22    }
23
24    pub fn from_degrees(
25        esc: E,
26        roll_factor_degrees: T,
27        pitch_factor_degrees: T,
28        yaw_factor: T,
29    ) -> Self
30    where
31        T: FromPrimitive,
32    {
33        Self::new(
34            esc,
35            Vector3::new(
36                (roll_factor_degrees + T::from_u8(90).unwrap())
37                    .to_radians()
38                    .cos(),
39                pitch_factor_degrees.to_radians().cos(),
40                yaw_factor,
41            ),
42            T::one(),
43        )
44    }
45
46    pub fn from_angle(esc: E, angle: T, yaw_factor: T) -> Self
47    where
48        T: FromPrimitive,
49    {
50        Self::from_degrees(esc, angle, angle, yaw_factor)
51    }
52}