We had the camera and the gyro working, but when we hooked up an encoder the gyro stopped working.
So…now we have the camera and an encoder working but not the gyro.
Do any teams have some kind of “Master Code” that has the camera, the gyro, and an encoder working together?
Would any be willing to distribute it?
Otherwise would you be willing to help us get the gyro working?
It doesn’t printf the angle at all and the rate doesn’t seem quite right either even though it is giving us values.
We made a turn command that turns the robot until the gyro says we have turn a given number of degrees.
Strangely it will turn for what seems to be a random amount of time and then stop. It’s never the angle we told it to go, but the gyro is registering something it seems.
Correct me if I’m wrong, but the gyroscope gives you an analog value; interrupts are irrelevant when working with analog sources. The encoder needs 2 digital inputs.
Grab a voltmeter and verify that you are getting the 5v out of the 5v pins. That’s my guess as to what is going on. Check for shavings and make sure all your RC’s lights are flashing green when your 'bot is enabled.
Post your code. I’d be happy to look at it. Just zip it up and attach it to your post.
You’re not exactly wrong, but it sounds like you haven’t worked with the gyro. In order to get the best results from a gyro-based control routine, the analog value must be sampled with extremely regular timing. Kevin Watson provides a framework for using the gyro which does use interrupts to do the analog conversions in the background.
Putting his encoder and gyro software together isn’t particularly complicated, but getting the interrupt service routines combined properly does take some thought.
I have worked with the gyro, but I didn’t use Kevin’s base gyro code; I created my own. I am having accuracy issues, and it makes sense that it needs to be called very regularly. I’ll read over Kevin’s code and probably rewrite my gyro stuff today.
Now I know why you’d use interrupts with a gyro. You learn new stuff every day…
I see you have commented out the part of the interrupt service routine that deals with the encoder. Make sure you fix that before you start tearing your hair out because the encoders don’t work either.
I don’t see anything obviously wrong. What leads you to say your gyro code isn’t working? And just for completeness, are you sure Process_Data_From_Local_IO() is being called from your main loop?
You have a piece of redundant code that clears the encoder interrupt flags before the encoder code executes. See my comment in user_routines_fast.c. In user_routines_fast_rkw.c I’ve fixed the problem and re-arranged the ISRs to be more efficient. As I don’t know if you’re using both serial ports and the number of encoders, you should delete any code for features you’re not using. Also, keep the ADC sample rate as low as you can and keep the encoder-generated interrupts as low as possible (a few hundred per second is fine).
Thanks Kevin and everybody, we re-assembled all the parts of the code, cam, gyro etc, and now it seems to be working. Its nice to see that we can expect quick help.