EvoMotor#
-
class EvoMotor#
Class to control a motor using EvoPWMDriver and an encoder.
Initialisation & Setup
-
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
-
bool EvoMotor::isEncoderAvailable()#
Checks if encoder is available.
- Returns:
True if encoder is available, false otherwise.
-
int EvoMotor::getCountPerRevolution()#
Gets encoder count per revolution.
- Returns:
The count per revolution.
Motor Control Functions
-
void EvoMotor::stop()#
Stops the motor based on the stop behaviour set using setStopBehaviour(MotorState motorStopState).
-
void EvoMotor::setHoldPower(uint16_t power)#
Set power used when holding.
- Parameters:
power – power to hold (0-4096)
-
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.