vex_sdk/
motor.rs

1//! V5 Smart Motor
2
3use crate::{device::V5_DeviceT, map_jump_table};
4
5use core::ffi::c_double;
6
7#[repr(transparent)]
8#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
9pub struct V5MotorBrakeMode(pub core::ffi::c_uchar);
10
11impl V5MotorBrakeMode {
12    pub const kV5MotorBrakeModeCoast: Self = Self(0);
13    pub const kV5MotorBrakeModeBrake: Self = Self(1);
14    pub const kV5MotorBrakeModeHold: Self = Self(2);
15}
16
17#[repr(transparent)]
18#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
19pub struct V5MotorControlMode(pub core::ffi::c_uchar);
20
21impl V5MotorControlMode {
22    pub const kMotorControlModeOFF: Self = Self(0);
23    pub const kMotorControlModeBRAKE: Self = Self(1);
24    pub const kMotorControlModeHOLD: Self = Self(2);
25    pub const kMotorControlModeSERVO: Self = Self(3);
26    pub const kMotorControlModePROFILE: Self = Self(4);
27    pub const kMotorControlModeVELOCITY: Self = Self(5);
28    pub const kMotorControlModeUNDEFINED: Self = Self(6);
29}
30
31#[repr(transparent)]
32#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
33pub struct V5MotorEncoderUnits(pub core::ffi::c_uchar);
34
35impl V5MotorEncoderUnits {
36    pub const kMotorEncoderDegrees: Self = Self(0);
37    pub const kMotorEncoderRotations: Self = Self(1);
38    pub const kMotorEncoderCounts: Self = Self(2);
39}
40
41#[repr(transparent)]
42#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
43pub struct V5MotorGearset(pub core::ffi::c_uchar);
44
45impl V5MotorGearset {
46    pub const kMotorGearSet_36: Self = Self(0);
47    pub const kMotorGearSet_18: Self = Self(1);
48    pub const kMotorGearSet_06: Self = Self(2);
49}
50
51#[repr(packed)]
52#[derive(Default, Copy, Clone, Eq, PartialEq, Debug)]
53pub struct V5_DeviceMotorPid {
54    pub kf: u8,
55    pub kp: u8,
56    pub ki: u8,
57    pub kd: u8,
58    pub filter: u8,
59    pub pad1: u8,
60    pub limit: u16,
61    pub threshold: u8,
62    pub loopspeed: u8,
63    pub pad2: [u8; 2],
64}
65
66map_jump_table! {
67    0x2d0 => pub fn vexDeviceMotorVelocitySet(device: V5_DeviceT, velocity: i32),
68    0x2d4 => pub fn vexDeviceMotorVelocityGet(device: V5_DeviceT) -> i32,
69    0x2d8 => pub fn vexDeviceMotorActualVelocityGet(device: V5_DeviceT) -> c_double,
70    0x2dc => pub fn vexDeviceMotorDirectionGet(device: V5_DeviceT) -> i32,
71    0x2e0 => pub fn vexDeviceMotorModeSet(device: V5_DeviceT, mode: V5MotorControlMode),
72    0x2e4 => pub fn vexDeviceMotorModeGet(device: V5_DeviceT) -> V5MotorControlMode,
73    0x2e8 => pub fn vexDeviceMotorPwmSet(device: V5_DeviceT, pwm: i32),
74    0x2ec => pub fn vexDeviceMotorPwmGet(device: V5_DeviceT) -> i32,
75    0x2f0 => pub fn vexDeviceMotorCurrentLimitSet(device: V5_DeviceT, limit: i32),
76    0x2f4 => pub fn vexDeviceMotorCurrentLimitGet(device: V5_DeviceT) -> i32,
77    0x2f8 => pub fn vexDeviceMotorCurrentGet(device: V5_DeviceT) -> i32,
78    0x2fc => pub fn vexDeviceMotorPowerGet(device: V5_DeviceT) -> c_double,
79    0x300 => pub fn vexDeviceMotorTorqueGet(device: V5_DeviceT) -> c_double,
80    0x304 => pub fn vexDeviceMotorEfficiencyGet(device: V5_DeviceT) -> c_double,
81    0x308 => pub fn vexDeviceMotorTemperatureGet(device: V5_DeviceT) -> c_double,
82    0x30c => pub fn vexDeviceMotorOverTempFlagGet(device: V5_DeviceT) -> bool,
83    0x310 => pub fn vexDeviceMotorCurrentLimitFlagGet(device: V5_DeviceT) -> bool,
84    0x314 => pub fn vexDeviceMotorZeroVelocityFlagGet(device: V5_DeviceT) -> bool,
85    0x318 => pub fn vexDeviceMotorZeroPositionFlagGet(device: V5_DeviceT) -> bool,
86    0x31c => pub fn vexDeviceMotorReverseFlagSet(device: V5_DeviceT, reverse: bool),
87    0x320 => pub fn vexDeviceMotorReverseFlagGet(device: V5_DeviceT) -> bool,
88    0x324 => pub fn vexDeviceMotorEncoderUnitsSet(device: V5_DeviceT, units: V5MotorEncoderUnits),
89    0x328 => pub fn vexDeviceMotorEncoderUnitsGet(device: V5_DeviceT) -> V5MotorEncoderUnits,
90    0x32c => pub fn vexDeviceMotorBrakeModeSet(device: V5_DeviceT, mode: V5MotorBrakeMode),
91    0x330 => pub fn vexDeviceMotorBrakeModeGet(device: V5_DeviceT) -> V5MotorBrakeMode,
92    0x334 => pub fn vexDeviceMotorPositionSet(device: V5_DeviceT, position: c_double),
93    0x338 => pub fn vexDeviceMotorPositionGet(device: V5_DeviceT) -> c_double,
94    0x33c => pub fn vexDeviceMotorPositionRawGet(
95        device: V5_DeviceT,
96        timestamp: *mut u32,
97    ) -> i32,
98    0x340 => pub fn vexDeviceMotorPositionReset(device: V5_DeviceT),
99    0x344 => pub fn vexDeviceMotorTargetGet(device: V5_DeviceT) -> c_double,
100    0x348 => pub fn vexDeviceMotorServoTargetSet(device: V5_DeviceT, position: c_double),
101    0x34c => pub fn vexDeviceMotorAbsoluteTargetSet(
102        device: V5_DeviceT,
103        position: c_double,
104        veloctiy: i32,
105    ),
106    0x350 => pub fn vexDeviceMotorRelativeTargetSet(
107        device: V5_DeviceT,
108        position: c_double,
109        velocity: i32,
110    ),
111    0x354 => pub fn vexDeviceMotorFaultsGet(device: V5_DeviceT) -> u32,
112    0x358 => pub fn vexDeviceMotorFlagsGet(device: V5_DeviceT) -> u32,
113    0x35c => pub fn vexDeviceMotorVoltageSet(device: V5_DeviceT, voltage: i32),
114    0x360 => pub fn vexDeviceMotorVoltageGet(device: V5_DeviceT) -> i32,
115    0x364 => pub fn vexDeviceMotorGearingSet(device: V5_DeviceT, gearset: V5MotorGearset),
116    0x368 => pub fn vexDeviceMotorGearingGet(device: V5_DeviceT) -> V5MotorGearset,
117    0x36c => pub fn vexDeviceMotorVoltageLimitSet(device: V5_DeviceT, limit: i32),
118    0x370 => pub fn vexDeviceMotorVoltageLimitGet(device: V5_DeviceT) -> i32,
119    0x374 => pub fn vexDeviceMotorVelocityUpdate(device: V5_DeviceT, velocity: i32),
120    0x378 => pub fn vexDeviceMotorPositionPidSet(device: V5_DeviceT, pid: *mut V5_DeviceMotorPid),
121    0x37c => pub fn vexDeviceMotorVelocityPidSet(device: V5_DeviceT, pid: *mut V5_DeviceMotorPid),
122    0x380 => pub fn vexDeviceMotorExternalProfileSet(
123        device: V5_DeviceT,
124        position: c_double,
125        velocity: i32,
126    ),
127}