Skip to content

Commit 4277938

Browse files
committed
pbio/servo: Add hook for device overrides.
Remove hardcoded EV3 value and replace with generic hook for any device that does not generalize entirely from the minimized settings. Also update medium motor model to account for a bit more friction.
1 parent 3332011 commit 4277938

4 files changed

Lines changed: 47 additions & 28 deletions

File tree

lib/pbio/doc/control/motor_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ def rpm_to_rad_s(rpm):
185185
i_x=0.37,
186186
w_x=rpm_to_rad_s(165),
187187
tau_0=0,
188-
i_0=0.08,
188+
i_0=0.1,
189189
w_0=rpm_to_rad_s(260),
190190
a=math.radians(2000 / 0.1),
191-
Lm=0.0005 * 30,
191+
Lm=0.0008 * 30,
192192
h=0.01,
193193
)
194194
)

lib/pbio/include/pbio/servo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pbio_error_t pbio_servo_setup(pbio_servo_t *srv, lego_device_type_id_t type, pbi
142142
pbio_error_t pbio_servo_actuate(pbio_servo_t *srv, pbio_dcmotor_actuation_t actuation_type, int32_t payload);
143143
int32_t pbio_servo_get_max_voltage(lego_device_type_id_t id);
144144
const pbio_servo_settings_reduced_t *pbio_servo_get_reduced_settings(lego_device_type_id_t id);
145+
void pbio_servo_override_settings(pbio_control_settings_t *settings, lego_device_type_id_t id);
145146
void pbio_servo_update_all(void);
146147
/** @endcond */
147148

lib/pbio/src/motor/servo_settings.c

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,23 @@ static const pbio_observer_model_t model_ev3_l = {
186186
};
187187

188188
static const pbio_observer_model_t model_ev3_m = {
189-
.d_angle_d_speed = 90029,
190-
.d_speed_d_speed = 959,
191-
.d_current_d_speed = -185122,
192-
.d_angle_d_current = 2377978,
193-
.d_speed_d_current = 21415,
194-
.d_current_d_current = -4432336,
195-
.d_angle_d_voltage = 1996477,
196-
.d_speed_d_voltage = 8917,
197-
.d_current_d_voltage = 202362,
198-
.d_angle_d_torque = -401501,
199-
.d_speed_d_torque = -2047,
200-
.d_current_d_torque = 467397,
201-
.d_voltage_d_torque = 47722,
202-
.d_torque_d_voltage = 8051,
189+
.d_angle_d_speed = 89465,
190+
.d_speed_d_speed = 950,
191+
.d_current_d_speed = -197440,
192+
.d_angle_d_current = 1568301,
193+
.d_speed_d_current = 12886,
194+
.d_current_d_current = -5095199,
195+
.d_angle_d_voltage = 2220112,
196+
.d_speed_d_voltage = 9410,
197+
.d_current_d_voltage = 209263,
198+
.d_angle_d_torque = -399652,
199+
.d_speed_d_torque = -2034,
200+
.d_current_d_torque = 546357,
201+
.d_voltage_d_torque = 49219,
202+
.d_torque_d_voltage = 7806,
203203
.d_torque_d_speed = 7365,
204204
.d_torque_d_acceleration = 9355,
205-
.torque_friction = 18317,
205+
.torque_friction = 24593,
206206
};
207207

208208
static const pbio_observer_model_t model_nxt = {
@@ -241,17 +241,17 @@ static const pbio_servo_settings_reduced_t servo_settings_reduced[] = {
241241
.id = LEGO_DEVICE_TYPE_ID_EV3_LARGE_MOTOR,
242242
.model = &model_ev3_l,
243243
.rated_max_speed = 800,
244-
.feedback_gain_low = 45,
244+
.feedback_gain_low = 30,
245245
.precision_profile = 10,
246-
.pid_kp_low_speed_threshold = 0,
246+
.pid_kp_low_speed_threshold = 100,
247247
},
248248
{
249249
.id = LEGO_DEVICE_TYPE_ID_NXT_MOTOR,
250250
.model = &model_nxt,
251251
.rated_max_speed = 800,
252252
.feedback_gain_low = 90,
253253
.precision_profile = 5,
254-
.pid_kp_low_speed_threshold = 0,
254+
.pid_kp_low_speed_threshold = 100,
255255
},
256256
#endif // PBIO_CONFIG_SERVO_EV3_NXT
257257
#if PBIO_CONFIG_SERVO_PUP_MOVE_HUB
@@ -356,4 +356,29 @@ const pbio_servo_settings_reduced_t *pbio_servo_get_reduced_settings(lego_device
356356
return NULL;
357357
}
358358

359+
/**
360+
* Overrides device specific settings.
361+
*
362+
* The reduced settings work well enough for a range of devices, simplifing
363+
* tuning and reducing code size. This function provides a hook for devices
364+
* that still need some specific tuning.
365+
*
366+
* @param [in] settings Base settings, unpacked from minimal settings.
367+
* @param [in] id Type identifier for which to look up the settings.
368+
*/
369+
370+
void pbio_servo_override_settings(pbio_control_settings_t *settings, lego_device_type_id_t id) {
371+
#if PBIO_CONFIG_SERVO_EV3_NXT
372+
if (id == LEGO_DEVICE_TYPE_ID_EV3_MEDIUM_MOTOR) {
373+
settings->pid_kp /= 3;
374+
settings->pid_ki /= 2;
375+
settings->pid_kd /= 10;
376+
} else if (id == LEGO_DEVICE_TYPE_ID_EV3_LARGE_MOTOR || id == LEGO_DEVICE_TYPE_ID_NXT_MOTOR) {
377+
settings->pid_kp = settings->pid_kp * 2 / 3;
378+
settings->pid_ki = settings->pid_ki * 2 / 3;
379+
settings->pid_kd /= 6;
380+
}
381+
#endif
382+
}
383+
359384
#endif // PBIO_CONFIG_SERVO

lib/pbio/src/servo.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,7 @@ static pbio_error_t pbio_servo_initialize_settings(pbio_servo_t *srv, lego_devic
305305
.coulomb_friction_speed_cutoff = 500,
306306
};
307307

308-
// HACK: The general purpose minimized settings don't capture the stronger
309-
// motors very well. Generalize settings profile.
310-
#if PBIO_CONFIG_SERVO_EV3_NXT
311-
// REVISIT: Unify across all three motors since we can't have auto ID on nxt
312-
srv->control.settings.pid_kp = 50000;
313-
srv->control.settings.pid_ki = 18000;
314-
srv->control.settings.pid_kd = 2000;
315-
#endif
308+
pbio_servo_override_settings(&srv->control.settings, type);
316309

317310
return PBIO_SUCCESS;
318311
}

0 commit comments

Comments
 (0)