mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 15:28:53 +08:00
fix fmu: make sure init() is called on the new task
This was only a problem when running as a task not on the work queue. The problem was that init() opened the RC serial device, which was then read in the main loop, which is a different context when run as a task.
This commit is contained in:
+19
-10
@@ -171,6 +171,11 @@ public:
|
||||
/** @see ModuleBase::run() */
|
||||
void run() override;
|
||||
|
||||
/**
|
||||
* run the main loop: if running as task, continuously iterate, otherwise execute only one single cycle
|
||||
*/
|
||||
void cycle();
|
||||
|
||||
/** @see ModuleBase::print_status() */
|
||||
int print_status() override;
|
||||
|
||||
@@ -1062,7 +1067,7 @@ PX4FMU::cycle_trampoline(void *arg)
|
||||
_object = dev;
|
||||
}
|
||||
|
||||
dev->run();
|
||||
dev->cycle();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1181,6 +1186,18 @@ PX4FMU::update_pwm_out_state(bool on)
|
||||
|
||||
void
|
||||
PX4FMU::run()
|
||||
{
|
||||
if (init() != 0) {
|
||||
PX4_ERR("init failed");
|
||||
exit_and_cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
cycle();
|
||||
}
|
||||
|
||||
void
|
||||
PX4FMU::cycle()
|
||||
{
|
||||
while (true) {
|
||||
|
||||
@@ -3355,15 +3372,7 @@ PX4FMU::fake(int argc, char *argv[])
|
||||
PX4FMU *PX4FMU::instantiate(int argc, char *argv[])
|
||||
{
|
||||
// No arguments to parse. We also know that we should run as task
|
||||
PX4FMU *dev = new PX4FMU(true);
|
||||
|
||||
if (dev && dev->init() != 0) {
|
||||
PX4_ERR("init failed");
|
||||
delete dev;
|
||||
dev = nullptr;
|
||||
}
|
||||
|
||||
return dev;
|
||||
return new PX4FMU(true);
|
||||
}
|
||||
|
||||
int PX4FMU::custom_command(int argc, char *argv[])
|
||||
|
||||
Reference in New Issue
Block a user