51 #include <mathlib/mathlib.h> 53 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 77 typedef enum : int32_t {
85 typedef enum : int32_t {
93 #define commandParamToInt(n) static_cast<int>(n >= 0 ? n + 0.5f : n - 0.5f) 236 ScheduledWorkItem(MODULE_NAME,
px4::wq_configurations::lp_default),
282 switch (_camera_interface_mode) {
305 PX4_ERR(
"unknown camera interface mode: %i", (
int)_camera_interface_mode);
315 PX4_WARN(
"Trigger interval too low for PWM interface, setting to 40 ms");
322 if (!_cam_cap_fback) {
368 if (local.xy_valid) {
499 vcmd.command = vehicle_command_s::VEHICLE_CMD_DO_DIGICAM_CONTROL;
502 vcmd_pub.publish(vcmd);
509 int poll_interval_usec = 5000;
512 unsigned cmd_result = vehicle_command_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED;
513 bool need_ack =
false;
526 if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_DIGICAM_CONTROL) {
540 cmd_result = vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED;
542 }
else if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_TRIGGER_CONTROL) {
566 cmd_result = vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED;
568 }
else if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_SET_CAM_TRIGG_DIST) {
576 if (cmd.param1 > 0.0f) {
591 if (cmd.param2 > 0.0f) {
599 if (cmd.param3 > 0.0f) {
604 cmd_result = vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED;
606 }
else if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_SET_CAM_TRIGG_INTERVAL) {
610 if (cmd.param1 > 0.0f) {
616 if (cmd.param2 > 0.0f) {
623 cmd_result = vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED;
642 poll_interval_usec = 3000000;
701 if (updated && need_ack) {
705 command_ack.command = cmd.command;
706 command_ack.result = (uint8_t)cmd_result;
707 command_ack.target_system = cmd.source_system;
708 command_ack.target_component = cmd.source_component;
713 ScheduleDelayed(poll_interval_usec);
738 px4_clock_gettime(CLOCK_REALTIME, &tv);
739 trigger.
timestamp_utc = (uint64_t) tv.tv_sec * 1000000 + tv.tv_nsec / 1000;
804 PX4_INFO(
"interval : %.2f [ms]", (
double)
_interval);
808 PX4_INFO(
"distance : %.2f [m]", (
double)
_distance);
821 PX4_INFO(
"usage: camera_trigger {start|stop|status|test|test_power}\n");
831 if (!strcmp(argv[1],
"start")) {
834 PX4_WARN(
"already running");
841 PX4_WARN(
"alloc failed");
846 PX4_WARN(
"failed to start camera trigger");
854 PX4_WARN(
"not running");
857 }
else if (!strcmp(argv[1],
"stop")) {
860 }
else if (!strcmp(argv[1],
"status")) {
863 }
else if (!strcmp(argv[1],
"test")) {
866 }
else if (!strcmp(argv[1],
"test_power")) {
void status()
Display status.
Interface with cameras via pwm.
static void keep_alive_up(void *arg)
Enables keep alive signal.
CameraTrigger()
Constructor.
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
static void disengage_turn_on_off(void *arg)
Resets on/off.
struct hrt_call _keepalivecall_up
struct hrt_call _disengage_turn_on_off_call
__EXPORT int param_set_no_notification(param_t param, const void *val)
Set the value of a parameter, but do not notify the system about the change.
void(* hrt_callout)(void *arg)
Callout function type.
virtual void send_toggle_power(bool enable)
send command to turn the camera on/off
~CameraTrigger() override
Destructor, also kills task.
bool publish(const T &data)
Publish the struct.
orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data)
virtual bool is_powered_on()
Checks if the camera connected to the interface is turned on.
bool start()
Start the task.
High-resolution timer with callouts and timekeeping.
CameraInterface * _camera_interface
instance of camera interface
uORB::Subscription _lpos_sub
void stop()
Stop the task.
Global flash based parameter store.
__EXPORT int camera_trigger_main(int argc, char *argv[])
static void engage(void *arg)
Fires trigger.
void toggle_power()
Toggle camera power (on/off)
param_t _p_activation_time
orb_advert_t _trigger_pub
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
__EXPORT void hrt_call_after(struct hrt_call *entry, hrt_abstime delay, hrt_callout callout, void *arg)
Call callout(arg) after delay has elapsed.
static void keep_alive_down(void *arg)
Disables keep alive signal.
static void engange_turn_on_off(void *arg)
Fires on/off.
virtual void send_keep_alive(bool enable)
send command to prevent the camera from sleeping
trigger_mode_t _trigger_mode
void shoot_once()
Trigger the camera just once.
void update_distance()
Run distance-based trigger update.
virtual void info()
Display info.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
void enable_keep_alive(bool on)
Toggle keep camera alive functionality.
virtual void trigger(bool trigger_on_true)
trigger the camera
struct hrt_call _engage_turn_on_off_call
struct hrt_call _disengagecall
__EXPORT void hrt_call_every(struct hrt_call *entry, hrt_abstime delay, hrt_abstime interval, hrt_callout callout, void *arg)
Call callout(arg) after delay, and then after every interval.
CameraTrigger * g_camera_trigger
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
struct hrt_call _keepalivecall_down
void update_intervalometer()
Run intervalometer update.
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
Interface supported cameras using a Seagull MAP2 interface.
void Run() override
Vehicle command handler.
struct hrt_call _engagecall
uORB::Subscription _command_sub
matrix::Vector2f _last_shoot_position
camera_interface_mode_t _camera_interface_mode
uORB::PublicationQueued< vehicle_command_ack_s > _cmd_ack_pub
bool update(void *dst)
Update the struct.
virtual bool has_power_control()
Checks if the interface has support for camera power control.
#define commandParamToInt(n)
void test()
Trigger one image.
static void disengage(void *arg)
Resets trigger.
bool copy(void *dst)
Copy the struct.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
uint32_t param_t
Parameter handle.
__EXPORT void hrt_cancel(struct hrt_call *entry)
Remove the entry from the callout list.