ZIBO speed breaks

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

ZIBO speed breaks

#1 Post by bebe100 »

Ok now I know haw to play with (value) to calibrate analog imputs but speed breaks operate from -0,5 to 1.
The question is haw to materialize that.
And thx again

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

Re: ZIBO speed breaks

#2 Post by jph »

A bit of math is needed, that's all ;)

Code: Select all

--  Joe(JPH) - map AM adc input to ZIBO speed brake value

function zibo_speed_brake_adc_convert(x) -- input 0 to 1, output -0.5 to 1.0
  return ( x * ( 1.5 / 1 )) - 0.5
end

-- test the input range
adc_value = 0.5  -- (half range read of a  0 to 1 output)

-- call the convert (map) function
zibo_speed_brake_val = zibo_speed_brake_adc_convert(adc_value)

-- debug print the result
print (zibo_speed_brake_val)
Joe

edit I just realised the hw adc read in AM is 0 to 1 , not 0 to 1023 as per a 10 bit adc so amended the above. It will now work ok with hw_adc_add / read with an output of 0 to 1 converting to -0.5 to 1
Joe. CISSP, MSc.

bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

Re: ZIBO speed breaks

#3 Post by bebe100 »

Thank you very much.I shall try.

bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

Re: ZIBO speed breaks

#4 Post by bebe100 »

Thank you very much.I shall try.

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

Re: ZIBO speed breaks

#5 Post by jph »

No problem.
You may well find that your potentiometer does not have full scale reading when it is fitted. Full scale will give a value between 0 and 1 in AM
If you are not using full scale and full travel, then you can use a function I have provided called 'map()' to map the input range to an output range.

For example, if you set all your hardware up and find that the potentiometer reading in AM with hw_adc_input_read at the 'low' end is 0.178 and at the high end (the end of your mechanical travel when fitted) is, say, 0.743 then use this function to 'map' 0.178 ~ 0.743 to your desired output range of -0.5 ~ 1

Syntax
map(value, fromLow, fromHigh, toLow, toHigh)

Parameters
value: the number to map.
fromLow: the lower bound of the value’s current range.
fromHigh: the upper bound of the value’s current range.
toLow: the lower bound of the value’s target range.
toHigh: the upper bound of the value’s target range.

Returns
The mapped value.

Code: Select all

-- Joe (JPH) - AM - map() function.
function map ( x, in_min, in_max, out_min,  out_max ) 
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
end
-- you can convert the range of travel of your potentiometer to the required level by calling the map() function having previously noted the minimum and maximum adc --- read values such as -
value = map(adc_reading,0.178,0.743,-0.5,1)
Your readings from the limited mechanical travel of the pot are now 'mapped' to the required range for the sim.
Just build this into your code and calls as required.
You can call the function map() at any time with new values for different potentiometers in your sim so it is always easy and simple to convert the range to the required values.
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#6 Post by Keith Baxter »

Hi,

Or you could do something as simple as what I did with the tiller. Note the dataref range is (-1) -> (+1)
As soon as AM4.2 beta has a fix for sorting, I should be able to find a speed break example as I have done it . ;)

It is a simple math one liner...

Code: Select all

hw_adc_input_add("Tiller", function(val)
        xpl_dataref_write("laminar/B738/nosewheel_steer_ratio","FLOAT", (val*2)-1)	   	
end)

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

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

Re: ZIBO speed breaks

#7 Post by jph »

Keith Baxter wrote: Sat Oct 22, 2022 5:48 pm Hi,

Or you could do something as simple as what I did with the tiller. Note the dataref range is (-1) -> (+1)
As soon as AM4.2 beta has a fix for sorting, I should be able to find a speed break example as I have done it . ;)

It is a simple math one liner...

Code: Select all

hw_adc_input_add("Tiller", function(val)
        xpl_dataref_write("laminar/B738/nosewheel_steer_ratio","FLOAT", (val*2)-1)	   	
end)

Keith
You are not understanding Keith. This is allowing for the variations in the mechanical travel of the potentiometer as well, not some simple look up and calc. That is simple.
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#8 Post by Keith Baxter »

jph wrote: Sat Oct 22, 2022 6:12 pm
Keith Baxter wrote: Sat Oct 22, 2022 5:48 pm Hi,

Or you could do something as simple as what I did with the tiller. Note the dataref range is (-1) -> (+1)
As soon as AM4.2 beta has a fix for sorting, I should be able to find a speed break example as I have done it . ;)

It is a simple math one liner...

Code: Select all

hw_adc_input_add("Tiller", function(val)
        xpl_dataref_write("laminar/B738/nosewheel_steer_ratio","FLOAT", (val*2)-1)	   	
end)

Keith
You are not understanding Keith. This is allowing for the variations in the mechanical travel of the potentiometer as well, not some simple look up and calc. That is simple.
Hi,

I do not understand. A potentiometer Is a divider between the total value of the resistance.
Mechanical design should include the total scope of the potentiometer.

Are you suggesting that AM should have a function to compensate for this?

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

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

Re: ZIBO speed breaks

#9 Post by jph »

Keith Baxter wrote: Sat Oct 22, 2022 6:42 pm
Hi,

I do not understand. A potentiometer Is a divider between the total value of the resistance.
Mechanical design should include the total scope of the potentiometer.

Are you suggesting that AM should have a function to compensate for this?

Keith
Hi Keith,
You should ALWAYS be able to compensate and calibrate in code in an easy and simple way. 'mechanical' design will not be perfect and it is certainly NOT (hardly ever) a case where the total 'scope' of the potentiometer should be or is utilised in the design. Most often it is a portion of travel that is used, and not necessarily from one specific end. The need for accuracy and resolution depends on the usage. If as a feedback positional sensor it is far more critical than simple linear - or even mechanically non linear - positioning control however this is not a lesson in mechanical connection methods to the various myriad of analogue input devices and position encoders. It is standard practice to NOT use full travel and functions already exist that can be used - amongst other things - for this. map() in the maker community being one such method but also used for any type of value range conversion.
It is apparent that you have limited real world experience with hardware and electronics in certain areas but the more you actually use analogue input devices the more you will understand that you will come across a multitude of options and hurdles in linkages and drives. When you starting using ADC inputs in closed loop positioning such as A/T or control loading it will become even more evident.
A 'potentiometer' is also not the only option and can be and are being replaced by solid state linked and contactless devices such as a hall unit of the simple variety or the more complex absolute encoders with extremely high accuracy. Even your common or garden game controller often uses only a small portion of the travel and can have 3 setup routines. It is FAR FAR easier and eminently more logical and sensible to make adjustments in code than by 'mechanical' means. Even the most basic 'joystick' only uses a fraction of the potentiometer travel and has multiple calibration and scale setting routines.
Joe
Joe. CISSP, MSc.

bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

Re: ZIBO speed breaks

#10 Post by bebe100 »

Hello Thx to everyone and please make peace.

Post Reply