Skip to content

Commit cdc5817

Browse files
author
Steve Nguyen
committed
add conversions
1 parent be2bd87 commit cdc5817

File tree

3 files changed

+102
-7
lines changed

3 files changed

+102
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/pollen-robotics/rustypot"
1010
readme = "README.md"
1111
keywords = ["robotics", "dynamixel"]
1212
categories = ["science::robotics"]
13-
#autoexamples = false #disable auto discovery of examples
13+
autoexamples = false #disable auto discovery of examples
1414

1515

1616
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/device/xl330.rs

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ reg_read_write!(max_voltage_limit, 32, u16);
2121
reg_read_write!(min_voltage_limit, 34, u16);
2222
reg_read_write!(pwm_limit, 36, u16);
2323
reg_read_write!(current_limit, 38, u16);
24+
reg_read_write!(torque_limit, 38, u16); //Duplicate with MX name for compatibility
2425
reg_read_write!(acceleration_limit, 40, u32);
2526
reg_read_write!(velocity_limit, 44, u32);
27+
reg_read_write!(moving_speed, 44, u32); //Duplicate with MX name for compatibility
2628
reg_read_write!(max_position_limit, 48, u32);
2729
reg_read_write!(min_position_limit, 52, u32);
30+
2831
reg_read_write!(startup_configuration, 60, u8);
2932
reg_read_write!(pwm_slope, 62, u8);
3033
reg_read_write!(shutdown, 63, u8);
@@ -42,19 +45,20 @@ reg_read_write!(position_p_gain, 84, u16);
4245
reg_read_write!(feedforward_2nd_gain, 88, u16);
4346
reg_read_write!(feedforward_1st_gain, 90, u16);
4447
reg_read_write!(bus_watchdog, 98, u8);
48+
4549
reg_read_write!(goal_pwm, 100, u16);
46-
reg_read_write!(goal_current, 102, u16);
47-
reg_read_write!(goal_velocity, 104, u32);
50+
reg_read_write!(goal_current, 102, i16);
51+
reg_read_write!(goal_velocity, 104, i32);
4852
reg_read_write!(profile_acceleration, 108, u32);
4953
reg_read_write!(profile_velocity, 112, u32);
50-
reg_read_write!(goal_position, 116, u32);
54+
reg_read_write!(goal_position, 116, i32);
5155
reg_read_only!(realtime_tick, 120, u16);
5256
reg_read_only!(moving, 122, u8);
5357
reg_read_only!(moving_status, 123, u8);
5458
reg_read_only!(present_pwm, 124, u16);
55-
reg_read_only!(present_current, 126, u16);
56-
reg_read_only!(present_velocity, 128, u32);
57-
reg_read_only!(present_position, 132, u32);
59+
reg_read_only!(present_current, 126, i16);
60+
reg_read_only!(present_velocity, 128, i32);
61+
reg_read_only!(present_position, 132, i32);
5862
reg_read_only!(velocity_trajectory, 136, u32);
5963
reg_read_only!(position_trajectory, 140, u32);
6064
reg_read_only!(present_input_voltage, 144, u16);
@@ -73,3 +77,93 @@ reg_read_write!(indirect_data_3, 226, u8);
7377
reg_read_write!(indirect_data_4, 227, u8);
7478
reg_read_write!(indirect_data_5, 228, u8);
7579
reg_read_write!(indirect_data_6, 229, u8);
80+
81+
/// Unit conversion for XL330 motors (same as XM?)
82+
pub mod conv {
83+
use std::f32::consts::PI;
84+
85+
/// Dynamixel angular position to radians
86+
///
87+
/// Works in joint and multi-turn mode
88+
/// 2048->180° is the center position with 0.088 [deg/pulse]
89+
90+
pub fn dxl_pos_to_radians(pos: i32) -> f32 {
91+
(2.0 * PI * (pos as f32) / 4096.0) - PI
92+
}
93+
/// Radians to dynamixel angular position
94+
///
95+
/// Works in joint and multi-turn mode
96+
pub fn radians_to_dxl_pos(rads: f32) -> i32 {
97+
(4096.0 * (PI + rads) / (2.0 * PI)) as i32
98+
}
99+
100+
/// Dynamixel velocity in rpm
101+
///
102+
/// Works for present_velocity instance
103+
pub fn dxl_vel_to_rpm(vel: i32) -> f32 {
104+
vel as f32 * 0.229
105+
}
106+
/// Velocity (rpm) to dynamixel velocity
107+
///
108+
/// It should be in [-velocity_limit, +velocity_limit] with an absolute max at 1023 (324.267rpm)
109+
/// Works for goal_current for instance
110+
pub fn rpm_to_dxl_vel(rpm: f32) -> i32 {
111+
(rpm / 0.229) as i32
112+
}
113+
114+
/// Dynamixel current to mA
115+
///
116+
/// Works for present_current instance
117+
pub fn dxl_current_to_ma(current: i16) -> f32 {
118+
current as f32 * 2.69
119+
}
120+
/// Current (mA) to dynamixel current
121+
///
122+
/// It should be in [-current_limit, +current_limit] with an absolute max at 1193 (3209.17mA)
123+
/// Works for goal_current for instance
124+
pub fn ma_to_dxl_current(current: f32) -> i16 {
125+
(current / 2.69) as i16
126+
}
127+
128+
/// Dxl Temperature (°C)
129+
///
130+
/// read_current_temperature
131+
pub fn dxl_to_temperature(temp: u8) -> f32 {
132+
temp as f32
133+
}
134+
135+
/// Temperature (°C) to dxl
136+
///
137+
/// write_temperature_limit
138+
pub fn temperature_to_dxl(temp: f32) -> u8 {
139+
temp as u8
140+
}
141+
142+
/// Dynamixel pwm to %
143+
///
144+
/// Works for present_pwm
145+
pub fn dxl_pwm_to_percentage(pwm: u16) -> f32 {
146+
pwm as f32 * 0.113
147+
}
148+
149+
/// PWM (%) to dynamixel pwm
150+
///
151+
/// Works for pwm_limit
152+
pub fn percentage_to_dxl_pwm(pwm: f32) -> u16 {
153+
(pwm / 0.113) as u16
154+
}
155+
156+
/// Dynamixel voltage to V
157+
///
158+
/// Works for present_voltage
159+
pub fn dxl_to_volt(volt: u16) -> f32 {
160+
volt as f32 * 0.1
161+
}
162+
163+
/// V to dynamixel voltage
164+
///
165+
/// Works for voltage_limit
166+
pub fn volt_to_dxl(volt: f32) -> u16 {
167+
(volt / 0.1) as u16
168+
}
169+
}

src/device/xm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ reg_read_write!(max_position_limit, 48, u32);
3030
reg_read_write!(min_position_limit, 52, u32);
3131

3232
reg_read_write!(shutdown, 63, u8);
33+
3334
reg_read_write!(torque_enable, 64, u8);
3435
reg_read_write!(led, 65, u8);
3536
reg_read_write!(status_return_level, 68, u8);

0 commit comments

Comments
 (0)