Go to Post I also hate it when I keep seeing this message: "You must spread some Reputation around before giving it to Andy Baker again." - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-02-2008, 08:37
rjn rjn is offline
Registered User
no team
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Why is this required
Posts: 15
rjn is an unknown quantity at this point
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;
}
}
Any help would be very appreciated.

Last edited by rjn : 18-02-2008 at 08:44.
  #2   Spotlight this post!  
Unread 18-02-2008, 09:37
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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);
Printf's '%d' directive tells printf to look for an int, and although I didn't check, I suspect the dig_in values are not ints.

What are the values of the pwm's at the end of the function?
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.

Last edited by gnormhurst : 18-02-2008 at 09:41.
  #3   Spotlight this post!  
Unread 18-02-2008, 09:42
rjn rjn is offline
Registered User
no team
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Why is this required
Posts: 15
rjn is an unknown quantity at this point
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   Spotlight this post!  
Unread 18-02-2008, 09:59
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
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   Spotlight this post!  
Unread 18-02-2008, 10:04
Jeff Waegelin's Avatar
Jeff Waegelin Jeff Waegelin is offline
El Jefe de 148
AKA: Midwest Refugee
FRC #0148 (Robowranglers)
Team Role: Engineer
 
Join Date: Aug 2001
Rookie Year: 2001
Location: Greenville, TX
Posts: 3,132
Jeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond reputeJeff Waegelin has a reputation beyond repute
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.
__________________
Jeff Waegelin
Mechanical Engineer, Innovation First Labs
Lead Engineer, Team 148 - The Robowranglers
  #6   Spotlight this post!  
Unread 18-02-2008, 10:05
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Please help with our IR code, we are so confused

Quote:
Originally Posted by rjn View Post
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;
}
I am pretty sure you cant assign digital outputs (rc_dig_in0x) to zero. Digital inputs are not variables, they are alias to input ports on the microcontroller and I am pretty sure if you set them as input, you cant write that register. So what is probably happening is all digital inputs are 1 (and not getting zerod) and move is being set to 1 (since that is first in else if block). Move if ((rc_dig_in01 + rc_dig_in02 + rc_dig_in03 + rc_dig_in04) > 1) {} to the first statement in the "move setting" else if block. Also you IR sensor is probably not hooked up correctly if you are getting all 1s.

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.
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"

Last edited by The Lucas : 18-02-2008 at 10:07.
  #7   Spotlight this post!  
Unread 18-02-2008, 10:17
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 545
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
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.
__________________
Team 2052- KnightKrawler
Mentor and volunteer
  #8   Spotlight this post!  
Unread 18-02-2008, 10:28
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Please help with our IR code, we are so confused

Quote:
Originally Posted by Tanis View Post
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.
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.
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"
  #9   Spotlight this post!  
Unread 18-02-2008, 10:40
rjn rjn is offline
Registered User
no team
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Why is this required
Posts: 15
rjn is an unknown quantity at this point
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:
IFI>
IFI User Process Initiated...
And our timer even starts over.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 22:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi