V5 inertia sensor code

I just changed the line of code and it still does not move or attempt to move the robot

You don’t need the waitUntil(true) thing. You would either calibrate the code in auton or pre-auton, whichever you prefer. If you calibrate it in pre auton, you will need a competition switch. You have to wait until the robot is set up how you want it, then press run on the controller, having it plugged into the competition switch the whole time. Then you would wait a few seconds and run the code. If you calibrate it in auton, you would just need to calibrate the inertial sensor, and then wait 2 seconds and then go on to the actual program. And yes, You just copy/paste that into auton. It will work.

1 Like

So like I said, you could either calibrate it in auton or pre auton. I would rather you calibrate it in pre auton because it doesn’t take away two seconds from the program. This is an example of calibrating it inside of auton though.

inertial.calibrate();
wait(2,seconds);
FL.spin(fwd, 20, pct);
BL.spin(fwd, 20, pct);
FR.spin(reverse, 20, pct);
BR.spin(reverse, 20, pct);

waitUntil(inertial.heading(degrees)>40 and inertial.heading(degrees) < 43);

FL.stop();
BL.stop();
FR.stop();
BR.stop();
1 Like

sorry for the screen shot but its the only way to show the errors

image

You’re not using the instance of the inertial sensor in that example. Looks like it should be a capital I for inertial.

Inertial is your device instance
inertial is the base class

Top tip: name your devices something that’s not so close to the class name, it makes it a lot harder to make mistakes like this.

3 Likes

In our code, we the inertial sensor “gyro” or “rotSensor”, as examples for this exact reason.

where it says inertial, you would put the name of your inertial sensor. so if it was named inertiathing, it would be inertiathing.calibrate(); and inertiathing.heading(degrees)

1 Like

yes. My inertial sensor is literally named mom.

2 Likes
void tug(int deg,int spe){

if(deg < 0){

  FrontL.spin(directionType::rev, spe,velocityUnits::pct);
  BackL.spin(directionType::rev, spe,velocityUnits::pct);
  FrontR.spin(directionType::rev, spe,velocityUnits::pct);
  BackR.spin(directionType::rev, spe,velocityUnits::pct);

waitUntil(Inertial.heading(degrees)>(deg - 2) && Inertial.heading(degrees) < (deg + 2));

FrontL.stop();
BackL.stop();
FrontR.stop();
BackR.stop();

}
if(deg >0){

FrontL.spin(directionType::fwd, spe,velocityUnits::pct);
BackL.spin(directionType::fwd, spe,velocityUnits::pct);
FrontR.spin(directionType::fwd, spe,velocityUnits::pct);
BackR.spin(directionType::fwd, spe,velocityUnits::pct);

waitUntil(Inertial.heading(degrees)>(360 - ((deg - 2)*-1)) && Inertial.heading(degrees) < (360 - ((deg + 2)*-1)));

FrontL.stop();
BackL.stop();
FrontR.stop();
BackR.stop();

}
} 

So I have taken the code that you provided and if I put it into the regular auton it does work even though it always overshoots its target but i put it into the funcion above the only problem is that the robot doesn’t stop

degree is never below zero. it is 1-360.

1 Like

Try this:

void tug(int deg,int spe){
while(1){
  if(deg < 0){

    FrontL.spin(directionType::rev, spe,velocityUnits::pct);
    BackL.spin(directionType::rev, spe,velocityUnits::pct);
    FrontR.spin(directionType::rev, spe,velocityUnits::pct);
    BackR.spin(directionType::rev, spe,velocityUnits::pct);

    if (Inertial.heading(degrees)>(deg - 2) && Inertial.heading(degrees) < (deg + 2)){
      FrontL.stop();
      BackL.stop();
      FrontR.stop();
      BackR.stop();
    }

  }
  if(deg >0){

    FrontL.spin(directionType::fwd, spe,velocityUnits::pct);
    BackL.spin(directionType::fwd, spe,velocityUnits::pct);
    FrontR.spin(directionType::fwd, spe,velocityUnits::pct);
    BackR.spin(directionType::fwd, spe,velocityUnits::pct);

    if(Inertial.heading(degrees)>(360 - ((deg - 2)*-1)) && Inertial.heading(degrees) < (360 - ((deg + 2)*-1))){
      FrontL.stop();
      BackL.stop();
      FrontR.stop();
      BackR.stop();
    }
  }
}

sadly this did not work the function still never stopped it just kepted doing 360s