0

I am trying to get an average sensitivity level between two joysticks Y axis.

Fully pressed UP is a value of 0
Fully pressed DOWN is a value of 100.

(So I'm basically working with percentages)

The neutral zone (when the stick is not being pressed) is a value of 50 (with a padding of 3, so..)

The neutral zone for UP ends at 47
The neutral zone for DOWN ends at 53

I am able to find the average sensitivity when both sticks are pressed up or down together by using the equation:

avgSens:= (JoyY + JoyZ)/2

Both sticks values count the same direction so there is no problem here.

My problem begins when one stick is pressed up but the other is pressed down. I want to find the average sensitivity level in the ranges of 0 to 47 and 53 to 100 and when one counts one direction but the other counts the other..

I imagine that the easiest way to do this would be to make them both count the same way.

For example if JoyY were to be pressed to 100(down) and JoyZ were to be pressed to 0(up) all I'd have to do is find the inverted value of one or the other (Counting in the same direction) and then use the same equation as before

newJoyZ:= *some equation goes here..*
avgSens:= (JoyY + newJoyZ)/2

But for the life of me I can't figure out how to find the inverted percentage of 100.

I've tried things like (JoyY + ((100-JoyZ)*2))/2 and it's just a horrible mess.

I'll be happy to provide example code or more information if necessary, please go easy on me, my math is terrible.. and thank you in advance for any help you can provide.

Partack
  • 886
  • 11
  • 24

2 Answers2

2

What I would do is change neutral zone to 0, then full down will be 100 and full up -100 on both joysticks. Then, if one is full down (100) and the other is full up (-100), the average will be 0. Hope this helps.

UPDATE

I've expanded my answer after some tests. What you need to do first is to convert both Y values to the format I mentioned, that is 100 full down, 0 to neutral and -100 to full up. You can do this with this simple formula:

NewyValueJoy1 = (ActualYValue-50)*2

So for one Joystick you get:

If is full down (100) you get (100-50)*2=100.

On neutral (50) you get (50-50)*2=0

If full up (0) you get (0-50)*2=-100

So once you do this conversion with the values from both joystick you can do:

AverageYValue = (NewyValueJoy1+NewyValueJoy2) / 2

Very simple! Hope this helps you.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
ericpap
  • 2,917
  • 5
  • 33
  • 52
  • That, um doesn't do it. Instead of 0 and 100 averaging to 50 (neutral), you've now got -100 and 100 averaging to 0 (neutral). – Dane Apr 04 '14 at 19:24
  • It does gives the average value from both y axis, even if one axis is full up and the other full down. If its needed in the same base it can be transform again with the same formula. – ericpap Apr 04 '14 at 19:27
  • As I understand him, he wants the absolute distance from neutral, so that if both joysticks are far from neutral, the average is far from neutral. I've shown what I understand in my own answer now. – Dane Apr 04 '14 at 19:33
1

You're looking for abs(): http://www.autohotkey.com/docs/Functions.htm#Abs

avgSens:= (abs(JoyY-50) + abs(JoyZ-50))/2

The above will give you a number from 0 to 50. 0 is both at neutral. 50 is both as far from neutral as they go (both at either 0 or 100).

Dane
  • 1,201
  • 8
  • 17