Coding gps in pros visual studio

does anyone have any suggestions to get started in programming gps in pros? cant seem to find a lot of info? maybe some sample start code or someting ?
thanks

Reading the documentation is a good start.

Here is the PROS API for the GPS Sensor.
Here is the tutorial for using it.

Hope this helps!

2 Likes

Assuming you meant PROS and not vexcode PRO, your answer is here:

https://pros.cs.purdue.edu/v5/tutorials/topical/gps.html

Thank you for your help !!! Will have my son look into it

I looked through it but when I inset the commands it doesn’t work. Also what is the command that insets the x position or the y position because in the documentary it doesn’t really explain and it instead it says to “set the position” and does it manually.

Typically, when asking programming questions on an online forum, you will get more mileage the more specific you are about the problems you encounter. There are a lot of ways that a command might “not work.” Which way did you find? Maybe a squiggly red line under the code? Maybe the robot output the wrong position? Maybe you’re actually using Vexcode Pro but asked about “pros” which is something else entirely? Clarity helps.

5 Likes

Same thing I said on the other post:
It would be helpful to us if you could post screenshots of the code that you tried and whatever error messages you got.

I’m not entirely sure what you mean by “insets the x position or the y position”. If you are talking about accounting for the offset of the gps sensor from the center of your robot, you are looking for this function, very nicely named set_offset.

2 Likes

@BennyBoy
@2775Josh

Ok let me clarify more about what I am trying to write. In addition, firstly, yes I am using PROS from visual studio not the Vex Pros. Next, let me clarify the GPS part of the code. And here’s an example of the code I did:

#include "robot.h"
#include "gps.h"
#include "pros/adi.hpp"
#include "pros/motors.h"
using namespace pros;
using namespace std;

int status;
int gps_e;
#define GPS_PORT 9
#define X_INITIAL -1.15
#define Y_INITIAL 1.45
#define HEADING_INITIAL 90
void gpsmove() {
  double *x;
    double *y;
     

    while (true) {
      pros::c::gps_status_s_t status;
      status = gps.get_status();


        gps.get_offset(x, y);
        std::int32_t get_offset(double* xOffset, double* yOffset);

        
        pros::delay(20);

  
  // pros::Gps gps(GPS_PORT);
  // pros::Gps gps(GPS_PORT, X_INITIAL, Y_INITIAL, HEADING_INITIAL);
 
    pros::screen::print(TEXT_MEDIUM, 1, "X Position: %3f", X_OFFSET);
    pros::screen::print(TEXT_MEDIUM, 2, "Y Position: %3f", Y_OFFSET);
    // pros::screen::print(TEXT_MEDIUM, 3, "Pitch: %3f", HEADING_INITIAL);
    // pros::screen::print(TEXT_MEDIUM, 3, "e: %3f", status);
    }
}

In addition, basically I am trying to print the x and y position of the bot using the GPS sensor. But the problem is when I print the x position it always gives me the same number. Also, I think this code doesn’t work because I am not using the right command or I am using the command incorrectly. In addition, if this is completely wrong what command would I use to get the x-position of the robot? In addition, I am trying to get the same number you get when you look on the brain screen, where the brain tells you its x, y, and heading direction.

Also, I would like to thank you for all the work you did to help me make this and thank you for all the help you given me. Including the time and effort you put into it.


This is the relevant section of the documentation.

You’re doing good with status = gps.get_status() (although I think you should move the line pros::c::gps_status_s_t status; to be outside the while loop). From here, to access the data just use status.x and status.y.
So all other code aside,

pros::screen::print(TEXT_MEDIUM, 1, "X Position: %3f", status.x);
pros::screen::print(TEXT_MEDIUM, 2, "Y Position: %3f", status.y);

would do what you want, I believe.

1 Like

Hello! I made it so the GPS prints the coordinates and also made it so the robot will keep driving until it reaches that certain x position. But the main problem is I can’t make it go to a certain position like (-100, 0) unless I make it turn using a complicated formula. Furthermore, what would the formula be if I wanted it to turn into a certain coordinate. In addition, here is some of the code I did.

#include "robot.h"
#include "gps.h"
#include "pros/adi.hpp"
#include "pros/motors.h"
using namespace pros;
using namespace std;

int status;
double gps_x;
double gps_y;
int be;
int ce;
int ae;
int angle;
#define xthing 0
#define ything 0

#define GPS_PORT 9
#define X_INITIAL -1.15
#define Y_INITIAL 1.45
#define HEADING_INITIAL 90
void gpsmove() {
  double *x;
    double *y;
     
pros::c::gps_status_s_t status;
    while (true) {
      
      status = gps.get_status();
      gps_x = status.x * 100;
      gps_y = status.y * 100;
      


        gps.get_offset(x, y);
        std::int32_t get_offset(double* xOffset, double* yOffset);

        
        pros::delay(20);

  
  // pros::Gps gps(GPS_PORT);L);
 
  // pros::Gps gps(GPS_PORT, X_INITIAL, Y_INITIAL, HEADING_INITIA
    // pros::screen::print(TEXT_MEDIUM, 1, "X Position: %3f", X_OFFSET);
    // pros::screen::print(TEXT_MEDIUM, 2, "Y Position: %3f", Y_OFFSET);
    // pros::screen::print(TEXT_MEDIUM, 3, "Pitch: %3f", HEADING_INITIAL);
    // pros::screen::print(TEXT_MEDIUM, 3, "e: %3f", status);
    pros::screen::print(TEXT_MEDIUM, 1, "X Position: %3f", gps_x);
pros::screen::print(TEXT_MEDIUM, 2, "Y Position: %3f", gps_y);
  
  


  
    if(xthing > gps_x) {
      LF.move(100);
      LB.move(100);
      RF.move(100);
      RB.move(100);
      
      
    } else{
      LF.brake();
      LB.brake();
      RF.brake();
      RB.brake();

      // LF.move(0);
      // LB.move(0);
      // RF.move(0);
      // RB.move(0);
      

    }

    }
    }