Nearest Way Point
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Nearest Way Point
Hey guys. I'm finishing an instrument with great difficulty due to my still insufficient knowledge of Lua Script and the peculiarities with the Air Manager. Could any Lua, Air Manger and Navigation experts give me an idea of how to capture the next Way point and show its identification on the screen, at the same time showing the other necessary samples on this screen? I would greatly appreciate a clarification.
I would like justthe Waypoint nearest in the panel. The other entrees I will solve.
Thanks
I would like justthe Waypoint nearest in the panel. The other entrees I will solve.
Thanks
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Nearest Way Point
Hi,
Yes it can be done using the NAV features.
I will point you in the right direction tomorrow. I am busy helping someone else right now.
Keith
Yes it can be done using the NAV features.
I will point you in the right direction tomorrow. I am busy helping someone else right now.
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
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Nearest Way Point
Thank You.
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Nearest Way Point
Good morning boys.
One thing I still didn't get right was capturing WAYPOINTS to make it appear in a NEAREST WAYPOINT field. If possible, could you send me an example for a coordinate
Lat - 23,620 and Lon - 46,661
I would appreciate this knowledge. I tried with the information received, but with no success.
Thank you all
One thing I still didn't get right was capturing WAYPOINTS to make it appear in a NEAREST WAYPOINT field. If possible, could you send me an example for a coordinate
Lat - 23,620 and Lon - 46,661
I would appreciate this knowledge. I tried with the information received, but with no success.
Thank you all
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Nearest Way Point
Hi,Marcnamara2021 wrote: ↑Tue Dec 07, 2021 8:24 am Good morning boys.
One thing I still didn't get right was capturing WAYPOINTS to make it appear in a NEAREST WAYPOINT field. If possible, could you send me an example for a coordinate
Lat - 23,620 and Lon - 46,661
I would appreciate this knowledge. I tried with the information received, but with no success.
Thank you all
I do not mind helping but it seems that you have a lot of lua basics to learn.
What you are attempting is for advanced users and you should be attempting simpler instruments till you understand how everything works.
I simply took this from the API example I pointed you to.
The code examples in the API (WIKI) are there to assist. Try and solve them yourself first and then ask for help as to where you are going wrong. That way you learn faster. Try just short bits of code and then incorporate into the bigger instrument.
NOTE: The sim must be running for this code to work. The NAV features work via the sim plugin.
Code: Select all
robR_36witC="font:arimo_bold.ttf; size:36px; color: white; halign:left; valign:center;"
background = canvas_add(0, 0, 600, 600, function()
_rect(0,0,400,512)
_fill("blue")
end)
---What this function is doing is creating a TABLE named <waypoints>
local function data_callback(waypoints)
if waypoints ~= nil then
-- Print the found waypoints to log
canvas_draw( background,function()
_rect(0,0,400,512)
_fill("blue")
for i=1, #waypoints do
print(" name:" .. waypoints[i]["ICAO"] .. " lon:" .. waypoints[i]["LONGITUDE"] .. " lat:" .. waypoints[i]["LATITUDE"])
_txt(waypoints[i]["ICAO"],robR_36witC,200,100+ (i*35))
end
end)
else
print("Error while querying nav data")
end
end
-- Find the nearest 5 waypoints from a certain latitude and longitude
nav_get_nearest("WAYPOINT", 23.620, 46.661, 5, data_callback)
after adding your wpt_text=txt_add(bla,bla,bla.) outside the function.
inside the data_callback function
txt_set(wpt_text,waypoints[1]["ICAO"] )
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
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Nearest Way Point
Hi.
After trying a few times to configure the resource to find the closest waypoint, having the position of the aircraft as the coordinate source, only the first detected waypoint remains, but no new detections occur during the flight. Could you redirect me to some topic that can complete this script?
Thanks.
After trying a few times to configure the resource to find the closest waypoint, having the position of the aircraft as the coordinate source, only the first detected waypoint remains, but no new detections occur during the flight. Could you redirect me to some topic that can complete this script?
Thanks.
Code: Select all
robR_36witC="font:arimo_bold.ttf; size:36px; color: white; halign:left; valign:center;"
background = canvas_add(0, 0, 600, 600, function()
_rect(0,0,400,512)
_fill("blue")
end)
---What this function is doing is creating a TABLE named <waypoints>
local function data_callback(waypoints)
if waypoints ~= nil then
-- Print the found waypoints to log
canvas_draw( background,function()
_rect(0,0,400,512)
_fill("blue")
for i=1, #waypoints do
print(" name:" .. waypoints[i]["ICAO"] .. " lon:" .. waypoints[i]["LONGITUDE"] .. " lat:" .. waypoints[i]["LATITUDE"])
_txt(waypoints[i]["ICAO"],robR_36witC,200,100+ (i*35))
end
end)
else
print("Error while querying nav data")
end
end
function latitude_callback_and_longitude_callback(lat1, lon1)
print("Latitude: " .. lat1)
print("Longitude: " .. lon1)
nav_get_nearest("WAYPOINT",lat1, lon1, 1, data_callback)
end
xpl_dataref_subscribe("sim/flightmodel/position/latitude", "DOUBLE",
"sim/flightmodel/position/longitude", "DOUBLE", latitude_callback_and_longitude_callback)
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Nearest Way Point
Hi,
Call the data_callback() inside the latitude_callback_and_longitude_callback(lat1, lon1) function. However it is best to use the dataref_throttle or timer function for this. Else you will be creating a loop of sorts and inviting a search of the waypoint database every time a dataref fires in the latitude_callback_and_longitude_callback(lat1, lon1) callback.
https://www.forums.siminnovations.com/v ... 248#p31769
Keith
Call the data_callback() inside the latitude_callback_and_longitude_callback(lat1, lon1) function. However it is best to use the dataref_throttle or timer function for this. Else you will be creating a loop of sorts and inviting a search of the waypoint database every time a dataref fires in the latitude_callback_and_longitude_callback(lat1, lon1) callback.
https://www.forums.siminnovations.com/v ... 248#p31769
Keith
Last edited by Keith Baxter on Fri Dec 10, 2021 10:18 am, edited 1 time in total.
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
Re: Nearest Way Point
You could also call the data_callback with a timer, every x amount of seconds. That would be a quick and dirty method. Or maybe more elegant, a delta check in your coordinates. If your position differs an x amount of the position you had with the last check, then you do another call to the data_callback.
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Nearest Way Point
100's Ralph.Ralph wrote: ↑Fri Dec 10, 2021 10:18 am You could also call the data_callback with a timer, every x amount of seconds. That would be a quick and dirty method. Or maybe more elegant, a delta check in your coordinates. If your position differs an x amount of the position you had with the last check, then you do another call to the data_callback.
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
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Nearest Way Point
Hi!
Maybe I'm doing something really wrong, or maybe my language's number system doesn't match the right scores. I can't get the waypoint to update on the screen by trying all methods. It captures only the first one that stays static the entire flight time. As you said, in my basic knowledge, it is better to carry out simple instruments, but I believe that the simple search for updating a navigation data is a very simple task. I just want to know where I'm going wrong, as some of the examples that were posted here didn't work. In this little script, I could make it functional, so if it's ok, testing here would make sure I have a system compatibility issue and then I'll take the right steps.
Thanks
Maybe I'm doing something really wrong, or maybe my language's number system doesn't match the right scores. I can't get the waypoint to update on the screen by trying all methods. It captures only the first one that stays static the entire flight time. As you said, in my basic knowledge, it is better to carry out simple instruments, but I believe that the simple search for updating a navigation data is a very simple task. I just want to know where I'm going wrong, as some of the examples that were posted here didn't work. In this little script, I could make it functional, so if it's ok, testing here would make sure I have a system compatibility issue and then I'll take the right steps.
Thanks
Code: Select all
robR_36witC="font:arimo_bold.ttf; size:36px; color: white; halign:left; valign:center;"
background = canvas_add(0, 0, 600, 600, function()
_rect(0,0,400,512)
_fill("blue")
end)
---What this function is doing is creating a TABLE named <waypoints>
local function data_callback(waypoints)
if waypoints ~= nil then
-- Print the found waypoints to log
canvas_draw( background,function()
_rect(0,0,400,512)
_fill("blue")
for i=1, #waypoints do
print(" name:" .. waypoints[i]["ICAO"] .. " lon:" .. waypoints[i]["LONGITUDE"] .. " lat:" .. waypoints[i]["LATITUDE"])
_txt(waypoints[i]["ICAO"],robR_36witC,200,100+ (i*35))
end
end)
else
print("Error while querying nav data")
end
end
function latitude_callback_and_longitude_callback(lat1, lon1)
print("Latitude: " .. lat1)
print("Longitude: " .. lon1)
nav_get_nearest("WAYPOINT",lat1, lon1, 1, data_callback)
end
xpl_dataref_subscribe("sim/flightmodel/position/latitude", "DOUBLE",
"sim/flightmodel/position/longitude", "DOUBLE", latitude_callback_and_longitude_callback)