41 #ifndef OPTICFLOW_AGL_ID
42 #define OPTICFLOW_AGL_ID ABI_BROADCAST
46 #ifndef OPTICFLOW_SENDER_ID
47 #define OPTICFLOW_SENDER_ID 1
51 #ifndef OPTICFLOW_DEVICE
52 #define OPTICFLOW_DEVICE /dev/video2
57 #ifndef OPTICFLOW_DEVICE_SIZE
58 #define OPTICFLOW_DEVICE_SIZE 320,240
60 #define __SIZE_HELPER(x, y) #x", "#y
61 #define _SIZE_HELPER(x) __SIZE_HELPER(x)
65 #ifndef OPTICFLOW_DEVICE_BUFFERS
66 #define OPTICFLOW_DEVICE_BUFFERS 15
84 #if PERIODIC_TELEMETRY
93 pthread_mutex_lock(&opticflow_mutex);
94 pprz_msg_send_OPTIC_FLOW_EST(trans, dev, AC_ID,
95 &opticflow_result.fps, &opticflow_result.corner_cnt,
96 &opticflow_result.tracked_cnt, &opticflow_result.flow_x,
97 &opticflow_result.flow_y, &opticflow_result.flow_der_x,
98 &opticflow_result.flow_der_y, &opticflow_result.vel_x,
99 &opticflow_result.vel_y, &opticflow_result.div_size,
100 &opticflow_result.surface_roughness, &opticflow_result.divergence);
101 pthread_mutex_unlock(&opticflow_mutex);
114 opticflow_state.phi = 0;
115 opticflow_state.theta = 0;
116 opticflow_state.agl = 0;
120 opticflow_got_result =
FALSE;
122 #ifdef OPTICFLOW_SUBDEV
124 PRINT_CONFIG_VAR(OPTICFLOW_SUBDEV)
128 printf(
"[opticflow_module] Could not initialize the %s subdevice.\n", STRINGIFY(OPTICFLOW_SUBDEV));
136 if (opticflow_dev == NULL) {
137 printf(
"[opticflow_module] Could not initialize the video device\n");
140 #if PERIODIC_TELEMETRY
151 pthread_mutex_lock(&opticflow_mutex);
157 if (opticflow_got_result) {
159 uint8_t quality = opticflow_result.divergence;
161 opticflow_result.flow_x,
162 opticflow_result.flow_y,
163 opticflow_result.flow_der_x,
164 opticflow_result.flow_der_x,
166 opticflow_state.agl);
168 if (opticflow_result.tracked_cnt > 0) {
170 opticflow_result.vel_x,
171 opticflow_result.vel_y,
173 opticflow_result.noise_measurement
176 opticflow_got_result =
FALSE;
178 pthread_mutex_unlock(&opticflow_mutex);
187 if (opticflow_calc_thread != 0) {
188 printf(
"[opticflow_module] Opticflow already started!\n");
195 printf(
"[opticflow_module] Could not initialize opticflow thread (return code: %d)\n", rc);
220 printf(
"[opticflow_module] Could not start capture of the camera\n");
237 pthread_mutex_lock(&opticflow_mutex);
240 pthread_mutex_unlock(&opticflow_mutex);
247 pthread_mutex_lock(&opticflow_mutex);
249 opticflow_got_result =
TRUE;
250 pthread_mutex_unlock(&opticflow_mutex);
282 opticflow_state.agl = distance;
Event structure to store callbacks in a linked list.
bool_t v4l2_start_capture(struct v4l2_device *dev)
Start capturing images in streaming mode (Thread safe)
void opticflow_module_stop(void)
Stop the optical flow calculation.
Generic transmission transport header.
struct opticflow_t opticflow
Opticflow calculations.
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Periodic telemetry system header (includes downlink utility and generated code).
static struct v4l2_device * opticflow_dev
The opticflow camera V4L2 device.
void v4l2_image_free(struct v4l2_device *dev, struct image_t *img)
Free the image and enqueue the buffer (Thread safe) This must be done after processing the image...
void v4l2_image_get(struct v4l2_device *dev, struct image_t *img)
Get the latest image buffer and lock it (Thread safe, BLOCKING) This functions blocks until image acc...
static struct opticflow_state_t opticflow_state
State of the drone to communicate with the opticflow.
void opticflow_calc_init(struct opticflow_t *opticflow, uint16_t w, uint16_t h)
Initialize the opticflow calculator.
optical-flow calculation for Parrot Drones
static abi_event opticflow_agl_ev
The altitude ABI event.
void image_free(struct image_t *img)
Free the image.
Capture images from a V4L2 device (Video for Linux 2)
Main include for ABI (AirBorneInterface).
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
bool_t v4l2_stop_capture(struct v4l2_device *dev)
Stop capturing of the image stream (Thread safe) This function is blocking until capturing thread is ...
void rtp_frame_send(struct UdpSocket *udp, struct image_t *img, uint8_t format_code, uint8_t quality_code, uint8_t has_dri_header, uint32_t delta_t)
Send an RTP frame.
void opticflow_module_init(void)
Initialize the optical flow module for the bottom camera.
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static pthread_mutex_t opticflow_mutex
Mutex lock fo thread safety.
void jpeg_encode_image(struct image_t *in, struct image_t *out, uint32_t quality_factor, bool_t add_dri_header)
Encode an YUV422 image.
void opticflow_calc_frame(struct opticflow_t *opticflow, struct opticflow_state_t *state, struct image_t *img, struct opticflow_result_t *result)
Run the optical flow on a new image frame.
static pthread_t opticflow_calc_thread
The optical flow calculation thread.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
#define DefaultPeriodic
Set default periodic telemetry.
static struct opticflow_result_t opticflow_result
The opticflow result.
#define OPTICFLOW_SENDER_ID
bool_t v4l2_init_subdev(char *subdev_name, uint8_t pad, uint8_t which, uint16_t code, uint16_t width, uint16_t height)
Initialize a V4L2 subdevice.
Encode images with the use of the JPEG encoding.
static const struct usb_device_descriptor dev
API to get/set the generic vehicle states.
#define OPTICFLOW_DEVICE
The video device.
#define OPTICFLOW_DEVICE_BUFFERS
The video device buffers (the amount of V4L2 buffers)
void opticflow_module_run(void)
Update the optical flow state for the calculation thread and update the stabilization loops with the ...
void opticflow_module_start(void)
Start the optical flow calculation.
#define OPTICFLOW_DEVICE_SIZE
The video device size (width, height)
Encodes a vide stream with RTP (JPEG)
static bool_t opticflow_got_result
When we have an optical flow calculation.
#define OPTICFLOW_AGL_ID
Default sonar/agl to use in opticflow visual_estimator.
static void * opticflow_module_calc(void *data)
The main optical flow calculation thread.
struct v4l2_device * v4l2_init(char *device_name, uint16_t width, uint16_t height, uint8_t buffers_cnt, uint32_t _pixelformat)
Initialize a V4L2(Video for Linux 2) device.
static void opticflow_agl_cb(uint8_t sender_id, float distance)
Callback function of the ground altitude.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
An JPEG encoded image (not per pixel encoded)