Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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  &time_sec, &electrical.vsupply);
68 }
69 
70 static void send_energy(struct transport_tx *trans, struct link_device *dev)
71 {
72  uint8_t throttle = 100 * autopilot.throttle / MAX_PPRZ;
73  float power = electrical.vsupply * electrical.current;
74  pprz_msg_send_ENERGY(trans, dev, AC_ID,
76 }
77 
78 static void send_fp(struct transport_tx *trans, struct link_device *dev)
79 {
80  int32_t carrot_east = POS_BFP_OF_REAL(nav.carrot.x);
81  int32_t carrot_north = POS_BFP_OF_REAL(nav.carrot.y);
82  int32_t carrot_up = 0;
83  int32_t carrot_heading = ANGLE_BFP_OF_REAL(nav.heading);
85  pprz_msg_send_ROTORCRAFT_FP(trans, dev, AC_ID,
89  &(stateGetSpeedEnu_i()->x),
90  &(stateGetSpeedEnu_i()->y),
91  &(stateGetSpeedEnu_i()->z),
95  &carrot_east,
96  &carrot_north,
97  &carrot_up,
98  &carrot_heading,
99  &cmd,
101 }
102 
103 
104 #ifdef RADIO_CONTROL
105 static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
106 {
107 #ifdef RADIO_KILL_SWITCH
109 #else
110  int16_t _kill_switch = 42;
111 #endif
112  pprz_msg_send_ROTORCRAFT_RADIO_CONTROL(trans, dev, AC_ID,
118  &_kill_switch,
120 }
121 #endif
122 
124 {
125  // register messages
126  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROVER_STATUS, send_status);
128  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_FP, send_fp);
129 #ifdef RADIO_CONTROL
130  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_RADIO_CONTROL, send_rotorcraft_rc);
131 #endif
132 }
133 
137 void autopilot_event(void)
138 {
139 }
140 
Int32Eulers::theta
int32_t theta
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:148
radio_control.h
electrical.h
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
uint16_t
unsigned short uint16_t
Definition: types.h:16
send_status
static void send_status(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:55
RADIO_ROLL
#define RADIO_ROLL
Definition: intermcu_ap.h:41
motor_mixing.h
send_fp
static void send_fp(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:78
EnuCoor_i::y
int32_t y
North.
Definition: pprz_geodetic_int.h:79
EnuCoor_i::x
int32_t x
East.
Definition: pprz_geodetic_int.h:78
pprz_autopilot::flight_time
uint16_t flight_time
flight time in seconds
Definition: autopilot.h:65
pprz_autopilot::mode
uint8_t mode
current autopilot mode
Definition: autopilot.h:63
RoverNavigation::carrot
struct EnuCoor_f carrot
carrot position
Definition: navigation.h:89
nav_geofence.h
stateGetPositionEnu_i
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition: state.h:674
RADIO_MODE
#define RADIO_MODE
Definition: intermcu_ap.h:44
nav
struct RoverNavigation nav
Definition: navigation.c:49
send_energy
static void send_energy(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:70
Electrical::vsupply
float vsupply
supply voltage in V
Definition: electrical.h:45
EnuCoor_f::y
float y
in meters
Definition: pprz_geodetic_float.h:74
RadioControl::frame_rate
uint8_t frame_rate
Definition: radio_control.h:67
telemetry.h
Electrical::charge
float charge
consumed electric charge in Ah
Definition: electrical.h:47
Int32Eulers::psi
int32_t psi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:149
pprz_autopilot::motors_on
bool motors_on
motor status
Definition: autopilot.h:68
Int32Eulers::phi
int32_t phi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:147
stateGetSpeedEnu_i
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
Definition: state.h:872
gps.h
Device independent GPS code (interface)
GpsState::fix
uint8_t fix
status of fix
Definition: gps.h:107
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
ANGLE_BFP_OF_REAL
#define ANGLE_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:210
pprz_autopilot::throttle
pprz_t throttle
throttle level as will be displayed in GCS
Definition: autopilot.h:66
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
RadioControl::status
uint8_t status
Definition: radio_control.h:64
autopilot_event
void autopilot_event(void)
autopilot event function
Definition: autopilot_firmware.c:211
autopilot_firmware_init
void autopilot_firmware_init(void)
Init function.
Definition: autopilot_firmware.c:114
RADIO_THROTTLE
#define RADIO_THROTTLE
Definition: intermcu_ap.h:40
int32_t
signed long int32_t
Definition: types.h:19
sys_time
Definition: sys_time.h:71
RADIO_YAW
#define RADIO_YAW
Definition: intermcu_ap.h:43
POS_BFP_OF_REAL
#define POS_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:216
autopilot_firmware.h
NedCoor_f::x
float x
in meters
Definition: pprz_geodetic_float.h:64
stateGetNedToBodyEulers_i
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
EnuCoor_i::z
int32_t z
Up.
Definition: pprz_geodetic_int.h:80
electrical
struct Electrical electrical
Definition: electrical.c:66
EnuCoor_f::x
float x
in meters
Definition: pprz_geodetic_float.h:73
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
Electrical::energy
float energy
consumed energy in Wh
Definition: electrical.h:48
RADIO_PITCH
#define RADIO_PITCH
Definition: intermcu_ap.h:42
RADIO_KILL_SWITCH
#define RADIO_KILL_SWITCH
Definition: intermcu_ap.h:45
RoverNavigation::heading
float heading
heading setpoint (in radians)
Definition: navigation.h:90
gps
struct GpsState gps
global GPS state
Definition: gps.c:69
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
send_rotorcraft_rc
static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:105
Electrical::current
float current
current in A
Definition: electrical.h:46
radio_control
struct RadioControl radio_control
Definition: radio_control.c:30
RadioControl::values
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69