// User defined function
void myblockfunction_drive_heading_x_v_kp(double myblockfunction_drive_heading_x_v_kp__heading, double myblockfunction_drive_heading_x_v_kp__x, double myblockfunction_drive_heading_x_v_kp__v, double myblockfunction_drive_heading_x_v_kp__kp);
float myVariable, error, output_velocity;
// User defined function
void myblockfunction_drive_heading_x_v_kp(double myblockfunction_drive_heading_x_v_kp__heading, double myblockfunction_drive_heading_x_v_kp__x, double myblockfunction_drive_heading_x_v_kp__v, double myblockfunction_drive_heading_x_v_kp__kp) {
leftmotor.setPosition(0.0, degrees);
rightmotor.setPosition(0.0, degrees);
if (myblockfunction_drive_heading_x_v_kp__v > 0.0) {
while ((leftmotor.position(degrees) < myblockfunction_drive_heading_x_v_kp__x)) {
error = myblockfunction_drive_heading_x_v_kp__heading - BrainInertial.heading();
output_velocity = error * myblockfunction_drive_heading_x_v_kp__kp;
leftmotor.setVelocity((myblockfunction_drive_heading_x_v_kp__v - output_velocity), percent);
rightmotor.setVelocity((myblockfunction_drive_heading_x_v_kp__v + output_velocity), percent);
leftmotor.spin(forward);
rightmotor.spin(forward);
wait(20, msec);
}
}
else {
while ((leftmotor.position(degrees) > myblockfunction_drive_heading_x_v_kp__x)) {
error = myblockfunction_drive_heading_x_v_kp__heading - BrainInertial.heading();
output_velocity = error * myblockfunction_drive_heading_x_v_kp__kp;
leftmotor.setVelocity((myblockfunction_drive_heading_x_v_kp__v - output_velocity), percent);
rightmotor.setVelocity((myblockfunction_drive_heading_x_v_kp__v + output_velocity), percent);
leftmotor.spin(forward);
rightmotor.spin(forward);
wait(20, msec);
}
}
leftmotor.stop();
rightmotor.stop();
}
// "when started" hat block
int whenStarted1() {
leftmotor.setStopping(brake);
rightmotor.setStopping(brake);
BrainInertial.calibrate();
while (BrainInertial.isCalibrating()) { task::sleep(50); }
myblockfunction_drive_heading_x_v_kp(90.0, 100.0, 70.0, 3.0);
return 0;
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
whenStarted1();
}
Your code is not very readable. if you want help try to add comments, and spaces. It looks like you also switched it from a block program to C++, because as fat as I know no one calls a function 'myblockfunction_drivePheading_x_v_kp__kp" Programing it in block switch is easier at first. Actual help:
It looks like you are looking at “leftmotor position” not gyro, this would totaly mess it up. PID is based on Gyro’s not motor degrees.
2. You are defining a void function (No output parameters) but then trying to use a output parameter.
3. The last bit of your code is readable, but this is weird code. If you make it more readable, I might try and help more