text
stringlengths 0
715
|
---|
Controller1.Screen.setCursor(3, 1);
|
}
|
//graphing data, used for PID tuning
|
void graphPID(std::vector<int> errorHistory, std::vector<float> powerHistory, int goal, float error, int time) {
|
//goal is the PID goal
|
//error history is a list of all of the errors
|
//powerHistory is -1 to 1 of the power applied
|
//setup: clear screen and draw the target line
|
Brain.Screen.clearScreen();
|
Brain.Screen.setPenWidth(2);
|
Brain.Screen.setPenColor(white);
|
Brain.Screen.drawLine(0, 60, 480, 60);
|
Brain.Screen.setPenWidth(1);
|
Brain.Screen.setPenColor(green);
|
//also display amps
|
Brain.Screen.setCursor(1, 1);
|
Brain.Screen.clearLine(1);
|
Brain.Screen.print(" Final Error: ");
|
Brain.Screen.print(error);
|
Brain.Screen.print(" Time: ");
|
Brain.Screen.print(time);
|
//y positions
|
//bottom (0) is 215
|
//top (100) is 60
|
//above (110) (overshoot) is <60
|
int minY = 60;
|
int maxY = 230;
|
//for x, start at 30 and end at 450
|
int minX = 10;
|
int maxX = 470;
|
for (int i = 0; i < errorHistory.size() - 1; i++) {
|
int x = minX + (maxX - minX) * i / errorHistory.size();
|
//graph velocity
|
Brain.Screen.setPenColor(green);
|
Brain.Screen.drawLine(x, minY + (float)errorHistory.at(i) / goal * (maxY - minY), x + (float)(maxX - minX) / errorHistory.size(), minY + (float)errorHistory.at(i + 1) / goal * (maxY - minY));
|
//graph power
|
//change color based on direction
|
if (powerHistory.at(i) > 0) {
|
Brain.Screen.setPenColor(orange);
|
} else {
|
Brain.Screen.setPenColor(yellow);
|
}
|
Brain.Screen.drawLine(x, maxY - std::abs(powerHistory.at(i)) * (maxY - minY), x + (float)(maxX - minX) / errorHistory.size(), maxY - std::abs(powerHistory.at(i + 1)) * (maxY - minY));
|
}
|
}
|
void drawRobotPath(std::vector<int> x, std::vector<int> y) {
|
//draws the path of the robot (as discerned from odometry) on the brain of the robot
|
Brain.Screen.clearScreen();
|
Brain.Screen.setPenWidth(1);
|
Brain.Screen.setPenColor(green);
|
Brain.Screen.drawLine(0, 120, 480, 120);
|
Brain.Screen.drawLine(240, 0, 240, 240);
|
Brain.Screen.setPenColor(white);
|
Brain.Screen.setPenWidth(2);
|
int originX = 240;
|
int originY = 120;
|
float scale = 2;
|
for (int i = 0; i < x.size() - 1; i++) {
|
Brain.Screen.drawLine(x.at(i) * scale + originX, 240 - (y.at(i) * scale + originY), x.at(i + 1) * scale + originX, 240 - (y.at(i + 1) * scale + originY));
|
}
|
//draw robot as dot
|
Brain.Screen.setPenColor(red);
|
Brain.Screen.drawCircle(x.at(x.size() - 1) * scale + originX, 240 - (y.at(x.size() - 1) * scale + originY), 5);
|
}
|
/*template for a thread/task (task is a higher level abstraction of thread):
|
int myTaskCallback() {
|
while (true) {
|
//do something
|
wait(25, msec);
|
}
|
// A task's callback must return an int, even though the code will never get
|
// here. You must return an int here. Tasks can exit, but this one does not.
|
return 0;
|
}
|
in some other function like main():
|
task myTask = task(myTaskCallback);
|
*/
|
void driveCode() {
|
//drives the robot around based on controller input, double arcade controls
|
//don't drive if the robot is currently being controlled autonomously
|
if (auton) return;
|
Left1.spin(forward);
|
Left2.spin(forward);
|
Left3.spin(forward);
|
Right1.spin(forward);
|
Right2.spin(forward);
|
Right3.spin(forward);
|
int forward1 = Controller1.Axis3.value();
|
int turn = Controller1.Axis1.value();
|
//fix drift
|
if (std::abs(forward1) < 7) forward1 = 0;
|
if (std::abs(turn) < 7) turn = 0;
|
//calculate proper motor powers
|
int left;
|
int right;
|
int curveTime = 0;
|
if (curveDrive) {
|
//curvature drive, yay
|
//adjust the straight variable to be non-linear
|
/*
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.