PX4 Firmware
PX4 Autopilot Software http://px4.io
camera_capture.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2018 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file camera_capture.hpp
36  *
37  */
38 
39 #pragma once
40 
42 #include <drivers/drv_hrt.h>
44 #include <drivers/drv_pwm_output.h>
45 #include <lib/parameters/param.h>
46 #include <px4_platform_common/px4_config.h>
47 #include <px4_platform_common/defines.h>
48 #include <px4_platform_common/module.h>
49 #include <px4_platform_common/tasks.h>
50 #include <px4_platform_common/workqueue.h>
51 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
52 #include <uORB/Publication.hpp>
54 #include <uORB/Subscription.hpp>
58 
59 #define PX4FMU_DEVICE_PATH "/dev/px4fmu"
60 
61 // For AV-X board
62 #define GPIO_TRIG_AVX /* PD14 */ (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN14)
63 
64 
65 class CameraCapture : public px4::ScheduledWorkItem
66 {
67 public:
68  /**
69  * Constructor
70  */
71  CameraCapture();
72 
73  /**
74  * Destructor, also kills task.
75  */
77 
78  /**
79  * Start the task.
80  */
81  int start();
82 
83  /**
84  * Stop the task.
85  */
86  void stop();
87 
88  void status();
89 
90  // Low-rate command handling loop
91  void Run() override;
92 
93  static void capture_trampoline(void *context, uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state,
94  uint32_t overflow);
95 
96  void set_capture_control(bool enabled);
97 
98  void reset_statistics(bool reset_seq);
99 
100  void publish_trigger();
101 
102 
103  static struct work_s _work_publisher;
104 
105 private:
106 
107  // Publishers
110 
111  // Subscribers
113 
114  // Trigger Buffer
115  struct _trig_s {
116  uint32_t chan_index;
118  uint32_t edge_state;
119  uint32_t overflow;
120  } _trigger{};
121 
122  ringbuffer::RingBuffer *_trig_buffer{nullptr};
123 
124  bool _capture_enabled{false};
125  bool _gpio_capture{false};
126 
127  // Parameters
129  float _strobe_delay{0.0f};
134 
135  // Signal capture statistics
136  uint32_t _capture_seq{0};
140  uint32_t _capture_overflows{0};
141 
142  // Signal capture callback
143  void capture_callback(uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
144 
145  // GPIO interrupt routine (for AV_X board)
146  static int gpio_interrupt_routine(int irq, void *context, void *arg);
147 
148  // Signal capture publish
149  static void publish_trigger_trampoline(void *arg);
150 
151 };
152 
153 struct work_s CameraCapture::_work_publisher;
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
Definition: param.h:103
hrt_abstime _last_exposure_time
int start()
Start the task.
static int gpio_interrupt_routine(int irq, void *context, void *arg)
void stop()
Stop the task.
uint32_t _capture_seq
void capture_callback(uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
ringbuffer::RingBuffer * _trig_buffer
void Run() override
hrt_abstime _last_trig_begin_time
int32_t _camera_capture_edge
uORB::Publication< camera_trigger_s > _trigger_pub
void reset_statistics(bool reset_seq)
static struct work_s _work_publisher
High-resolution timer with callouts and timekeeping.
Global flash based parameter store.
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
uint32_t _capture_overflows
struct CameraCapture::_trig_s _trigger
static void capture_trampoline(void *context, uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
CameraCapture()
Constructor.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
param_t _p_camera_capture_edge
int32_t _camera_capture_mode
hrt_abstime _last_trig_time
void set_capture_control(bool enabled)
~CameraCapture()
Destructor, also kills task.
uORB::PublicationQueued< vehicle_command_ack_s > _command_ack_pub
static void publish_trigger_trampoline(void *arg)
param_t _p_camera_capture_mode
param_t _p_strobe_delay
uORB::Subscription _command_sub
uint32_t param_t
Parameter handle.
Definition: param.h:98