Skip to content

Commit

Permalink
pbio/servo: only reset used servos
Browse files Browse the repository at this point in the history
After a program completed we were resetting all hbridges for simplicity, but this was also turning off sensors that need power, like the Powered Up Color Sensor.

This ensures that we only reset those motors for which we have a dc motor reference, which could only be initialized if there was a tacho.

We will still need a mechanism for resetting dc motors.
  • Loading branch information
laurensvalk committed Dec 23, 2020
1 parent 64620ca commit 79a3347
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/pbio/src/servo.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ pbio_error_t pbio_servo_setup(pbio_servo_t *srv, pbio_direction_t direction, fix
return PBIO_ERROR_INVALID_OP;
}

// Get, coast, and configure dc motor
err = pbio_dcmotor_get(srv->port, &srv->dcmotor, direction, true);
// Get and reset tacho
err = pbio_tacho_get(srv->port, &srv->tacho, direction, gear_ratio);
if (err != PBIO_SUCCESS) {
return err;
}

// Get and reset tacho
err = pbio_tacho_get(srv->port, &srv->tacho, direction, gear_ratio);
// Get, coast, and configure dc motor
err = pbio_dcmotor_get(srv->port, &srv->dcmotor, direction, true);
if (err != PBIO_SUCCESS) {
return err;
}

// Reset state
pbio_control_stop(&srv->control);

Expand Down Expand Up @@ -255,12 +256,11 @@ pbio_error_t pbio_servo_stop_force(pbio_servo_t *srv) {
// Release claim from drivebases or other classes
srv->claimed = false;

// Try to stop / coast motor whether or not initialized already
// Try to stop / coast motor
if (srv->dcmotor) {
return pbio_dcmotor_coast(srv->dcmotor);
} else {
return pbdrv_motor_coast(srv->port);
}
return PBIO_SUCCESS;
}

pbio_error_t pbio_servo_run(pbio_servo_t *srv, int32_t speed) {
Expand Down

0 comments on commit 79a3347

Please sign in to comment.