@@ -21,10 +21,13 @@ reg_read_write!(max_voltage_limit, 32, u16);
2121reg_read_write ! ( min_voltage_limit, 34 , u16 ) ;
2222reg_read_write ! ( pwm_limit, 36 , u16 ) ;
2323reg_read_write ! ( current_limit, 38 , u16 ) ;
24+ reg_read_write ! ( torque_limit, 38 , u16 ) ; //Duplicate with MX name for compatibility
2425reg_read_write ! ( acceleration_limit, 40 , u32 ) ;
2526reg_read_write ! ( velocity_limit, 44 , u32 ) ;
27+ reg_read_write ! ( moving_speed, 44 , u32 ) ; //Duplicate with MX name for compatibility
2628reg_read_write ! ( max_position_limit, 48 , u32 ) ;
2729reg_read_write ! ( min_position_limit, 52 , u32 ) ;
30+
2831reg_read_write ! ( startup_configuration, 60 , u8 ) ;
2932reg_read_write ! ( pwm_slope, 62 , u8 ) ;
3033reg_read_write ! ( shutdown, 63 , u8 ) ;
@@ -42,19 +45,20 @@ reg_read_write!(position_p_gain, 84, u16);
4245reg_read_write ! ( feedforward_2nd_gain, 88 , u16 ) ;
4346reg_read_write ! ( feedforward_1st_gain, 90 , u16 ) ;
4447reg_read_write ! ( bus_watchdog, 98 , u8 ) ;
48+
4549reg_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 ) ;
4852reg_read_write ! ( profile_acceleration, 108 , u32 ) ;
4953reg_read_write ! ( profile_velocity, 112 , u32 ) ;
50- reg_read_write ! ( goal_position, 116 , u32 ) ;
54+ reg_read_write ! ( goal_position, 116 , i32 ) ;
5155reg_read_only ! ( realtime_tick, 120 , u16 ) ;
5256reg_read_only ! ( moving, 122 , u8 ) ;
5357reg_read_only ! ( moving_status, 123 , u8 ) ;
5458reg_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 ) ;
5862reg_read_only ! ( velocity_trajectory, 136 , u32 ) ;
5963reg_read_only ! ( position_trajectory, 140 , u32 ) ;
6064reg_read_only ! ( present_input_voltage, 144 , u16 ) ;
@@ -73,3 +77,93 @@ reg_read_write!(indirect_data_3, 226, u8);
7377reg_read_write ! ( indirect_data_4, 227 , u8 ) ;
7478reg_read_write ! ( indirect_data_5, 228 , u8 ) ;
7579reg_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+ }
0 commit comments