drivers.motor module¶
- class drivers.motor.Motor(pwm, tim, channel, slp, dir, battAdc)[source]¶
Bases:
objectSimple motor driver wrapper for a Romi-style motor driver.
- Responsibilities:
configure a PWM channel for the motor
control the direction pin
control the sleep (enable) pin
provide a simple set_effort(value) interface where value is in -100..100 (percent). Positive values select one direction, negative values select the other direction.
- Notes:
pwm/slp/dir arguments may be either Pin instances or arguments that the pyb.Pin constructor accepts
- disable()[source]¶
Disable the motor driver by setting the SLEEP pin low.
The original implementation also set effort to zero when disabling; we preserve that behavior by calling set_effort(0) first.
- set_effort(value)[source]¶
Set motor effort.
value is interpreted as percent in the range -100..100 (as in the original code). Positive selects one direction, negative the opposite. The method writes the direction pin and then sets PWM duty to the absolute magnitude of value (via pulse_width_percent).
The effort is capped such that 100% effort corresponds to 6.5V by measuring battery voltage and applying a scale factor to the effort requested
IMPORTANT: behavior unchanged from original code — there is no extra validation/clamping here.