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
sensors_hitl.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 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
22#include "modules/imu/imu.h"
23#include "modules/gps/gps.h"
24#include "modules/core/abi.h"
26#include "generated/airframe.h"
29#include "nps_sensors_params_common.h"
30#if USE_BATTERY_MONITOR
32#endif
33
43
47
48static bool sensors_hitl_msg_available = false;
51
53{
54 pprz_transport_init(&sensors_hitl_tp); // for receiving only
55
56 gps_has_fix = true;
57
59 imu_hitl.mag_available = false;
61
62 // Set the default scaling
63 const struct Int32Rates gyro_scale[2] = {
66 };
67 const struct Int32Rates gyro_neutral = {
69 };
70 const struct Int32Vect3 accel_scale[2] = {
73 };
74 const struct Int32Vect3 accel_neutral = {
76 };
77 const struct Int32Vect3 mag_scale[2] = {
80 };
81 const struct Int32Vect3 mag_neutral = {
83 };
87}
88
90#if USE_BATTERY_MONITOR
91#ifdef MAX_BAT_LEVEL
92 // init vsupply to MAX_BAT in case battery voltage is not available
94#else
95 electrical.vsupply = 12.f; // 3S battery
96#endif
97#endif
98}
99
123
125{
126 if (DL_HITL_GPS_ac_id(buf) != AC_ID) {
127 return;
128 }
129
130 gps_hitl.week = 1794;
131 gps_hitl.tow = DL_HITL_GPS_time(buf) * 1000;
132
137
140 gps_hitl.lla_pos.alt = DL_HITL_GPS_alt(buf) * 1000.;
142
143 gps_hitl.hmsl = DL_HITL_GPS_hmsl(buf) * 1000.;
145
146 /* calc NED speed from ECEF */
147 struct LtpDef_i ref_ltp;
149 struct NedCoor_i ned_vel_i;
155 struct NedCoor_f ned_vel_f;
157
158 /* horizontal and 3d ground speed in cm/s */
161
162 /* ground course in radians * 1e7 */
165
166 gps_hitl.pacc = 650;
167 gps_hitl.hacc = 450;
168 gps_hitl.vacc = 200;
169 gps_hitl.sacc = 100;
170 gps_hitl.pdop = 650;
171
172 if (gps_has_fix) {
173 gps_hitl.num_sv = 11;
175 } else {
176 gps_hitl.num_sv = 1;
178 }
179
180 // publish gps data
184 if (gps_hitl.fix == GPS_FIX_3D) {
187 }
189}
190
192 if (DL_HITL_AIR_DATA_ac_id(buf) != AC_ID) {
193 return;
194 }
195
197 if (bit_is_set(flag, 0)) {
199 float pressure = DL_HITL_AIR_DATA_baro(buf);
201 }
202 if (bit_is_set(flag, 1)) {
204 }
205 if (bit_is_set(flag, 2) || bit_is_set(flag, 3)) {
206 uint8_t incidence_flag = (flag >> 2) & (0x3);
207 float aoa = DL_HITL_AIR_DATA_aoa(buf);
208 float sideslip = DL_HITL_AIR_DATA_sideslip(buf);
210 }
211}
212
213
234
236void imu_feed_mag(void) {}
237void gps_feed_value(void) {}
238
Main include for ABI (AirBorneInterface).
#define BARO_SIM_SENDER_ID
#define IMU_NPS_ID
#define INCIDENCE_NPS_ID
#define GPS_SIM_ID
#define AIRSPEED_NPS_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
float vsupply
supply voltage in V
Definition electrical.h:45
Device independent GPS code (interface)
uint32_t tow
GPS time of week in ms.
Definition gps.h:109
int32_t hmsl
height above mean sea level (MSL) in mm
Definition gps.h:94
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition gps.h:92
uint32_t sacc
speed accuracy in cm/s
Definition gps.h:103
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition gps.h:99
#define GPS_VALID_VEL_ECEF_BIT
Definition gps.h:51
#define GPS_VALID_VEL_NED_BIT
Definition gps.h:52
uint32_t hacc
horizontal accuracy in cm
Definition gps.h:101
#define GPS_VALID_POS_LLA_BIT
Definition gps.h:49
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition gps.h:114
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition gps.h:95
uint16_t pdop
position dilution of precision scaled by 100
Definition gps.h:105
#define GPS_FIX_NONE
No GPS fix.
Definition gps.h:42
#define GPS_VALID_HMSL_BIT
Definition gps.h:53
struct NedCoor_i ned_vel
speed NED in cm/s
Definition gps.h:96
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition gps.h:117
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition gps.h:115
uint32_t pacc
position accuracy in cm
Definition gps.h:100
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition gps.h:97
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition gps.h:88
uint32_t vacc
vertical accuracy in cm
Definition gps.h:102
#define GPS_FIX_3D
3D GPS fix
Definition gps.h:44
uint16_t speed_3d
norm of 3d speed in cm/s
Definition gps.h:98
#define GPS_VALID_COURSE_BIT
Definition gps.h:54
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition gps.h:116
uint8_t num_sv
number of sat in fix
Definition gps.h:106
uint16_t week
GPS week.
Definition gps.h:108
uint8_t fix
status of fix
Definition gps.h:107
data structure for GPS information
Definition gps.h:87
#define RATES_ASSIGN(_ra, _p, _q, _r)
#define VECT3_ASSIGN(_a, _x, _y, _z)
angular rates
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t z
Down.
int32_t z
in centimeters
int32_t x
in centimeters
int32_t y
East.
int32_t y
in centimeters
int32_t lon
in degrees*1e7
int32_t x
North.
void ned_of_ecef_vect_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Rotate a vector from ECEF to NED.
#define VECT3_FLOAT_OF_CM(_o, _i)
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
definition of the local (flat earth) coordinate system
vector in North East Down coordinates
void imu_set_defaults_mag(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to e...
Definition imu.c:640
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition imu.c:610
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct Int32Rates *scale)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition imu.c:580
Inertial Measurement Unit interface.
#define MSG_SIZE
Definition main_demo5.c:62
uint16_t foo
Definition main_demo5.c:58
static const struct Int32Vect3 accel_neutral
Definition navdata.c:104
static const struct Int32Vect3 mag_scale[2]
Default mag scale.
Definition navdata.c:111
static const struct Int32Rates gyro_scale[2]
Default gyro scale.
Definition navdata.c:92
static const struct Int32Vect3 accel_scale[2]
Default accel scale/neutral.
Definition navdata.c:100
vector in North East Down coordinates Units: meters
static bool sensors_hitl_msg_available
void imu_feed_mag(void)
uint8_t accel_available
void sensors_hitl_event(void)
struct ImuHitl imu_hitl
void sensors_hitl_periodic(void)
void imu_feed_gyro_accel(void)
void gps_feed_value(void)
bool gps_has_fix
uint8_t mag_available
struct Int32Vect3 accel
static uint8_t sensors_hitl_dl_buffer[MSG_SIZE]
uint8_t gyro_available
void sensors_hitl_parse_HITL_AIR_DATA(uint8_t *buf)
void sensors_hitl_parse_HITL_GPS(uint8_t *buf)
struct Int32Vect3 mag
struct Int32Rates gyro
struct GpsState gps_hitl
void sensors_hitl_parse_HITL_IMU(uint8_t *buf)
void sensors_hitl_init(void)
static struct pprz_transport sensors_hitl_tp
volatile uint32_t nb_sec
full seconds since startup
Definition sys_time.h:72
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition sys_time.h:73
Periodic telemetry system header (includes downlink utility and generated code).
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.