|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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)
{
int move, othermove;
//printf("Time=%lu", Get_Time( ));
if ((rc_dig_in01 + rc_dig_in02 + rc_dig_in03 + rc_dig_in04) > 1)
{
rc_dig_in01 = rc_dig_in02 = rc_dig_in03 = rc_dig_in04 = 0;
}
othermove = move;
if (rc_dig_in01 == 1) {
move = 1;
}
else if (rc_dig_in02 == 1) {
move = 2;
}
else if (rc_dig_in03 == 1) {
move = 3;
}
else if (rc_dig_in04 == 1) {
move = 4;
}
else {
move = othermove;
}
printf("Move: %d In01: %d, In02: %d, In03: %d, In04: %d \r \n", move, rc_dig_in01, rc_dig_in02, rc_dig_in03, rc_dig_in04);
if (move == 0)
{
pwm01 = 127;
pwm02 = 127;
pwm03 = 127;
pwm04 = 127;
}
else if (move == 1) {
pwm01 = 187;
pwm02 = 67;
pwm03 = 187;
pwm04 = 67;
}
else if (move == 2) {
pwm01 = 187;
pwm02 = 187;
pwm03 = 67;
pwm04 = 67;
}
else if (move == 3) {
pwm01 = 67;
pwm02 = 187;
pwm03 = 67;
pwm04 = 187;
}
else if (move == 4) {
pwm01 = 67;
pwm02 = 67;
pwm03 = 187;
pwm04 = 187;
}
else {
pwm01 = 127;
pwm02 = 127;
pwm03 = 127;
pwm04 = 127;
}
}
Last edited by rjn : 18-02-2008 at 08:44. |
|
#2
|
|||||
|
|||||
|
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? Last edited by gnormhurst : 18-02-2008 at 09:41. |
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
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.
|
|
#5
|
|||||
|
|||||
|
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. |
|
#6
|
|||||
|
|||||
|
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. Last edited by The Lucas : 18-02-2008 at 10:07. |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||||
|
|||||
|
Re: Please help with our IR code, we are so confused
Still need to move the greater than one test to the first statement in the else if block that sets move. Otherwise you are setting move to zero then setting to something else later.
|
|
#9
|
|||
|
|||
|
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:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help with our default code | coolguybigt | Programming | 14 | 19-02-2007 10:17 |
| What are with the Ls in Kevin's code??!!! HELP!!! | RbtGal1351 | Programming | 2 | 18-02-2005 16:57 |
| What is wrong with this code???? It won't Compile and I don't know why? Please Help | CrashZero | Programming | 23 | 26-03-2004 09:44 |
| Little help Please (with dead reconing code) | Xufer | Programming | 17 | 22-02-2004 20:12 |
| hey need some help with writing a code please help me here | magical hands | Programming | 9 | 01-01-2004 21:46 |