View Single Post
  #3   Spotlight this post!  
Unread 10-02-2011, 16:23
Aaron V Aaron V is offline
Registered User
FRC #1325 (Inverse Paradox)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Ontario, Canada
Posts: 13
Aaron V is an unknown quantity at this point
Re: Manipulating throttle output (function)

So as I understand what you're asking: you basically want to scale the range of -1 to 1 to, say, X to 1.

You're totally right in your (Z + 1) / 2 as a start. (The general equation for values not between -1 and 1 is: (Z - oldMinimum) / (oldMaximum - oldMinimum) assuming Z is you value. If you want to know more about why this is, let me know, but I don't think this is your main question). Now what this does is it gives you a value between 0 and 1 (always). Let's call this value P.

Now that you have this, you want to convert it to a new minimum. To get the new equation, you can just rearrange the old one to get: (newMax - newMin) * P + newMin.

So you can combine these things to get a general equation:
(newMax - newMin) * (Z - oldMin) / (oldMax - oldMin) + newMin

Or, you can do them separately if you want.