Hi, all!
I am using Pixhawk and recently I’ve been developing a module/function to read a large size (around 1.5MB) 4-D matrix of float type from a binary file in the SD card and store the read matrix into the flash memory, 2MB on Pixhawk. The matrix is used for controller gain scheduling, so it should be accessed every time the main loop runs.
As I am starting from scratch, I tried reading a 2*4 test matrix of float type and it went well. However, when I tried with the large matrix, I could not build because I ran out of SRAM, as shown in the error message “region `sram’ overflowed by 524024 bytes”. So I suppose that once the large matrix is read in, it’s stored in the RAM, 256KB on pixhawk, yet it’s way less than enough. Therefore, I was wondering how can I read the matrix from the SD card and store it directly into the flash memory, in order not to overflow the RAM?
Here’s a snippet of my coding, it’s rather simple:
#include <AP_HAL/AP_HAL.h>
#include <stdio.h>
void setup();
void loop();
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
float T_hat_in[103][103][4][4];
void setup(void)
{
hal.scheduler->delay(5000);
hal.console->begin(57600);
hal.console->printf("SD Card reading test startup...\n");
FILE *fp;
fp = fopen("/fs/microsd/table/T_pixhawk.bin", "rb");
fread(&T_hat_in, sizeof(float), 103*103*16, fp);
fclose(fp);
}
void loop(void)
{
hal.console->printf("Read %f \n",T_hat_in[1][1][1][1]);
hal.scheduler->delay(500);
}
AP_HAL_MAIN();