Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
opticflow_module.c File Reference

optical-flow based hovering for Parrot AR.Drone 2.0 More...

#include "opticflow_module.h"
#include <stdio.h>
#include <pthread.h>
#include "state.h"
#include "subsystems/abi.h"
#include "lib/v4l/v4l2.h"
#include "lib/encoding/jpeg.h"
#include "lib/encoding/rtp.h"
#include "errno.h"
#include "cv.h"
#include "subsystems/datalink/telemetry.h"
+ Include dependency graph for opticflow_module.c:

Go to the source code of this file.

Macros

#define OPTICFLOW_AGL_ID   ABI_BROADCAST
 Default sonar/agl to use in opticflow visual_estimator. More...
 
#define OPTICFLOW_IMU_ID   ABI_BROADCAST
 Default IMU (accelerometers) to use in opticflow visual_estimator. More...
 
#define OPTICFLOW_BODY_TO_IMU_ID   ABI_BROADCAST
 Default body to IMU to use in opticflow visual_estimator. More...
 
#define OPTICFLOW_SEND_ABI_ID   1
 Default ID to send abi messages. More...
 
#define OPTICFLOW_FPS   0
 Default FPS (zero means run at camera fps) More...
 

Functions

struct image_topticflow_module_calc (struct image_t *img)
 The main optical flow calculation thread. More...
 
static void opticflow_agl_cb (uint8_t sender_id, float distance)
 Callback function of the ground altitude. More...
 
static void opticflow_imu_accel_cb (uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
 Callback function of the IMU's accelerometers. More...
 
static void opticflow_body_to_imu_cb (uint8_t sender_id, struct FloatQuat *q_b2i_f)
 Callback function of imu to body. More...
 
static void opticflow_telem_send (struct transport_tx *trans, struct link_device *dev)
 Send optical flow telemetry information. More...
 
void opticflow_module_init (void)
 Initialize the optical flow module for the bottom camera. More...
 
void opticflow_module_run (void)
 Update the optical flow state for the calculation thread and update the stabilization loops with the newest result. More...
 

Variables

struct opticflow_t opticflow
 Opticflow calculations. More...
 
static struct opticflow_result_t opticflow_result
 The opticflow result. More...
 
static struct opticflow_state_t opticflow_state
 State of the drone to communicate with the opticflow. More...
 
static abi_event opticflow_imu_accel_ev
 The altitude ABI event. More...
 
static abi_event opticflow_agl_ev
 The accelerometers ABI event. More...
 
static abi_event opticflow_body_to_imu_ev
 The body-to-imu ABI event. More...
 
static bool opticflow_got_result
 When we have an optical flow calculation. More...
 
static pthread_mutex_t opticflow_mutex
 Mutex lock fo thread safety. More...
 

Detailed Description

optical-flow based hovering for Parrot AR.Drone 2.0

Sensors from vertical camera and IMU of Parrot AR.Drone 2.0

Definition in file opticflow_module.c.

Macro Definition Documentation

#define OPTICFLOW_AGL_ID   ABI_BROADCAST

Default sonar/agl to use in opticflow visual_estimator.

Definition at line 45 of file opticflow_module.c.

Referenced by opticflow_module_init().

#define OPTICFLOW_BODY_TO_IMU_ID   ABI_BROADCAST

Default body to IMU to use in opticflow visual_estimator.

Definition at line 55 of file opticflow_module.c.

Referenced by opticflow_module_init().

#define OPTICFLOW_FPS   0

Default FPS (zero means run at camera fps)

Definition at line 65 of file opticflow_module.c.

Referenced by opticflow_module_init().

#define OPTICFLOW_IMU_ID   ABI_BROADCAST

Default IMU (accelerometers) to use in opticflow visual_estimator.

Definition at line 50 of file opticflow_module.c.

Referenced by opticflow_module_init().

#define OPTICFLOW_SEND_ABI_ID   1

Default ID to send abi messages.

Definition at line 60 of file opticflow_module.c.

Referenced by opticflow_module_run().

Function Documentation

static void opticflow_agl_cb ( uint8_t  sender_id,
float  distance 
)
static

Callback function of the ground altitude.

Get the altitude above ground of the drone.

Parameters
[in]sender_idThe id that send the ABI message (unused)
[in]distanceThe distance above ground level in meters

Definition at line 209 of file opticflow_module.c.

Referenced by opticflow_module_init().

+ Here is the caller graph for this function:

static void opticflow_body_to_imu_cb ( uint8_t  sender_id,
struct FloatQuat q_b2i_f 
)
static

Callback function of imu to body.

Get the body-to-imu quaternion.

Parameters
[in]sender_idThe id that send the ABI message (unused)
[in]q_b2i_fThe body-to-imu quaternion

Definition at line 233 of file opticflow_module.c.

References float_quat_invert().

Referenced by opticflow_module_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void opticflow_imu_accel_cb ( uint8_t  sender_id,
uint32_t  stamp,
struct Int32Vect3 accel 
)
static

Callback function of the IMU's accelerometers.

Get the accelerometer measurements of the imu.

Parameters
[in]sender_idThe id that send the ABI message (unused)
[in]stampThe timestamp of when the message is send
[in]accelThe accelerometer measurements of the imu

Definition at line 223 of file opticflow_module.c.

Referenced by opticflow_module_init().

+ Here is the caller graph for this function:

struct image_t * opticflow_module_calc ( struct image_t img)

The main optical flow calculation thread.

The main optical flow calculation thread This thread passes the images trough the optical flow calculator.

Parameters
[in]*imgThe image_t structure of the captured image
Returns
*img The processed image structure

Definition at line 180 of file opticflow_module.c.

References get_rotation_at_timestamp(), opticflow_calc_frame(), opticflow_state, image_t::pprz_ts, pose_t::rates, and opticflow_state_t::rates.

Referenced by opticflow_module_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void opticflow_module_run ( void  )

Update the optical flow state for the calculation thread and update the stabilization loops with the newest result.

Definition at line 145 of file opticflow_module.c.

References get_sys_time_usec(), and OPTICFLOW_SEND_ABI_ID.

+ Here is the call graph for this function:

static void opticflow_telem_send ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Send optical flow telemetry information.

Parameters
[in]*transThe transport structure to send the information over
[in]*devThe link to send the data over

Definition at line 95 of file opticflow_module.c.

Referenced by opticflow_module_init().

+ Here is the caller graph for this function:

Variable Documentation

struct opticflow_t opticflow

Opticflow calculations.

Definition at line 70 of file opticflow_module.c.

abi_event opticflow_agl_ev
static

The accelerometers ABI event.

Definition at line 74 of file opticflow_module.c.

abi_event opticflow_body_to_imu_ev
static

The body-to-imu ABI event.

Definition at line 75 of file opticflow_module.c.

bool opticflow_got_result
static

When we have an optical flow calculation.

Definition at line 77 of file opticflow_module.c.

abi_event opticflow_imu_accel_ev
static

The altitude ABI event.

Definition at line 73 of file opticflow_module.c.

pthread_mutex_t opticflow_mutex
static

Mutex lock fo thread safety.

Definition at line 78 of file opticflow_module.c.

struct opticflow_result_t opticflow_result
static

The opticflow result.

Definition at line 71 of file opticflow_module.c.

struct opticflow_state_t opticflow_state
static

State of the drone to communicate with the opticflow.

Definition at line 72 of file opticflow_module.c.

Referenced by opticflow_module_calc().