text
stringlengths 0
715
|
---|
Controller1.Screen.setCursor(3, 1);
|
Controller1.Screen.print(i);
|
}
|
void printControllerSetup() {
|
//sets up the controller to be printed on
|
Controller1.Screen.clearLine(3);
|
Controller1.Screen.setCursor(3, 1);
|
}
|
//graphing data, used for flywheel velocity control
|
void graphFlywheelVelocity(std::vector<int> velocityHistory, std::vector<int> powerHistory) {
|
//Given some data, display a graph showing the current velocity and voltage draw of the flywheel motor
|
//the velocity history is a list of integers (range: 0-the maximum flywheel speed) that is the current speed of the flywheel, in RPM
|
//the power history is a list of integers (range: 0-100) that is the percentage amount representing how much power the motors applied.
|
//For example, if the motor was spun at half power at a certain point in time, this corresponding value would be 50
|
//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 some helpful information on the top of the brain screen
|
Brain.Screen.setCursor(1, 1);
|
Brain.Screen.clearLine(1);
|
Brain.Screen.print(Flywheel.current());
|
Brain.Screen.print(" Amperes ");
|
Brain.Screen.print(Flywheel.velocity(rpm) * 5); //times 5 to account for the gear ratio of the flywheel
|
Brain.Screen.print(" RPM ");
|
Brain.Screen.print(Flywheel.voltage());
|
Brain.Screen.print(" Volts ");
|
//establish parameters that determine where the graph is drawn on the screen
|
//for y, bottom (0) is 215 and top (100) is 60
|
int minY = 60;
|
int maxY = 230;
|
//for x, start at 10 and end at 470, so don't draw the graph within 10px of the border
|
int minX = 10;
|
int maxX = 470;
|
//horizontalScale adjusts how much of the graph to draw on the screen (ex: last 3 seconds or last 10 seconds)
|
float horizontalScale = 400;
|
//loop through every data point and draw a line between it and the next one, to create a smooth graph.
|
for (int i = std::max((int)velocityHistory.size() - (int)horizontalScale, 0); i < velocityHistory.size() - 1; i++) {
|
//calculate where to draw this part of the graph
|
int x = maxX - (maxX - minX) * (velocityHistory.size() - i) / horizontalScale;
|
//graph velocity
|
Brain.Screen.setPenColor(green);
|
Brain.Screen.drawLine(x, maxY - (float)velocityHistory.at(i) / flywheelTargetRPM * (maxY - minY), x + (float)(maxX - minX) / horizontalScale, maxY - (float)velocityHistory.at(i + 1) / flywheelTargetRPM * (maxY - minY));
|
//graph power
|
Brain.Screen.setPenColor(orange);
|
Brain.Screen.drawLine(x, maxY - powerHistory.at(i) / 100.0f * (maxY - minY), x + (float)(maxX - minX) / horizontalScale, maxY - powerHistory.at(i + 1) / 100.0f * (maxY - minY));
|
}
|
}
|
//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);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.