Hope everyone is coming along with their bots this year! Our team has been working on autonomous with the new V5 System but have come into a roadblock. We’ve attempted to create an Autonomous selection that runs on the Brain screen before the match and will determine which autonomous function the robot will execute. Here’s our Autonomous Button code -
#include "robot-config.h"
void BlueFront(){
Brain.Screen.clearScreen();
}
void RedFront(){
Brain.Screen.clearScreen();
Brain.Screen.setFont(fontType::mono20);
Brain.Screen.printAt(100, 100, "Hello");
}
void Buttons(){
Brain.Screen.setPenColor(color::white);
Brain.Screen.setFont(fontType::mono20);
Brain.Screen.drawRectangle(12, 10, 105, 105, color::blue);
Brain.Screen.drawRectangle(129, 10, 105, 105, color::blue);
Brain.Screen.drawRectangle(246, 10, 105, 105, color::blue);
Brain.Screen.drawRectangle(363, 10, 105, 105, color::blue);
Brain.Screen.drawRectangle(12, 125, 105, 105, color::red);
Brain.Screen.drawRectangle(129, 125, 105, 105, color::red);
Brain.Screen.drawRectangle(246, 125, 105, 105, color::red);
Brain.Screen.drawRectangle(363, 125, 105, 105, color::red);
Brain.Screen.printAt(38, 62, "Front");
Brain.Screen.printAt(155, 62, "Back");
Brain.Screen.printAt(38, 177, "Front");
Brain.Screen.printAt(155, 177, "Back");
}
// Draws a circle around the place on the screen that is touched
void ScreenTouch() {
Brain.Screen.setPenColor(color::white);
Brain.Screen.drawCircle(Brain.Screen.xPosition(),Brain.Screen.yPosition(),30, color::transparent);
}
void AutonLocation(){
// Allows us to draw on the screen without the system rendering until we tell it to
Brain.Screen.render(true,false);
while (1) {
// Prevents flicker from constant rendering
if (LocationVal == 0){
Brain.Screen.clearScreen();
Buttons();
Brain.Screen.render();
}
else if (Brain.Screen.pressing() && LocationVal == 0){
while(Brain.Screen.pressing()){
Brain.Screen.clearScreen();
Buttons();
ScreenTouch();
Brain.Screen.render();
}
task::sleep(500);
if (Brain.Screen.yPosition() >= 10 || Brain.Screen.yPosition() <= 115){
// First blue button
if (Brain.Screen.xPosition() >= 12 || Brain.Screen.xPosition() <= 117){
LocationVal = 1;
}
// Second blue button
else if (Brain.Screen.xPosition() >= 129 || Brain.Screen.xPosition() <= 234){
LocationVal = 3;
}
}
else if (Brain.Screen.yPosition() >= 115 || Brain.Screen.yPosition() <= 230){
// First red button
if (Brain.Screen.xPosition() >= 12 || Brain.Screen.xPosition() <= 117){
LocationVal = 2;
}
// Second red button
else if (Brain.Screen.xPosition() >= 129 || Brain.Screen.xPosition() <= 234){
LocationVal = 4;
}
}
}
}
}
I’ve replaced the Autonomous functions with simple commands that either clear the screen or print “Hello”. The major problem that we are having is deciding when to run the function. We have to select the function we are going to use before the match starts, so it can’t be in the autonomous function. I’ve tried placing it in the pre_auton function, but that didn’t seem to work either. Any help on this problem would be very appreciated!