19type = motoron.CurrentSenseType.MOTORON_18V18
23min_vin_voltage_mv = 6500
27def calibrate_current():
31 desired_sample_count = 32
35 last_time_conditions_not_met = time.monotonic()
37 status_mask = ((1 << motoron.STATUS_FLAG_MOTOR_FAULTING) |
38 (1 << motoron.STATUS_FLAG_NO_POWER) |
39 (1 << motoron.STATUS_FLAG_MOTOR_OUTPUT_ENABLED) |
40 (1 << motoron.STATUS_FLAG_MOTOR_DRIVING))
41 status_desired = 1 << motoron.STATUS_FLAG_MOTOR_OUTPUT_ENABLED
43 if ((mc.get_status_flags() & status_mask) != status_desired
or
44 (mc.get_vin_voltage_mv(reference_mv) < min_vin_voltage_mv)):
45 last_time_conditions_not_met = time.monotonic()
49 if (time.monotonic() - last_time_conditions_not_met) > 0.02:
50 totals[0] += mc.get_current_sense_raw(1)
51 totals[1] += mc.get_current_sense_raw(2)
53 if sample_count == desired_sample_count:
break
55 mc.set_current_sense_offset(1, round(totals[0] / desired_sample_count))
56 mc.set_current_sense_offset(2, round(totals[1] / desired_sample_count))
57 mc.set_current_sense_minimum_divisor(1, 100)
58 mc.set_current_sense_minimum_divisor(2, 100)
60 print(f
"Current sense offsets: {mc.get_current_sense_offset(1)} {mc.get_current_sense_offset(2)}")
73mc.set_max_acceleration(1, 200)
74mc.set_max_deceleration(1, 200)
77mc.set_max_acceleration(2, 200)
78mc.set_max_deceleration(2, 200)
86 type, reference_mv, mc.get_current_sense_offset(1)))
88 type, reference_mv, mc.get_current_sense_offset(2)))
94 processed = mc.get_current_sense_processed(1)
95 print(f
"Motor 1 current: {processed} = {round(processed * units)} mA")
101 processed = mc.get_current_sense_processed(2)
102 print(f
"Motor 2 current: {processed} = {round(processed * units)} mA")
106except KeyboardInterrupt:
def calculate_current_limit(milliamps, type, reference_mv, offset)
Calculates a current limit value that can be passed to the Motoron using set_current_limit().
def current_sense_units_milliamps(type, reference_mv)
Calculates the units for the Motoron's current sense reading returned by get_current_sense_processed(...
Represents an I2C connection to a Pololu Motoron Motor Controller.