Determining pot values

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
baranismen
Posts: 193
Joined: Sun Jun 02, 2019 6:26 pm

Re: Determining pot values

#11 Post by baranismen »

Ok so, my current pots are 10k, and multiplying the value with 4 gives a good range, but the thing is I have to arrange the pots physical position so precisely otherwise it doesn't move within my physical movement range.

Let's say pot range is between 0 and 10, and the dataref value in XP11 is 0 and 1
As I don't use the whole physical range of pot, I'm limited within 3.5 and 7 let's say.
When I introduce this into the AM, it lacks the range in XP-11 and multiplying the value doesn'T help.
Basically, I need something to convert this 3.5- 7 range into 0 and 1.

Hope I could explain :D

baranismen
Posts: 193
Joined: Sun Jun 02, 2019 6:26 pm

Re: Determining pot values

#12 Post by baranismen »

I tried to explain it in here better.

https://www.dropbox.com/s/wg8jtz515ao6v ... 1.mp4?dl=0

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Determining pot values

#13 Post by Sling »

baranismen wrote: Sat Jan 09, 2021 7:51 am Basically, I need something to convert this 3.5- 7 range into 0 and 1.
That’s just a simple maths conversion. Multiplying does indeed help but only if you make sure to apply an offset.

AM actually gets 0 to 1 on ADC inputs so given your example this would be something like 0.35 to 0.7. If you want to force this into a 0 to 1 range then you simply multiply by the ratio of the output range over the input range. You also need to apply an offset to always start at 0 by subtracting the lowest input value. In this case that would give (adc_input_value - 0.35) * (1/(0.7-0.35)). I’d put this into a var_cap for completeness so the result can never go outside of the 0 to 1 range.

baranismen
Posts: 193
Joined: Sun Jun 02, 2019 6:26 pm

Re: Determining pot values

#14 Post by baranismen »

Sling wrote: Sat Jan 09, 2021 8:31 am
baranismen wrote: Sat Jan 09, 2021 7:51 am Basically, I need something to convert this 3.5- 7 range into 0 and 1.
That’s just a simple maths conversion. Multiplying does indeed help but only if you make sure to apply an offset.

AM actually gets 0 to 1 on ADC inputs so given your example this would be something like 0.35 to 0.7. If you want to force this into a 0 to 1 range then you simply multiply by the ratio of the output range over the input range. You also need to apply an offset to always start at 0 by subtracting the lowest input value. In this case that would give (adc_input_value - 0.35) * (1/(0.7-0.35)). I’d put this into a var_cap for completeness so the result can never go outside of the 0 to 1 range.
I've done something like this but refuses to work, can you help me with this?

Code: Select all

function adc_input_change(value)

percent = var_round(value*100, 0)
print("Input is at " .. percent .. "%")

val = var_cap((adc_input_value - 0.35) * (1/(0.7-0.35)))

xpl_dataref_write("laminar/B738/axis/speedbrake_lever", "FLOAT", {val})
end
hw_adc_input_add("ARDUINO_UNO_A_A0", 0.008, adc_input_change)

baranismen
Posts: 193
Joined: Sun Jun 02, 2019 6:26 pm

Re: Determining pot values

#15 Post by baranismen »

Code: Select all

function adc_input_change(value)

print(value)

xpl_dataref_write("laminar/B738/axis/speedbrake_lever", "FLOAT", (value - 0.4) * (1/(0.56-0.4)))
end
hw_adc_input_add("ARDUINO_UNO_A_A0", 0.009, adc_input_change)
this works okay, just need to integrate the var_cap function into this.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Determining pot values

#16 Post by Sling »

Go to the wiki page for var_cap and make sure you put all the arguments into the function. The first code is correct other than the var_cap which is missing the cap limits and you need to replace the variable name adc_input_value with the name of the var you chose (value). It looks like you changed your values in the second piece of code so you’ll have to put those into the first bit of code and all will be good.

You have not got much travel on that pot as you are only seeing a 0.16 range. It would be better if you could gear the drive to that pot if you can.

baranismen
Posts: 193
Joined: Sun Jun 02, 2019 6:26 pm

Re: Determining pot values

#17 Post by baranismen »

Thanks for the help, I've finally managed to do everything in the correct order. I had a minor problem with the flaps axis but I used the throttle panel codes in the community to fix the angles to 0.125 and multiples until 1 using <= and => and it's all good now.

User avatar
Huberflight
Posts: 42
Joined: Sat Mar 31, 2018 2:27 pm

Re: Determining pot values

#18 Post by Huberflight »

Hi all. @baranismen can you please post your final code?
thx
When it looks not right, go around. It's easier to explain why you done it, than for others to finde out why you don't.

baranismen
Posts: 193
Joined: Sun Jun 02, 2019 6:26 pm

Re: Determining pot values

#19 Post by baranismen »

Huberflight wrote: Sat Feb 13, 2021 8:36 pm Hi all. @baranismen can you please post your final code?
thx
Hi, sorry for the late response, If I won't forget, I'll do it tonight :)

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Determining pot values

#20 Post by jph »

It is important that you ensure the range of movement of the potentiometer is suitable for your purpose. 'Sling' - mentions potential gearing and is more or less right.
A 'pot' connected to an adc, with the appropriate - nominal - voltage applied to the fixed resistor part, will only output, on the wiper, the proportion of the range of the adc voltage change in direct relationship to the 'pot' maximum movement (usually about 270 degrees) / the pot actual movement in your design, in degrees, hence, for your example of your 'control' in the video - presuming a nominal pot with a 270 degree rotation end to end, (pretty standard) and the movement of around 40 degrees that you are applying, then the output ADC voltage change 'swing' would only be around V max applied to the 'pot' / (270/40) - or, in reality,- ADC 'swing' = V max applied to Pot fixed part / (actual max angle of pot rotation / your implemented angle of rotation)
Hence the low values.
This also introduces an issue with 'resolution' as the voltage 'step change' (resolution) is now equal to the original ADC resolution / (270 / 40) ... or whatever your maximum 'throw' percentage is.
It is just worth noting and understanding the above.
For non critical items such as - say - flap levers - even perhaps, throttles, mixture etc, then is probably doesn't make much difference apart from a lack of 'fine' adjustment'
It is definitely an issue for people trying to use a similar system with a limited range of movement compared to the pot max range in degrees, when it comes to flight controls.
as an example - let us presume a 0-5V range.
Our POT is 270 degrees range. Our design limits the pot to 43 degrees movement.
So, 270/ 43 = 6.28 (throw ratio)
0-1 (which is the adjusted value for the range in AM = max of 1. (0-1)
The solution is -
AM limit =1
Hence :-
1 / (max pot angle / used pot angle) = AM change
As in - a pot rotation of 270 degrees with a 43 degrees used rotation =
1 / 6.28 = 0.16 (change in value over range of movement.)
Knowing the actual pot rotation max angle, and the change in AM, this could be used in reverse to also calculate the actual throw angle of your pot usage. (although it is easier to measure it with a protractor ;) ).
Also, the percentage difference between the used rotation value and the max rotation value is also directly related when the AM range is 0-1 . In this case, it is 16%, so 16% of 1 = 0.16..... our magic number again.
Resolution change is also proportional. - it DECREASES in relation to the nominal value / (Pot range / pot used range)
Note - the 'value' in Ohms of the POT and the Voltage applied to the fixed section is of no relevance providing it is within ADC limits as per the processor datasheet. The results are the same.
The above is simply for assessing the values achieved.
Joe.
Joe. CISSP, MSc.

Post Reply