Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cam.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2003 Pascal Brisset, Antoine Drouin
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
27#include <math.h>
28#include "cam.h"
29#include "modules/nav/common_nav.h" //needed for WaypointX, WaypointY and ground_alt
30#include "autopilot.h"
31#include "generated/flight_plan.h"
32#include "state.h"
33#ifdef POINT_CAM
34#include "point.h"
35#endif // POINT_CAM
36
38
39#ifdef TEST_CAM
46#endif // TEST_CAM
47
48//FIXME: use radians
49#ifdef CAM_PAN_NEUTRAL
50#if (CAM_PAN_MAX == CAM_PAN_NEUTRAL)
51#error CAM_PAN_MAX has to be different from CAM_PAN_NEUTRAL
52#endif
53#if (CAM_PAN_NEUTRAL == CAM_PAN_MIN)
54#error CAM_PAN_MIN has to be different from CAM_PAN_NEUTRAL
55#endif
56#endif
57
58//FIXME: use radians
59#ifdef CAM_TILT_NEUTRAL
60#if ((CAM_TILT_MAX) == (CAM_TILT_NEUTRAL))
61#error CAM_TILT_MAX has to be different from CAM_TILT_NEUTRAL
62#endif
63#if (CAM_TILT_NEUTRAL == CAM_TILT_MIN)
64#error CAM_TILT_MIN has to be different from CAM_TILT_NEUTRAL
65#endif
66#endif
67
68//FIXME: use radians
69#ifndef CAM_PAN0
70#define CAM_PAN0 RadOfDeg(0)
71#endif
73
74//FIXME: use radians
75#ifndef CAM_TILT0
76#define CAM_TILT0 RadOfDeg(0)
77#endif
79
82
86
87#ifndef CAM_MODE0
88#define CAM_MODE0 CAM_MODE_OFF
89#endif
92
95
96void cam_nadir(void);
97void cam_angles(void);
98void cam_target(void);
99void cam_waypoint_target(void);
100void cam_ac_target(void);
101
102static void send_cam(struct transport_tx *trans, struct link_device *dev)
103{
108 pprz_msg_send_CAM(trans, dev, AC_ID, &phi, &theta, &x, &y);
109}
110
111#ifdef SHOW_CAM_COORDINATES
112static void send_cam_point(struct transport_tx *trans, struct link_device *dev)
113{
116}
117#endif
118
128
129void cam_periodic(void)
130{
131#if defined(CAM_FIXED_FOR_FPV_IN_AUTO1) && CAM_FIXED_FOR_FPV_IN_AUTO1 == 1
132 //Position the camera for straight view.
134#endif
135 switch (cam_mode) {
136 case CAM_MODE_OFF:
139 cam_angles();
140 break;
141 case CAM_MODE_ANGLES:
142 cam_angles();
143 break;
144 case CAM_MODE_NADIR:
145 cam_nadir();
146 break;
148 cam_target();
149 break;
152 break;
155 break;
156 // In this mode the target coordinates are calculated continuously from the pan and tilt radio channels.
157 // The "TARGET" waypoint coordinates are not used.
158 // If the "-DSHOW_CAM_COORDINATES" is defined then the coordinates of where the camera is looking are calculated.
161 break;
162 // In this mode the angles come from the pan and tilt radio channels.
163 // The "TARGET" waypoint coordinates are not used but i need to call the "cam_waypoint_target()" function
164 // in order to calculate the coordinates of where the camera is looking.
165 case CAM_MODE_RC:
167 break;
168 default:
169 break;
170 }
171#if defined(CAM_FIXED_FOR_FPV_IN_AUTO1) && CAM_FIXED_FOR_FPV_IN_AUTO1 == 1
172 } else if (autopilot_get_mode() == AP_MODE_AUTO1) {
173 //Position the camera for straight view.
174
175#if defined(CAM_TILT_POSITION_FOR_FPV)
177#else
178 cam_tilt_c = RadOfDeg(90);
179#endif
180#if defined(CAM_PAN_POSITION_FOR_FPV)
182#else
183 cam_pan_c = RadOfDeg(0);
184#endif
185 cam_angles();
186#ifdef SHOW_CAM_COORDINATES
187 cam_point_lon = 0;
188 cam_point_lat = 0;
190#endif
191 }
192#endif
193
194
195#if defined(COMMAND_CAM_PWR_SW)
197#elif defined(VIDEO_TX_SWITCH)
199#endif
200}
201
203void cam_angles(void)
204{
205 float cam_pan = 0;
206 float cam_tilt = 0;
209 } else {
212 }
213 }
214
217 } else {
220 }
221 }
222
223#ifdef CAM_PAN_NEUTRAL
225 if (pan_diff > 0) {
227 } else {
229 }
230#else
232#endif
233
234#ifdef CAM_TILT_NEUTRAL
236 if (tilt_diff > 0) {
238 } else {
240 }
241#else
244#endif
245
248
251
252#ifdef COMMAND_CAM_PAN
254#endif
255#ifdef COMMAND_CAM_TILT
257#endif
258}
259
278
280void cam_nadir(void)
281{
282 struct EnuCoor_f *pos = stateGetPositionEnu_f();
283#ifdef TEST_CAM
286#else
287 cam_target_x = pos->x;
288 cam_target_y = pos->y;
289#endif
290 cam_target_alt = -10;
291 cam_target();
292}
293
294
304
305#ifdef TRAFFIC_INFO
307
308void cam_ac_target(void)
309{
311 cam_target_x = ac->x;
312 cam_target_y = ac->y;
314 cam_target();
315}
316#else
317void cam_ac_target(void) {}
318#endif // TRAFFIC_INFO
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition autopilot.c:222
Core autopilot interface common to all firmwares.
#define CAM_PAN0
Definition cam.c:70
void cam_periodic(void)
For CAM_MODE_AC_TARGET mode.
Definition cam.c:129
void cam_init(void)
Definition cam.c:119
static void send_cam(struct transport_tx *trans, struct link_device *dev)
Definition cam.c:102
float cam_target_y
Definition cam.c:83
void cam_angles(void)
Computes the servo values from cam_pan_c and cam_tilt_c.
Definition cam.c:203
float cam_pan_c
Definition cam.c:72
uint8_t cam_mode
Definition cam.c:90
#define CAM_TILT0
Definition cam.c:76
#define CAM_MODE0
Definition cam.c:88
void cam_ac_target(void)
Definition cam.c:317
uint8_t cam_target_wp
For CAM_MODE_XY_TARGET mode.
Definition cam.c:84
void cam_waypoint_target(void)
Definition cam.c:295
uint8_t cam_target_ac
For CAM_MODE_WP_TARGET mode.
Definition cam.c:85
void cam_nadir(void)
Point straight down.
Definition cam.c:280
void cam_target(void)
Computes the right angles from target_x, target_y, target_alt.
Definition cam.c:261
bool cam_lock
Definition cam.c:91
int16_t cam_tilt_command
Definition cam.c:94
float cam_tilt_c
Definition cam.c:78
float cam_target_x
Radians, for CAM_MODE_ANGLES mode.
Definition cam.c:83
int16_t cam_pan_command
Definition cam.c:93
float cam_phi_c
Definition cam.c:80
float cam_theta_c
Definition cam.c:81
float cam_target_alt
Definition cam.c:83
Pan/Tilt camera API.
#define CAM_MODE_XY_TARGET
Definition cam.h:36
#define CAM_PAN_MIN
Definition cam.h:47
#define CAM_MODE_RC
Definition cam.h:40
#define CAM_TILT_MIN
Definition cam.h:53
#define CAM_MODE_NADIR
Definition cam.h:35
#define CAM_MODE_OFF
Definition cam.h:33
#define CAM_MODE_STABILIZED
Definition cam.h:39
#define CAM_TILT_MAX
Definition cam.h:50
#define CAM_MODE_AC_TARGET
Definition cam.h:38
#define CAM_PAN_MAX
Definition cam.h:44
#define CAM_MODE_ANGLES
Definition cam.h:34
#define CAM_MODE_WP_TARGET
Definition cam.h:37
#define LED_ON(i)
Definition led_hw.h:51
#define LED_OFF(i)
Definition led_hw.h:52
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:46
const uint8_t nb_waypoint
Definition common_nav.c:43
#define WaypointX(_wp)
Definition common_nav.h:45
#define WaypointY(_wp)
Definition common_nav.h:46
#define AP_MODE_AUTO2
#define AP_MODE_AUTO1
static struct EnuCoor_f * acInfoGetPositionEnu_f(uint8_t ac_id)
Get position in local ENU coordinates (float).
static struct UtmCoor_f * acInfoGetPositionUtm_f(uint8_t ac_id)
Get position from UTM coordinates (float).
float phi
in radians
float theta
in radians
euler angles
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition state.h:821
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
Definition state.h:1085
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
#define TRIM_PPRZ(pprz)
Definition paparazzi.h:11
#define MIN_PPRZ
Definition paparazzi.h:9
void vPoint(float fPlaneEast, float fPlaneNorth, float fPlaneAltitude, float fRollAngle, float fPitchAngle, float fYawAngle, float fObjectEast, float fObjectNorth, float fAltitude, float *fPan, float *fTilt)
Definition point.c:164
float y
in meters
float x
in meters
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
vector in East North Up coordinates Units: meters
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
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.