ev3_drivebase/
motor.rs

1use ev3dev_lang_rust::motors::MotorPort;
2
3/// Required metadata for each motor of the drivebase
4#[derive(Debug, Clone, Copy)]
5pub struct Motor {
6    /// The port of the motor
7    pub port: MotorPort,
8    /// The direction the motor needs to turn to make the robot go forward.
9    pub direction: Direction,
10}
11
12impl Motor {
13    /// Creates a new `Motor` struct
14    #[must_use]
15    pub const fn new(port: MotorPort, direction: Direction) -> Self {
16        Self { port, direction }
17    }
18}
19
20/// The direction to make the robot go forward
21#[derive(Debug, Clone, Copy)]
22#[repr(i8)]
23pub enum Direction {
24    /// Motor needs to turn clockwise to move forward
25    Clockwise = 1,
26    /// Motor needs to turn counter-clockwise to move forward
27    CounterClockwise = -1,
28}
29
30impl Direction {
31    /// Gets the sign of the Direction
32    #[inline]
33    #[must_use]
34    pub const fn sign(self) -> i32 {
35        self as i8 as i32
36    }
37}