def _calibrate_steering_pid(io_device): _setup_steering_pid() steering_pid_params = _query_steering_pid_params() p = steering_pid_params['p'] i = steering_pid_params['i'] d = steering_pid_params['d'] while True: p, i, d = _easy_ask("Steering PID [space-separated p i d]", [p, i, d], lambda s: (float(v) for v in s.split(' ')), io_device, adj_delta=0.1) STORE.put('CAR_STEERING_PID_P', p) STORE.put('CAR_STEERING_PID_I', i) STORE.put('CAR_STEERING_PID_D', d) _setup_steering_pid() m.straight(m.CAR_THROTTLE_FORWARD_SAFE_SPEED, 2.5, invert_output=False) # <-- uses gyro m.straight(m.CAR_THROTTLE_REVERSE_SAFE_SPEED, 2.5, invert_output=True) # <-- uses gyro if _choice_input(prompt="Keep?", choices=['n', 'y'], io_device=io_device) == 'y': break _setup_steering_pid(save=True)
def reverse(duration=1.0, verbose=True): """ Drive the car in reverse for `duration` seconds. """ from car import motors if duration > 5.0: print( "Error: The duration exceeds 5 seconds; will reset to 5 seconds.") duration = 5.0 if verbose: print("Driving in reverse for {} seconds.".format(duration)) if duration <= 0.0: return motors.straight(motors.CAR_THROTTLE_REVERSE_SAFE_SPEED, duration, invert_output=True)
def reverse(sec=None, cm=None, verbose=True): """ Drive the car in reverse for `sec` seconds or `cm` centimeters (passing in both will raise an error). If neither is passed in, the car will drive for 1 second. """ from car import motors if sec is not None and cm is not None: _ctx_print_all( "Error: Please specify duration (sec) OR distance (cm) - not both." ) return if sec is None and cm is None: sec = 1.0 if sec is not None: if sec > 5.0: _ctx_print_all( "Error: The duration (sec) exceeds 5 seconds; will reset to 5 seconds." ) sec = 5.0 if sec <= 0.0: return if verbose: _ctx_print_all("Driving in reverse for {} seconds.".format(sec)) if cm is not None: if cm > 300.0: _ctx_print_all( "Error: The distance (cm) exceeds 300 cm (~10 feet); will reset to 300 cm." ) cm = 300.0 if cm <= 0.0: return if verbose: _ctx_print_all("Driving in reverse for {} centimeters.".format(cm)) motors.straight(motors.safe_reverse_throttle(), sec, cm, invert_output=True)