Trying to get a drone to log coordinates into a .txt or .csv file while in flight. Not getting any success. I’m using a slightly modified version of the example script here. I have modified it to save to SD only and to log ahrs.get_position() instead of roll, etc (I’ll paste my script at the bottom). I’ve enabled SCR_ENABLE and increased SCR_HEAP_SIZE to 65k up from 44k.
I have the .txt file created in the same directory as the script, and tried stepping back to just writing “Hello World” but can’t get anything to print. One issue I had but got around was having my scripts show up in mission planner as file_name.lua.txt but that was fixed by saving as filename.LUA at which point the system seems to recognize it as the correct format. As I understand it the scripts run on startup. Is the SD card what I’m accessing from mission planner when connected by USB? Accessing the SD card on this chip requires dismantling the drone.
I was wondering if anyone had pointers that could help me get this working. Thanks!
-- example of logging to a file on the SD card and to data flash local file_name = "LOG_DATA.txt" local file -- the data local coords = ahrs.get_position() local function write_to_file() if not file then error("Could not open file") end -- write data -- separate with comas and add a carriage return file:write(tostring(millis()) .. ", " .. coords .. "\n") -- make sure file is upto date file:flush() end function update() coords = ahrs:get_position() -- write to then new file the SD card write_to_file() return update, 3000 -- reschedules the loop end -- make a file -- note that this appends to the same the file each time, you will end up with a very big file -- you may want to make a new file each time using a unique name file = io.open(file_name, "a") if not file then error("Could not make file") end -- write the CSV header file:write('Time Stamp(ms), coordinates\n') file:write("Hello World\n") file:flush() return update, 10000