0

Im trying to make a code using the GPS sensor that can drive to a specific coordinate using if statements. I've only done the X portion, and it works, but I'm looking for how I can stop checking the X statement, and move on to the Y:

void driveTo (int xPos, int yPos) {
  printPos();
  if(xPos > 0){
   Drivetrain.turnToHeading(90, degrees);
   while (GPS14.xPosition(mm) < xPos) {
     Drivetrain.drive(forward);
   }
    Drivetrain.stop();
 }
    if(xPos < 0){
 Drivetrain.turnToHeading(-90, degrees);
 while (GPS14.xPosition(mm) > xPos) {
    Drivetrain.drive(forward);
   }
    Drivetrain.stop();
   }
 }

 int main() {
   driveTo (0, 0);
 }`
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • If you're looking for improvements on already working code, ask at https://codereview.stackexchange.com/ please! – πάντα ῥεῖ Mar 22 '23 at 16:52
  • @πάνταῥεῖ, it looks like the code isn't yet working (it's only considering the x ordinate, but should also consider y), so not ready for review. – Toby Speight Mar 22 '23 at 17:05
  • @TobySpeight well, then the question is simply lacking details / debugging details here and should be closed. As is it's _off-topic_ here. – πάντα ῥεῖ Mar 22 '23 at 17:07

0 Answers0