How do I create files under AP with externally-supplied data?

I want to create a very richly formatted configuration file on my AP platform (Pixhawk w/ Black Cube); the contents of this file are defined on my PC. I want to transfer the file from my PC to my AP platform. How might I do that? I am, of course, also using MissionPlanner (I am thinking MP might help somehow).

Once the file is in place on my AP platform, some AP code that I have added would read and digest its contents; the contents would affect flight. For operational purposes, I would like, at the end of flight ops, to be able to read the file from my AP platform back to my PC to log exactly the bits that were on the AP platform during flight.

All tips, hints and comments on how to remotely create/write/read files are welcome!

Thanks much.


Use MAVFTP to transfer the files to and from the CubeBlack
Use lua scripting to read the files on the CubeBlack and affect the flight
Use lua scripting to collect data during the flight to the sdcard.

Thanks for the quick response.

Ideally, I want to read the files from within AP (eg. from code called from Copter.cpp) at start-up time. As I understand it (and I could be wrong), Lua runs beside AP; that makes me wonder, if Lua were to read the files, how AP would effectively grab the data from Lua.



lua runs beside arducopter and communicates with it. You should not need to change copter.cpp, just write lua

I will also recommend using lua scripting for what you looking to do, checkout this example

Still if you trying to implement file I/O within ardupilot codebase, you can take a hint from this example, to implement something like this example within ardupilot codebase then make sure that file I/O operations happen within a separate IO thread, don’t try to read/write files from SD card within scheduler tasks, with that you will endup blocking the main thread, and ardupilot watchdog will reboot the FC inflight and your vehicle will come crashing to the ground

Thanks for the quick and helpful responses! Much appreciated.