19mc.set_port(
"/dev/serial0")
23vin_type = motoron.VinSenseType.MOTORON_256
27min_vin_voltage_mv = 4500
31 (1 << motoron.STATUS_FLAG_PROTOCOL_ERROR) |
32 (1 << motoron.STATUS_FLAG_CRC_ERROR) |
33 (1 << motoron.STATUS_FLAG_COMMAND_TIMEOUT_LATCHED) |
34 (1 << motoron.STATUS_FLAG_MOTOR_FAULT_LATCHED) |
35 (1 << motoron.STATUS_FLAG_NO_POWER_LATCHED) |
36 (1 << motoron.STATUS_FLAG_UART_ERROR) |
37 (1 << motoron.STATUS_FLAG_RESET) |
38 (1 << motoron.STATUS_FLAG_COMMAND_TIMEOUT))
45mc.set_error_response(motoron.ERROR_RESPONSE_COAST)
46mc.set_error_mask(error_mask)
50mc.set_command_timeout_milliseconds(100)
53mc.set_max_acceleration(1, 140)
54mc.set_max_deceleration(1, 300)
60while mc.get_motor_driving_flag():
pass
64def check_for_problems():
65 status = mc.get_status_flags()
66 if (status & error_mask):
70 print(
"Controller error: 0x%x" % status, file=sys.stderr)
73 voltage_mv = mc.get_vin_voltage_mv(reference_mv, vin_type)
74 if voltage_mv < min_vin_voltage_mv:
76 print(
"VIN voltage too low:", voltage_mv, file=sys.stderr)
83 if int(time.monotonic() * 1000) & 2048:
90except KeyboardInterrupt:
Represents a serial connection to a Pololu Motoron Motor Controller.