Math behind Expos

Started by girishsarwal, June 10, 2013, 06:29:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

girishsarwal

Gentlemen,
I am currently wiring up some code to redo Expos for this -> http://www.rcindia.org/self-designed-diy-and-college-projects/flying-on-a-3d-joystick

The code I have right now is very kludgy and broken and fidgety. I have tried various expression till now. Also checked out the code for er9x, pretty convoluted.  :banghead: I understand the basic idea of expos pretty well, just need to get my head around the formula.

I am little stumped at the moment by the maths that is involved for applying the exponential transformation/incorporating it while calculating the channel width. I'm hopeful with the kind of talent we have at RCI, from control theory and robotics and mathematics, I will get some advise from the seniors... :help: I know we have cent percent scorers amongst us

Any help is appreciated, discussions trigger further thoughts...

GS
gs

sanjayrai55

Draw an abcissa & an ordinate (X&Y axes) on a sheet of paper

draw a line at 45 deg from (0,0) This is y=x

Now, try y= ln x (logarithm to the base 'e')

See what you get. Try in Excel for say x = 1 to 10 in increment of 1

Plot in a graph. Instead of linear proportional, you will get a graph that will show less y for the same x value initially.

Sorry if it is not too clear an explanation, it's been about 35 years  ;D

rcpilotacro

Since technically it is stepped output, discrete maths incl Combinatorics is easier approach in coding, incl for adding logic 'Choose' fn
Gusty's Hangar and Introduction.

A Good pilot will practice until he gets it right,
A Great pilot will practice until he can't get it wrong.

santhosh-r

Spektrum DX6i | Phoenix V4 | CoroTrainer | Tamiya Baja king 2WD | RCTimer F450 Quadcopter

saikat

Aha ! - something to separate the men from the boys -

girishsarwal

Many thanks everyone.

Sanjay sir, spot on. I started with y= ln(x) as the starting function. I must get deeper into the details. The natural log function was the easy part; putting in the coefficient (which will range from let us say 0-100, adjustable by the pilot, and will determine the tightness of the graph) is where the problem comes in. I cant multiply it directly as that will only cause the upper range to shift and the range parameters will have to be recalculated which I wish to avoid :(. I am looking for having that coefficient as a part of the equation (preferably adjusting for negative values automagically in the equation). I will call you in a little while.

Gusty sir, I agree having a finite set of values and choosing will help easy out the programming, I was thinking if an equation works well, even if takes longer to identify, it is a long term knowledge investment :). Have a question for you in the last but one paragraph!

Santhosh sir, that link looks great as a starting point. I think i will closely read it up tonite. However, at the onset I do feel it is still linear as k * expo/100 will yield a linear multiplier. Using fooplot to do all the visualization and both ln(x) multiplied by a constant and the specified equation give close results but they don't look ideal :(

If we look at it graphically, I am looking at the expo graph being a straight line at 0 expo (y=x) and when increased in the positive side by the pilot, the curve should ideally be moved as if pinched from the exact center of the line and pulled to the southeast corner, thereby tighetning the graph. Gusty sir, do you think my understanding is correct in achieving an ideal expo graph.

Woah! I'm so tripped on this thing, I haven't done any useful work at office today...lol. I will now have to read up beizers maybe...And i still have another problem. I dont know if the ATmega will natural logs for me :(
gs

santhosh-r

You can use Microsoft mathematics to easily plot equations and visualize them..also easily adjust constant /coefficients..
Spektrum DX6i | Phoenix V4 | CoroTrainer | Tamiya Baja king 2WD | RCTimer F450 Quadcopter

girishsarwal

Hey thanks for the tip Santhosh sir. Didn't know about MS maths...gotta get hold of it now
gs

santhosh-r

Don't call me "santhosh sir"- just "santhosh"
Spektrum DX6i | Phoenix V4 | CoroTrainer | Tamiya Baja king 2WD | RCTimer F450 Quadcopter

rcpilotacro

First question is why is expo needed ? well! in real aeroplane we have something called Gain, since control effectiveness increases as a function of the air speed, as the speed increases aeroplane becomes more sensitive and difficult to control. therefore the throw was adjusted continuously as a function of speed and altitude (Altitude because as you climbed density reduced and aeroplane became sluggish, therefore as you climbed more throw was needed ). In a model aeroplane DR is manually done, because there is no speed, altitude info adjusting throw automatically (Telemetry radio could technically do that though) expo makes, centre soft.

Having understood this what we need to see is throw, throw is finite, servo output is finite too, so it is essentially a DISCRETE math problem rather than CONTINUOUS math problem. essentially Factorials, Choose etc

Why DISCRETE ? faster, clean, predictable, finite, possibility of error is least, scalable ? definitely.

CONTINUOUS is preferred for, i think easy to comprehend and cool, though it really is for something changing against something, not for something choosing something where order does/doesn't matter.

Many codes i have come across are, sorry to say really belongs to quantum physics rather than aeromodelling. Fact is it is Easy to complicate and difficult to simplify, Paradox ! but true.

As a challenge, just for fun, try DISCRETE approach, you will know what i mean.
Gusty's Hangar and Introduction.

A Good pilot will practice until he gets it right,
A Great pilot will practice until he can't get it wrong.

kakka_rao

sir jee , I like your easy lang.

girishsarwal

Gusty sir,

I am convinced with what you say. It is indeed a discrete function, and the limits are so well established. And I so agree with "Fact is it is Easy to complicate and difficult to simplify, Paradox ! but true."

The closest I've been able to come with a continuous function for expo is a parabola. A modified version (x^2n) comes up well but also suffers from almost linear variance as it reaches its higher limits.

I now think a discrete 5/7/9 point curve with linear interpolation between the points should be enough for providing an expo. DR can be linearly factored in. In fact many radios do the same I believe. And once good curves are established, with your help, I can program them as presets based on an expo setting, so an expo of 20 would mean choose some curve from the presets. In theory it will take quite some memory on the chip, but that I have plenty

Out of curiosity, do you mean that in real airplanes, gain is auto adjusted (with perhaps a manual override) based on the conditions?

Quotebecause there is no speed, altitude info adjusting throw automatically (Telemetry radio could technically do that though) expo makes
. This will be fun to do in a model airplane. although altitude changes might not be significant.

GS
gs

rcpilotacro

Quote from: girishsarwal on June 11, 2013, 07:40:02 AM

Out of curiosity, do you mean that in real airplanes, gain is auto adjusted (with perhaps a manual override) based on the conditions?...


This will be fun to do in a model airplane. although altitude changes might not be significant.

GS


Yes Auto adjusted with a facility of manual override in older versions of aeroplanes and quadruplex redundancy in newer version of aeroplanes (With no manual override), so in a quad channel failure situation (possibility of which is 1 in 1015) quitting the sick aeroplane is the only choice

Altitude is Altitude Above Mean Sea Level, so models flying at Shillong are already at 7000 feet, therefore needs to be factored in, Air Speed however is IAS and not GPS Speed (Which is ground speed), so an IAS probe for making auto gain in a model aeroplane is an inescapable requirement
Gusty's Hangar and Introduction.

A Good pilot will practice until he gets it right,
A Great pilot will practice until he can't get it wrong.

santhosh-r

Quote from: rcpilotacro on June 11, 2013, 08:50:58 AM
Quote from: girishsarwal on June 11, 2013, 07:40:02 AM

Out of curiosity, do you mean that in real airplanes, gain is auto adjusted (with perhaps a manual override) based on the conditions?...



This will be fun to do in a model airplane. although altitude changes might not be significant.

GS


Yes Auto adjusted with a facility of manual override in older versions of aeroplanes and quadruplex redundancy in newer version of aeroplanes (With no manual override), so in a quad channel failure situation (possibility of which is 1 in 1015) quitting the sick aeroplane is the only choice

Altitude is Altitude Above Mean Sea Level, so models flying at Shillong are already at 7000 feet, therefore needs to be factored in, Air Speed however is IAS and not GPS Speed (Which is ground speed), so an IAS probe for making auto gain in a model aeroplane is an inescapable requirement


WoW :o
Spektrum DX6i | Phoenix V4 | CoroTrainer | Tamiya Baja king 2WD | RCTimer F450 Quadcopter

girishsarwal

Quoteso an IAS probe for making auto gain in a model aeroplane is an inescapable requirement
Gusty sir, so you have an IAS probe in most of your model planes already or is it still a requirement?

Something on the lines of this, linked back to the Tx:
http://www.hobbyking.com/hobbyking/store/__7838__Airspeed_Expander_V3.html
gs

girishsarwal

#15
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


Attached is a PDF that highlights this code done in a sample in C#. 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.
gs

sanjayrai55


sanjayrai55

Lerp  :giggle: :giggle:

COGTEST   :rofl:

Where's the graph, you kludgy lerp? Or is in the Cogtest?

girishsarwal

Graphs coming up soon. You know my way. Solutions come out in a split second but then I end up waiting for a year for the split second to arrive

PS Cogtest is the cognitive testing product I take care of where I work so yea the solution was in there somewhere.. ;) technically and figuratively. Wait till the boss gets to know of it..
gs

sanjayrai55

Boss? Don't worry about that kludge. He's such a lerp he won't cogtest