![]() |
Please help with our IR code, we are so confused
This is our code for our hybrid, and we honestly have no idea what is wrong, it constantly blasts forward, even after a new button is hit
Code:
void Autonomous(void) |
Re: Please help with our IR code, we are so confused
What does the printf tell you? I only see one suspicious thing. In your printf you should probably cast the values to int:
Code:
printf("Move: %d In01: %d, In02: %d, In03: %d, In04: %d \r \n", move, (int)rc_dig_in01, (int)rc_dig_in02, (int)rc_dig_in03, (int)rc_dig_in04);What are the values of the pwm's at the end of the function? |
Re: Please help with our IR code, we are so confused
Oh, sorry, it's kind've early, atleast for me. Our code is meant to fly in a direction based on the last button pressed on our remote, it compiles great, but when we flip our autonomous switch, even without any signals from the ir board, it goes still says move = 1(goes forward), and even after hitting a button, it simply goes back to move = 1, even though it should stay in a different move case(stored as an int). We honestly have no idea.
|
Re: Please help with our IR code, we are so confused
The variable 'move' should be static. Otherwise it will reset every time the function is called. Being a static variable causes it to remember its state from the previous call, and move as you would expect it. See if that works.
|
Re: Please help with our IR code, we are so confused
Do the lights on your IR board light up properly when you press a button on your remote? (and do they turn off when you're not pressing a button?) It's possible the PIC on your IR board could have been corrupted- see Team Update 10 for info on how to fix that. We had a similar problem on Saturday, and that was the cause.
Also, try checking the wiring of your IR board with an oscilloscope to make sure your RC is receiving the correct signal. You should get a 5V square wave on each output from the IR board if it's working right. When you think is right, but you still can't get it to work, it's always a good idea to make sure your sensors are fully functional in the first place. |
Re: Please help with our IR code, we are so confused
Quote:
Also it would be better if you declared move as static (static int move) and removed othermove. A static int never gets destroyed so it will keep its value from one loop to the other. |
Re: Please help with our IR code, we are so confused
That version of our code is a tad outdated.
The digital ins are no longer being set to zero if their total is greater than one; when they are greater than one, move is now set to zero. Changing it to static may fix it, so we'll try that. If any of you are still confused- Its supposed to "remember" what button was last pushed (stored in move), but the variable move changes only when a button is pressed, then it immediately goes back to one. The IR sensor IS hooked up right, and the printfs show that dig ins are zero until a button is pressed, when it gets a 1 every 100ms. |
Re: Please help with our IR code, we are so confused
Quote:
|
Re: Please help with our IR code, we are so confused
Making the int static did save it for the next loop, but a new problem has arrived, although it moves, everytime a new button is hit(or sometimes when you just hit a button) it seems to just reset, in that the terminal window says
Quote:
|
| All times are GMT -5. The time now is 00:54. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi