Skip to content

Commit a677f67

Browse files
committed
pbio/servo_settings: Move friction torque reduction.
The friction torque value was previously reduced because friction compensation caused too much overshoot. But the model isn't the right place to do this. This restores the original values and moves the factor 2 reduction to wherever the friction value is used. Now, we can decide for each case if it makes sense to keep this reduction.
1 parent f7fcde6 commit a677f67

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

lib/pbio/doc/control/motor_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def make_model(name, *, V, tau_0, tau_x, w_0, w_x, i_0, i_x, a, Lm, h, gain):
190190
.d_torque_d_voltage = {round(PRESCALE_VOLTAGE / dtau_dv.subs(model).evalf())},
191191
.d_torque_d_speed = {round(PRESCALE_SPEED / dtau_dw.subs(model).evalf())},
192192
.d_torque_d_acceleration = {round(PRESCALE_ACCELERATION / dtau_da.subs(model).evalf())},
193-
.torque_friction = {round(tau_s * c_tau / 2)},
193+
.torque_friction = {round(tau_s * c_tau)},
194194
.gain = {gain},
195195
}};"""
196196
)

lib/pbio/src/motor/servo_settings.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static const pbio_observer_model_t model_technic_s_angular = {
3030
.d_torque_d_voltage = 17203,
3131
.d_torque_d_speed = 12282,
3232
.d_torque_d_acceleration = 354592,
33-
.torque_friction = 4591,
33+
.torque_friction = 9182,
3434
.gain = 500,
3535
};
3636

@@ -51,7 +51,7 @@ static const pbio_observer_model_t model_technic_m_angular = {
5151
.d_torque_d_voltage = 8071,
5252
.d_torque_d_speed = 5903,
5353
.d_torque_d_acceleration = 163151,
54-
.torque_friction = 10707,
54+
.torque_friction = 21413,
5555
.gain = 2000,
5656
};
5757

@@ -72,7 +72,7 @@ static const pbio_observer_model_t model_technic_l_angular = {
7272
.d_torque_d_voltage = 2872,
7373
.d_torque_d_speed = 1919,
7474
.d_torque_d_acceleration = 40344,
75-
.torque_friction = 11620,
75+
.torque_friction = 23239,
7676
.gain = 4000,
7777
};
7878

@@ -93,7 +93,7 @@ static const pbio_observer_model_t model_interactive = {
9393
.d_torque_d_voltage = 11923,
9494
.d_torque_d_speed = 10599,
9595
.d_torque_d_acceleration = 207820,
96-
.torque_friction = 5613,
96+
.torque_friction = 11227,
9797
.gain = 2000,
9898
};
9999

@@ -114,7 +114,7 @@ static const pbio_observer_model_t model_technic_l = {
114114
.d_torque_d_voltage = 6110,
115115
.d_torque_d_speed = 6837,
116116
.d_torque_d_acceleration = 108520,
117-
.torque_friction = 13215,
117+
.torque_friction = 26430,
118118
.gain = 1500,
119119
};
120120

@@ -135,7 +135,7 @@ static const pbio_observer_model_t model_technic_xl = {
135135
.d_torque_d_voltage = 6908,
136136
.d_torque_d_speed = 7713,
137137
.d_torque_d_acceleration = 116867,
138-
.torque_friction = 6446,
138+
.torque_friction = 12893,
139139
.gain = 2000,
140140
};
141141

@@ -158,7 +158,7 @@ static const pbio_observer_model_t model_movehub = {
158158
.d_torque_d_voltage = 8438,
159159
.d_torque_d_speed = 10851,
160160
.d_torque_d_acceleration = 155017,
161-
.torque_friction = 12417,
161+
.torque_friction = 24835,
162162
.gain = 2000,
163163
};
164164

@@ -185,7 +185,7 @@ static const pbio_observer_model_t model_ev3_l = {
185185
.d_torque_d_voltage = 3587,
186186
.d_torque_d_speed = 2083,
187187
.d_torque_d_acceleration = 19838,
188-
.torque_friction = 8238,
188+
.torque_friction = 16476,
189189
.gain = 4000,
190190
};
191191

@@ -206,7 +206,7 @@ static const pbio_observer_model_t model_ev3_m = {
206206
.d_torque_d_voltage = 8051,
207207
.d_torque_d_speed = 7365,
208208
.d_torque_d_acceleration = 94428,
209-
.torque_friction = 9159,
209+
.torque_friction = 18317,
210210
.gain = 2000,
211211
};
212212

lib/pbio/src/observer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void update_stall_state(pbio_observer_t *obs, uint32_t time, pbio_dcmotor
9292
// fully stuck (where applied voltage equals feedback).
9393
-feedback_voltage > (voltage * 3) / 4 &&
9494
// Feedback voltage is nonnegligible, i.e. larger than friction torque.
95-
voltage > 5 * pbio_observer_torque_to_voltage(obs->model, obs->model->torque_friction)
95+
voltage > 5 * pbio_observer_torque_to_voltage(obs->model, obs->model->torque_friction / 2)
9696
) {
9797
// If this is the rising edge of the stall flag, reset start time.
9898
if (!obs->stalled) {
@@ -157,7 +157,7 @@ void pbio_observer_update(pbio_observer_t *obs, uint32_t time, const pbio_angle_
157157
voltage += feedback_voltage;
158158

159159
// The only modeled torque is a static friction torque.
160-
int32_t torque = obs->speed > 0 ? m->torque_friction: -m->torque_friction;
160+
int32_t torque = obs->speed > 0 ? m->torque_friction / 2: -m->torque_friction / 2;
161161

162162
// Get next state based on current state and input: x(k+1) = Ax(k) + Bu(k)
163163
pbio_angle_add_mdeg(&obs->angle,
@@ -207,7 +207,7 @@ bool pbio_observer_is_stalled(const pbio_observer_t *obs, uint32_t time, uint32_
207207

208208
int32_t pbio_observer_get_feedforward_torque(const pbio_observer_model_t *model, int32_t rate_ref, int32_t acceleration_ref) {
209209

210-
int32_t friction_compensation_torque = model->torque_friction * pbio_int_math_sign(rate_ref);
210+
int32_t friction_compensation_torque = model->torque_friction / 2 * pbio_int_math_sign(rate_ref);
211211
int32_t back_emf_compensation_torque = PRESCALE_SPEED * pbio_int_math_clamp(rate_ref, MAX_NUM_SPEED) / model->d_torque_d_speed;
212212
int32_t acceleration_torque = PRESCALE_ACCELERATION * pbio_int_math_clamp(acceleration_ref, MAX_NUM_ACCELERATION) / model->d_torque_d_acceleration;
213213

0 commit comments

Comments
 (0)