I am sure this is a somewhat crude program, but this is the what I am using to run the V5 through a first check. I’ll run this before giving any V5 to teams, and I’ll keep it around to use for troubleshooting later.
If anyone has tips to streamline the code I’m all ears.
#include "robot-config.h"
void MT1(int MT1t){
Motor1.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT1t);
Motor1.stop(brakeType::coast);
}
void MT2(int MT2t){
Motor2.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT2t);
Motor2.stop(brakeType::coast);
}
void MT3(int MT3t){
Motor3.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT3t);
Motor3.stop(brakeType::coast);
}
void MT4(int MT4t){
Motor4.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT4t);
Motor4.stop(brakeType::coast);
}
void MT5(int MT5t){
Motor5.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT5t);
Motor5.stop(brakeType::coast);
}
void MT6(int MT6t){
Motor6.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT6t);
Motor6.stop(brakeType::coast);
}
void MT7(int MT7t){
Motor7.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT7t);
Motor7.stop(brakeType::coast);
}
void MT8(int MT8t){
Motor8.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT8t);
Motor8.stop(brakeType::coast);
}
void MT9(int MT9t){
Motor9.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT9t);
Motor9.stop(brakeType::coast);
}
void MT10(int MT10t){
Motor10.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT10t);
Motor10.stop(brakeType::coast);
}
void MT11(int MT11t){
Motor11.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT11t);
Motor11.stop(brakeType::coast);
}
void MT12(int MT12t){
Motor12.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT12t);
Motor12.stop(brakeType::coast);
}
void MT13(int MT13t){
Motor13.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT13t);
Motor13.stop(brakeType::coast);
}
void MT14(int MT14t){
Motor14.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT14t);
Motor14.stop(brakeType::coast);
}
void MT15(int MT15t){
Motor15.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT15t);
Motor15.stop(brakeType::coast);
}
void MT16(int MT16t){
Motor16.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT16t);
Motor16.stop(brakeType::coast);
}
void MT17(int MT17t){
Motor17.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT17t);
Motor17.stop(brakeType::coast);
}
void MT18(int MT18t){
Motor18.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT18t);
Motor18.stop(brakeType::coast);
}
void MT19(int MT19t){
Motor19.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT19t);
Motor19.stop(brakeType::coast);
}
void MT20(int MT20t){
Motor20.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(MT20t);
Motor20.stop(brakeType::coast);
}
// create a function containing the code to run
void autonomous( void ) {
Brain.Screen.clearScreen();
Brain.Screen.print("Motor testing");
MT1(2000);
MT2(2000);
MT3(2000);
MT4(2000);
MT5(2000);
Controller1.Screen.clearScreen();
Controller1.Screen.print("prev: Motors 1-5");
Controller1.rumble(".-.-");
MT6(2000);
MT7(2000);
MT8(2000);
MT9(2000);
MT10(2000);
Controller1.Screen.clearScreen();
Controller1.Screen.print("prev: Motors 6-10");
Controller1.rumble(".-.-");
MT11(2000);
MT12(2000);
MT13(2000);
MT14(2000);
MT15(2000);
Controller1.Screen.clearScreen();
Controller1.Screen.print("prev: Motors 11-15");
Controller1.rumble(".-.-");
MT16(2000);
MT17(2000);
MT18(2000);
MT19(2000);
MT20(2000);
Controller1.Screen.clearScreen();
Controller1.Screen.print("prev: Motors 16-20");
task::sleep(2000);
//end autonomous
}
void usercontrol( void ) {
while(1){
//first shift set
if(Controller1.ButtonL1.pressing()) {
//left set of controller buttons
if(Controller1.ButtonUp.pressing()) {
Motor9.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonRight.pressing()) {
Motor10.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonDown.pressing()) {
Motor11.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonLeft.pressing()) {
Motor12.spin(directionType::fwd,50,velocityUnits::pct);
}
//right side of controller buttons
else if(Controller1.ButtonX.pressing()) {
Motor13.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonA.pressing()) {
Motor14.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonB.pressing()) {
Motor15.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonY.pressing()) {
Motor16.spin(directionType::fwd,50,velocityUnits::pct);
}
else { //If these buttons are not pressed...
Motor9.stop(brakeType::coast);
Motor10.stop(brakeType::coast);
Motor11.stop(brakeType::coast);
Motor12.stop(brakeType::coast);
Motor13.stop(brakeType::coast);
Motor14.stop(brakeType::coast);
Motor15.stop(brakeType::coast);
Motor16.stop(brakeType::coast);
}
}
//second shift set
else if(Controller1.ButtonL2.pressing()) {
//left set of controller buttons
if(Controller1.ButtonUp.pressing()) {
Motor17.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonRight.pressing()) {
Motor18.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonDown.pressing()) {
Motor19.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonLeft.pressing()) {
Motor20.spin(directionType::fwd,50,velocityUnits::pct);
}
else { //If these buttons are not pressed...
Motor17.stop(brakeType::coast);
Motor18.stop(brakeType::coast);
Motor19.stop(brakeType::coast);
Motor20.stop(brakeType::coast);
}
}
//no shift set
else {
//left set of controller buttons
if(Controller1.ButtonUp.pressing()) {
Motor1.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonRight.pressing()) {
Motor2.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonDown.pressing()) {
Motor3.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonLeft.pressing()) {
Motor4.spin(directionType::fwd,50,velocityUnits::pct);
}
//right side of controller buttons
else if(Controller1.ButtonX.pressing()) {
Motor5.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonA.pressing()) {
Motor6.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonB.pressing()) {
Motor7.spin(directionType::fwd,50,velocityUnits::pct);
}
else if(Controller1.ButtonY.pressing()) {
Motor8.spin(directionType::fwd,50,velocityUnits::pct);
}
else { //If these buttons are not pressed...
Motor1.stop(brakeType::coast);
Motor2.stop(brakeType::coast);
Motor3.stop(brakeType::coast);
Motor4.stop(brakeType::coast);
Motor5.stop(brakeType::coast);
Motor6.stop(brakeType::coast);
Motor7.stop(brakeType::coast);
Motor8.stop(brakeType::coast);
}
}
task::sleep(100);
}
//end usercontrol
}
int main() {
// tell the competition code what to run for the autonomous period
Competition.autonomous( autonomous );
// tell the competition code what to run for the driver control period
Competition.drivercontrol( usercontrol );
//Prevent main from exiting with an infinite loop.
while(1) {
task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
}