Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SITL segfault in camera trigger #12547

Merged
merged 2 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ROMFS/px4fmu_common/init.d-posix/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ then
param set SENS_DPRES_OFF 0.001
param set SYS_RESTART_TYPE 2

param set TRIG_INTERFACE 3

param set WEST_EN 0
fi

Expand Down
27 changes: 23 additions & 4 deletions src/drivers/camera_trigger/camera_trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CameraTrigger : public px4::ScheduledWorkItem
/**
* Start the task.
*/
void start();
bool start();

/**
* Stop the task.
Expand Down Expand Up @@ -329,7 +329,9 @@ CameraTrigger::CameraTrigger() :

CameraTrigger::~CameraTrigger()
{
delete (_camera_interface);
if (_camera_interface != nullptr) {
delete (_camera_interface);
}

camera_trigger::g_camera_trigger = nullptr;
}
Expand Down Expand Up @@ -427,9 +429,19 @@ CameraTrigger::shoot_once()
}
}

void
bool
CameraTrigger::start()
{
if (_camera_interface == nullptr) {
if (camera_trigger::g_camera_trigger != nullptr) {
delete (camera_trigger::g_camera_trigger);
bkueng marked this conversation as resolved.
Show resolved Hide resolved
camera_trigger::g_camera_trigger = nullptr;

}

return false;
}

if ((_trigger_mode == TRIGGER_MODE_INTERVAL_ALWAYS_ON ||
_trigger_mode == TRIGGER_MODE_DISTANCE_ALWAYS_ON) &&
_camera_interface->has_power_control() &&
Expand All @@ -456,6 +468,8 @@ CameraTrigger::start()

// start to monitor at high rate for trigger enable command
ScheduleNow();

return true;
}

void
Expand All @@ -472,6 +486,7 @@ CameraTrigger::stop()

if (camera_trigger::g_camera_trigger != nullptr) {
delete (camera_trigger::g_camera_trigger);
camera_trigger::g_camera_trigger = nullptr;
}
}

Expand Down Expand Up @@ -827,7 +842,11 @@ int camera_trigger_main(int argc, char *argv[])
return 1;
}

camera_trigger::g_camera_trigger->start();
if (!camera_trigger::g_camera_trigger->start()) {
PX4_WARN("failed to start camera trigger");
return 1;
}

return 0;
}

Expand Down