Select Curve with a Joystick Axis

Official forum for open source FreePIE discussion and development.
Post Reply
Billhelm
One Eyed Hopeful
Posts: 12
Joined: Fri Oct 11, 2013 7:01 pm

Select Curve with a Joystick Axis

Post by Billhelm »

Hello,

I'm trying to use a joystick slider/axis as a curve select. I've tried the following and got a syntax error:

Code: Select all

if joystick[2].sliders[0] in range (0, 204.8):
	x = Cyclic.1.getY(joystick[1].x)
	y = Cyclic.1.getY(joystick[1].y)
	z = Rudder.1.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (204.9, 409.6):
	x = Cyclic.2.getY(joystick[1].x)
	y = Cyclic.2.getY(joystick[1].y)
	z = Rudder.2.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (409.7, 614.4):
	x = Cyclic.3.getY(joystick[1].x)
	y = Cyclic.3.getY(joystick[1].y)
	z = Rudder.3.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (614.5, 819.2):
	x = Cyclic.4.getY(joystick[1].x)
	y = Cyclic.4.getY(joystick[1].y)
	z = Rudder.4.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (819.3, 1024):
	x = Cyclic.5.getY(joystick[1].x)
	y = Cyclic.5.getY(joystick[1].y)
	z = Rudder.5.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (1024.1, 1228.8):
	x = Cyclic.6.getY(joystick[1].x)
	y = Cyclic.6.getY(joystick[1].y)
	z = Rudder.6.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (1228.9, 1433.6):
	x = Cyclic.7.getY(joystick[1].x)
	y = Cyclic.7.getY(joystick[1].y)
	z = Rudder.7.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (1433.7, 1638.4):
	x = Cyclic.8.getY(joystick[1].x)
	y = Cyclic.8.getY(joystick[1].y)
	z = Rudder.8.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (1638.5, 1843.2):
	x = Cyclic.9.getY(joystick[1].x)
	y = Cyclic.9.getY(joystick[1].y)
	z = Rudder.9.getY(joystick[6].zRotation)
if joystick[2].sliders[0] in range (1843.3, 2048):
	x = Cyclic.getY(joystick[1].x)
	y = Cyclic.getY(joystick[1].y)
	z = Rudder.getY(joystick[6].zRotation)
I have 10 curves and I'm trying to divide the slider into 10 positions. In this case the 0-204.8 range would be the least aggressive curve, and 1843.3-2048 would be the most aggressive curve, with each curve becoming progressively more aggressive. I feel like I'm almost barking up the right tree, but my syntax is definitely wrong. Does anyone have any suggestions?

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: Select Curve with a Joystick Axis

Post by Jabberwock »

Is 'Cyclic.1' a valid curve name? Maybe that is what causes the syntax error?

FrenchyKiel
One Eyed Hopeful
Posts: 47
Joined: Thu Oct 03, 2013 7:10 am

Re: Select Curve with a Joystick Axis

Post by FrenchyKiel »

maybe range function is not right here

i dont write this
if joystick[2].sliders[0] in range (0, 204.8):

but

Code: Select all

value = joystick[2].sliders[0]
if  0 <= value < 204.9):
   x = Cyclic.1.getY(joystick[1].x)
   y = Cyclic.1.getY(joystick[1].y)
   z = Rudder.1.getY(joystick[6].zRotation)
if  204.9 <= value < 409.6):
   x = Cyclic.2.getY(joystick[1].x)
   y = Cyclic.2.getY(joystick[1].y)
   z = Rudder.2.getY(joystick[6].zRotation)
and so on

Billhelm
One Eyed Hopeful
Posts: 12
Joined: Fri Oct 11, 2013 7:01 pm

Re: Select Curve with a Joystick Axis

Post by Billhelm »

Thanks for the suggestions. Having dots in the names of the curves was a problem, and so was the way that I was trying to define ranges. Here is my current code, which is now working as expected.

Code: Select all

slider = joystick[2].sliders[0]
if  (0 <= slider <= 204.8):
	x = Cyclic100.getY(joystick[1].x)
	y = Cyclic100.getY(joystick[1].y)
	z = Rudder100.getY(joystick[6].zRotation)
if (204.9 <= slider <= 409.6):
	x = Cyclic90.getY(joystick[1].x)
	y = Cyclic90.getY(joystick[1].y)
	z = Rudder90.getY(joystick[6].zRotation)
if (409.7 <= slider <= 614.4):
	x = Cyclic80.getY(joystick[1].x)
	y = Cyclic80.getY(joystick[1].y)
	z = Rudder80.getY(joystick[6].zRotation)
if (614.5 <= slider <= 819.2):
	x = Cyclic70.getY(joystick[1].x)
	y = Cyclic70.getY(joystick[1].y)
	z = Rudder70.getY(joystick[6].zRotation)
if (819.3 <= slider <= 1024):
	x = Cyclic60.getY(joystick[1].x)
	y = Cyclic60.getY(joystick[1].y)
	z = Rudder60.getY(joystick[6].zRotation)
if (1024.1 <= slider <= 1228.8):
	x = Cyclic50.getY(joystick[1].x)
	y = Cyclic50.getY(joystick[1].y)
	z = Rudder50.getY(joystick[6].zRotation)
if (1228.9 <= slider <= 1433.6):
	x = Cyclic40.getY(joystick[1].x)
	y = Cyclic40.getY(joystick[1].y)
	z = Rudder40.getY(joystick[6].zRotation)
if (1433.7 <= slider <= 1638.4):
	x = Cyclic30.getY(joystick[1].x)
	y = Cyclic30.getY(joystick[1].y)
	z = Rudder30.getY(joystick[6].zRotation)
if (1638.5 <= slider <= 1843.2):
	x = Cyclic20.getY(joystick[1].x)
	y = Cyclic20.getY(joystick[1].y)
	z = Rudder20.getY(joystick[6].zRotation)
if (1843.3 <= slider <= 2048):
	x = Cyclic10.getY(joystick[1].x)
	y = Cyclic10.getY(joystick[1].y)
	z = Rudder10.getY(joystick[6].zRotation)
I'm making progress, but the behavior is still not quite right. The problem seems to be with the curves themselves. I've defined a series of curves to limit output when given maximum input. As an example, here's my least aggressive cyclic curve.

Code: Select all

    <Curve>
      <Name>Cyclic10</Name>
      <Points>
        <Point>
          <X>0</X>
          <Y>921.6</Y>
        </Point>
        <Point>
          <X>42.5</X>
          <Y>937.8</Y>
        </Point>
        <Point>
          <X>98.3</X>
          <Y>952.7</Y>
        </Point>
        <Point>
          <X>167.4</X>
          <Y>966.3</Y>
        </Point>
        <Point>
          <X>249.9</X>
          <Y>978.5</Y>
        </Point>
        <Point>
          <X>345.6</X>
          <Y>989.4</Y>
        </Point>
        <Point>
          <X>454.7</X>
          <Y>999</Y>
        </Point>
        <Point>
          <X>577</X>
          <Y>1007.3</Y>
        </Point>
        <Point>
          <X>712.7</X>
          <Y>1014.2</Y>
        </Point>
        <Point>
          <X>861.7</X>
          <Y>1019.8</Y>
        </Point>
        <Point>
          <X>1024</X>
          <Y>1024</Y>
        </Point>
        <Point>
          <X>1186.3</X>
          <Y>1028.2</Y>
        </Point>
        <Point>
          <X>1335.3</X>
          <Y>1033.8</Y>
        </Point>
        <Point>
          <X>1471</X>
          <Y>1040.7</Y>
        </Point>
        <Point>
          <X>1593.3</X>
          <Y>1049</Y>
        </Point>
        <Point>
          <X>1702.4</X>
          <Y>1058.6</Y>
        </Point>
        <Point>
          <X>1798.1</X>
          <Y>1069.5</Y>
        </Point>
        <Point>
          <X>1880.6</X>
          <Y>1081.7</Y>
        </Point>
        <Point>
          <X>1949.7</X>
          <Y>1095.3</Y>
        </Point>
        <Point>
          <X>2005.5</X>
          <Y>1110.2</Y>
        </Point>
        <Point>
          <X>2048</X>
          <Y>1126.4</Y>
        </Point>
      </Points>
      <ValidateCurve>true</ValidateCurve>
    </Curve>
Despite the first point being defined as 0,921.6, it seems to behave as if the first point is 0,0. As a result, moving the stick full right or full down limits the output range, but moving the stick full left or full up does not. The curve is limiting the output range effectively until full deflection, at which point it abruptly transitions from limited output to full. I've tried a few hacks at limiting the range, but none of my efforts have succeeded. Any ideas?

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Select Curve with a Joystick Axis

Post by CyberVillain »

There was a bug with the curve math, its fixed in this commit

https://github.com/AndersMalmgren/FreeP ... 569d02a155

Post Reply

Return to “FreePIE”