Hello,
I’m trying to build a kind af API for inserting code that’s generated from Simulink Models (I know theres a support package but I won’t use it). I’m using the 1.9.2 (stable) version. The following codes are minimized to only show relevant content, so some logics may look useless.
The idea is to call a function foo every 10ms with hrt_call_every (see test_module.cpp). This function reads in sensor topics, provides them to a step function that includes the simulink model code and forwards the outputs to the actuator_outputs_0 topic.
Now I have a problem with reading the sensor topics. With sitl (jmavsim) everything works. But when I upload the code on my Pixhawk 4 and start the module, the PH reboots and the Bootloader Error for the FMU is solid (fault log below). The return value from orb_copy turns after a few cycles to -1, so there is an error somewhere. How can I fix this, so that I can read the sensor topics every 10ms?
Thanks in advance!
EDIT: I’ve found an easier way to reproduce the problem (see code below)
#include <px4_config.h>
#include <px4_tasks.h>
#include <px4_posix.h>
#include <drivers/drv_hrt.h>
#include <stdio.h>
#include <uORB/uORB.h>
#include <uORB/topics/sensor_gyro.h>
#include <uORB/topics/sensor_accel.h>
int subs[2];
sensor_gyro_s gyro_data = {};
sensor_accel_s accel_data = {};
int foo(void);
int foo(void)
{
// copy topics
orb_copy(ORB_ID(sensor_gyro), subs[0], &gyro_data);
orb_copy(ORB_ID(sensor_accel), subs[1], &gyro_data);
return 0;
}
extern "C" __EXPORT int test_module_main(int argc, char *argv[]);
int test_module_main(int argc, char *argv[])
{
// Initialize
struct hrt_call loopcall;
subs[0] = orb_subscribe(ORB_ID(sensor_gyro));
subs[1] = orb_subscribe(ORB_ID(sensor_accel));
hrt_call_every(&loopcall, 0, (0.1 * 1000 * 1000), (hrt_callout)&foo, 0);
while (true) {
px4_sleep(1);
}
return 0;
}
fault log
(I don’t have a reader for the SD-Card here. If you need the full file, I’ll get one)