MicroPython EvoMotor#

class evo.EvoMotor(port=evo.M1, type=evo.GENERICWITHENCODER, flip=False)#

Native single DC motor class. port selects evo.M1 to evo.M4. type selects a motor preset and encoder counts-per-rotation. flip reverses the effective wiring and encoder direction. Constructor returns a new motor object.

Power Control

EvoMotor.run(power)#
EvoMotor.runPower(power)#

Drive the motor with raw PWM power. Positive and negative values select direction. run() is an alias of runPower(). Returns None.

EvoMotor.runSpeed(target_dps)#

Run closed-loop speed control toward target_dps degrees per second. Returns None.

EvoMotor.runTime(dps, seconds)#

Run at dps degrees per second for seconds, then stop. Raises ValueError if seconds is negative. Returns None.

EvoMotor.runAngle(dps, angle)#

Run until the encoder has moved angle degrees. The sign of angle selects direction; dps is treated as a speed magnitude. Returns None.

Stop Behaviour

EvoMotor.brake()#

Electrically brake the motor. Returns None.

EvoMotor.coast()#

Let the motor coast freely. Returns None.

EvoMotor.hold()#

Hold the current motor position using the configured hold behaviour. Returns None.

EvoMotor.setStopBehaviour(behaviour)#
EvoMotor.setStopBehavior(behaviour)#

Set the default stop behaviour to evo.COAST, evo.BRAKE or evo.HOLD. Raises ValueError for invalid values. Returns None.

Encoder Position

EvoMotor.getPosition()#

Return the raw encoder count as an integer.

EvoMotor.resetPosition()#

Reset the raw encoder count to zero. Returns None.

EvoMotor.getAngle()#

Return the encoder position converted to degrees as an integer.

EvoMotor.resetAngle()#

Reset the angle reference to zero. Returns None.

EvoMotor.setCountsPerRotation(counts)#

Set encoder counts per full shaft rotation. counts must be greater than zero or ValueError is raised. Returns None.

EvoMotor.flipEncoderDirection()#

Invert the encoder direction used by angle and speed calculations. Returns None.

Speed Feedback

EvoMotor.updateSpeed()#

Refresh cached encoder speed measurements. Returns None.

EvoMotor.getSpeed()#
EvoMotor.getSpeedDPS()#

Return the most recent speed estimate in degrees per second as a float.

EvoMotor.getSpeedCPS()#

Return the most recent speed estimate in encoder counts per second as a float.

EvoMotor.getPower()#

Return the last PWM power output generated by closed-loop speed control.

EvoMotor.setSpeedPID(kp, ki, kd)#

Set closed-loop speed PID gains. Returns None.

EvoMotor.setSpeedLimits(min_power, max_power)#

Set the feed-forward minimum power and absolute maximum output power used by speed control. Returns None.

EvoMotor.resetSpeedControl()#

Clear speed-control integrator and cached speed state. Returns None.

Driver Enable

EvoMotor.enableAllMotors()#
EvoMotor.enableAll()#

Enable the shared motor driver sleep line when the board defines NSLEEP_PIN. Returns None.

EvoMotor.disableAllMotors()#
EvoMotor.disableAll()#

Disable the shared motor driver sleep line when the board defines NSLEEP_PIN. Returns None.

EvoMotor.deinit()#

Stop the motor according to its stop behaviour and detach encoder interrupt resources. Returns None.