Gyro in PROS

#1

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

#2

Anyone knows? Very urgent

0 Likes

#3

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

0 Likes

#4

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.

0 Likes

#5

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

0 Likes

#6

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

0 Likes

#7

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)

0 Likes

#8

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

#10

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

but the result is still glitchy lick before

0 Likes

#11

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?

0 Likes

#12

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

0 Likes

#13

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

0 Likes

#14

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

0 Likes

#15

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

0 Likes

How to Properly Initialize Gyro on PROS V5 (URGENT)