The length unit used is the unit you set the radius and length parameter as.
For example, if you want to use millimeters, you can set the radius and length in millimeters, and all the methods involving distances or coordinates will use millimeters.
PreMo(float radius, float length, double kp, double kd, MotorManager* motorManager, EncoderManager* encoderManager)
Constructor
radius
- radius of the wheel.length
- axle length (distance from the left wheel to right wheel).kp
- proportional PID constant for path following.kd
- derivative PID constant for path following.motorManager
- object that manages the motor speed.encoderManager
- object containing the encoder information.void forward(float distance)
- Move forward by distance.
void reverse(float distance)
- Move reverse by distance
void twist(float targetHeading, int twist=TWIST_MIN)
- Twist the robot to targetHeading. The heading angle is defined in the dead reckoner documentation.
void stop()
- Stop the robot. This also stops path following or twisting. There is no resume method.
void continuePathFollowing()
- Continues path following if following a path.
void isFollowingPath()
- Returns true if the robot is following a path.
void setPID(float kp, float kd, float ki=0)
- Set the PID constants for path following.
void startPathFollowing(float* pathX, float* pathY, int pathLength)
- Start following the path defined by the coordinates.
pathX
: Pointer to the array of x-values.pathY
: Pointer to the array of y-values.pathLength
: length of the path arrays.void startPathFollowing(float* pathX, float* pathY, int pathLength, bool isForward)
- When isForward is set to false, the robot will follow the path backwards. Otherwise, same as above.
double getX()
- Get the current x location of the robot.
double getY()
- Get the current y location of the robot.
The setX() and setY() methods are useful when you are using another position reference to account for drift.
void setX()
- Set the x location of the robot.
void setY()
- Set the y location of the robot.
getGoalX()
- Get the x-value of the goal point.
getGoalY()
- Get the y-value of the goal point.
getHeading()
- Get the robot heading.
getOutput()
- Get the PID output.
printPath()
- Print the path neatly.
EncoderManager(volatile unsigned long* leftEncoderPos, volatile unsigned long* rightEncoderPos, int ticksPerRev)
volatile unsigned long* getLeftPosPointer()
-
volatile unsigned long* getRightPosPointer();
-
int getTicksPerRev()
-
MotorManager(functiontypeint leftForward, functiontypeint leftReverse, functiontypeint rightForward, functiontypeint rightReverse)
First define the following methods in your code:
leftForward(int speed)
- Move the left robot wheel forward at speed.leftReverse(int speed)
- Move the left robot wheel reverse at speed.rightForward(int speed)
- Move the right robot wheel forward at speed.rightReverse(int speed)
- Move the right robot wheel reverse at speed.Then pass these functions into the constructor:
MotorManager(leftForward, leftReverse, rightForward, rightReverse)
setStop(functiontype stop)
- Set the function to stop the robot.
setSpeedLimits(int min, int max)
- Set the motor speed limits for leftForward, leftReverse, rightForward, and righReverse.
int getMinMotorSpeed()
- Get min speed limit.
int getMaxMotorSpeed()
- Get max speed limit.