Go to Post Maybe we should put one of those advisory signs: "Don't try this at home ... or at Robotics competitions" - Franchesca [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 14-02-2005, 17:51
the_undefined's Avatar
the_undefined the_undefined is offline
German FES
AKA: Felix Geisendörfer
#1648 (Gearbox Gangstas)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Germany
Posts: 77
the_undefined has a spectacular aura aboutthe_undefined has a spectacular aura about
Problems with NullZone

Hey Guys,

we have a problem with a scale function that we wrote in order to have a rectangular NullZone where the joystick is deactivated. Once the Joystick get s out of the Zone (for example p1_x > 147) then we want to scale the new value over the full range of the output (here from 147 - 255 TO 127 - 255) in order to not start with like 20 speed when we get out of the zone.

The function that we came up with works in calculators and other c-Compilers but not with the RC so I hope somebody could help us with this:

Here is the Function:
unsigned char scale ( unsigned char sNum , // Value to Scale
unsigned char sMin , // Old Min Value
unsigned char sMax , // Old Max Value
unsigned char eMin , // New Min Value
unsigned char eMax) // New Max Value
{
unsigned char eNum = (( sNum - sMin ) * ( eMax - eMin ) / ( sMax - sMin ) + eMin);
return eNum;
}

And here where we call it (N_ZONE_X = 40):
(int)scale((unsigned char)p1_x, 127 + (N_ZONE_X / 2), 254, 127, 254);

the value that we get is always either 127 or 254 but never stuff in between so we're kinda confused : ( ...

Thanks,

bye

Felix
  #2   Spotlight this post!  
Unread 14-02-2005, 18:45
AIBob's Avatar
AIBob AIBob is offline
AI Programmer
AKA: Bob Frank DOT org
FRC #0358 (Hauppauge Robotic Eagles)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Long Island, NY (in Binghamton now)
Posts: 297
AIBob is a splendid one to beholdAIBob is a splendid one to beholdAIBob is a splendid one to beholdAIBob is a splendid one to beholdAIBob is a splendid one to beholdAIBob is a splendid one to beholdAIBob is a splendid one to behold
Send a message via ICQ to AIBob Send a message via AIM to AIBob Send a message via MSN to AIBob Send a message via Yahoo to AIBob
Re: Problems with NullZone

In your code you may not be typecasting enough, when you are subtracting the two unsigned characters there may be some problems in that code, try this:

unsigned char eNum = (unsigned char) ((( (signed int)sNum - (signed int)sMin ) * ( (signed int)eMax - (signed int)eMin )) / ( (signed int)sMax - (signed int)sMin ) + (signed int)eMin);
__________________
- from B B frank

  #3   Spotlight this post!  
Unread 14-02-2005, 18:53
the_undefined's Avatar
the_undefined the_undefined is offline
German FES
AKA: Felix Geisendörfer
#1648 (Gearbox Gangstas)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Germany
Posts: 77
the_undefined has a spectacular aura aboutthe_undefined has a spectacular aura about
Re: Problems with NullZone

Quote:
Originally Posted by AIBob
In your code you may not be typecasting enough, when you are subtracting the two unsigned characters there may be some problems in that code, try this:

unsigned char eNum = (unsigned char) ((( (signed int)sNum - (signed int)sMin ) * ( (signed int)eMax - (signed int)eMin )) / ( (signed int)sMax - (signed int)sMin ) + (signed int)eMin);
Ok I'll try that tomorrow, thanks for your help ... C Typecasting makes me just crazy ^^, I'll be so happy when I'll finish our Teams Homepage in PHP after Shipping Date you can't imagine : ) ...
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
PC problems. . . opnickc IT / Communications 5 12-01-2005 16:53
Robot Rodeo - fixing control problems Gary Dillard Off-Season Events 7 26-10-2004 00:46
Joystick problems archiver 2001 3 24-06-2002 02:40
Radio problems -- not archiver 2000 1 23-06-2002 22:23


All times are GMT -5. The time now is 19:18.

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