EvoMotor#

class EvoMotor#

Class to control a motor using EvoPWMDriver and an encoder.

Initialisation & Setup

void EvoMotor::begin()#

Initializes the motor.

EvoMotor::EvoMotor(MotorPort motorPort, MotorType motorType = GENERICWITHENCODER, bool motorFlip = false)#

Constructor for EvoMotor.

Parameters:
  • motorPort – The motor port.

  • motorType – The type of motor.

  • motorFlip – Whether the motor direction should be flipped.

void EvoMotor::flipEncoderDirection(bool flip)#

Flips the direction of the encoder.

Parameters:

flip – Whether the encoder direction should be flipped.

void EvoMotor::setSpeedLimit(int maxSpd, int minSpd)#

Sets the minimum and maximum speed of the motor.

Parameters:
  • maxSpd – Maximum speed.

  • minSpd – Minimum speed.

void EvoMotor::getSpeedLimit(int *maxSpd, int *minSpd)#

Gets the speed limits.

Parameters:
  • maxSpd – Pointer to store the maximum speed.

  • minSpd – Pointer to store the minimum speed

Encoder Control Functions

void EvoMotor::setEncoderAvailable(bool avail)#

Sets encoder availability.

bool EvoMotor::isEncoderAvailable()#

Checks if encoder is available.

Returns:

True if encoder is available, false otherwise.

void EvoMotor::setCountPerRevolution(int countPerRevolution)#

Sets encoder count per revolution.

int EvoMotor::getCountPerRevolution()#

Gets encoder count per revolution.

Returns:

The count per revolution.

void EvoMotor::setCount(int count)#

Sets the encoder count.

int EvoMotor::getCount()#

Gets the encoder count.

Returns:

The encoder count.

void EvoMotor::resetCount()#

Resets the encoder count.

Motor Control Functions

void EvoMotor::stop()#

Stops the motor based on the stop behaviour set using setStopBehaviour(MotorState motorStopState).

void EvoMotor::hold()#

Holds the motor in its current position.

void EvoMotor::setHoldPower(uint16_t power)#

Set power used when holding.

Parameters:

power – power to hold (0-4096)

void EvoMotor::coast()#

Removes power from the motors.

void EvoMotor::brake()#

Applys braking force on the motor to stop the motor.

void EvoMotor::run(int speed)#

Runs the motor at a specified speed.

Parameters:

speed – Motor speed.

void EvoMotor::runCount(int speed, int count, bool blocking = true)#

Runs the motor for a specified encoder count.

Parameters:
  • speed – Motor speed.

  • count – Encoder count.

  • blocking – Wait for action to be completed.

void EvoMotor::runAngle(int speed, int degrees, bool blocking = true)#

Runs the motor for a specified motor degree.

Parameters:
  • speed – Motor speed.

  • degrees – Motor degrees.

  • blocking – Wait for action to be completed.

void EvoMotor::runTime(int speed, int timeMS, bool blocking = true)#

Runs the motor for a specified time.

Parameters:
  • speed – Motor speed.

  • timeMS – Time in miliseconds.

  • blocking – Wait for action to be completed.

void EvoMotor::runTarget(int speed, int angle, MotorStop then = MotorStop::HOLD, bool blocking = true)#

Runs the motor to a specified absolute position.

Parameters:
  • speed – Motor speed.

  • angle – Motor absolute degree.

  • then – Motor stop action after moving to target.

  • blocking – Wait for action to be completed.

void EvoMotor::setTargetPD(float kp, float kd)#

Sets PD control values for runTarget()

Parameters:
  • kp – Proportional gain.

  • kd – Derivative gain.

void EvoMotor::getTargetPD(float *kp, float *kd)#

Gets the PD control values for runTarget()

Parameters:
  • kp – Pointer to store proportional gain.

  • kd – Pointer to store derivative gain.

void EvoMotor::runUntilStalled(int speed, bool blocking = true)#

Runs the motor until it is stalled.

Parameters:
  • speed – Motor speed.

  • blocking – Wait for action to be completed.

int EvoMotor::getSpeed()#

Gets the motor speed.

Returns:

speed in deg/s

void EvoMotor::setAngle(int degrees)#

Sets the current motor angle.

int EvoMotor::getAngle()#

Gets the current motor angle.

Returns:

The angle in degrees.

void EvoMotor::resetAngle()#

Resets the motor angle.

bool EvoMotor::isStalled()#

Checks if the motor is stalled.

Returns:

True if stalled, false otherwise.

void EvoMotor::setStallThreshold(int threshold)#

Sets motor stall thresholds.

void EvoMotor::setStopBehaviour(MotorStop motorStopState)#

Sets motor stop behavior.