Hello, I have been working on GPS for a little while now. I can get the robot to travel along the X axis to the point I want it to go to from almost any place on the field. The only issue is that when it turns on the Y axis, it over or under calculates. I was just wondering if there was any line of code that helps fix over calculation for turning.
Can you post what code you currently have?
void driveToPositionX(double x) {
// Reorient the robot before driving along the X-axis
if (GPS8.xPosition(mm) < x) {
referenceAngle = 90;
}
else {
referenceAngle = 270;
}
// Using an absolute reference angle along with the GPS heading,
// we can turn the robot to face the correct direction before driving along the X-axis
GPS8.calibrate();
Drivetrain.turnFor(right, (referenceAngle - GPS8.heading()), degrees, true);
Drivetrain.drive(reverse);
// Keep driving until the GPS position for the X-axis is within 20mm of the target X position
while (!(GPS8.xPosition(mm) - x > -20 && GPS8.xPosition(mm) - x < 20)) {
wait(0.1, seconds);
GPS8.calibrate();
}
// This will allow the drivetrain to stop in time, preventing the robot from overshooting the target
Drivetrain.stop();
}
void driveToPositionY(double y) {
// Reorient the robot before driving along the Y-axis
if (GPS8.yPosition(mm) < y) {
referenceAngle = 0;
}
else {
referenceAngle = 180;
}
// Using an absolute reference angle along with the GPS heading,
// we can turn the robot to face the correct direction before driving along the Y-axis
GPS8.calibrate();
Drivetrain.turnFor(right, (referenceAngle - GPS8.heading()), degrees, true);
Drivetrain.drive(reverse);
// Keep driving until the GPS position for the Y-axis is within 20mm of the target Y position
while (!(GPS8.yPosition(mm) - y > -20 && GPS8.yPosition(mm) - y < 20)) {
wait(0.1, seconds);
GPS8.calibrate();
}
// This will allow the drivetrain to stop in time, preventing the robot from overshooting the target
Drivetrain.stop();
}
void printPosition() {
// Print GPS position values to the V5 Brain
Brain.Screen.print("X: %.2f", GPS8.xPosition(mm));
Brain.Screen.print(" Y: %.2f", GPS8.yPosition(mm));
Brain.Screen.newLine();
}
int main() {
// Calibrate the GPS before starting
GPS8.calibrate();
while (GPS8.isCalibrating()) { task::sleep(50); }
Drivetrain.setTurnVelocity(25, percent);
// Print the starting position of the robot
printPosition();
// Drive the robot to the specified X and Y position
driveToPositionX(0);
driveToPositionY(0);
// Print the ending position of the robot
printPosition();
}
It is the example code for GPS.
Hi,
The link below is to the vex explanation of the GPS sensor, which might be useful if you haven’t read it already. To clarify, I am assuming the problem that you have is with the robot turning exactly on the axis, not with driving the correct distance on that axis.
If so, I think an incorrect offset (negative/positive, or incorrectly calculated) might be a cause of a miscalculation for the heading. You could try running a program that just prints the GPS heading and see if it matches your observations closely. -Alternatively, if the error is small enough, it might just be the drivetrain moving too quickly or the wheels slipping. You might be able to link the drivetrain to the rotation detection in the GPS as opposed to simply giving it a # of degrees to turn.
Lastly, if moving on the axis (not turning) is an issue, it might be caused by the use of GPS8.calibrate(). According to jpearman on another thread, the .calibrate does nothing but delay for 200 milliseconds, which means you would only be checking if you have reached the correct zone every 3/10 second instead of every 1/10 second. (This thread)
I recommend using a PID Controller here, as it allows you to negate the wheel’s slippage as much as possible.
Highly Recommended article (You will have to translate some pseudocode from Java, or you could fully implement the equations on your own.) - The PID Controller - CTRL ALT FTC
Feel Free to ask any questions and ping me if you would like further explanation!
-Blaziumm