@@ -242,10 +242,9 @@ static pbio_error_t pbio_drivebase_stop_from_servo(void *drivebase, bool clear_p
242242 * @param [in] right Right servo instance.
243243 * @param [in] wheel_diameter Wheel diameter in um.
244244 * @param [in] axle_track Distance between wheel-ground contact points in um.
245- * @param [in] use_gyro Whether to use a gyro for heading (true) or the builtin rotation sensors (false).
246245 * @return Error code.
247246 */
248- pbio_error_t pbio_drivebase_get_drivebase (pbio_drivebase_t * * db_address , pbio_servo_t * left , pbio_servo_t * right , int32_t wheel_diameter , int32_t axle_track , bool use_gyro ) {
247+ pbio_error_t pbio_drivebase_get_drivebase (pbio_drivebase_t * * db_address , pbio_servo_t * left , pbio_servo_t * right , int32_t wheel_diameter , int32_t axle_track ) {
249248
250249 // Can't build a drive base with just one motor.
251250 if (left == right ) {
@@ -287,8 +286,8 @@ pbio_error_t pbio_drivebase_get_drivebase(pbio_drivebase_t **db_address, pbio_se
287286 db -> left = left ;
288287 db -> right = right ;
289288
290- // Whether to use the gyro for steering and driving straight .
291- db -> use_gyro = use_gyro ;
289+ // By default, don't use gyro.
290+ db -> use_gyro = false ;
292291
293292 // Set parents of both servos, so they can stop this drivebase.
294293 pbio_parent_set (& left -> parent , db , pbio_drivebase_stop_from_servo );
@@ -336,6 +335,28 @@ pbio_error_t pbio_drivebase_get_drivebase(pbio_drivebase_t **db_address, pbio_se
336335 return PBIO_SUCCESS ;
337336}
338337
338+ /**
339+ * Makes the drivebase use gyro or motor rotation sensors for heading control.
340+ *
341+ * This function will stop the drivebase if it is running.
342+ *
343+ * @param [in] db Drivebase instance.
344+ * @param [in] use_gyro Whether to use the gyro for heading control.
345+ * @return Error code.
346+ */
347+ pbio_error_t pbio_drivebase_set_use_gyro (pbio_drivebase_t * db , bool use_gyro ) {
348+
349+ // We stop so that new commands will reinitialize the state using the
350+ // newly selected input for heading control.
351+ pbio_error_t err = pbio_drivebase_stop (db , PBIO_CONTROL_ON_COMPLETION_COAST );
352+ if (err != PBIO_SUCCESS ) {
353+ return err ;
354+ }
355+
356+ db -> use_gyro = use_gyro ;
357+ return PBIO_SUCCESS ;
358+ }
359+
339360/**
340361 * Stops a drivebase.
341362 *
@@ -821,7 +842,7 @@ pbio_error_t pbio_drivebase_is_stalled(pbio_drivebase_t *db, bool *stalled, uint
821842 * @return Error code.
822843 */
823844pbio_error_t pbio_drivebase_get_drivebase_spike (pbio_drivebase_t * * db_address , pbio_servo_t * left , pbio_servo_t * right ) {
824- pbio_error_t err = pbio_drivebase_get_drivebase (db_address , left , right , 1000 , 1000 , false );
845+ pbio_error_t err = pbio_drivebase_get_drivebase (db_address , left , right , 1000 , 1000 );
825846
826847 // The application input for spike bases is degrees per second average
827848 // between both wheels, so in millidegrees this is x1000.
0 commit comments