I’ll quickly start you up with a n explanation of functions and how to use them to make your programming easier. I will use the drive as an example and you can use the example and apply it to make more functions.
Let’s say you have a 4 motor drive and you want to make your robot move forward. You could make your drive move forward 100 rotations by using the following code:
void autonomous(){
LBDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm, false);
LBDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm, false);
FBDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm, false);
LFDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm);
}
The first parameter is used to define the amount of rotations, the second parameter specifies the rotation units, the third parameter defines the velocity the motors, must move at, the fourth parameter defines the velocity units, and the final parameter defines whether the statement is a considered a blocking or non blocking statement.
Creating a function makes this task much easier.
void drive(Int rev, int spd){
LBDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm, false);
LBDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm, false);
FBDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm, false);
LFDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm);
}
void autonomous(){
drive(100,200);
}
In this instance, we defined a function called drive and included parameter for rotations and speed. In this sense, you can now callback the function using just those two parameters and you can easily make and autonomous. I will leave tuning and such to you. Think about how turning works and make sure you understand everything. If you have any questions please ask!