Resetting Gyro In VCS C++

  1. 7 weeks ago

    As the title suggests how should I reset my Gyro in VCS C++. I’m looking for a command like the .resetEncoder command. Any Ideas?

    @Gear Geeks Sample code?

    Let's say you had in your code:

    // <------- Something here that would set the gyro to 0.
    while(Gyro1.value(roationUnits::deg)) < 90){
       LeftMotor.spin(directionType::rev, 50, velocityUnits::pct);
       RightMotor.spin(directionType::fwd, 50, velocityUnits::pct);
    }
    LeftMotor.stop();
    RightMotor.stop();

    Change it to:

    double targetGyroValue; // earlier in the code
    
    targetGyroValue = Gyro1.value(roationUnits::deg)) + 90;
    while(Gyro1.value(roationUnits::deg)) < targetGyroValue){
       LeftMotor.spin(directionType::rev, 50, velocityUnits::pct);
       RightMotor.spin(directionType::fwd, 50, velocityUnits::pct);
    }
    LeftMotor.stop();
    RightMotor.stop();

    You really don't need to store huge numbers. Your gyro is unlikely to ever get to a really big or really small angle because you're generally turning and turning back or driving in a sort of box. So you should rarely see values breaking 1000 degrees.

  2. 6 weeks ago

    LordVader5

    Nov 30 V5 Beta Tester Longmont, Colorado 6047 EDR and 10424 VEX IQ

    We are having the same exact issue. Our programmers can't figure this out either and we have comp tomorrow.

  3. callen

    Nov 30 Braintree, MA, USA

    You really don't need to ever reset a gyro. I know it's nice from a cleanliness standpoint. But it doesn't really serve any other purpose. When you would reset the gyro, just read its value and store that value. Then make your targets equal to that value plus whatever you would have used before.

  4. Gear Geeks

    Nov 30 Event Partner, V5 Beta Tester Virginia, USA 8044

    Sample code?

  5. callen

    Nov 30 Answer Braintree, MA, USA
    Edited 6 weeks ago by callen

    @Gear Geeks Sample code?

    Let's say you had in your code:

    // <------- Something here that would set the gyro to 0.
    while(Gyro1.value(roationUnits::deg)) < 90){
       LeftMotor.spin(directionType::rev, 50, velocityUnits::pct);
       RightMotor.spin(directionType::fwd, 50, velocityUnits::pct);
    }
    LeftMotor.stop();
    RightMotor.stop();

    Change it to:

    double targetGyroValue; // earlier in the code
    
    targetGyroValue = Gyro1.value(roationUnits::deg)) + 90;
    while(Gyro1.value(roationUnits::deg)) < targetGyroValue){
       LeftMotor.spin(directionType::rev, 50, velocityUnits::pct);
       RightMotor.spin(directionType::fwd, 50, velocityUnits::pct);
    }
    LeftMotor.stop();
    RightMotor.stop();

    You really don't need to store huge numbers. Your gyro is unlikely to ever get to a really big or really small angle because you're generally turning and turning back or driving in a sort of box. So you should rarely see values breaking 1000 degrees.

  6. Gear Geeks

    Nov 30 Event Partner, V5 Beta Tester Virginia, USA 8044

    Thank you! My programmers are struggling with the gyro, too.

  7. callen

    Nov 30 Braintree, MA, USA

    If they're familiar with physics (since it's seen a lot there), you can tell them they're really looking for ∆ø to reach a value (90 degrees in my example), not ø.

    More explicitly, but harder to follow: setting ø = 0 somewhere just means ∆ø = øf - øi = øf - 0 = øf. My example just plugs in what was read for øi instead of the 0 that they want to force upon it.

  8. 3 weeks ago

    @Gear Geeks could you post a sample program you are currently using for your gyro sensor? We tried the one above but it seems to not be working right.

  9. @[TVA]Connor could you post a sample code for your gyro sensor? the one above isn't working.

  10. callen

    Dec 22 Braintree, MA, USA

    @bbot @Gear Geeks could you post a sample program you are currently using for your gyro sensor? We tried the one above but it seems to not be working right.

    If you tried what I posted, it won't. I just showed how to change from using a reset to not using a reset. I didn't write code that would work generally, just for a 90 degree turn in one direction. You would have to do more to take the direction of the turn into account, and adjust the angle.

 

or Sign Up to reply!