Log in

View Full Version : Help wiring gyro, then programming... please.


iv1777
18-01-2011, 20:46
hey guys.
I'm trying to get our gyro working but having no success...
First thing I tried was to plug it in the PWM ports on the sidecar, to no avail, then plugging to the digital I/O on the sidecar, again to no avail...
Today tried plugging to analog I/O on cRio yet again to no avail...
Well, perhaps we did something wrong...
When plugged into PWM or digital I/O it gave us something like -1.81546 or some number like that, and that number would fluctuate a tiny bit, maybe get up to around -1.9 and down to -1.7, it would be fluctuating while the thing was perfectly still... Then upon moving bot or spinning it, number wouldn't really change except those small fluxes between -1.9 and -1.7...
When we plugged into the Analog I/O it was telling us Gyro : -Infinity
Really? Negative infinity? So... Are we time traveling? Or...
You get the idea :)
help us figure out exactly where it plugs in and then how to get a simple readout from it in Java, please and thanks so much in advance.

PS : WE DID READ DOCUMENTS! So at least we tried to help our selves before coming on here :)

Jon236
18-01-2011, 20:51
look at the 2010 Sensor Manual which I have uploaded here http://www.chiefdelphi.com/forums/showthread.php?t=89450

Make sure you have connected the proper contacts on the gyro for analog output to the PWM wire, then make sure you have correctly plugged it into the Analog break-out.

Are you using one of the example programs?

iv1777
18-01-2011, 21:01
That is the same manual I used to figure out how to plug the gyro in in the first place. :O
We currently have the wires connected to the "Rate" contacts... I assumed that was the correct one for some reason...
Should it be connected to "Temp" for simple "Get current angle in comparson with a previously specified state" outputs?
We have tried sample code and also setting the Gyro's output to a line on the FRC Driver Station.
Thanks for a quick response.

Jon236
18-01-2011, 21:46
No, connected to 'Rate' is correct. One test is useful to ensure the 'magic smoke' wasn't released by any of your previous efforts. Wire the 5v supply and ground to a regulated power supply. Then measure the voltage from the Rate wire. It should be around 2.5 v when not moving. Then rotate the gyro horizontally as the little circle with arrow shows. You should see the voltage change proportional to the speed at which you move the sensor. If this works, the magic smoke is still inside. Carefully connect to the Analog Break-out, looking at the diagram to indicate where the signal (white) wire goes.

In the code, make sure that in whatever language you use, you have declared the correct slot and port.

Good luck!

iv1777
18-01-2011, 22:01
Can we use DSC for the regulated power supply and multimeter to test rate wire? Thanks again

mikets
18-01-2011, 22:01
First thing I tried was to plug it in the PWM ports on the sidecar, to no avail, then plugging to the digital I/O on the sidecar, again to no avail...

What?! Plugging the gyro into the PWM port? I hope you did not fry it. Gyro is an analog sensor, so it should be connected to an analog channel. A few years back, because of mis-communication, one of the members of our team hooked the two encoders to the PWM ports and fried them both. That was hard to debug until we put an oscilloscope on the encoders and saw nothing there. So please don't try things out by hooking them to random ports.

iv1777
18-01-2011, 22:09
What?! Plugging the gyro into the PWM port? I hope you did not fry it. Gyro is an analog sensor, so it should be connected to an analog channel. A few years back, because of mis-communication, one of the members of our team hooked the two encoders to the PWM ports and fried them both. That was hard to debug until we put an oscilloscope on the encoders and saw nothing there. So please don't try things out by hooking them to random ports.


Ahh.... Lesson learned. Thank you for the input.
Good thing is we have an unused gyro from last year somewhere around here so if that is the case, all is not lost.
Thank you.

iv1777
21-01-2011, 17:15
We have tested both the same and a different gyro on the Analog breakout, made sure it's wire correctly (in relation to 5v Ground and Sig wiring)
And whenever we try to get a readout it's saying some numbers in the negative range - around -.8 something.... It will change a small amount but it refuses to go positive.
Also if we jsut unplug the gyro and run code it gives us the same numbers!
We are using Java and could not find any sample code, so..
Gyro is on slot 1 of analog input on slot 1 of the cRIO
private Gyro gyro = new Gyro(1, 1);
then used outputs
gyro.getAngle();
assigned to Driver Station user message line 3..
which gave us the negative numbers...
What are we doing wrong?

Thanks in advance!

mikets
21-01-2011, 17:40
Can you print that to the debug console instead? That will reduce the number of variables that could go wrong.

iv1777
21-01-2011, 17:45
We tried that too and got similar readings.
Thanks for response of course.

mikets
21-01-2011, 17:54
Are you printing out the value using:

void PrintfLine(Line line, const char *writeFmt, ...);

Can you paste your line of code here?

iv1777
21-01-2011, 18:02
We're using Java, though.

System.out.println("gyroAngle: " + gyro.getAngle());
userMessages.println(DriverStationLCD.Line.kUser3, 1, "gyroAngle: " + gyro.getAngle());

That's our current code.

mikets
21-01-2011, 18:14
That looks alright. Do you have any other analog sensors on the robot that works just to prove that the code reading an analog channel works? I suggest to check the wiring again to make sure everything is connected properly. If you make your own PWM cable, make sure the connectivity is good. If you are reading the same random values with the sensor plugged in or unplugged, that really means there was no connection to the analog channel.

Alan Anderson
21-01-2011, 19:00
We are using Java and could not find any sample code, so..

I don't know the proper Java way to do a gyro, but if it's anything like the C++ or LabVIEW way you probably need to do some initialization before you can read from it. I only have LabVIEW installed to look at here. With luck, someone will be able to point you to the appropriate Java examples.

mikets
21-01-2011, 20:04
I don't know much about Java either, but according the the WPILib sources, the gyro initialization is done in its constructor. So the moment you created the gyro object, it should be ready to use.

iv1777
22-01-2011, 09:57
Okay,
tested the spliced PWM (needed a female/female) and each connection is fine from end to end.
Then tried putting the gyro on the analog breakout, and checking volts and it seems to be about right, it was 2.5 then increased when I turned in the indicated direction...
So it IS something with our code?
Waiting for the main programmed to get here with his laptop, we will look at the code then... Perhaps we are doing something wrong, somewhere...

dominique
24-01-2011, 09:48
In your java proram you need to
a- disable the watchdog
b- reset the gyro
c- enable the watchdog

in this order - the command gyro.reset() takes time.