-
Notifications
You must be signed in to change notification settings - Fork 1
Autonomous Functions
Type the following to include this library:
#include "autonomous_functions.h"
Note that nearly all the functions in this library have scaling factors that need to be adjusted
bool EncoderValReached(long MaxVal, tMotor motor)
(bool) Returns true when an encoder on motor has reached a value MaxVal. Corrects for a bug where an encoder will randomly return a very high value and cause a stage of an autonomous program to end early.
| Parameter | Explanation | Data Type |
|---|---|---|
| MaxVal | The value at which you want the motor encoder to go to | long |
| motor | The motor on which the encoder is reading data | tMotor |
tMotor motor = MotorA;
long Distance_to_go = 20000;
while (! EncoderValReached(Distance_to_go, motor)) {
motor[motor] = 100;
}
void GoToEncoderVal(long EncoderVal, tMotor motor)
(void) Rotates a motor motor until an equipped motor encoder reaches a value EncoderVal. Corrects for a bug where an encoder will randomly return a very high value and cause a stage of an autonomous program to end early.
| Parameter | Explanation | Data Type |
|---|---|---|
| EncoderVal | The encoder value at which you want the motor to stop | long |
| motor | The motor on which the encoder is reading data | tMotor |
tMotor motor = MotorA;
long Distance_to_go = 20000;
GoToEncoderVal(Distance_to_go, motor);
void rotate(int degrees, tMotor *DriveMotors, size_t numMotors)
(void) Rotates a robot with 2 drive motors to rotate in place
| Parameter | Explanation | Data Type |
|---|---|---|
| degrees | The number of degrees you want the robot to rotate. A positive value will rotate counter-clockwise, a negative value will rotate clockwise. | int |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveL, DriveR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 2 for this function) | size_t |
tMotor DriveMotors[] = { DriveL, DriveR };
int amount_to_rotate = 60;
rotate(amount_to_rotate, DriveMotors[], 2);
void move(int distanceCM, tMotor *DriveMotors, size_t numMotors)
(void) Moves a robot forwards or backwards a distance distanceCM.
| Parameter | Explanation | Data Type |
|---|---|---|
| distanceCM | The distance in centimeters you want the robot to go. A positive value will make the robot go forward, a negative value will make the robot go backward. | int |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveL, DriveR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 2 for this function) | size_t |
tMotor DriveMotors[] = { DriveL, DriveR };
int Distance_to_go = 2000;
move(Distance_to_go, DriveMotors[], 2);
void vector_move(vect vector, tMotor *DriveMotors, size_t numMotors)
(void) Uses a 3-D vector to both rotate the robot and move it. NOTE: The y-value of the vector must be 0.
| Parameter | Explanation | Data Type |
|---|---|---|
| vector | A 3-D vector initialized like this: vect vector = { 20, 0, 40 };. The y-value must be 0 for the function to work. |
vect |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveL, DriveR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 2 for this function) | size_t |
tMotor DriveMotors[] = { DriveL, DriveR };
vect vector_to_destination = { 20, 0, 40 };
vector_move(vector_to_destination, DriveMotors[], 2);
void omnimove(int distanceCM, direction_t direction, tMotor *DriveMotors, size_t numMotors)
(void) Moves a holonomic drive (omni wheels on diagonals) robot forward, backward, left, or right.
| Parameter | Explanation | Data Type |
|---|---|---|
| distanceCM | The distance in centimeters you want the robot to go. A positive value will make the robot go forward, a negative value will make the robot go backward. | int |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveFL, DriveFR, DriveBL, DriveBR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 4 for this function) | size_t |
| direction | What direction you want the robot to go in; FORWARD, BACKWARD, LEFT, and RIGHT, are the choices. |
direction_t |
tMotor DriveMotors[] = { DriveFL, DriveFR, DriveBL, DriveBR };
int Distance_to_go = 2000;
omnimove(Distance_to_go, DriveMotors[], 4, LEFT);
void omnirotate(int degrees, tMotor *DriveMotors, size_t numMotors)
(void) Rotates a holonomic drive (omni wheels on diagonals) robot on a dime
| Parameter | Explanation | Data Type |
|---|---|---|
| degrees | The number of degrees you want the robot to rotate. A positive value will rotate counter-clockwise, a negative value will rotate clockwise. | int |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveFL, DriveFR, DriveBL, DriveBR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 4 for this function) | size_t |
tMotor DriveMotors[] = { DriveFL, DriveFR, DriveBL, DriveBR };
int amount_to_rotate = 60;
omnirotate(amount_to_rotate, DriveMotors[], 4);
void srotate(int degrees, tMotor *DriveMotors, size_t numMotors)
(void) A rotate function, uses a rotation sensor (compass, gyroscopic) to measure rotation instead of encoders
| Parameter | Explanation | Data Type |
|---|---|---|
| degrees | The number of degrees you want the robot to rotate. A positive value will rotate counter-clockwise, a negative value will rotate clockwise. | int |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveL, DriveR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 2 for this function) | size_t |
tMotor DriveMotors[] = { DriveL, DriveR };
int amount_to_rotate = 60;
srotate(amount_to_rotate, DriveMotors[], 2);
void somnirotate(int degrees, tMotor *DriveMotors, size_t numMotors)
(void) A omni-directional (omni-wheels on diagonals) rotate function, it uses a rotation sensor (compass, gyroscopic) instead of encoders to measure rotation.
| Parameter | Explanation | Data Type |
|---|---|---|
| degrees | The number of degrees you want the robot to rotate. A positive value will rotate counter-clockwise, a negative value will rotate clockwise. | int |
| *DriveMotors | An array, initialized like this: tMotor DriveMotors[] = { DriveFL, DriveFR, DriveBL, DriveBR }; that accounts for all the robot's drive motors. |
tMotor |
| numMotors | The number of drive motors on the robot (must be exactly 4 for this function) | size_t |
tMotor DriveMotors[] = { DriveFL, DriveFR, DriveBL, DriveBR };
int amount_to_rotate = 60;
somnirotate(amount_to_rotate, DriveMotors[], 4);