I don't know how to code the Vex V5 GPS sensor using Vex V5 pro software

Me and my team want to use the V5 GPS sensor for our robots skills this year. I know how to put it in the code and how to put it on the robot, and how to measure the offset of the sensor, but I have no idea how to code it and everything I see for coding help is using block V5 code but I have only ever used V5 pro. I was wondering what should I look into to start and how do I even start the process of coding the sensor to move the robot to a location on the field.

Here are the gps docs:

https://api.vexcode.cloud/v5/abstract/class/classvex_1_1gps

So, looks like you’ll initialize it in robot-config.cpp with

myGPS = GPS(port, x_origin, y_origin)

and then to use it, just use

x = myGPS.xPosition();
y = myGPS.yPosition();

and everything’s in mm for some reason.

Using the GPS data to move is a bit harder, and that part is up to you.

3 Likes

The vex gps sensor returns the position and orientation of the robot. You can use these values to program your own motion algorithms. There is an example program inside of vexcode pro v5. There are many prevoius posts about coding a vex GPS.
GPS Code Help
GPS Sensor, how to code?
GPS Sensor Coding Help
Autonomous coding and using gps and vision sensors

2 Likes

You can go to top right corner of your screen, press the question mark, and go to sensing. There, you can find many commands for GPS.

Mainly, it is used with the inertial sensor. Here is my code:

int gpsGetHeadingToPoint(int targetX=0,int targetY=0){
int targetHeading=0;
targetHeading=90-atan2((targetY-GPS.yPosition(mm)),(targetX-GPS.xPosition(mm)))/M_PI*180;
return targetHeading;
}

void inertialTurnToHeading(double targetHeading = 0){
double perror=999,derror=0, lasterror=0;
double kd=0.3;
double kp=1.5, pdspeed=0;
while(true){

perror=angleConvert(targetHeading-Inertial.heading());

derror=perror-lasterror;
lasterror=perror;
pdspeed=perror*kp+derror*kd;
//printf("%f,%f,%f\n",perror,Inertial.heading(),pdspeed);
driveTrainTurn(pdspeed);
if(fabs(perror)<2){
  break;
}
wait(20,msec);

}
driveTrainStop();
}

To use it: inertialTurnToHeading(gpsGetHeadingToPoint(plug in x coordinate,plug in y coordinate));

From my personal experience, GPS is pretty inaccurate, but if you don’t understand odometry, and want autoaim(kinda), use GPS.


just measure how much offset the GPS sensor is from the middle of your robot. Adjust it until you think the picture matches with your robot.

My guess is that offsets are so small that inches are not precise enough