Math behind Expos

So, I've finally been able to crack this after numerous hours of reading the exponential function http://en.wikipedia.org/wiki/Exponential_function and banging my head.

I tried with discrete maths but that didnt really work out because large look up tables had to be created in the small Atmega memory, so had to fall back to continous function analysis.

The objective
Given
1. An input range (stick position), ILOW -> IHIGH
2. An output range (servo timing in ms) OLOW -> OHIGH
3. An expo value E
4. A value (current stick position)

the function should be able calculate the output O such that OHIGH>=O>=OLOW and follows the expo curves. The output curve gets tighter with increasing expo values

Here's the basic idea:
- Whenever the expo changes, calculate the min and max expo adjustment factors. the lower range will always be 0, and the upper range will approach e (natural antilog). ELOW and EHIGH
- The exponential function (1+x/n)n allows us to create the expo adjustment. Yes the same function for compound interest. x is the ratio of movement and n is the expo setting, as that is compounded over travel.
- Get the stick position for a channel
- Interpolate using LERP to find the stick movement ratio over the complete travel
- adjust this values with the expo setting - this will range between the interval [0, e] where e is the natural antilog
- get a ratio of movement between EHIGH and ELOW
- interpolate this to the output range OLOW to OHIGH


Code walkthru coming soon. For source code, visit: http://gt-jtx.googlecode.com



Will do this code in atmega to see effects but as of now it's fast enough for a microcontroller.

Comments

Popular Posts