1pub const DEFAULT_BAUDRATE: u32 = 1_000_000;
4pub const LATENCY_TIMER: f64 = 50.0;
5
6pub const TXPACKET_MAX_LEN: usize = 250;
7pub const RXPACKET_MAX_LEN: usize = 250;
8
9pub const MIN_POSITION: u16 = 0;
10pub const MAX_POSITION: u16 = 4095;
11
12pub const MAX_SPEED: u16 = 3400;
13pub const MAX_CORRECTION: u16 = 2047;
14
15pub const PKT_HEADER_0: usize = 0;
17pub const PKT_HEADER_1: usize = 1;
18pub const PKT_ID: usize = 2;
19pub const PKT_LENGTH: usize = 3;
20pub const PKT_INSTRUCTION: usize = 4;
21pub const PKT_ERROR: usize = 4;
22pub const PKT_PARAMETER0: usize = 5;
23
24pub const ERRBIT_VOLTAGE: u8 = 1;
26pub const ERRBIT_ANGLE: u8 = 2;
27pub const ERRBIT_OVERHEAT: u8 = 4;
28pub const ERRBIT_OVERELE: u8 = 8;
29pub const ERRBIT_OVERLOAD: u8 = 32;
30
31pub const BROADCAST_ID: u8 = 0xFE; pub const MAX_ID: u8 = 0xFC; pub const STS_END: u8 = 0;
34
35pub const INST_PING: u8 = 1;
37pub const INST_READ: u8 = 2;
38pub const INST_WRITE: u8 = 3;
39pub const INST_REG_WRITE: u8 = 4;
40pub const INST_ACTION: u8 = 5;
41pub const INST_SYNC_WRITE: u8 = 131; pub const INST_SYNC_READ: u8 = 130; #[derive(Debug, Clone, Copy, PartialEq, Eq)]
46pub enum CommResult {
47 Success = 0,
48 PortBusy = -1,
49 TxFail = -2,
50 RxFail = -3,
51 TxError = -4,
52 RxWaiting = -5,
53 RxTimeout = -6,
54 RxCorrupt = -7,
55 NotAvailable = -9,
56}
57
58impl CommResult {
59 pub fn is_success(&self) -> bool {
60 matches!(self, CommResult::Success)
61 }
62
63 pub fn as_i32(&self) -> i32 {
64 *self as i32
65 }
66}
67
68#[allow(dead_code)]
70pub const STS_1M: u8 = 0;
71#[allow(dead_code)]
72pub const STS_0_5M: u8 = 1;
73#[allow(dead_code)]
74pub const STS_250K: u8 = 2;
75#[allow(dead_code)]
76pub const STS_128K: u8 = 3;
77#[allow(dead_code)]
78pub const STS_115200: u8 = 4;
79#[allow(dead_code)]
80pub const STS_76800: u8 = 5;
81#[allow(dead_code)]
82pub const STS_57600: u8 = 6;
83#[allow(dead_code)]
84pub const STS_38400: u8 = 7;
85
86pub const STS_MODEL_L: u8 = 3;
88pub const STS_MODEL_H: u8 = 4;
89
90pub const STS_ID: u8 = 5;
92pub const STS_BAUD_RATE: u8 = 6;
93pub const STS_MIN_ANGLE_LIMIT_L: u8 = 9;
94pub const STS_MIN_ANGLE_LIMIT_H: u8 = 10;
95pub const STS_MAX_ANGLE_LIMIT_L: u8 = 11;
96pub const STS_MAX_ANGLE_LIMIT_H: u8 = 12;
97pub const STS_CW_DEAD: u8 = 26;
98pub const STS_CCW_DEAD: u8 = 27;
99pub const STS_OFS_L: u8 = 31;
100pub const STS_OFS_H: u8 = 32;
101pub const STS_MODE: u8 = 33;
102
103pub const STS_TORQUE_ENABLE: u8 = 40;
105pub const STS_ACC: u8 = 41;
106pub const STS_GOAL_POSITION_L: u8 = 42;
107pub const STS_GOAL_POSITION_H: u8 = 43;
108pub const STS_GOAL_TIME_L: u8 = 44;
109pub const STS_GOAL_TIME_H: u8 = 45;
110pub const STS_GOAL_SPEED_L: u8 = 46;
111pub const STS_GOAL_SPEED_H: u8 = 47;
112pub const STS_LOCK: u8 = 55;
113
114pub const STS_PRESENT_POSITION_L: u8 = 56;
116pub const STS_PRESENT_POSITION_H: u8 = 57;
117pub const STS_PRESENT_SPEED_L: u8 = 58;
118pub const STS_PRESENT_SPEED_H: u8 = 59;
119pub const STS_PRESENT_LOAD_L: u8 = 60;
120pub const STS_PRESENT_LOAD_H: u8 = 61;
121pub const STS_PRESENT_VOLTAGE: u8 = 62;
122pub const STS_PRESENT_TEMPERATURE: u8 = 63;
123pub const STS_STATUS: u8 = 65;
124pub const STS_MOVING: u8 = 66;
125pub const STS_PRESENT_CURRENT_L: u8 = 69;
126pub const STS_PRESENT_CURRENT_H: u8 = 70;