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
74
76#if USE_BATTERY_MONITOR
77#ifdef MAX_BAT_LEVEL
78 // init vsupply to MAX_BAT in case battery voltage is not available
80#else
81 electrical.vsupply = 12.f; // 3S battery
82#endif
83#endif
84}
85
109
111{
112 if (DL_HITL_GPS_ac_id(buf) != AC_ID) {
113 return;
114 }
115
116 gps_hitl.week = 1794;
117 gps_hitl.tow = DL_HITL_GPS_time(buf) * 1000;
118
123
126 gps_hitl.lla_pos.alt = DL_HITL_GPS_alt(buf) * 1000.;
128
129 gps_hitl.hmsl = DL_HITL_GPS_hmsl(buf) * 1000.;
131
132 /* calc NED speed from ECEF */
133 struct LtpDef_i ref_ltp;
135 struct NedCoor_i ned_vel_i;
141 struct NedCoor_f ned_vel_f;
143
144 /* horizontal and 3d ground speed in cm/s */
147
148 /* ground course in radians * 1e7 */
151
152 gps_hitl.pacc = 650;
153 gps_hitl.hacc = 450;
154 gps_hitl.vacc = 200;
155 gps_hitl.sacc = 100;
156 gps_hitl.pdop = 650;
157
158 if (gps_has_fix) {
159 gps_hitl.num_sv = 11;
161 } else {
162 gps_hitl.num_sv = 1;
164 }
165
166 // publish gps data
170 if (gps_hitl.fix == GPS_FIX_3D) {
173 }
175}
176
178 if (DL_HITL_AIR_DATA_ac_id(buf) != AC_ID) {
179 return;
180 }
181
183 if (bit_is_set(flag, 0)) {
185 float pressure = DL_HITL_AIR_DATA_baro(buf);
187 }
188 if (bit_is_set(flag, 1)) {
190 }
191 if (bit_is_set(flag, 2) || bit_is_set(flag, 3)) {
192 uint8_t incidence_flag = (flag >> 2) & (0x3);
193 float aoa = DL_HITL_AIR_DATA_aoa(buf);
194 float sideslip = DL_HITL_AIR_DATA_sideslip(buf);
196 }
197}
198
199
220
222void imu_feed_mag(void) {}
223void gps_feed_value(void) {}
224
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
angular rates
#define RATES_ASSIGN(_ra, _p, _q, _r)
#define VECT3_ASSIGN(_a, _x, _y, _z)
#define RATE_FLOAT_OF_BFP(_ai)
#define ACCEL_FLOAT_OF_BFP(_ai)
#define MAG_FLOAT_OF_BFP(_ai)
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_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct FloatRates *scale_f)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition imu.c:612
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition imu.c:641
void imu_set_defaults_mag(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to e...
Definition imu.c:670
Inertial Measurement Unit interface.
#define MSG_SIZE
Definition main_demo5.c:62
uint16_t foo
Definition main_demo5.c:58
static const struct FloatVect3 mag_scale_f
Default mag scale.
Definition navdata.c:106
static const struct FloatVect3 accel_scale_f
Default accel scale/neutral.
Definition navdata.c:97
static const struct Int32Vect3 accel_neutral
Definition navdata.c:99
static const struct FloatRates gyro_scale_f
Default gyro scale.
Definition navdata.c:92
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.