diff --git a/src/drivers/camera_trigger/camera_trigger.cpp b/src/drivers/camera_trigger/camera_trigger.cpp index 965d7671ab..1cc87c95bf 100644 --- a/src/drivers/camera_trigger/camera_trigger.cpp +++ b/src/drivers/camera_trigger/camera_trigger.cpp @@ -372,18 +372,37 @@ CameraTrigger::cycle_trampoline(void *arg) if (pos.xy_valid) { - // Initialize position if not done yet - math::Vector<2> current_position(pos.x, pos.y); + if (updated && trig->_mode == 4) { - if (!trig->_valid_position) { - trig->_last_shoot_position = current_position; - trig->_valid_position = pos.xy_valid; + // Check update from command + struct vehicle_command_s cmd; + orb_copy(ORB_ID(vehicle_command), trig->_vcommand_sub, &cmd); + + if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_SET_CAM_TRIGG_DIST) { + + // Set trigger to false if the set distance is not positive + trig->_trigger_enabled = cmd.param1 > 0.0f; + trig->_distance = cmd.param1; + } } - // Check that distance threshold is exceeded and the time between last shot is large enough - if ((trig->_last_shoot_position - current_position).length() >= trig->_distance) { - trig->shootOnce(); - trig->_last_shoot_position = current_position; + if (trig->_trigger_enabled || trig->_mode < 4) { + + // Initialize position if not done yet + math::Vector<2> current_position(pos.x, pos.y); + + if (!trig->_valid_position) { + // First time valid position, take first shot + trig->_last_shoot_position = current_position; + trig->_valid_position = pos.xy_valid; + trig->shootOnce(); + } + + // Check that distance threshold is exceeded and the time between last shot is large enough + if ((trig->_last_shoot_position - current_position).length() >= trig->_distance) { + trig->shootOnce(); + trig->_last_shoot_position = current_position; + } } } else { diff --git a/src/drivers/camera_trigger/camera_trigger_params.c b/src/drivers/camera_trigger/camera_trigger_params.c index 50693e899c..a9b7ecc701 100644 --- a/src/drivers/camera_trigger/camera_trigger_params.c +++ b/src/drivers/camera_trigger/camera_trigger_params.c @@ -77,11 +77,11 @@ PARAM_DEFINE_FLOAT(TRIG_ACT_TIME, 0.5f); /** * Camera trigger mode * - * 0 disables the trigger, 1 sets it to enabled on command, 2 always on, 3 distance based + * 0 disables the trigger, 1 sets it to enabled on command, 2 always on, 3 distance based, 4 distance based enabled on command * * * @min 0 - * @max 3 + * @max 4 * @group Camera trigger */ PARAM_DEFINE_INT32(TRIG_MODE, 0);