Skip to main content

can_motor_control/
spec.rs

1//! Builder input types.
2
3use motor_codec::MotorTypeId;
4
5/// Whether increasing raw motor position increases or decreases gripper opening.
6#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
7pub enum OpeningDirection {
8    /// Increasing raw motor position moves the gripper toward fully open.
9    IncreasingPosition,
10    /// Decreasing raw motor position moves the gripper toward fully open.
11    DecreasingPosition,
12}
13
14impl OpeningDirection {
15    /// Sign to apply to a positive opening span in raw motor position units.
16    pub(crate) fn sign(self) -> f64 {
17        match self {
18            Self::IncreasingPosition => 1.0,
19            Self::DecreasingPosition => -1.0,
20        }
21    }
22}
23
24/// Configuration required for normalized gripper opening commands.
25#[derive(Copy, Clone, Debug, PartialEq)]
26pub struct GripperOpeningSpec {
27    /// Opening direction for this gripper mechanism.
28    pub direction: OpeningDirection,
29    /// Default per-unit current used when opening commands omit one.
30    pub default_current: Option<f64>,
31}
32
33impl GripperOpeningSpec {
34    /// Constructor for normalized gripper opening configuration.
35    pub fn new(direction: OpeningDirection, default_current: Option<f64>) -> Self {
36        Self {
37            direction,
38            default_current,
39        }
40    }
41}
42
43/// User-supplied motor specification for the [`crate::RobotBuilder`].
44#[derive(Clone, Debug, PartialEq)]
45pub struct MotorSpec {
46    /// Human-readable motor name unique within the group.
47    pub name: String,
48    /// Vendor type identifier (e.g. `MotorTypeId::Damiao(<DM4340 disc>)`).
49    pub motor_type: MotorTypeId,
50    /// CAN ID this motor accepts commands on.
51    pub send_id: u32,
52    /// CAN ID this motor emits state and replies from.
53    pub recv_id: u32,
54}
55
56impl MotorSpec {
57    /// Convenience constructor.
58    pub fn new(
59        name: impl Into<String>,
60        motor_type: impl Into<MotorTypeId>,
61        send_id: u32,
62        recv_id: u32,
63    ) -> Self {
64        Self {
65            name: name.into(),
66            motor_type: motor_type.into(),
67            send_id,
68            recv_id,
69        }
70    }
71}
72
73/// Group kind discriminator the builder uses.
74#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
75pub enum GroupSpecKind {
76    /// Articulated arm.
77    Arm,
78    /// One-motor gripper.
79    Gripper,
80    /// Generic catch-all.
81    Generic,
82}