Go to Post After talking with the students on these teams I could see the light in their eyes. These were their robots! Inspired? That would be a definate YES! - Steve W [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 02-02-2006, 09:32
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Strange but...need fresh eyes

We've been trying to figure this one out for a couple of days. Here is the code in question:

p1_y = (unsigned char) (((double) p1_y + (double)127)*.75);

if (p1_y > 250)
{
p1_y = (unsigned char)250;
}

PrintToScreen ("P1_y is %d\n", (int)p1_y);


The first line is a conversion we need to use to make our steering wheel paddles work. p1_y is the value sent to the drive motors. What is happening is the wheels spin forward until the upper limit (250) at which point they immediately spin backwards or stop. Output from the print line reflects this condition, increasing to 250 then converting to 1 or 127. We thought maybe the steering wheel had started to send the wrong signal at its limit, but changing the limit set point (i.e. from 250 down to 245) results in the same thing. Any ideas?
  #2   Spotlight this post!  
Unread 02-02-2006, 09:58
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: Strange but...need fresh eyes

Quote:
Originally Posted by TubaMorg
We've been trying to figure this one out for a couple of days. Here is the code in question:

p1_y = (unsigned char) (((double) p1_y + (double)127)*.75);

if (p1_y > 250)
{
p1_y = (unsigned char)250;
}

PrintToScreen ("P1_y is %d\n", (int)p1_y);


The first line is a conversion we need to use to make our steering wheel paddles work. p1_y is the value sent to the drive motors. What is happening is the wheels spin forward until the upper limit (250) at which point they immediately spin backwards or stop. Output from the print line reflects this condition, increasing to 250 then converting to 1 or 127. We thought maybe the steering wheel had started to send the wrong signal at its limit, but changing the limit set point (i.e. from 250 down to 245) results in the same thing. Any ideas?
Are you overflowing?

Does p1_y go from -128 to 127, or from 0 to 255.

If its from 0 to 255, then adding 127 definitely takes you out of the range of an unsigned char.

If its from -128 to 127, then it seems that saving (127+127) to a signed char would also result in overflow.

If you want to scale by 75% you can multiply by three, then divide by four:

p1_y = 3*(p1_y + 127)/4;

No need for floats.
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003
  #3   Spotlight this post!  
Unread 02-02-2006, 15:08
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Strange but...need fresh eyes

Quote:
Originally Posted by Joel J.
Are you overflowing?

Does p1_y go from -128 to 127, or from 0 to 255.

If its from 0 to 255, then adding 127 definitely takes you out of the range of an unsigned char.

If its from -128 to 127, then it seems that saving (127+127) to a signed char would also result in overflow.

If you want to scale by 75% you can multiply by three, then divide by four:

p1_y = 3*(p1_y + 127)/4;

No need for floats.
Well the first line of the code works ok I believe. p1_y from the steering wheel goes from around 60 to 150 or something like that. The correction fixes it ok. If I change the if statement to, say, 254, the code will work correctly until 254 then flop to 1. If I change the if statement to 145, the code will work correctly until 145 then flop to 1. So I am deducing that my assignment in the if block is causing the headache. That being said, I am going to try what you suggested, because once things over range, all logic can be thrown out the window!
  #4   Spotlight this post!  
Unread 02-02-2006, 15:24
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Strange but...need fresh eyes

Another idea I had was to maintain my drive variables as int to avoid overranging and then of course make sure they are 0-254 before sending them to the PWM ports. That way if there is any spurious or temporary overranging, I won't lose control of the variable. Because no matter how you look at it, if you take and unsigned char with a value > 127 and add 127, then you have over ranged even though subsequent operations are designed to bring it back into range. With ints this shouldn't be a problem right? Unless I really, really really, go out of range.
  #5   Spotlight this post!  
Unread 02-02-2006, 17:12
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: Strange but...need fresh eyes

Quote:
Originally Posted by TubaMorg
Another idea I had was to maintain my drive variables as int to avoid overranging and then of course make sure they are 0-254 before sending them to the PWM ports. That way if there is any spurious or temporary overranging, I won't lose control of the variable. Because no matter how you look at it, if you take and unsigned char with a value > 127 and add 127, then you have over ranged even though subsequent operations are designed to bring it back into range. With ints this shouldn't be a problem right? Unless I really, really really, go out of range.
Yep. with a signed int, you can go on the range: [-32768, 32767].
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003
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
Strange Behavior Gary Bonner Control System 17 09-11-2005 19:01
Strange products upon running code... neilsonster Programming 17 10-08-2005 00:20
strange error Anthony Kesich Programming 2 25-02-2004 18:55
"Regional Competition Edition" of Fresh From the Forum Ken Leung CD Forum Support 5 21-03-2002 08:21
"Motors and Drive train edition" of Fresh From the Forum Ken Leung CD Forum Support 6 29-01-2002 12:32


All times are GMT -5. The time now is 01:52.

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