@@ -164,6 +164,7 @@ static void pbio_drivebase_stop_drivebase_control(pbio_drivebase_t *db) {
164164 // Stop drivebase control so polling will stop
165165 pbio_control_stop (& db -> control_distance );
166166 pbio_control_stop (& db -> control_heading );
167+ db -> control_paused = false;
167168}
168169
169170/**
@@ -291,6 +292,7 @@ pbio_error_t pbio_drivebase_get_drivebase(pbio_drivebase_t **db_address, pbio_se
291292 // Stop any existing drivebase controls
292293 pbio_control_reset (& db -> control_distance );
293294 pbio_control_reset (& db -> control_heading );
295+ db -> control_paused = false;
294296
295297 // Reset both motors to a passive state
296298 pbio_drivebase_stop_servo_control (db );
@@ -405,13 +407,18 @@ static pbio_error_t pbio_drivebase_update(pbio_drivebase_t *db) {
405407 pbio_trajectory_reference_t ref_distance ;
406408 int32_t distance_torque ;
407409 pbio_dcmotor_actuation_t distance_actuation ;
408- pbio_control_update (& db -> control_distance , time_now , & state_distance , & ref_distance , & distance_actuation , & distance_torque );
410+ bool distance_external_pause = db -> control_paused ;
411+ pbio_control_update (& db -> control_distance , time_now , & state_distance , & ref_distance , & distance_actuation , & distance_torque , & distance_external_pause );
409412
410413 // Get reference and torque signals for heading control.
411414 pbio_trajectory_reference_t ref_heading ;
412415 int32_t heading_torque ;
413416 pbio_dcmotor_actuation_t heading_actuation ;
414- pbio_control_update (& db -> control_heading , time_now , & state_heading , & ref_heading , & heading_actuation , & heading_torque );
417+ bool heading_external_pause = db -> control_paused ;
418+ pbio_control_update (& db -> control_heading , time_now , & state_heading , & ref_heading , & heading_actuation , & heading_torque , & heading_external_pause );
419+
420+ // If either controller is paused, pause both.
421+ db -> control_paused = distance_external_pause || heading_external_pause ;
415422
416423 // If either controller coasts, coast both, thereby also stopping control.
417424 if (distance_actuation == PBIO_DCMOTOR_ACTUATION_COAST ||
@@ -430,19 +437,6 @@ static pbio_error_t pbio_drivebase_update(pbio_drivebase_t *db) {
430437 return PBIO_ERROR_FAILED ;
431438 }
432439
433- // Both controllers are able to stop the other when it stalls. This ensures
434- // they complete at exactly the same time.
435- if (pbio_control_type_is_position (& db -> control_distance ) &&
436- pbio_position_integrator_is_paused (& db -> control_distance .position_integrator )) {
437- // If distance controller is paused, pause heading control too.
438- pbio_position_integrator_pause (& db -> control_heading .position_integrator , time_now );
439- }
440- if (pbio_control_type_is_position (& db -> control_heading ) &&
441- pbio_position_integrator_is_paused (& db -> control_heading .position_integrator )) {
442- // If heading controller is paused, pause distance control too.
443- pbio_position_integrator_pause (& db -> control_distance .position_integrator , time_now );
444- }
445-
446440 // The left servo drives at a torque and speed of (average) + (difference).
447441 int32_t feed_forward_left = pbio_observer_get_feedforward_torque (
448442 db -> left -> observer .model ,
0 commit comments