INNER CODE UNIT · Python

run

ryan4yin/knowledge · electrical-engineering/raspberrypi/robot_car_pi.py:35

def run(x_value, y_value):
    y_abs_value = min(abs(y_value), 1)

    x_action = "turn_right" if x_value >= 0 else "turn_left"
    x_abs_value = min(abs(x_value), 1)

    if x_action == "turn_right":
        l_speed = min(1.0, y_value + x_abs_value)
        r_speed = max(-1.0, y_value - x_abs_value)
    else:
        l_speed = max(-1.0, y_value - x_abs_value)
        r_speed = min(1.0, y_value + x_abs_value)


    l_motor_action = "forward" if l_speed >= 0 else "backward"
    r_motor_action = "forward" if r_speed >= 0 else "backward"

    l_speed = abs(l_speed)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…