View Single Post
  #1   Spotlight this post!  
Unread 28-11-2010, 20:07
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: [FTC]: Not Deadbands now.....speed limits

NOTE: I am relatively unfamiliar with Robot C, I have one season of coaching BEST worth of experience with it. Please check that my assumptions are correct. The first bit might not actually be an issue...

There may be a bug hiding in this line:
float ratio = ((joyVal * joyVal) / (16129));
If Robot C handles casting like C does, the actual math will be done in integer math, and then cast to a float at the end. Follow it through the parenthesis to find this:
  1. float ratio = ((joyVal * joyVal) / (16129));
  2. float ratio = float ((int * int) / (const int));
  3. float ratio = float (int / const int);
  4. float ratio = float (int);

In the 3rd step, dividing an int by a const int will truncate to an int. When it is cast to a float in the 4th step, the information is already lost. It is likely that this doesn't really matter, but it makes for a confusing read.

I'd recommend replacing the line with
float ratio = ((joyVal * joyVal) / (16129.0));
Now you are dividing an int by a const float, which will be done in floating point math.



Do you want to rescale the sticks so that full forward on the stick is 60%, and everything in between is rescaled? Or, do you just want to chop off the top of the sticks so that anything above 60 is limited to 60?

Rescale:
The key to rescaling is to find center of your range, pull it to zero, do your scaling, and then push it back to the real center. Then, shuffle your math around until it looks good for a computer.

For example, lets rescale around 127:
recentered = input - 127;
scaled = recentered * ratio;
output = scaled + 127;

Put it all on one line:
output = (input-127) * ratio + 127;

If ratio is a floating point number between 0 and 1, you are done. If you want to rephrase it as your new maximum value, write it like this:
output = (input-127) * max_value / 127.0 + 127;

You can likely leave off the ".0" from "127.0". Just be sure you follow the golden rule of integer division: Multiply, then divide. Going the other way around kills your accuracy.


PS/EDIT: I'm confused as to your goal still. Could you please draw a graph of what you want to do, with "input from the joystick" on the x axis and "output to the motors" on the y axis? You can sketch it in mspaint or whatever, just label a few key spots.

Last edited by EricVanWyk : 28-11-2010 at 20:15.
Reply With Quote