How to create a turning formula using GPS on PROS

How would you make it so I can turn to a certain position like (-100, 0) would you need a complicated formula if so what would it be? 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);
      

    }

    }
    }
1 Like

You can use the trigonometric function tan inverse of the difference in y/ difference in x. In code this would be atan2(difference in y, difference in x)