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
jevois_mavlink.c
Go to the documentation of this file.
1/*
2 * Copyright (C) MAVLab
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, see
18 * <http://www.gnu.org/licenses/>.
19 */
27
28
29#define DEBUG_PRINT printf
30#include <stdio.h>
31
32
33/*
34 * MavLink protocol
35 */
36
37#include <mavlink/mavlink_types.h>
38#include "mavlink/paparazzi/mavlink.h"
39
40#include "modules/imu/imu.h"
41#include "autopilot.h"
42#include "generated/modules.h"
43
44#include "modules/core/abi.h"
46
47#include "std.h"
49
50
52
53#ifndef MAVLINK_SYSID
54#define MAVLINK_SYSID 1
55#endif
56
57
58
59static void mavlink_send_heartbeat(void);
60static void mavlink_send_attitude(void);
61static void mavlink_send_highres_imu(void);
62static void mavlink_send_set_mode(void);
63
64
65/*
66 * Exported data
67 */
68
69
72 int count;
73 int x;
74 int y;
75 int w;
76 int h;
78 int source;
79} jevois_visual_target = {false, 0, 0, 0, 0, 0, 0};
80
82 int received;
83 int cnt;
84 float x;
85 float y;
86 float z;
87} jevois_vision_position = {false, 0, 0.0f, 0.0f, 0.0f};
88
89/*
90 * Paparazzi Module functions : filter functions
91 */
92
94
98
105
108{
109 init_butterworth_2_low_pass_int(&ax_filtered, 20.0, 1.0 / ((float)MODULES_FREQUENCY), imu.accel_unscaled.x);
110 init_butterworth_2_low_pass_int(&ay_filtered, 20.0, 1.0 / ((float)MODULES_FREQUENCY), imu.accel_unscaled.y);
111 init_butterworth_2_low_pass_int(&az_filtered, 20.0, 1.0 / ((float)MODULES_FREQUENCY), imu.accel_unscaled.z);
112}
113
114/*
115 * Paparazzi Module functions : forward to telemetry
116 */
117
118// Send Manual Setpoint over telemetry using ROTORCRAFT_RADIO_CONTROL message
119
134
149
150/*
151 * Paparazzi Module functions : communications
152 */
153
155{
156 // Initialize Mavlink parser
157 mavlink_system.sysid = MAVLINK_SYSID; // System ID, 1-255
158 mavlink_system.compid = 0; // Component/Subsystem ID, 1-255
159
160 // Initialize Anti-Aliasing Sensor Filter
162
163 // Send telemetry
166}
167
175
176#ifndef JEVOIS_MAVLINK_ABI_ID
177#define JEVOIS_MAVLINK_ABI_ID 34
178#endif
179
180
181
183{
186
187
188 while (MAVLinkChAvailable()) {
189 uint8_t c = MAVLinkGetch();
191 //printf("msg.msgid is %d\n",msg.msgid);
192 switch (msg.msgid) {
196 // do something with heartbeat variable
197 DEBUG_PRINT("[jevois mavlink] heartbeat\n");
198 }
199 break;
200
204
205 DEBUG_PRINT("[jevois mavlink] debug value is %f\n", jevois_mavlink_debug.value);
206 DEBUG_PRINT("[jevois mavlink] debug ind is %d\n", jevois_mavlink_debug.ind);
207 }
208 break;
212
221
222
224 jevois_visual_target.x, // pixel-x
225 jevois_visual_target.y, // pixel-y
226 jevois_visual_target.w, // size
227 jevois_visual_target.h, // size
228 jevois_visual_target.quality, // quality
230
231 DEBUG_PRINT("[jevois mavlink] VISUAL_DETECTION %f,%f\n", jevois_mavlink_visual_target.xacc,
233
234 }
235 break;
236
240
245
246 DEBUG_PRINT("[jevois mavlink] phi_cmd = %f\n", DegOfRad(jevois_mavlink_manual_setpoint.roll));
247 DEBUG_PRINT("[jevois mavlink] theta_cmd = %f\n", DegOfRad(jevois_mavlink_manual_setpoint.pitch));
248 DEBUG_PRINT("[jevois mavlink] psi_cmd = %f\n", DegOfRad(jevois_mavlink_manual_setpoint.yaw));
249 DEBUG_PRINT("[jevois mavlink] alt_cmd = %f\n", jevois_mavlink_manual_setpoint.thrust);
250
251 }
252 break;
253
254
258
264
270 0.0f,
271 0.0f,
272 0.0f);
273
274 DEBUG_PRINT("[jevois mavlink] VISION_POSITION_ESTIMATE %f,%f,%f \n", jevois_vision_position.x,
276
277 }
278 break;
279
280 }
281 }
282 }
283}
284
285
287
288
289#include "state.h"
290#include "mcu_periph/sys_time.h"
291
292
293
294static void mavlink_send_attitude(void)
295{
298 stateGetNedToBodyEulers_f()->phi, // Phi
299 stateGetNedToBodyEulers_f()->theta, // Theta
300 stateGetNedToBodyEulers_f()->psi, // Psi
301 stateGetBodyRates_f()->p, // p
302 stateGetBodyRates_f()->q, // q
303 stateGetBodyRates_f()->r); // r
305}
306
307
308static void mavlink_send_set_mode(void)
309{
312 0, //autopilotMode.currentMode,
313 0
314 );
316}
317
328
329
350
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
Main include for ABI (AirBorneInterface).
Convenience defines for ABI sender IDs.
Core autopilot interface common to all firmwares.
static uint8_t status
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
Definition state.h:1367
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
struct Imu imu
global IMU state
Definition imu.c:422
Inertial Measurement Unit interface.
static float p[2][2]
static uint32_t s
Simple first order low pass filter with bilinear transform.
static int32_t get_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter)
Get current value of the second order Butterworth low pass filter(fixed point version).
static void init_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter, float cut_off, float sample_time, int32_t value)
Init a second order Butterworth filter.
static int32_t update_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter, int32_t value)
Update second order Butterworth low pass filter state with a new value(fixed point version).
uint16_t foo
Definition main_demo5.c:58
struct mavlink_heartbeat heartbeat
Definition px4flow.c:42
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
Architecture independent timing functions.
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
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.