Skip to content

Commit 66e4e18

Browse files
committed
pbio/drivebase: Validate actuation type.
1 parent 7dcce2d commit 66e4e18

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/pbio/src/drivebase.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ static pbio_error_t pbio_drivebase_update(pbio_drivebase_t *db) {
394394
return pbio_drivebase_stop(db, PBIO_CONTROL_ON_COMPLETION_BRAKE);
395395
}
396396

397+
// The only other expected actuation type is torque, so make sure it is.
398+
if (distance_actuation != PBIO_DCMOTOR_ACTUATION_TORQUE ||
399+
heading_actuation != PBIO_DCMOTOR_ACTUATION_TORQUE) {
400+
return PBIO_ERROR_FAILED;
401+
}
402+
397403
// Both controllers are able to stop the other when it stalls. This ensures
398404
// they complete at exactly the same time.
399405
if (pbio_control_type_is_position(&db->control_distance) && !db->control_distance.position_integrator.trajectory_running) {
@@ -405,14 +411,14 @@ static pbio_error_t pbio_drivebase_update(pbio_drivebase_t *db) {
405411

406412
// The left servo drives at a torque and speed of sum + dif
407413
int32_t feed_forward_left = pbio_observer_get_feedforward_torque(db->left->observer.model, ref_distance.speed + ref_heading.speed, ref_distance.acceleration + ref_heading.acceleration);
408-
err = pbio_servo_actuate(db->left, distance_actuation, distance_torque + heading_torque + feed_forward_left);
414+
err = pbio_servo_actuate(db->left, PBIO_DCMOTOR_ACTUATION_TORQUE, distance_torque + heading_torque + feed_forward_left);
409415
if (err != PBIO_SUCCESS) {
410416
return err;
411417
}
412418

413419
// The right servo drives at a torque and speed of sum - dif
414420
int32_t feed_forward_right = pbio_observer_get_feedforward_torque(db->right->observer.model, ref_distance.speed - ref_heading.speed, ref_distance.acceleration - ref_heading.acceleration);
415-
return pbio_servo_actuate(db->right, heading_actuation, distance_torque - heading_torque + feed_forward_right);
421+
return pbio_servo_actuate(db->right, PBIO_DCMOTOR_ACTUATION_TORQUE, distance_torque - heading_torque + feed_forward_right);
416422
}
417423

418424
/**

0 commit comments

Comments
 (0)