Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot_firmware.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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  */
20 
29 
30 #include "generated/modules.h"
31 
32 #include <stdint.h>
33 #include "subsystems/electrical.h"
36 
37 #if USE_GPS
38 #include "subsystems/gps.h"
39 #else
40 #if NO_GPS_NEEDED_FOR_NAV
41 #define GpsIsLost() FALSE
42 #else
43 #define GpsIsLost() TRUE
44 #endif
45 #endif
46 
47 
48 /* Geofence exceptions */
50 
51 #if USE_MOTOR_MIXING
53 #endif
54 
55 static void send_status(struct transport_tx *trans, struct link_device *dev)
56 {
57 #if USE_GPS
58  uint8_t fix = gps.fix;
59 #else
60  uint8_t fix = 0;
61 #endif
62  uint8_t motors_on = autopilot.motors_on;
63  uint16_t time_sec = sys_time.nb_sec;
64  pprz_msg_send_ROVER_STATUS(trans, dev, AC_ID,
66  &fix, &autopilot.mode, &motors_on,
67  &electrical.vsupply, &time_sec);
68 }
69 
70 static void send_energy(struct transport_tx *trans, struct link_device *dev)
71 {
73  if (fabs(electrical.energy) >= INT16_MAX) {
74  e = INT16_MAX;
75  }
76  float vsup = ((float)electrical.vsupply) / 10.0f;
77  float curs = ((float)electrical.current) / 1000.0f;
78  float power = vsup * curs;
79  pprz_msg_send_ENERGY(trans, dev, AC_ID, &vsup, &curs, &e, &power);
80 }
81 
82 static void send_fp(struct transport_tx *trans, struct link_device *dev)
83 {
84  int32_t carrot_east = POS_BFP_OF_REAL(nav.carrot.x);
85  int32_t carrot_north = POS_BFP_OF_REAL(nav.carrot.y);
86  int32_t carrot_up = 0;
87  int32_t carrot_heading = ANGLE_BFP_OF_REAL(nav.heading);
88  int32_t cmd = (int32_t)(ABS(commands[COMMAND_SPEED]));
89  pprz_msg_send_ROTORCRAFT_FP(trans, dev, AC_ID,
93  &(stateGetSpeedEnu_i()->x),
94  &(stateGetSpeedEnu_i()->y),
95  &(stateGetSpeedEnu_i()->z),
96  &(stateGetNedToBodyEulers_i()->phi),
97  &(stateGetNedToBodyEulers_i()->theta),
98  &(stateGetNedToBodyEulers_i()->psi),
99  &carrot_east,
100  &carrot_north,
101  &carrot_up,
102  &carrot_heading,
103  &cmd,
105 }
106 
107 
108 #ifdef RADIO_CONTROL
109 static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
110 {
111 #ifdef RADIO_KILL_SWITCH
113 #else
114  int16_t _kill_switch = 42;
115 #endif
116  pprz_msg_send_ROTORCRAFT_RADIO_CONTROL(trans, dev, AC_ID,
122  &_kill_switch,
124 }
125 #endif
126 
128 {
129  // register messages
130  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROVER_STATUS, send_status);
132  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_FP, send_fp);
133 #ifdef RADIO_CONTROL
134  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_RADIO_CONTROL, send_rotorcraft_rc);
135 #endif
136 }
137 
141 void autopilot_event(void)
142 {
143 }
144 
struct RoverNavigation nav
Definition: navigation.c:49
int32_t current
current in milliamps
Definition: electrical.h:49
unsigned short uint16_t
Definition: types.h:16
#define RADIO_ROLL
Definition: intermcu_ap.h:40
float y
in meters
void autopilot_firmware_init(void)
Init function.
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t status
Definition: radio_control.h:64
#define POS_BFP_OF_REAL(_af)
static void send_energy(struct transport_tx *trans, struct link_device *dev)
uint16_t flight_time
flight time in seconds
Definition: autopilot.h:61
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
float z
in meters
#define RADIO_MODE
Definition: intermcu_ap.h:43
float x
in meters
Interface for electrical status: supply voltage, current, battery status, etc.
Device independent GPS code (interface)
Rover specific autopilot interface and initialization.
signed short int16_t
Definition: types.h:17
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
struct RadioControl radio_control
Definition: radio_control.c:30
static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
static void send_fp(struct transport_tx *trans, struct link_device *dev)
#define RADIO_THROTTLE
Definition: intermcu_ap.h:39
float heading
heading setpoint (in radians)
Definition: navigation.h:90
signed long int32_t
Definition: types.h:19
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
void autopilot_event(void)
autopilot event function
static void send_status(struct transport_tx *trans, struct link_device *dev)
bool motors_on
arming status
Definition: autopilot.h:63
unsigned char uint8_t
Definition: types.h:14
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
Definition: commands.c:30
#define RADIO_PITCH
Definition: intermcu_ap.h:41
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
Definition: state.h:872
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
#define RADIO_YAW
Definition: intermcu_ap.h:42
float energy
consumed energy in mAh
Definition: electrical.h:51
struct Electrical electrical
Definition: electrical.c:65
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition: state.h:674
#define RADIO_KILL_SWITCH
Definition: intermcu_ap.h:44
Motor Mixing.
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
struct EnuCoor_f carrot
carrot position
Definition: navigation.h:89
uint8_t fix
status of fix
Definition: gps.h:99
float y
in meters
struct GpsState gps
global GPS state
Definition: gps.c:75
uint8_t mode
current autopilot mode
Definition: autopilot.h:59
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
float x
in meters
uint8_t frame_rate
Definition: radio_control.h:67