Exemple #1
0
def _query_steering_pid_params():
    return {
        'p'              : STORE.get('CAR_STEERING_PID_P', 1.0),
        'i'              : STORE.get('CAR_STEERING_PID_I', 0.3),
        'd'              : STORE.get('CAR_STEERING_PID_D', 0.3),
        'error_accum_max': STORE.get('CAR_STEERING_PID_EAM', 0.0),
    }
Exemple #2
0
def _calibrate_safe_throttle(io_device):
    while True:
        # Ask user for new values.
        safe_forward = _easy_ask("Safe forward throttle  (0, 100]",
                                 m.CAR_THROTTLE_FORWARD_SAFE_SPEED,
                                 int,
                                 io_device,
                                 min_val=1,
                                 max_val=100)
        safe_reverse = _easy_ask("Safe reverse throttle [-100, 0)",
                                 m.CAR_THROTTLE_REVERSE_SAFE_SPEED,
                                 int,
                                 io_device,
                                 min_val=-100,
                                 max_val=-1)
        m.CAR_THROTTLE_FORWARD_SAFE_SPEED = safe_forward
        m.CAR_THROTTLE_REVERSE_SAFE_SPEED = safe_reverse
        STORE.put('CAR_THROTTLE_FORWARD_SAFE_SPEED',
                  m.CAR_THROTTLE_FORWARD_SAFE_SPEED)
        STORE.put('CAR_THROTTLE_REVERSE_SAFE_SPEED',
                  m.CAR_THROTTLE_REVERSE_SAFE_SPEED)

        _demo_forward_reverse_no_pid()

        if _choice_input(prompt="Keep?",
                         choices=['n', 'y'],
                         io_device=io_device) == 'y':
            break
Exemple #3
0
def _calibrate_safe_throttle():
    while True:
        # Ask user for new values.
        safe_forward = _easy_ask("Safe forward throttle  (0, 100]", m.CAR_THROTTLE_FORWARD_SAFE_SPEED, int)
        safe_reverse = _easy_ask("Safe reverse throttle [-100, 0)", m.CAR_THROTTLE_REVERSE_SAFE_SPEED, int)
        m.CAR_THROTTLE_FORWARD_SAFE_SPEED = safe_forward
        m.CAR_THROTTLE_REVERSE_SAFE_SPEED = safe_reverse
        STORE.put('CAR_THROTTLE_FORWARD_SAFE_SPEED', m.CAR_THROTTLE_FORWARD_SAFE_SPEED)
        STORE.put('CAR_THROTTLE_REVERSE_SAFE_SPEED', m.CAR_THROTTLE_REVERSE_SAFE_SPEED)

        _demo_forward_reverse_no_pid()

        if input("Keep? [n/y] ") == 'y':
            break
Exemple #4
0
def calibrate():
    """
    Run the end-to-end calibration routine for this car.
    """

    if input("Calibrate microcontroller (e.g. gyro & accelerometer)? [n/y] ") == 'y':
        _calibrate_microcontroller()

    if input("Calibrate safe throttle speed? [n/y] ") == 'y':
        _calibrate_safe_throttle()

    if input("Calibrate servo range? [n/y] ") == 'y':
        _calibrate_servo_range()

    if input("Calibrate steering PID? [n/y] ") == 'y':
        _calibrate_steering_pid()

    if input("Disable battery monitor? [n/y] ") == 'y':
        STORE.put('BATTERY_MONITOR_DISABLED', True)
Exemple #5
0
def _query_motor_params():
    return {
        'top'             : STORE.get('CAR_MOTOR_TOP', 40000),
        'steering_left'   : STORE.get('CAR_MOTOR_STEERING_LEFT', 2100),
        'steering_mid'    : STORE.get('CAR_MOTOR_STEERING_MID', 3000),
        'steering_right'  : STORE.get('CAR_MOTOR_STEERING_RIGHT', 4100),
        'throttle_forward': STORE.get('CAR_MOTOR_THROTTLE_FORWARD', 4000),
        'throttle_mid'    : STORE.get('CAR_MOTOR_THROTTLE_MID', 3000),
        'throttle_reverse': STORE.get('CAR_MOTOR_THROTTLE_REVERSE', 2000),
    }
Exemple #6
0
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.forward(2.5)  # <-- uses gyro
        m.reverse(2.5)  # <-- uses gyro

        if _choice_input(prompt="Keep?", choices=['n', 'y'], io_device=io_device) == 'y':
            break

    _setup_steering_pid(save=True)
Exemple #7
0
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)
Exemple #8
0
def _calibrate_servo_range():
    _setup_motors()

    motor_params = _query_motor_params()
    steering_left  = motor_params['steering_left']
    steering_mid   = motor_params['steering_mid']
    steering_right = motor_params['steering_right']

    _setup_motors(30000)
    m.set_steering(45.0)
    v = _easy_ask("Steering left PWM value", steering_left, int)
    while True:
        steering_left = v
        STORE.put('CAR_MOTOR_STEERING_LEFT', steering_left)
        _setup_motors(30000)  # <-- nearabout the max possible timeout
        m.set_steering(45.0)
        v = _easy_ask("Steering left PWM value", steering_left, int)
        if v == steering_left:
            break  # break when the user doesn't change the value

    _setup_motors(30000)
    m.set_steering(-45.0)
    v = _easy_ask("Steering right PWM value", steering_right, int)
    while True:
        steering_right = v
        STORE.put('CAR_MOTOR_STEERING_RIGHT', steering_right)
        _setup_motors(30000)  # <-- nearabout the max possible timeout
        m.set_steering(-45.0)
        v = _easy_ask("Steering right PWM value", steering_right, int)
        if v == steering_right:
            break  # break when the user doesn't change the value

    _setup_motors()
    m.set_steering(0)
    v = _easy_ask("Steering mid PWM value", steering_mid, int)
    while True:
        steering_mid = v
        STORE.put('CAR_MOTOR_STEERING_MID', steering_mid)
        _setup_motors()
        _demo_forward_reverse_no_pid()
        v = _easy_ask("Steering mid PWM value", steering_mid, int)
        if v == steering_mid:
            break  # break when the user doesn't change the value

    _setup_motors(save=True)
Exemple #9
0
def _calibrate_steering_pid():
    _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: tuple(float(v) for v in s.split(' ')))

        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.forward(2.5)  # <-- uses gyro
        m.reverse(2.5)  # <-- uses gyro

        if input("Keep? [n/y] ") == 'y':
            break

    _setup_steering_pid(save=True)
Exemple #10
0
 def demo_mid(new_val):
     STORE.put('CAR_MOTOR_STEERING_MID', new_val)
     _setup_motors(30000)  # <-- nearabout the max possible timeout
     m.set_steering(0.0)   # <-- mid-steering ("straight")
Exemple #11
0
 def demo_right(new_val):
     STORE.put('CAR_MOTOR_STEERING_RIGHT', new_val)
     _setup_motors(30000)  # <-- nearabout the max possible timeout
     m.set_steering(-45.0) # <-- max right
Exemple #12
0
 def demo_left(new_val):
     STORE.put('CAR_MOTOR_STEERING_LEFT', new_val)
     _setup_motors(30000)  # <-- nearabout the max possible timeout
     m.set_steering(45.0)  # <-- max left