INNER CODE UNIT · Python
l_speed
ryan4yin/knowledge · electrical-engineering/raspberrypi/robot_car_pi.py:45
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)
r_speed = abs(r_speed)
print(f"左轮速度:{l_speed:.2} 方向:{l_motor_action};右轮速度:{r_speed:.2},方向 {r_motor_action}")
motor_l_tail.__getattribute__(l_motor_action)(l_speed)
motor_l_head.__getattribute__(l_motor_action)(l_speed)
motor_r_head.__getattribute__(r_motor_action)(r_speed)
motor_r_tail.__getattribute__(r_motor_action)(r_speed)