40 {
"X5_1", GEAR_RATIO_X5_1},
41 {
"X5_4", GEAR_RATIO_X5_4},
42 {
"X5_9", GEAR_RATIO_X5_9},
43 {
"X8_3", GEAR_RATIO_X8_3},
44 {
"X8_9", GEAR_RATIO_X8_9},
45 {
"X8_16", GEAR_RATIO_X8_16}};
53 std::shared_ptr<HebirosGazeboJoint> hebiros_joint) {
55 hebiros_group->settings.name.push_back(hebiros_joint->name);
57 int i = hebiros_joint->command_index;
61 hebiros_joint->gear_ratio =
gear_ratios[hebiros_joint->model_name];
68 hebiros_group->settings.control_strategy.push_back(
71 SetDefaultGains(hebiros_group, hebiros_joint);
76 std::shared_ptr<HebirosGazeboJoint> hebiros_joint) {
78 std::string model_name = hebiros_joint->model_name;
79 int i = hebiros_joint->command_index;
80 int control_strategy = hebiros_group->settings.control_strategy[i];
82 if (model_name ==
"X5_1" && control_strategy == 2) {
83 hebiros_group->settings.position_gains.kp.push_back(5);
84 hebiros_group->settings.position_gains.ki.push_back(0);
85 hebiros_group->settings.position_gains.kd.push_back(0);
86 hebiros_group->settings.velocity_gains.kp.push_back(0.1);
87 hebiros_group->settings.velocity_gains.ki.push_back(0);
88 hebiros_group->settings.velocity_gains.kd.push_back(0);
89 hebiros_group->settings.effort_gains.kp.push_back(0.25);
90 hebiros_group->settings.effort_gains.ki.push_back(0);
91 hebiros_group->settings.effort_gains.kd.push_back(0.001);
93 else if (model_name ==
"X5_1" && control_strategy == 3) {
94 hebiros_group->settings.position_gains.kp.push_back(0.5);
95 hebiros_group->settings.position_gains.ki.push_back(0);
96 hebiros_group->settings.position_gains.kd.push_back(0);
97 hebiros_group->settings.velocity_gains.kp.push_back(0.05);
98 hebiros_group->settings.velocity_gains.ki.push_back(0);
99 hebiros_group->settings.velocity_gains.kd.push_back(0);
100 hebiros_group->settings.effort_gains.kp.push_back(0.25);
101 hebiros_group->settings.effort_gains.ki.push_back(0);
102 hebiros_group->settings.effort_gains.kd.push_back(0.001);
104 else if (model_name ==
"X5_1" && control_strategy == 4) {
105 hebiros_group->settings.position_gains.kp.push_back(5);
106 hebiros_group->settings.position_gains.ki.push_back(0);
107 hebiros_group->settings.position_gains.kd.push_back(0);
108 hebiros_group->settings.velocity_gains.kp.push_back(0.05);
109 hebiros_group->settings.velocity_gains.ki.push_back(0);
110 hebiros_group->settings.velocity_gains.kd.push_back(0);
111 hebiros_group->settings.effort_gains.kp.push_back(0.25);
112 hebiros_group->settings.effort_gains.ki.push_back(0);
113 hebiros_group->settings.effort_gains.kd.push_back(0.001);
115 else if (model_name ==
"X5_4" && control_strategy == 2) {
116 hebiros_group->settings.position_gains.kp.push_back(10);
117 hebiros_group->settings.position_gains.ki.push_back(0);
118 hebiros_group->settings.position_gains.kd.push_back(0);
119 hebiros_group->settings.velocity_gains.kp.push_back(0.2);
120 hebiros_group->settings.velocity_gains.ki.push_back(0);
121 hebiros_group->settings.velocity_gains.kd.push_back(0);
122 hebiros_group->settings.effort_gains.kp.push_back(0.25);
123 hebiros_group->settings.effort_gains.ki.push_back(0);
124 hebiros_group->settings.effort_gains.kd.push_back(0.001);
126 else if (model_name ==
"X5_4" && control_strategy == 3) {
127 hebiros_group->settings.position_gains.kp.push_back(1);
128 hebiros_group->settings.position_gains.ki.push_back(0);
129 hebiros_group->settings.position_gains.kd.push_back(0);
130 hebiros_group->settings.velocity_gains.kp.push_back(0.05);
131 hebiros_group->settings.velocity_gains.ki.push_back(0);
132 hebiros_group->settings.velocity_gains.kd.push_back(0);
133 hebiros_group->settings.effort_gains.kp.push_back(0.25);
134 hebiros_group->settings.effort_gains.ki.push_back(0);
135 hebiros_group->settings.effort_gains.kd.push_back(0.001);
137 else if (model_name ==
"X5_4" && control_strategy == 4) {
138 hebiros_group->settings.position_gains.kp.push_back(10);
139 hebiros_group->settings.position_gains.ki.push_back(0);
140 hebiros_group->settings.position_gains.kd.push_back(0);
141 hebiros_group->settings.velocity_gains.kp.push_back(0.05);
142 hebiros_group->settings.velocity_gains.ki.push_back(0);
143 hebiros_group->settings.velocity_gains.kd.push_back(0);
144 hebiros_group->settings.effort_gains.kp.push_back(0.25);
145 hebiros_group->settings.effort_gains.ki.push_back(0);
146 hebiros_group->settings.effort_gains.kd.push_back(0.001);
148 else if (model_name ==
"X5_9" && control_strategy == 2) {
149 hebiros_group->settings.position_gains.kp.push_back(15);
150 hebiros_group->settings.position_gains.ki.push_back(0);
151 hebiros_group->settings.position_gains.kd.push_back(0);
152 hebiros_group->settings.velocity_gains.kp.push_back(0.5);
153 hebiros_group->settings.velocity_gains.ki.push_back(0);
154 hebiros_group->settings.velocity_gains.kd.push_back(0);
155 hebiros_group->settings.effort_gains.kp.push_back(0.25);
156 hebiros_group->settings.effort_gains.ki.push_back(0);
157 hebiros_group->settings.effort_gains.kd.push_back(0.001);
159 else if (model_name ==
"X5_9" && control_strategy == 3) {
160 hebiros_group->settings.position_gains.kp.push_back(1.5);
161 hebiros_group->settings.position_gains.ki.push_back(0);
162 hebiros_group->settings.position_gains.kd.push_back(0);
163 hebiros_group->settings.velocity_gains.kp.push_back(0.05);
164 hebiros_group->settings.velocity_gains.ki.push_back(0);
165 hebiros_group->settings.velocity_gains.kd.push_back(0);
166 hebiros_group->settings.effort_gains.kp.push_back(0.25);
167 hebiros_group->settings.effort_gains.ki.push_back(0);
168 hebiros_group->settings.effort_gains.kd.push_back(0.001);
170 else if (model_name ==
"X5_9" && control_strategy == 4) {
171 hebiros_group->settings.position_gains.kp.push_back(15);
172 hebiros_group->settings.position_gains.ki.push_back(0);
173 hebiros_group->settings.position_gains.kd.push_back(0);
174 hebiros_group->settings.velocity_gains.kp.push_back(0.05);
175 hebiros_group->settings.velocity_gains.ki.push_back(0);
176 hebiros_group->settings.velocity_gains.kd.push_back(0);
177 hebiros_group->settings.effort_gains.kp.push_back(0.25);
178 hebiros_group->settings.effort_gains.ki.push_back(0);
179 hebiros_group->settings.effort_gains.kd.push_back(0.001);
181 if (model_name ==
"X8_3" && control_strategy == 2) {
182 hebiros_group->settings.position_gains.kp.push_back(3);
183 hebiros_group->settings.position_gains.ki.push_back(0);
184 hebiros_group->settings.position_gains.kd.push_back(0);
185 hebiros_group->settings.velocity_gains.kp.push_back(0.1);
186 hebiros_group->settings.velocity_gains.ki.push_back(0);
187 hebiros_group->settings.velocity_gains.kd.push_back(0);
188 hebiros_group->settings.effort_gains.kp.push_back(0.1);
189 hebiros_group->settings.effort_gains.ki.push_back(0);
190 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
192 else if (model_name ==
"X8_3" && control_strategy == 3) {
193 hebiros_group->settings.position_gains.kp.push_back(1);
194 hebiros_group->settings.position_gains.ki.push_back(0);
195 hebiros_group->settings.position_gains.kd.push_back(0);
196 hebiros_group->settings.velocity_gains.kp.push_back(0.03);
197 hebiros_group->settings.velocity_gains.ki.push_back(0);
198 hebiros_group->settings.velocity_gains.kd.push_back(0);
199 hebiros_group->settings.effort_gains.kp.push_back(0.1);
200 hebiros_group->settings.effort_gains.ki.push_back(0);
201 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
203 else if (model_name ==
"X8_3" && control_strategy == 4) {
204 hebiros_group->settings.position_gains.kp.push_back(3);
205 hebiros_group->settings.position_gains.ki.push_back(0);
206 hebiros_group->settings.position_gains.kd.push_back(0);
207 hebiros_group->settings.velocity_gains.kp.push_back(0.03);
208 hebiros_group->settings.velocity_gains.ki.push_back(0);
209 hebiros_group->settings.velocity_gains.kd.push_back(0);
210 hebiros_group->settings.effort_gains.kp.push_back(0.1);
211 hebiros_group->settings.effort_gains.ki.push_back(0);
212 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
214 else if (model_name ==
"X8_9" && control_strategy == 2) {
215 hebiros_group->settings.position_gains.kp.push_back(5);
216 hebiros_group->settings.position_gains.ki.push_back(0);
217 hebiros_group->settings.position_gains.kd.push_back(0);
218 hebiros_group->settings.velocity_gains.kp.push_back(0.1);
219 hebiros_group->settings.velocity_gains.ki.push_back(0);
220 hebiros_group->settings.velocity_gains.kd.push_back(0);
221 hebiros_group->settings.effort_gains.kp.push_back(0.1);
222 hebiros_group->settings.effort_gains.ki.push_back(0);
223 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
225 else if (model_name ==
"X8_9" && control_strategy == 3) {
226 hebiros_group->settings.position_gains.kp.push_back(2);
227 hebiros_group->settings.position_gains.ki.push_back(0);
228 hebiros_group->settings.position_gains.kd.push_back(0);
229 hebiros_group->settings.velocity_gains.kp.push_back(0.03);
230 hebiros_group->settings.velocity_gains.ki.push_back(0);
231 hebiros_group->settings.velocity_gains.kd.push_back(0);
232 hebiros_group->settings.effort_gains.kp.push_back(0.1);
233 hebiros_group->settings.effort_gains.ki.push_back(0);
234 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
236 else if (model_name ==
"X8_9" && control_strategy == 4) {
237 hebiros_group->settings.position_gains.kp.push_back(5);
238 hebiros_group->settings.position_gains.ki.push_back(0);
239 hebiros_group->settings.position_gains.kd.push_back(0);
240 hebiros_group->settings.velocity_gains.kp.push_back(0.03);
241 hebiros_group->settings.velocity_gains.ki.push_back(0);
242 hebiros_group->settings.velocity_gains.kd.push_back(0);
243 hebiros_group->settings.effort_gains.kp.push_back(0.1);
244 hebiros_group->settings.effort_gains.ki.push_back(0);
245 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
247 else if (model_name ==
"X8_16" && control_strategy == 2) {
248 hebiros_group->settings.position_gains.kp.push_back(5);
249 hebiros_group->settings.position_gains.ki.push_back(0);
250 hebiros_group->settings.position_gains.kd.push_back(0);
251 hebiros_group->settings.velocity_gains.kp.push_back(0.1);
252 hebiros_group->settings.velocity_gains.ki.push_back(0);
253 hebiros_group->settings.velocity_gains.kd.push_back(0);
254 hebiros_group->settings.effort_gains.kp.push_back(0.1);
255 hebiros_group->settings.effort_gains.ki.push_back(0);
256 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
258 else if (model_name ==
"X8_16" && control_strategy == 3) {
259 hebiros_group->settings.position_gains.kp.push_back(3);
260 hebiros_group->settings.position_gains.ki.push_back(0);
261 hebiros_group->settings.position_gains.kd.push_back(0);
262 hebiros_group->settings.velocity_gains.kp.push_back(0.03);
263 hebiros_group->settings.velocity_gains.ki.push_back(0);
264 hebiros_group->settings.velocity_gains.kd.push_back(0);
265 hebiros_group->settings.effort_gains.kp.push_back(0.1);
266 hebiros_group->settings.effort_gains.ki.push_back(0);
267 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
269 else if (model_name ==
"X8_16" && control_strategy == 4) {
270 hebiros_group->settings.position_gains.kp.push_back(5);
271 hebiros_group->settings.position_gains.ki.push_back(0);
272 hebiros_group->settings.position_gains.kd.push_back(0);
273 hebiros_group->settings.velocity_gains.kp.push_back(0.03);
274 hebiros_group->settings.velocity_gains.ki.push_back(0);
275 hebiros_group->settings.velocity_gains.kd.push_back(0);
276 hebiros_group->settings.effort_gains.kp.push_back(0.1);
277 hebiros_group->settings.effort_gains.ki.push_back(0);
278 hebiros_group->settings.effort_gains.kd.push_back(0.0001);
295 std::shared_ptr<HebirosGazeboJoint> hebiros_joint) {
297 CommandMsg target = hebiros_group->command_target;
298 int i = hebiros_joint->command_index;
301 if (i < target.settings.name.size()) {
302 hebiros_group->settings.name[i] = target.settings.name[i];
306 if (i < target.settings.control_strategy.size()) {
307 hebiros_group->settings.control_strategy[i] = target.settings.control_strategy[i];
311 if (i < target.settings.position_gains.kp.size()) {
312 hebiros_group->settings.position_gains.kp[i] = target.settings.position_gains.kp[i];
314 if (i < target.settings.position_gains.ki.size()) {
315 hebiros_group->settings.position_gains.ki[i] = target.settings.position_gains.ki[i];
317 if (i < target.settings.position_gains.kd.size()) {
318 hebiros_group->settings.position_gains.kd[i] = target.settings.position_gains.kd[i];
322 if (i < target.settings.velocity_gains.kp.size()) {
323 hebiros_group->settings.velocity_gains.kp[i] = target.settings.velocity_gains.kp[i];
325 if (i < target.settings.velocity_gains.ki.size()) {
326 hebiros_group->settings.velocity_gains.ki[i] = target.settings.velocity_gains.ki[i];
328 if (i < target.settings.velocity_gains.kd.size()) {
329 hebiros_group->settings.velocity_gains.kd[i] = target.settings.velocity_gains.kd[i];
333 if (i < target.settings.effort_gains.kp.size()) {
334 hebiros_group->settings.effort_gains.kp[i] = target.settings.effort_gains.kp[i];
336 if (i < target.settings.effort_gains.ki.size()) {
337 hebiros_group->settings.effort_gains.ki[i] = target.settings.effort_gains.ki[i];
339 if (i < target.settings.effort_gains.kd.size()) {
340 hebiros_group->settings.effort_gains.kd[i] = target.settings.effort_gains.kd[i];
346 std::shared_ptr<HebirosGazeboJoint> hebiros_joint,
347 double position,
double velocity,
double effort,
const ros::Duration& iteration_time) {
349 CommandMsg target = hebiros_group->command_target;
350 int i = hebiros_joint->command_index;
352 double target_position, target_velocity, target_effort;
353 double position_pid, velocity_pid, effort_pid;
354 double position_pwm, velocity_pwm, effort_pwm;
355 double intermediate_effort;
356 double gear_ratio, pwm, force, alpha;
359 if (i < target.position.size()) {
360 target_position = target.position[i];
363 target_position = position;
365 if (i < target.velocity.size()) {
366 target_velocity = target.velocity[i];
369 target_velocity = velocity;
371 if (i < target.effort.size()) {
372 target_effort = target.effort[i];
375 target_effort = effort;
379 int control_strategy = hebiros_group->settings.control_strategy[i];
380 switch (control_strategy) {
391 ComputePositionPID(hebiros_group, hebiros_joint, target_position, position, iteration_time);
393 ComputeVelocityPID(hebiros_group, hebiros_joint, target_velocity, velocity, iteration_time);
394 intermediate_effort = target_effort + position_pid + velocity_pid;
396 ComputeEffortPID(hebiros_group, hebiros_joint, intermediate_effort, effort, iteration_time),
403 ComputePositionPID(hebiros_group, hebiros_joint, target_position, position, iteration_time),
406 ComputeVelocityPID(hebiros_group, hebiros_joint, target_velocity, velocity, iteration_time),
409 ComputeEffortPID(hebiros_group, hebiros_joint, target_effort, effort, iteration_time),
411 pwm = Clip(position_pwm + velocity_pwm + effort_pwm,
MIN_PWM,
MAX_PWM);
416 ComputePositionPID(hebiros_group, hebiros_joint, target_position, position, iteration_time);
417 intermediate_effort = target_effort + position_pid;
419 ComputeEffortPID(hebiros_group, hebiros_joint, intermediate_effort, effort, iteration_time),
422 ComputeVelocityPID(hebiros_group, hebiros_joint, target_velocity, velocity, iteration_time),
431 gear_ratio = hebiros_joint->gear_ratio;
433 float voltage = 48.0f;
434 float motor_velocity = velocity * gear_ratio;
435 float speed_constant = 1530.0f;
436 float term_resist = 9.99f;
437 if (hebiros_joint->isX8()) {
438 speed_constant = 1360.0f;
442 pwm = hebiros_joint->temperature_safety.limit(pwm);
449 force = ((pwm*voltage - (motor_velocity/speed_constant)) / term_resist) * 0.00626 * gear_ratio * 0.65;
452 float prev_winding_temp = hebiros_joint->temperature.getMotorWindingTemperature();
457 float comp_speed_constant = speed_constant * 1.05f *
458 (1.f + .001f * (prev_winding_temp - 20.f));
459 float winding_resistance = term_resist *
460 (1.f + .004f * (prev_winding_temp - 20.f));
461 float back_emf = (motor_velocity * 30.f /
M_PI) / comp_speed_constant;
462 float winding_voltage = pwm * voltage - back_emf;
468 double power_in = winding_voltage * winding_voltage / winding_resistance;
469 hebiros_joint->temperature.update(power_in, iteration_time.
toSec());
470 hebiros_joint->temperature_safety.update(hebiros_joint->temperature.getMotorWindingTemperature());
481 std::shared_ptr<HebirosGazeboJoint> hebiros_joint,
482 double target_position,
double position,
const ros::Duration& iteration_time) {
484 double position_error_p, position_error_i, position_error_d;
486 position_error_p = target_position - position;
487 position_error_i = hebiros_joint->position_elapsed_error + position_error_p;
488 position_error_d = (position_error_p - hebiros_joint->position_prev_error) /
489 iteration_time.
toSec();
490 hebiros_joint->position_prev_error = position_error_p;
491 hebiros_joint->position_elapsed_error = position_error_i;
493 if (iteration_time.
toSec() <= 0) {
494 position_error_d = 0;
497 int i = hebiros_joint->command_index;
499 return (hebiros_group->settings.position_gains.kp[i] * position_error_p) +
500 (hebiros_group->settings.position_gains.ki[i] * position_error_i) +
501 (hebiros_group->settings.position_gains.kd[i] * position_error_d);
506 std::shared_ptr<HebirosGazeboJoint> hebiros_joint,
507 double target_velocity,
double velocity,
const ros::Duration& iteration_time) {
509 double velocity_error_p, velocity_error_i, velocity_error_d;
511 velocity_error_p = target_velocity - velocity;
512 velocity_error_i = hebiros_joint->velocity_elapsed_error + velocity_error_p;
513 velocity_error_d = (velocity_error_p - hebiros_joint->velocity_prev_error) /
514 iteration_time.
toSec();
515 hebiros_joint->velocity_prev_error = velocity_error_p;
516 hebiros_joint->velocity_elapsed_error = velocity_error_i;
518 if (iteration_time.
toSec() <= 0) {
519 velocity_error_d = 0;
522 int i = hebiros_joint->command_index;
524 return (hebiros_group->settings.velocity_gains.kp[i] * velocity_error_p) +
525 (hebiros_group->settings.velocity_gains.ki[i] * velocity_error_i) +
526 (hebiros_group->settings.velocity_gains.kd[i] * velocity_error_d);
531 std::shared_ptr<HebirosGazeboJoint> hebiros_joint,
532 double target_effort,
double effort,
const ros::Duration& iteration_time) {
534 double effort_error_p, effort_error_i, effort_error_d;
536 effort_error_p = target_effort - effort;
537 effort_error_i = hebiros_joint->effort_elapsed_error + effort_error_p;
538 effort_error_d = (effort_error_p - hebiros_joint->effort_prev_error) /
539 iteration_time.
toSec();
540 hebiros_joint->effort_prev_error = effort_error_p;
541 hebiros_joint->effort_elapsed_error = effort_error_i;
543 if (iteration_time.
toSec() <= 0) {
547 int i = hebiros_joint->command_index;
549 return (hebiros_group->settings.effort_gains.kp[i] * effort_error_p) +
550 (hebiros_group->settings.effort_gains.ki[i] * effort_error_i) +
551 (hebiros_group->settings.effort_gains.kd[i] * effort_error_d);
556 return std::min(std::max(x, low), high);
static constexpr double DEFAULT_POSITION_KD
static constexpr double DEFAULT_POSITION_KP
static constexpr control_strategies DEFAULT_CONTROL_STRATEGY
static void SetDefaultGains(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint)
static constexpr double DEFAULT_GEAR_RATIO
static constexpr double DEFAULT_EFFORT_KP
static constexpr double DEFAULT_EFFORT_KD
static double ComputeVelocityPID(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint, double target_velocity, double velocity, const ros::Duration &iteration_time)
static double ComputePositionPID(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint, double target_position, double position, const ros::Duration &iteration_time)
static void SetSettings(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint)
static constexpr double GEAR_RATIO_X5_1
static constexpr double MAX_PWM
static constexpr double GEAR_RATIO_X8_16
static constexpr double GEAR_RATIO_X8_3
static constexpr double DEFAULT_POSITION_KI
static constexpr double GEAR_RATIO_X5_4
static constexpr double GEAR_RATIO_X8_9
static constexpr double DEFAULT_VELOCITY_KI
static void ChangeSettings(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint)
static constexpr double MIN_PWM
static double ComputeEffortPID(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint, double target_effort, double effort, const ros::Duration &iteration_time)
static constexpr double DEFAULT_VELOCITY_KP
static constexpr double DEFAULT_EFFORT_KI
static constexpr double GEAR_RATIO_X5_9
static double Clip(double x, double low, double high)
static std::map< std::string, double > gear_ratios
static double ComputeForce(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint, double position, double velocity, double effort, const ros::Duration &iteration_time)
static constexpr double LOW_PASS_ALPHA
static constexpr double DEFAULT_VELOCITY_KD