text
stringlengths
0
715
//minimum voltage of 11V * .2
/*if (std::abs(slewRate) != .12) {
if (std::abs(motorPower) < 0.2) {
if (motorPower > 0) {
motorPower = 0.2;
} else {
motorPower = -0.2;
}
}
}*/
//apply motor voltages
Left1.spin(forward, 11 * motorPower * -1, volt);
Left2.spin(forward, 11 * motorPower * -1, volt);
Left3.spin(forward, 11 * motorPower * -1, volt);
Right1.spin(forward, 11 * motorPower, volt);
Right2.spin(forward, 11 * motorPower, volt);
Right3.spin(forward, 11 * motorPower, volt);
//update histories
errorHistory.push_back(error);
powerHistory.push_back(motorPower);
time += 20;
//update final variables
//printController(error);
//break out of the loop if we have reached the target or B is pressed
//we have reached the target if the error is less than 5 and the previous error is similar
if (absolute) {
if (Controller1.ButtonB.pressing() || exitPID || ((std::abs(error) < 0.4) && std::abs(error - prevError) < 1)) {
break;
}
} else {
if (Controller1.ButtonB.pressing() || exitPID || ((std::abs(error) < 0.5) && std::abs(error - prevError) < 2)) {
break;
}
}
prevMotorPower = motorPower;
prevError = error;
graphPID(errorHistory, powerHistory, driveDistance, error, time);
//don't hog CPU
wait(20, msec);
}
wait(20, msec); //allow time for status update to draw itself
//graph the PID at the end
drawMode = 1;
graphPID(errorHistory, powerHistory, driveDistance, error, time);
Left1.stop();
Left2.stop();
Left3.stop();
Right1.stop();
Right2.stop();
Right3.stop();
return 0;
}
void aDrive(float distance) {
driveDistance = distance;
drivePID();
}
void aTurn(float distance) {
driveDistance = distance;
turnPID(false);
}
void aDriveFor(int speed, int time) {
//drive the robot forward (or backward if speed is negative) for a specified amount of milliseconds
Left1.spin(forward);
Left2.spin(forward);
Left3.spin(forward);
Right1.spin(forward);
Right2.spin(forward);
Right3.spin(forward);
Left1.setVelocity(speed, percent);
Left2.setVelocity(speed, percent);
Left3.setVelocity(speed, percent);
Right1.setVelocity(speed, percent);
Right2.setVelocity(speed, percent);
Right3.setVelocity(speed, percent);
wait(time, msec);
Left1.stop();
Left2.stop();
Left3.stop();
Right1.stop();
Right2.stop();
Right3.stop();
}
//below code copied from jpearman on vexforum
int screen_origin_x = 150;
int screen_origin_y = 20;
int screen_width = 316;
int screen_height = 212;
// function to draw a single object
void drawObject( vision::object &obj, vex::color c ) {
int labelOffset = 0;
Brain.Screen.setPenColor( vex::color::yellow );
Brain.Screen.drawRectangle( screen_origin_x + obj.originX, screen_origin_y + obj.originY, obj.width, obj.height, c );
Brain.Screen.setFont( vex::fontType::mono12 );
if( obj.originX > 280 )
labelOffset = -40;
if( obj.originY > 10 )
Brain.Screen.printAt( screen_origin_x + obj.originX + labelOffset, screen_origin_y + obj.originY-3, "Sig %o", obj.id );
else
Brain.Screen.printAt( screen_origin_x + obj.originX + labelOffset, screen_origin_y + obj.originY+10, "Sig %o", obj.id );
}