Paparazzi UAS  v5.12_stable-4-g9b43e9b
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) 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 
37 float energy;
38 
41 
42 #if PERIODIC_TELEMETRY
44 #include "generated/settings.h"
45 
46 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
48 static void send_rc_settings(struct transport_tx *trans, struct link_device *dev)
49 {
50  if (!RcSettingsOff()) {
51  pprz_msg_send_SETTINGS(trans, dev, AC_ID, &slider_1_val, &slider_2_val);
52  }
53 }
54 #else
56 #endif
57 
58 static void send_mode(struct transport_tx *trans, struct link_device *dev)
59 {
60  pprz_msg_send_PPRZ_MODE(trans, dev, AC_ID,
62 }
63 
64 static void send_estimator(struct transport_tx *trans, struct link_device *dev)
65 {
66  pprz_msg_send_ESTIMATOR(trans, dev, AC_ID,
67  &(stateGetPositionUtm_f()->alt), &(stateGetSpeedEnu_f()->z));
68 }
69 
70 static void send_bat(struct transport_tx *trans, struct link_device *dev)
71 {
72  int16_t amps = (int16_t)(current / 10);
73  int16_t e = energy;
74  // prevent overflow
75  if (fabs(energy) >= INT16_MAX) {
76  e = INT16_MAX;
77  }
78  pprz_msg_send_BAT(trans, dev, AC_ID,
81  &block_time, &stage_time, &e);
82 }
83 
84 static void send_energy(struct transport_tx *trans, struct link_device *dev)
85 {
86  uint16_t e = energy;
87  if (fabs(energy) >= INT16_MAX) {
88  e = INT16_MAX;
89  }
90  float vsup = ((float)vsupply) / 10.0f;
91  float curs = ((float)current) / 1000.0f;
92  float power = vsup * curs;
93  pprz_msg_send_ENERGY(trans, dev, AC_ID, &vsup, &curs, &e, &power);
94 }
95 
96 // FIXME not the best place
98 #include CTRL_TYPE_H
99 static void send_desired(struct transport_tx *trans, struct link_device *dev)
100 {
101 #ifndef USE_AIRSPEED
102  float v_ctl_auto_airspeed_setpoint = NOMINAL_AIRSPEED;
103 #endif
104  pprz_msg_send_DESIRED(trans, dev, AC_ID,
107  &v_ctl_auto_airspeed_setpoint);
108 }
109 
110 static void send_airspeed(struct transport_tx *trans __attribute__((unused)),
111  struct link_device *dev __attribute__((unused)))
112 {
113  float airspeed = stateGetAirspeed_f();
114 #if USE_AIRSPEED
115  pprz_msg_send_AIRSPEED(trans, dev, AC_ID,
116  &airspeed, &v_ctl_auto_airspeed_setpoint,
118 #else
119  float zero = 0;
120  pprz_msg_send_AIRSPEED(trans, dev, AC_ID, &airspeed, &zero, &zero, &zero);
121 #endif
122 }
123 #endif /* PERIODIC_TELEMETRY */
124 
126 {
127  // use default telemetry here
128 #if DOWNLINK
129  send_mode(&(DefaultChannel).trans_tx, &(DefaultDevice).device);
130 #endif
131 }
132 
134 {
135  vsupply = 0;
136  current = 0;
137  energy = 0.f;
138 
139 #if PERIODIC_TELEMETRY
140  /* register some periodic message */
141  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_PPRZ_MODE, send_mode);
147 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
148  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_RC_SETTINGS, send_rc_settings);
149 #endif
150 #endif
151 }
152 
uint16_t block_time
unsigned short uint16_t
Definition: types.h:16
uint8_t mcu1_status
Second MCU status (FBW part)
static void send_airspeed(struct transport_tx *trans, struct link_device *dev)
void autopilot_firmware_init(void)
Init function.
uint8_t lateral_mode
float v_ctl_altitude_setpoint
in meters above MSL
Definition: energy_ctrl.c:88
uint8_t rc_settings_mode
Variable setting though the radio control.
Periodic telemetry system header (includes downlink utility and generated code).
#define RcSettingsOff()
Definition: rc_settings.h:70
int32_t current
Supply current in milliAmpere.
float h_ctl_course_setpoint
float v_ctl_auto_groundspeed_setpoint
in meters per second
Definition: energy_ctrl.c:125
float v_ctl_climb_setpoint
Definition: energy_ctrl.c:98
uint16_t flight_time
flight time in seconds
Definition: autopilot.h:61
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1407
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
float v_ctl_auto_airspeed_setpoint
in meters per second
Definition: energy_ctrl.c:121
Fixed wing horizontal control.
float energy
Energy consumption (mAh) This is the ap copy of the measurement from fbw FIXME use electrical module ...
uint16_t vsupply
Supply voltage in deciVolt.
static void send_desired(struct transport_tx *trans, struct link_device *dev)
Fixedwing specific autopilot interface and initialization.
float h_ctl_pitch_loop_setpoint
signed short int16_t
Definition: types.h:17
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
float slider_1_val
Definition: rc_settings.c:35
static void send_estimator(struct transport_tx *trans, struct link_device *dev)
uint8_t v_ctl_mode
Definition: energy_ctrl.c:74
uint16_t stage_time
In s.
void autopilot_send_mode(void)
Report autopilot mode on default downlink channel.
signed long int32_t
Definition: types.h:19
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
static void send_bat(struct transport_tx *trans, struct link_device *dev)
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:692
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
float slider_2_val
Definition: rc_settings.c:35
float h_ctl_roll_setpoint
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
Definition: state.h:917
static void send_energy(struct transport_tx *trans, struct link_device *dev)
static void send_mode(struct transport_tx *trans, struct link_device *dev)
bool kill_throttle
allow autopilot to use throttle
Definition: autopilot.h:63
pprz_t v_ctl_throttle_slewed
Definition: energy_ctrl.c:132
uint8_t mode
current autopilot mode
Definition: autopilot.h:59
float v_ctl_auto_airspeed_controlled
Definition: energy_ctrl.c:123
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46