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) 2012-2017 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 
30 
31 #include "state.h"
33 #include <stdint.h>
34 
35 // ap copy of fbw readings
37 
40 
41 #if PERIODIC_TELEMETRY
43 #include "generated/settings.h"
44 
45 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
47 static void send_rc_settings(struct transport_tx *trans, struct link_device *dev)
48 {
49  if (!RcSettingsOff()) {
50  pprz_msg_send_SETTINGS(trans, dev, AC_ID, &slider_1_val, &slider_2_val);
51  }
52 }
53 #else
55 #endif
56 
57 static void send_mode(struct transport_tx *trans, struct link_device *dev)
58 {
59  pprz_msg_send_PPRZ_MODE(trans, dev, AC_ID,
61 }
62 
63 static void send_estimator(struct transport_tx *trans, struct link_device *dev)
64 {
65  pprz_msg_send_ESTIMATOR(trans, dev, AC_ID,
66  &(stateGetPositionUtm_f()->alt), &(stateGetSpeedEnu_f()->z));
67 }
68 
69 static void send_energy(struct transport_tx *trans, struct link_device *dev)
70 {
71  uint8_t throttle = 100 * autopilot.throttle / MAX_PPRZ;
73  pprz_msg_send_ENERGY(trans, dev, AC_ID,
75 }
76 
77 // FIXME not the best place
79 #include CTRL_TYPE_H
80 static void send_desired(struct transport_tx *trans, struct link_device *dev)
81 {
82 #ifndef USE_AIRSPEED
83  float v_ctl_auto_airspeed_setpoint = NOMINAL_AIRSPEED;
84 #endif
85  pprz_msg_send_DESIRED(trans, dev, AC_ID,
89 }
90 
91 static void send_airspeed(struct transport_tx *trans __attribute__((unused)),
92  struct link_device *dev __attribute__((unused)))
93 {
94  float airspeed = stateGetAirspeed_f();
95 #if USE_AIRSPEED
96  pprz_msg_send_AIRSPEED(trans, dev, AC_ID,
97  &airspeed, &v_ctl_auto_airspeed_setpoint,
99 #else
100  float zero = 0;
101  pprz_msg_send_AIRSPEED(trans, dev, AC_ID, &airspeed, &zero, &zero, &zero);
102 #endif
103 }
104 #endif /* PERIODIC_TELEMETRY */
105 
107 {
108  // use default telemetry here
109 #if DOWNLINK
110  send_mode(&(DefaultChannel).trans_tx, &(DefaultDevice).device);
111 #endif
112 }
113 
115 {
116  ap_electrical.vsupply = 0.f;
117  ap_electrical.current = 0.f;
118  ap_electrical.charge = 0.f;
119  ap_electrical.energy = 0.f;
120 
121  ap_electrical.bat_critical = false;
122  ap_electrical.bat_low = false;
123 
124 #if PERIODIC_TELEMETRY
125  /* register some periodic message */
126  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_PPRZ_MODE, send_mode);
131 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
132  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_RC_SETTINGS, send_rc_settings);
133 #endif
134 #endif
135 }
136 
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
v_ctl_mode
uint8_t v_ctl_mode
Definition: energy_ctrl.c:74
send_desired
static void send_desired(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:80
pprz_autopilot::mode
uint8_t mode
current autopilot mode
Definition: autopilot.h:63
slider_1_val
float slider_1_val
Definition: rc_settings.c:35
Electrical
Definition: electrical.h:44
stabilization_attitude.h
stateGetPositionUtm_f
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:692
Electrical::vsupply
float vsupply
supply voltage in V
Definition: electrical.h:45
h_ctl_roll_setpoint
float h_ctl_roll_setpoint
Definition: stabilization_adaptive.c:157
send_energy
static void send_energy(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:69
h_ctl_pitch_loop_setpoint
float h_ctl_pitch_loop_setpoint
Definition: stabilization_adaptive.c:171
telemetry.h
ap_electrical
struct Electrical ap_electrical
Definition: autopilot_firmware.c:36
rc_settings.h
Electrical::charge
float charge
consumed electric charge in Ah
Definition: electrical.h:47
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
desired_x
float desired_x
Definition: nav.c:306
lateral_mode
uint8_t lateral_mode
Definition: autopilot_firmware.c:38
Electrical::bat_low
bool bat_low
battery low status
Definition: electrical.h:49
desired_y
float desired_y
Definition: nav.c:306
pprz_autopilot::throttle
pprz_t throttle
throttle level as will be displayed in GCS
Definition: autopilot.h:66
stateGetAirspeed_f
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1407
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
send_mode
static void send_mode(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:57
uint8_t
unsigned char uint8_t
Definition: types.h:14
v_ctl_climb_setpoint
float v_ctl_climb_setpoint
Definition: energy_ctrl.c:98
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
mcu1_status
uint8_t mcu1_status
Second MCU status (FBW part)
Definition: autopilot_firmware.c:39
v_ctl_auto_airspeed_controlled
float v_ctl_auto_airspeed_controlled
Definition: energy_ctrl.c:123
autopilot_firmware_init
void autopilot_firmware_init(void)
Init function.
Definition: autopilot_firmware.c:114
autopilot_firmware.h
nav.h
Electrical::bat_critical
bool bat_critical
battery critical status
Definition: electrical.h:50
v_ctl_auto_groundspeed_setpoint
float v_ctl_auto_groundspeed_setpoint
in meters per second
Definition: energy_ctrl.c:125
v_ctl_altitude_setpoint
float v_ctl_altitude_setpoint
in meters above MSL
Definition: energy_ctrl.c:88
send_airspeed
static void send_airspeed(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:91
stateGetSpeedEnu_f
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
Definition: state.h:917
rc_settings_mode
uint8_t rc_settings_mode
Definition: autopilot_firmware.c:54
v_ctl_auto_airspeed_setpoint
float v_ctl_auto_airspeed_setpoint
in meters per second
Definition: energy_ctrl.c:121
state.h
RcSettingsOff
#define RcSettingsOff()
Definition: rc_settings.h:70
Electrical::energy
float energy
consumed energy in Wh
Definition: electrical.h:48
send_estimator
static void send_estimator(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot_firmware.c:63
horizontal_mode
uint8_t horizontal_mode
Definition: nav.c:71
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
autopilot_send_mode
void autopilot_send_mode(void)
Report autopilot mode on default downlink channel.
Definition: autopilot_firmware.c:106
Electrical::current
float current
current in A
Definition: electrical.h:46
slider_2_val
float slider_2_val
Definition: rc_settings.c:35
h_ctl_course_setpoint
float h_ctl_course_setpoint
Definition: stabilization_adaptive.c:80