hey. can someone give me a example of the code for useing a gyro in C lanuage and a diagram on how to hook everything up? thanks alot in advance

First of all I would like to know what kind of gyro it is, weather it be a helicopter gyro that outputs PWM signals or more an analog gyro.

one piece of advice, before bringing up something that is not completely obscure, search the forums and also just go the the appropriate forum and make sure to change the start date from one week to one year or something along those lines. here’s one forum on gyroscopes and C and the like:

It is in fact an analog gyro. Its output is simply a voltage between 0-5V and can be read via an analog input pin on the robot controller.

what do you want to do with it? the output from the solid state gyro (the yaw rate sensor) that FIRST supplies with the kit puts out a signal that is proportional to the turn rate, in degrees per second.

you can use that signal directly if you are closing the loop on the steering - if you want your robot to steer precisely and responsively, have your code read the command from the drivers joystick tell you how fast he wants the bot to turn, then read the output from the yaw rate sensor telling you how fast the bot actually IS turing - the difference between the two is the error signal - you can use it to control the power to the motors (instead of using the joysitck signal)

another thing you can do with the yaw rate sensor is create a compass heading - since the signal is degrees per second, if you add the signal (adjusting for the 127 offset being zero) to a 16 bit register on every loop of the code, what you are doing is integrating the signal over time

the results is seconds * degrees / second = degrees. If you start the 16 bit register off at 32000, with the bot pointing in the same direction when you turn it on, then while the robot is running if it turns one way, that register will have positive numbers added to it, so it will increase - turn the other way and the register goes down - so you can tell relatively which way your robot is pointing all the time and how far it has turned since you turned it on (initialized the 16 bit register)

to get the actual angle dont waste your time dividing by constants - test your bot with the code running - turn it 45° and see what the register reads - turn it 90, 180…360 in both directions

you will be amazed at how simple this is and how well it works - the only thing you need to keep an eye on is to make sure you dont have too much code running so that the amount of time it takes to run one complete loop (through your code) stays fairly consistant.

you want that sensor input read at fixed intervals, every 7ms or every 30ms… whatever - it doesnt really matter what the interval is, as long at its consistantly the same - you calibrate the interval out when you turn the robot and seeing how much the register ‘count’ changes.