Last active
February 14, 2021 13:20
-
-
Save theely/ab6dcf35dc912cf3da30525f97950e04 to your computer and use it in GitHub Desktop.
Rolling GPS latlong logging. Stores the latest 100 distinct latlong coordinates (redundant coordinates are ignored). Coordinates are stored in: /LOGS/GPS_rolling_positions.log. Logging is paused if less than 4 satellites are available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- License https://www.gnu.org/licenses/gpl-3.0.en.html | |
-- OpenTX Lua script | |
-- FUNCTION | |
-- Place this file in SD Card > /SCRIPTS/FUNCTIONS/ | |
-- Author: Elia P. | |
-- Date: 2019 November 02 | |
-- Description | |
-- Rolling GPS latlong logging | |
-- Stores the latest 100 distinct latlong coordinates (redundant coordinates are ignored). | |
-- If the number of sats is smaller than 4 coordinates are not recorded. | |
-- requires GPS telemetry and SD Card | |
-- Set-iup: | |
-- Run the script every 2 seconds via a Logic Switch. | |
-- Create a timer Logic Switch with a duration of 0.1s and a pause 2s. | |
local NumCoordinatesToPersist = 100 | |
local function rnd(v,d) | |
if d then | |
return math.floor((v*10^d)+0.5)/(10^d) | |
else | |
return math.floor(v+0.5) | |
end | |
end | |
local function getGPSLatLon() | |
gpsLatLon = getValue("GPS") | |
if (type(gpsLatLon) == "table") then | |
return rnd(gpsLatLon["lat"],5) .. ", " .. rnd(gpsLatLon["lon"],5) | |
else | |
return "not currently available" | |
end | |
end | |
local function init_func() | |
end | |
local function log_position(latlog,alt,sats) | |
local logFile = "/LOGS/GPS_rolling_positions.log" | |
local logRead = io.open(logFile,"r") | |
local previous_positions = "" | |
if logRead ~= nil then | |
-- every log entry is exactly 90chars | |
previous_positions = io.read(logRead,90*(NumCoordinatesToPersist-1)) | |
previous_position = "" | |
for match in string.gmatch(previous_positions, 'LatLong: +"([0-9 ,.-]+)"') do | |
previous_position = match | |
break | |
end | |
io.close(logRead) | |
end | |
if latlog == previous_position then | |
return | |
end | |
local logWrite = io.open(logFile,'w') | |
if logWrite ~= nil then | |
io.write(logWrite,string.format("%-13s%-22s","LatLong:",'"'..latlog..'"')) | |
io.write(logWrite,string.format("%13s%07d","Altitude:",alt)) | |
io.write(logWrite,string.format("%11s%02d","Sats:",sats)) | |
local now = getDateTime() | |
io.write(logWrite,string.format("%21s", now.year.."-"..now.mon.."-"..now.day.." "..now.hour..":"..now.min..":"..now.sec)) | |
io.write(logWrite,"\n") | |
io.write(logWrite,previous_positions) | |
io.close(logWrite) | |
end | |
end | |
local function run_func() | |
latlog = getGPSLatLon() | |
alt = getValue("Alt") | |
sats = getValue("Sats") | |
if sats > 3 then | |
log_position(latlog,alt,sats) | |
end | |
end | |
return { run=run_func, init=init_func } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- License https://www.gnu.org/licenses/gpl-3.0.en.html | |
-- OpenTX Lua script | |
-- TELEMETRY | |
-- Place this file in SD Card > /SCRIPTS/TELEMETRY/ | |
-- Author: Elia P. | |
-- Date: 2019 November 02 | |
-- Description | |
-- Rolling GPS latlong log Screen | |
-- To be used with the FUNCTION/GPSLog.lua script. | |
-- Display on the screen the last 5 logged GPS coordinate | |
local function init_func() | |
end | |
local function bg_func() | |
-- Called periodically when screen is not visible | |
-- This could be empty | |
-- Place code here that would be executed even when the telemetry | |
-- screen is not being displayed on the Tx | |
end | |
local TextHeader = "GPS LOG " | |
local function run_func(event) | |
-- Called periodically when screen is visible | |
local logFile = "/LOGS/GPS_rolling_positions.log" | |
local logRead = io.open(logFile,"r") | |
lcd.clear() | |
-- XXLSIZE, MIDSIZE, SMLSIZE, INVERS, BLINK | |
lcd.drawText(1, 1, TextHeader, MIDSIZE + INVERS) | |
local line = 16; | |
if logRead ~= nil then | |
-- every log entry is exactly 90chars, read 5 lines meaning 450 chars | |
previous_positions = io.read(logRead,450) | |
for match in string.gmatch(previous_positions, 'LatLong: +"([0-9 ,.-]+)"') do | |
lcd.drawText(1, line, match,0) | |
line = line + 10 | |
end | |
io.close(logRead) | |
end | |
end | |
return { run=run_func, background=bg_func, init=init_func } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this. Any luck in getting the export to CSV?