Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
rotorcraft_cam.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2012 Gautier Hattenberger <gautier.hattenberger@enac.fr>,
3  * Antoine Drouin <poinix@gmail.com>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
42 
44 #include "state.h"
46 #include "std.h"
47 
49 
50 
56 #ifndef ROTORCRAFT_CAM_ON
57 #define ROTORCRAFT_CAM_ON gpio_set
58 #endif
59 
65 #ifndef ROTORCRAFT_CAM_OFF
66 #define ROTORCRAFT_CAM_OFF gpio_clear
67 #endif
68 
70 
71 #define _SERVO_PARAM(_s,_p) SERVO_ ## _s ## _ ## _p
72 #define SERVO_PARAM(_s,_p) _SERVO_PARAM(_s,_p)
73 
74 // Tilt definition
77 #if ROTORCRAFT_CAM_USE_TILT
78 #define CT_MIN Min(CAM_TA_MIN, CAM_TA_MAX)
79 #define CT_MAX Max(CAM_TA_MIN, CAM_TA_MAX)
80 #endif
81 
82 // Pan definition
84 #define ROTORCRAFT_CAM_PAN_MIN 0
85 #define ROTORCRAFT_CAM_PAN_MAX INT32_ANGLE_2_PI
86 
87 static void send_cam(struct transport_tx *trans, struct link_device *dev)
88 {
89  pprz_msg_send_ROTORCRAFT_CAM(trans, dev, AC_ID,
91 }
92 
94 {
96 #ifdef ROTORCRAFT_CAM_SWITCH_GPIO
98  ROTORCRAFT_CAM_OFF(ROTORCRAFT_CAM_SWITCH_GPIO);
99  } else {
100  ROTORCRAFT_CAM_ON(ROTORCRAFT_CAM_SWITCH_GPIO);
101  }
102 #endif
103 }
104 
106 {
107 #ifdef ROTORCRAFT_CAM_SWITCH_GPIO
108  gpio_setup_output(ROTORCRAFT_CAM_SWITCH_GPIO);
109 #endif
112 #if ROTORCRAFT_CAM_USE_TILT
113  ActuatorSet(ROTORCRAFT_CAM_TILT_SERVO, rotorcraft_cam_tilt_pprz);
114 #endif
116  rotorcraft_cam_pan = 0;
117 
118  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_CAM, send_cam);
119 }
120 
122 {
123 
124  switch (rotorcraft_cam_mode) {
126 #if ROTORCRAFT_CAM_USE_TILT
128 #endif
129 #if ROTORCRAFT_CAM_USE_PAN
131 #endif
132  break;
134  // nothing to do here, just apply tilt pwm at the end
135  break;
137 #if ROTORCRAFT_CAM_USE_TILT_ANGLES
138  Bound(rotorcraft_cam_tilt, CT_MIN, CT_MAX);
140  (CAM_TA_MAX - CAM_TA_MIN);
141 #endif
142 #if ROTORCRAFT_CAM_USE_PAN
145 #endif
146  break;
148 #ifdef ROTORCRAFT_CAM_TRACK_WP
149  {
150  struct Int32Vect2 diff;
151  VECT2_DIFF(diff, waypoints[ROTORCRAFT_CAM_TRACK_WP], *stateGetPositionEnu_i());
152  INT32_VECT2_RSHIFT(diff, diff, INT32_POS_FRAC);
153  rotorcraft_cam_pan = int32_atan2(diff.x, diff.y);
155 #if ROTORCRAFT_CAM_USE_TILT_ANGLES
156  int32_t dist, height;
157  dist = INT32_VECT2_NORM(diff);
158  height = (waypoints[ROTORCRAFT_CAM_TRACK_WP].z - stateGetPositionEnu_i()->z) >> INT32_POS_FRAC;
159  rotorcraft_cam_tilt = int32_atan2(height, dist);
160  Bound(rotorcraft_cam_tilt, CAM_TA_MIN, CAM_TA_MAX);
162  (CAM_TA_MAX - CAM_TA_MIN);
163 #endif
164  }
165 #endif
166  break;
167  default:
168  break;
169  }
170 #if ROTORCRAFT_CAM_USE_TILT
171  ActuatorSet(ROTORCRAFT_CAM_TILT_SERVO, rotorcraft_cam_tilt_pprz);
172 #endif
173 }
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:39
#define VECT2_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:92
int32_t psi
in rad with INT32_ANGLE_FRAC
#define INT32_POS_FRAC
#define INT32_VECT2_NORM(_v)
#define INT32_COURSE_NORMALIZE(_a)
#define ANGLE_FLOAT_OF_BFP(_ai)
#define INT32_VECT2_RSHIFT(_o, _i, _r)
int32_t z
Up.
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition: state.h:674
Hardware independent API for actuators (servos, motor controllers).
#define MAX_PPRZ
Definition: paparazzi.h:8
#define MIN_PPRZ
Definition: paparazzi.h:9
int32_t int32_atan2(int32_t y, int32_t x)
struct RotorcraftNavigation nav
Definition: navigation.c:51
Rotorcraft navigation functions.
float heading
heading setpoint (in radians)
Definition: navigation.h:133
static void send_cam(struct transport_tx *trans, struct link_device *dev)
#define ROTORCRAFT_CAM_ON
Gpio output to turn camera power power on.
#define ROTORCRAFT_CAM_OFF
Gpio output to turn camera power power off.
uint8_t rotorcraft_cam_mode
WP control.
int16_t rotorcraft_cam_pan
void rotorcraft_cam_periodic(void)
int16_t rotorcraft_cam_tilt
int16_t rotorcraft_cam_tilt_pprz
void rotorcraft_cam_set_mode(uint8_t mode)
void rotorcraft_cam_init(void)
Camera control module for rotorcraft.
#define ROTORCRAFT_CAM_MODE_MANUAL
#define ROTORCRAFT_CAM_MODE_WP
#define ROTORCRAFT_CAM_DEFAULT_MODE
Default mode is NONE.
#define ROTORCRAFT_CAM_MODE_HEADING
#define ROTORCRAFT_CAM_MODE_NONE
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:69
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98