Go to Post I have way too much time on my hands. - Brandon Martus [more]
Home
Go Back   Chief Delphi > Other > FIRST Tech Challenge
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5   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
 


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
[FTC]: Deadbands (axis/motor power restrictions) JohnFogarty FIRST Tech Challenge 4 04-11-2010 19:03
[FTC]: Anyone new to FTC or TETRIX, READ THIS NOW! PhilBot FIRST Tech Challenge 21 04-12-2009 17:34
[FTC]: DC Motor Speed ethan_orion FIRST Tech Challenge 8 28-10-2009 12:36
[FTC]: Your in Atlanta...now what? gdo FIRST Tech Challenge 0 10-04-2008 21:49
Speed Controller Limits yaman Technical Discussion 11 15-01-2003 18:40


All times are GMT -5. The time now is 08:24.

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