A question about adding a module and testing it

Hi all! I am using Ardupilot for a pixhawk 2 and I was just wondering how can I add a module which can read a .bin file from the SD card of pixhawk? The main code of the module is simple and already written, and it only uses a regular header like stdio.h for functions like fread, fopen and fclose, but I wonder whether reading from the SD card would use these same functions or some other?
Also, after adding the module and building the codes, how should I run the added module during SITL simulation? The console only seems to support some fixed command like, arm throttle, take off etc. When using PX4 earlier, I remember the modules added were directly shown in the console as built-in apps and could be executed as commands.

SD card access is probably best answered by @peterbarker
More broadly though, if you haven’t already I suggest getting familiar with the code structure (http://ardupilot.org/dev/ is a good starting place), as it is significantly different from px4.
SITL is really useful and powerful. Attaching a ground station like mavproxy (http://ardupilot.org/dev/docs/copter-sitl-mavproxy-tutorial.html) give access to a lot of functionality.

Check the DataFlash or Terrain libraries for examples of reading data from the SD card.

Please note that the critical thing is that your IO happen in a thread which isn’t the one flying the vehicle :slight_smile:

To control your module from SITL will require either implementing some mavlink messages to interact with the code (these will be applicable on normal vehicles, too), or implementing some sort of hacky backdoor into the code (checking for the existance of files in the filesystem, reading from a pipe, that sort of thing. Naturally, you could also use parameters to configure your module’s functionality.

Thanks much for the help, I’ll further look into the documentations you provided.:metal:

As I was learning through the dev’s guides, I also noticed that the IO module is running in a different thread from the controller, and I have some further question about it.
So basically, I would like to create a small lookup table function or module for gain scheduling that reads in a huge amount of table data (~8MB binary file) and checks the phi and theta angle to select the two needed matrices for the controller.
The designed gain scheduling controller depends on the lookup table data so this lookup table function should be executed with the same freq as the controller (400Hz). I was wondering is it possible to achieve this goal by just using the IO module to read in the table data from the storage or I should resort to some other method for loading them?