Page 1 of 1

Combining Axes for Trim

Posted: Wed Dec 10, 2014 8:35 pm
by Billhelm
Hello all,

I'm working on a project using FreePIE to fly RC aircraft. It's going pretty well, but I've run into a snag regarding trim. In the code below, Joystick 1 is aileron/elevator, joystick 2 is throttle, joystick 3 is rudder, and joystick 4 trims aileron, elevator, and rudder.
from System import Int16

if starting:
joystick[1].setRange(0, 2048)
joystick[2].setRange(0, 2048)
joystick[3].setRange(0, 2048)
joystick[4].setRange(0, 2048)

x = Cyclic.getY(joystick[4].x /2 -512 + joystick[1].x)
y = Cyclic.getY(joystick[4].y /2 -512 + joystick[1].y)
z = Rudder.getY(joystick[4].z /2 -512 + joystick[3].zRotation)

vJoy[0].x = filters.mapRange(x, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].y = filters.mapRange(y, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].z = filters.mapRange(z, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].rx = joystick[2].z
vJoy[0].ry = joystick[2].zRotation
It more or less works, but with two not so desirable side effects.

1) With this method, if I trim in one direction, I can never fully go in the other direction.
2) Because I'm using curves, once I have trimmed, I'm no longer in the center of the curve, and one direction will be more 'aggressive' than the other.

Is it possible to have trim without running into one or both problems? If so, would anyone know how to go about doing so?

Re: Combining Axes for Trim

Posted: Thu Dec 11, 2014 2:56 am
by CyberVillain
Can you please post a pic of your curve?

edit: Latest version have more control over the Curve, you can now use negative values etc, thats why I wonder

Re: Combining Axes for Trim

Posted: Thu Dec 11, 2014 8:22 am
by Billhelm
Here are my curves. They run from 0,0 to 2048,2048, and are symmetric at 1024,1024.

Image

Re: Combining Axes for Trim

Posted: Thu Dec 11, 2014 7:24 pm
by Billhelm
So a coworker and I puzzled this out:

Code: Select all

if starting:
   joystick[1].setRange(0, 2048) 
   joystick[2].setRange(0, 2048) 
   joystick[3].setRange(0, 2048)
   joystick[4].setRange(0, 8192)

x = Cyclic.getY(joystick[1].x)
y = Cyclic.getY(joystick[1].y)
z = Rudder.getY(joystick[3].zRotation)

Tx = joystick[4].x
Ty = joystick[4].y
Tz = joystick[4].z

vJoy[0].x = Tx -4096 + filters.mapRange(x, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].y = Ty -4096 + filters.mapRange(y, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].z = Tz -4096 + filters.mapRange(z, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].rx = joystick[2].z
vJoy[0].ry = joystick[2].zRotation
I'm not sure why we need such a large range for joystick[4].setRange, but the thing flies like a champ, so I won't complain.

Re: Combining Axes for Trim

Posted: Fri Dec 12, 2014 3:39 am
by CyberVillain
Glad you got it , a tip, you are not using latest version of FreePIE, the new version has much more control over the curves