Gyro in PROS

So i was trying to get the value of a gyroscope.

pros::ADIGyro gyro(8)

this is the code i used

void op control(){
gyro.reset;
while(1){
blablabla code…
pros::lcd::print(0,“%d”,gyro.get_value());
}
}

the problem is that it only prints 0s

How can i solve this problem?

1 Like

Anyone knows? Very urgent

or can anyone teach me the correct way to use gyros or give me sample code?

Does the gyro work in general? Check in vcs if you can get values. If you can’t, most likely one of your cables is plugged in backwards.

I tried and it worked in pros, i also calibriated it, bet the values are so off (like 9 degrees)

gyro.get_value returns a double. Changing %d to %f may help.

Thanks i will try changing it to %f

But even if it converts a double value to a integer value, it should be at most off by 1 right?

I turned the gyro 90 degs, then turned back to origin, but the value says -9.

Also, i tried that i need to rotate it a lot past the origin to let the gyro change value(so i turned it 90 degrees and turned back to the origin and try turning it more past the origin)

Well i’m not a C/C++ expert but double is stored as a 64-bit value with the sign[bit 63] ,exponent[next lower 11-bits], and mantissa[lowest 52 bits]. %d expects a 32-bit. So printf may get the sign, exponent and some mantissa or just the lower mantissa. BTW, casting to an int may also work so: printf(“gyro=%d”,(int)(gyro.get_value()));

Also, the API says the value of the gyro is 10x the degrees of rotation. So 90 degrees would be 900 counts back. So 9 would be about 1 degree. Maybe that is due to drift. I don’t have a feel for how much drift there is b/c I have not used the gyro yet.

1 Like

std::cout <<gyro.get_value() << “\n”;

but the result is still glitchy lick before

Looking at the Gyro doc it says this:

Initializes a gyroscope on the given port. If the given port has not previously been configured as a gyro, then this function starts a 1 second calibration period.

Are you waiting 1 second in initialize() after you instance the gyro?

Is your PROS kernel up to date? I’ve dealt with teams having gyro issues which were fixed by updating the kernel.

(good call, but we insert a delay during instantiation)

go to know. I wasn’t sure how to read that statement.

Ah yeah we could probably stand to clarify that it blocks for 1300ms (that wasn’t always the case but it is now)