Has anyone tried resetting the gyro in Robot Mesh IQ C++?

Hello,

I have tried programming my gyro to reset back to 0, but when I run the program in my robot, it ends up spiking up instead of resetting?

Any thoughts?

This is my code:

// VEX IQ C++ Project
    #include "vex.h"
    #include "math.h"
    using namespace vex;

//#region config_globals
vex::brain  Brain;
vex::motor  leftMotor(vex::PORT1);
vex::motor  rightMotor(vex::PORT3, true); // Reverse Polarity
vex::gyro   jyro(vex::PORT5);
vex::bumper bumper(vex::PORT9);
//#endregion config_globals

void Display()
{
    while(true)
    {
        Brain.Screen.printLine(1, "Gyro : %f", jyro.rotation(deg));
        
        Brain.Screen.clearScreen();
    }
}


void TurnLeft(int distance)
{
    jyro.resetRotation();
    
    while(jyro.rotation(deg) < distance)
    {
        leftMotor.spin(reverse);
        rightMotor.spin(fwd);
    }
    leftMotor.stop(hold);
    rightMotor.stop(hold);
}


int main(void) {
    // Start here
    thread t(Display);
    
   jyro.startCalibration();

  while(jyro.isCalibrating())
  {
       this_thread::sleep_for(3000);
  }

    TurnLeft(90);
}

Thank you!

I don’t have any ideas on how to help with this, but if you posted your code or made a viewable copy in robot mesh, I’m sure lots of other people could help.

1 Like

I totally forgot about it! Thanks a lot for reminding me!

1 Like

I don’t really understand C++, so I might be wrong here, but it looks like you reset the gyro at the start of the TurnLeft function instead of at the end.

What kind of values is it spiking to? Around 0-360 or arbitrarily high?

1 Like

I was thinking the same thing. Also you say you are turning left but your inequality and motor directions would suggest that you want to go right. That will get super confusing down the road and will often cause your robot to spin indefinitely or not at all.

4 Likes

That would be a good idea, but I don’t want to reset it at the end, because I want to ensure that the Gyro is at 0 when the functions begins so that I get it more accurate turns.

2 Likes

It spikes to the 3000 mark

1 Like

Yes, sorry. I just fixed my code, I did not realize it as I was typing it over

Well there goes my guess. Could be that it is a hardware issue. Have you tried using another gyroscope? Also is all of your firmware up to date? Does it do this if you reset your gyro before running your function because if it does it is likely not a problem with your code and some other issue.

1 Like

Well, the thing is that I work for a Robotic institution, so the same thing happens in classes where we have 12 robots at one time. Yes, they were updated to the latest version. And we also calibrated our gyros during the beginning of the program.