AOA Indexer Project

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

AOA Indexer Project

#1 Post by DH14300 »

Hello,
I'm new to the Sim Innovations community and built an AOA Indexer using an Arduino Nano and am using P3Dv5. I have 3 LEDs connected to my Nano (pins D2, D4 & D6). I have created the following script to interface with Air Manager and will be testing it out this evening. Take a look at it and let me know if you see any issues! During testing I will tweak the values (in radians) to match the virtual cockpit's AOA Indexer. I'll post pictures of my project to this thread later this evening as well:

led_AOAlow = hw_led_add("ARDUINO_NANO_A_D2", 1) --starts LED 'ON'
led_AOAnorm = hw_led_add("ARDUINO_NANO_A_D4", 1) --starts LED 'ON'
led_AOAhigh = hw_led_add("ARDUINO_NANO_A_D6", 1) --starts LED 'ON'

function new_data_fsx(AOAlow, AOAnorm, AOAhigh)

-- SLOW indicator
AOAlow <= 2.3
if AOAlow <= 2.3 then
hw_led_set(led_AOAlow, 1)
else
hw_led_set(led_AOAlow, 0)
end

-- ON SPEED indicator
AOAnorm <= 2.55 and AOAnorm >=2.25
if AOAnorm <= 2.55 and AOAnorm >=2.25 then
hw_led_set(led_AOAnorm, 1)
else
hw_led_set(led_AOAnorm, 0)
end

-- FAST indicator
AOAhigh >= 2.6
if AOAhigh <= 2.3 then
hw_led_set(led_AOAhigh, 1)
else
hw_led_set(led_AOAhigh, 0)
end
end

fsx_variable_subscribe("INCIDENCE ALPHA", "Radians", new_data_fsx)

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: AOA Indexer Project

#2 Post by SimPassion »

DH14300 wrote: Mon Sep 26, 2022 7:42 pm Hello,
I'm new to the Sim Innovations community and built an AOA Indexer using an Arduino Nano and am using P3Dv5. I have 3 LEDs connected to my Nano (pins D2, D4 & D6). I have created the following script to interface with Air Manager and will be testing it out this evening. Take a look at it and let me know if you see any issues! During testing I will tweak the values (in radians) to match the virtual cockpit's AOA Indexer. I'll post pictures of my project to this thread later this evening as well:

led_AOAlow = hw_led_add("ARDUINO_NANO_A_D2", 1) --starts LED 'ON'
led_AOAnorm = hw_led_add("ARDUINO_NANO_A_D4", 1) --starts LED 'ON'
led_AOAhigh = hw_led_add("ARDUINO_NANO_A_D6", 1) --starts LED 'ON'

function new_data_fsx(AOAlow, AOAnorm, AOAhigh)

-- SLOW indicator
AOAlow <= 2.3
if AOAlow <= 2.3 then
hw_led_set(led_AOAlow, 1)
else
hw_led_set(led_AOAlow, 0)
end

-- ON SPEED indicator
AOAnorm <= 2.55 and AOAnorm >=2.25
if AOAnorm <= 2.55 and AOAnorm >=2.25 then
hw_led_set(led_AOAnorm, 1)
else
hw_led_set(led_AOAnorm, 0)
end

-- FAST indicator
AOAhigh >= 2.6
if AOAhigh <= 2.3 then
hw_led_set(led_AOAhigh, 1)
else
hw_led_set(led_AOAhigh, 0)
end
end

fsx_variable_subscribe("INCIDENCE ALPHA", "Radians", new_data_fsx)
I've made a small fix for FAST Indicator, where you said it would be >= 2.6 and the check is showing : "if AOAhigh <= 2.3 then"

Code: Select all

led_AOAlow = hw_led_add("ARDUINO_NANO_A_D2", 1) --starts LED 'ON'
led_AOAnorm = hw_led_add("ARDUINO_NANO_A_D4", 1) --starts LED 'ON'
led_AOAhigh = hw_led_add("ARDUINO_NANO_A_D6", 1) --starts LED 'ON'

function new_data_fsx(AOAlow, AOAnorm, AOAhigh)

	-- SLOW indicator AOAlow <= 2.3

	if AOAlow <= 2.3 then
		hw_led_set(led_AOAlow, 1)
	else
		hw_led_set(led_AOAlow, 0)
	end

	-- ON SPEED indicator AOAnorm <= 2.55 and AOAnorm >=2.25

	if AOAnorm <= 2.55 and AOAnorm >=2.25 then
		hw_led_set(led_AOAnorm, 1)
	else
		hw_led_set(led_AOAnorm, 0)
	end

	-- FAST indicator AOAhigh >= 2.6

	if AOAhigh >= 2.6 then
		hw_led_set(led_AOAhigh, 1)
	else
		hw_led_set(led_AOAhigh, 0)
	end
end

fsx_variable_subscribe("INCIDENCE ALPHA", "Radians", new_data_fsx)

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#3 Post by DH14300 »

Thank you for looking at my code and finding that! Here's a couple pics of my project. I've re-mounted my Indexer on the left side of the HUD since these were taken and it's straighter as well. On to testing the new code! I'll post my results once I have them.
AoA2.jpg
AoA1.jpg

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#4 Post by DH14300 »

Progress!
I've remarked out 2 of the 3 LEDs to focus on just the 'AOAhigh' LED. I'm able turn it on but not off when it should. Here's the code and the read value. At this point I want the LED off but it's still on:
AOAprojectStatus1.PNG

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

Re: AOA Indexer Project

#5 Post by Sling »

Hi and welcome to Air Manager.

Your code has a couple of obvious issues at a quick glance.

1 - You have subscribed to a single variable but are using 3 different arguments in the associated callback. I’d suggest you just call this AoA.

2 - You are declaring the comparison variable before your if..else with a fixed value so it will always do the same thing (turn on the output).

Another thing that may help is if you make the subscribe type “Degrees” as these are easier to work with and comprehend.

If you are getting to grips with how the individual API functions are used I’d suggest studying the wiki API pages and the video tutorials linked in my signature below.

Hope this helps.

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: AOA Indexer Project

#6 Post by Ralph »

One more thing. If you're not going to dim the LED's, then you can use hw_output_add and _set. Then you can do your statement within the set. So for example hw_output_set(led_a, aoa >= 10)

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#7 Post by DH14300 »

Thank you guys both for your input! This is my first attempt at writing code so this helps me tremendously. Will make edit later today & test.

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#8 Post by DH14300 »

Ralph, regarding using degrees instead of radians, the sim variable is in radians by default so I would need a conversion line of code somewhere correct?

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: AOA Indexer Project

#9 Post by Ralph »

If you subscribe to degrees then you would just get different values from the simulator.

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#10 Post by DH14300 »

I'm rewriting the code based on the helpful feedback I've received so far. Changes include:
1. Using only 1 argument in the callback (just 'AOA') instead of 3 arguments previously
2. Changed Radians to Degrees
3. Using "hw_output_add" & "hw_output_set" instead of "hw_led_add" & "hw_led_set" (I don't need to adjust LED brightness)
4. Removed the fixed AOA values previously called out
Focusing on just 1 LED for now (AOAhigh), I want the LED to turn On for values >=8.8, otherwise Off. My revised code is as follows:

led_AOAhigh = hw_output_add("ARDUINO_NANO_A_D6", true)

function new_data_fsx(AOA)
if AOA >=8.8
hw_output_set(led_AOAhigh, true)
else
hw_output_set(led_AOAhigh, false)
end
end

fsx_variable_subscribe("INCIDENCE ALPHA", "Degrees", new_data_fsx)


I will be testing this out tonight and will post my results. Feel free to provide feedback as I continue development.
Thank you for all of your help!
Dan

Post Reply