So what is the offset value mean?does the gyro sensor measure values in degrees? If not what are the values of the gyro sensor (ie. is it -100 to 100, or something else?)

. Similar to encoders, gyros measure the number of angles from the point where you zero the gyro. For example, if you zero a gyro, then turn clockwise, it will read 90 when you have turned 90 degrees. Similarly, if you want to make sure you have done 2 full rotations, then the degree count would be 720. Likewise, if you turn the other way, the numeral number would be the same, but the value would be negative ( -90 for 90 degrees in the other direction). That is how an encoder essentially works. Like an encoder but does it with angle of rotation.

Now, if I am wrong, please let me know on this, I believe an offset value is used so that no data is negative. I guess this creates a range of positive numbers, but for the purpose for FTC, I would think using an offset value might be confusing.

Sat Dec 27, 2008 9:07 pm

AvidProgrammer

Rookie

Joined: Wed Jun 25, 2008 6:07 pmPosts: 46

Re: Where can i find out how to use the gyro sensor?

Arkarind,

Have you already bought a gyro sensor? If so, the best place to start would be to try the "HiTechnic Gyro.c" sample program. To find it:

1) Open RobotC2) Go to File -> Open Sample Program3) Open the "3rd Party Samples" directory4) You will find the "HiTechnic Gryo.c" file there

When you run the demo (which wants the sensor on port 3), you will notice that the program is able to display the difference between the angle of where the gyro is now, and where it was when the program started. In that regard, you can use it a little like a compass sensor, to determine which way your robot is pointing. Unlike the compass, though, you can use it along any rotational axis, not just the plane parallel to the floor.

It's important to realize, though, that the value you're seeing there is not the value that is being read directly from the gyro itself. In it's raw form, the gyro gives back sensor values to indicate the current angular velocity. What that means, is that if you hold the sensor steady, and read the raw values, you will get a value of 0, regardless of which direction the gyro is pointing. You would only see the value change while you are rotating. The value itself is measured in degrees/second. A value of 10, for example, should indicate that the sensor is currently rotating at about 10 degrees per second. (To experiment with the raw values, hook up the gyro and use the "try me" program for the light sensor. It will be able to show the raw gyro values and give you and idea of what's going on.)

If you play with the raw values, you'll notice that even when you hold the gyro steady, you don't actually get values of 0. I just tried it with my gyro, and was getting values of about 40. That's why the code recommends you subtract off an offset from the value read. In my case, I would want the offset to be 40, to accommodate for the bias being introduced by the sensor. As another note, it's important to realize that the offset value changes over time, and may even change while your robot is running its program. (That's just how gyros are.)

The reason the "HiTechnic Gyro.c" file is able to show the current angle, rather than just the rotational velocity, is that it is using an underlying GyroDriver.c file (also in the same directory) that handles the math of converting from angular velocity to angular position for you. The GyroDriver.c file, which is included by the demo program, creates a secondary task that continuously polls the raw values and integrates them into position value. It's really a convenient bit of work that has been done for you. (Thanks, RobotC team!)

If you're using the GyroDriver.c file in your own program to get position values, rather than velocity values, then what Sunny1261 said is correct. You can use the gyro pretty much like you would use the motor encoders. The 'offset' you asked about, though, isn't really meant to keep you from getting negative values. Negative values are fine. (They just indicate that you turned counter-clockwise past the point where the driver was initialized.) The 'offset' in the original code is related to the actual sensor bias which is hidden for you by the GyroDriver file.

Good luck with the gyro! It's a really neat sensor.

Sat Dec 27, 2008 11:54 pm

HiTechnic

Rookie

Joined: Thu Mar 20, 2008 6:17 amPosts: 1

Re: Where can i find out how to use the gyro sensor?

There are a couple of things to consider when using the gyro. The output of the gyro is a raw value from 0 - 1023 and will give you the rate of rotation in degrees / second. To get this simply read either the “SensorRaw[xx]” or “SensorValue[xx]”.

At rest you should see a value of ~ 600 which is the offset so if you subtract this value from the raw value it should give you 0 at rest. The offset may vary a little with temerature.

In order to dertermine an accurate angle of rotation you would have to include a calibration factor in the calculation and this can vary with each sensor. The GyroDriver.c does not do this so the result can be quite inaccurate. To determine the accuracy of your gyro without calibration, mount your gyro on a wheel or other fixture so it can be accurately turned through 90 or 180 degrees and run the HiTechnic Gyro.c example to see how close the result is to the actual angle turned.

SteveHiTechnic Support

_________________Steve
HiTechnic

Fri Jan 16, 2009 5:10 pm

Sunny1261

Novice

Joined: Thu Oct 09, 2008 7:58 pmPosts: 79

Re: Where can i find out how to use the gyro sensor?

is fGyroAngle the variable we use to call to check the value of the gyro?

Sat Jan 31, 2009 10:04 pm

Sunny1261

Novice

Joined: Thu Oct 09, 2008 7:58 pmPosts: 79

Re: Where can i find out how to use the gyro sensor?

Sorry for the double post, but when I went back to code the Gyro, RobotC gave me the error that it cannot find the GyroDriver.c include file. I went snooping and i found that the GyroDriver.c file was not in the includes folder. Yet, when i download the sample code, it runs fine, but when I put it into my code...it doesn't recognize it. The code is.

tempSensors.gyro.rate = SensorValue[GyroSensor]; // calculate the t0 rate so the first tempSensors.gyro.rate *= 1000; // average is good tempSensors.gyro.rate -= tempSensors.gyro.bias;

time1[GyroTimer] = 0; // Use a timer to calculate dt

That'll recalculate a bias value you can use. I've found this can't be precalculated...it must be done as close to when you want to use the gyro as possible. The cheapo sensor in the Hitechnic gyros is very very very sensistive to temp, angle of the floor, phase of the moon

Now periodically in your code call the following. Personally, I do it in a dedicated task that processes all the sensors every 10 msec.

You'll have to use your own variables as the example uses some global variable structures that I can access from anywhere in the program.

Also, some of the complexity above is because I use integer math. Mostly because I'm paranoid about the RobotC software float routines. Probably totally unfounded but I've found I don't ever have problems when I do it fixed-precision (and its faster this way)

Hope it helps.

BTW, this will still not be good enough if you let the robot sit on the floor for 5-10 min before starting a match (like when the FMS is struggling to register everyone else with 100s of bluetooth devices in the room)We learned this the hard way...so wait to bias and zero the gyro until autonomous actually starts. Also I make sure we're last in line to register... I'd rather wait with the robot off.

Don't forget to keep the robot still while you bias.

I'm hoping to write a kalman filter that uses a gyro and accelerometer to kill this bias/drift issue once and for all.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum