Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ins_vectornav.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Michal Podhradsky, michal.podhradsky@aggiemail.usu.edu
3 * Utah State University, http://aggieair.usu.edu/
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
31
33
34#if PERIODIC_TELEMETRY
36
44
50
60
74
75static void send_accel(struct transport_tx *trans, struct link_device *dev)
76{
80}
81
82static void send_gyro(struct transport_tx *trans, struct link_device *dev)
83{
85 pprz_msg_send_IMU_GYRO(trans, dev, AC_ID, &id,
87}
88
95
96static void send_gyro_scaled(struct transport_tx *trans, struct link_device *dev)
97{
101}
102#endif
103
104#ifndef USE_INS_NAV_INIT
105#define USE_INS_NAV_INIT TRUE
106PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE");
107#endif
108
109
117{
118 static uint16_t last_cnt = 0;
119 static uint16_t sec_cnt = 0;
120
122 ins_vn.vn_rate = sec_cnt; // update frequency counter
123
124 // we want at least 75% of periodic frequency to be able to control the airfcraft
125 if (ins_vn.vn_rate < (PERIODIC_FREQUENCY*0.75)) {
127 }
128
129 // Make gps pacc available in GPS page on GCS
130 static uint32_t last_pacc = 0;
131 // update only if pacc changes
132 if (last_pacc != gps.pacc) {
134 // we don't know the value of CNO, hence oscillate
135 // between 0 and 1 to not confuse the user
136 gps.svinfos[0].cno = (gps.svinfos[0].cno + 1) % 2;
137 }
138
139 // update counter
141
142 // reset mode
143 ins_vn.vn_data.mode = 0;
144}
145
146
151{
152 // receive data
154
155 // read message
160 }
161}
162
163
168{
169 // Initialize variables
171 ins_vn.vn_rate = 0;
172
173 // Initialize packet
182
187
188 // initialize data struct
189 memset(&(ins_vn.vn_data), 0, sizeof(struct VNData));
190
191#if USE_INS_NAV_INIT
193 ins_vn.ltp_initialized = true;
194#else
195 ins_vn.ltp_initialized = false;
196#endif
197
201
202#if PERIODIC_TELEMETRY
211#endif
212}
213
214
215
216
222{
223 gps.sacc = (uint32_t)(ins_vn.vn_data.vel_u * 100);
224}
225
231{
232 float pacc = ins_vn.vn_data.pos_u[0]; // in meters
233 if (ins_vn.vn_data.pos_u[1] > pacc) {
234 pacc = ins_vn.vn_data.pos_u[1];
235 }
236 if (ins_vn.vn_data.pos_u[2] > pacc) {
237 pacc = ins_vn.vn_data.pos_u[2];
238 }
239 gps.pacc = (uint32_t)(pacc * 100);
240}
241
242
243
249{
250 // Acceleration [m/s^2]
251 // in fixed point for sending as ABI and telemetry msgs
253
254 // Rates [rad/s]
255 static struct FloatRates body_rate;
256 // in fixed point for sending as ABI and telemetry msgs
258 float_rmat_ratemult(&body_rate, orientationGetRMat_f(&ins_vn.body_to_imu), &ins_vn.vn_data.gyro); // compute body rates
259 stateSetBodyRates_f(MODULE_INS_VECTORNAV_ID, &body_rate); // Set state [rad/s]
260
261 // Attitude [deg]
262 static struct FloatQuat imu_quat; // convert from euler to quat
264 static struct FloatRMat imu_rmat; // convert from quat to rmat
266 static struct FloatRMat ltp_to_body_rmat; // rotate to body frame
268 stateSetNedToBodyRMat_f(MODULE_INS_VECTORNAV_ID, &ltp_to_body_rmat); // set body states [rad]
269
270 // NED (LTP) velocity [m/s]
271 // North east down (NED), also known as local tangent plane (LTP),
272 // is a geographical coordinate system for representing state vectors that is commonly used in aviation.
273 // It consists of three numbers: one represents the position along the northern axis,
274 // one along the eastern axis, and one represents vertical position. Down is chosen as opposed to
275 // up in order to comply with the right-hand rule.
276 // The origin of this coordinate system is usually chosen to be the aircraft's center of gravity.
277 // x = North
278 // y = East
279 // z = Down
281
282 // NED (LTP) acceleration [m/s^2]
283 static struct FloatVect3 accel_meas_ltp;// first we need to rotate linear acceleration from imu-frame to body-frame
285 static struct NedCoor_f ltp_accel; // assign to NedCoord_f struct
287 stateSetAccelNed_f(MODULE_INS_VECTORNAV_ID, &ltp_accel); // then set the states
288 ins_vn.ltp_accel_f = ltp_accel;
289
290 // LLA position [rad, rad, m]
291 //static struct LlaCoor_f lla_pos; // convert from deg to rad, and from double to float
292 ins_vn.lla_pos.lat = RadOfDeg((float)ins_vn.vn_data.pos_lla[0]); // ins_impl.pos_lla[0] = lat
293 ins_vn.lla_pos.lon = RadOfDeg((float)ins_vn.vn_data.pos_lla[1]); // ins_impl.pos_lla[1] = lon
294 ins_vn.lla_pos.alt = ((float)ins_vn.vn_data.pos_lla[2]); // ins_impl.pos_lla[2] = alt
298
299 // ECEF velocity
300 // TODO: properly implement
301
302 // ECEF position
307
308 // GPS Ground speed
310 gps.gspeed = ((uint16_t)(speed * 100));
311
312 // GPS course
315
316 // Because we have not HMSL data from Vectornav, we are using LLA-Altitude
317 // as a workaround
319 gps.hmsl = (int32_t)((ins_vn.lla_pos.alt - geoid_h)* 1000.0f);
321
322 // Set GPS fix
324
325 // Set GPS num_sv
327
328 // set position uncertainty
330
331 // set velocity uncertainty
333
334 // check GPS status
337 if (gps.fix == GPS_FIX_3D) {
340 }
341
342 // update internal states for telemetry purposes
343 // TODO: directly convert vectornav output instead of using state interface
344 // to support multiple INS running at the same time
348}
#define IMU_VECTORNAV_ID
struct GpsState gps
global GPS state
Definition gps.c:74
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
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition gps.h:81
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition gps.h:91
#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
#define GPS_FIX_NONE
No GPS fix.
Definition gps.h:42
#define GPS_VALID_POS_ECEF_BIT
Definition gps.h:48
#define GPS_VALID_HMSL_BIT
Definition gps.h:53
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
#define GPS_FIX_3D
3D GPS fix
Definition gps.h:44
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition gps.h:112
#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
uint8_t fix
status of fix
Definition gps.h:107
float q
in rad/s
float phi
in radians
float p
in rad/s
float r
in rad/s
float theta
in radians
float psi
in radians
void float_rmat_ratemult(struct FloatRates *rb, struct FloatRMat *m_a2b, struct FloatRates *ra)
rotate anglular rates by rotation matrix.
void float_rmat_of_quat(struct FloatRMat *rm, struct FloatQuat *q)
void float_rmat_comp(struct FloatRMat *m_a2c, struct FloatRMat *m_a2b, struct FloatRMat *m_b2c)
Composition (multiplication) of two rotation matrices.
void float_quat_of_eulers(struct FloatQuat *q, struct FloatEulers *e)
quat of euler roation 'ZYX'
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
euler angles
Roation quaternion.
rotation matrix
angular rates
#define VECT3_ASSIGN(_a, _x, _y, _z)
#define RATES_BFP_OF_REAL(_ri, _rf)
#define ACCELS_BFP_OF_REAL(_ef, _ei)
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
#define INT32_VECT3_ZERO(_v)
int32_t lat
in degrees*1e7
int32_t hmsl
Height above mean sea level in mm.
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t z
Down.
int32_t z
in centimeters
struct LlaCoor_i lla
Reference point in lla.
int32_t x
in centimeters
int32_t y
East.
struct EcefCoor_i ecef
Reference point in ecef.
int32_t y
in centimeters
int32_t lon
in degrees*1e7
int32_t x
North.
#define LLA_BFP_OF_REAL(_o, _i)
static float wgs84_ellipsoid_to_geoid_f(float lat, float lon)
Get WGS84 ellipsoid/geoid separation.
static void orientationSetEulers_f(struct OrientationReps *orientation, struct FloatEulers *eulers)
Set vehicle body attitude from euler angles (float).
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
static void stateSetAccelNed_f(uint16_t id, struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
Definition state.h:1147
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
Definition state.h:1177
static void stateSetNedToBodyRMat_f(uint16_t id, struct FloatRMat *ned_to_body_rmat)
Set vehicle body attitude from rotation matrix (float).
Definition state.h:1260
static struct EcefCoor_i * stateGetPositionEcef_i(void)
Get position in ECEF coordinates (int).
Definition state.h:785
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
Definition state.h:794
static void stateSetPositionLla_i(uint16_t id, struct LlaCoor_i *lla_pos)
Set position from LLA coordinates (int).
Definition state.h:658
static void stateSetBodyRates_f(uint16_t id, struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Definition state.h:1346
static void stateSetSpeedNed_f(uint16_t id, struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition state.h:947
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
Definition state.h:1004
void ins_init_origin_i_from_flightplan(uint16_t id, struct LtpDef_i *ltp_def)
initialize the local origin (ltp_def in fixed point) from flight plan position
Definition ins.c:33
void ins_vectornav_monitor(void)
Monitors vectornav data rate and changes GPS lock if the data rate is too low.
static void send_ins(struct transport_tx *trans, struct link_device *dev)
void ins_vectornav_set_pacc(void)
Find maximum uncertainty (NED) position accuracy in cm.
struct InsVectornav ins_vn
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
static void send_ins_z(struct transport_tx *trans, struct link_device *dev)
void ins_vectornav_set_sacc(void)
Set speed (velocity) uncertainty (NED) speed accuracy in cm/s.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
static void send_gyro_scaled(struct transport_tx *trans, struct link_device *dev)
static void send_gyro(struct transport_tx *trans, struct link_device *dev)
void ins_vectornav_init(void)
Initialize Vectornav struct.
void ins_vectornav_event(void)
Event handling for Vectornav.
static void send_vn_info(struct transport_tx *trans, struct link_device *dev)
static void send_accel(struct transport_tx *trans, struct link_device *dev)
static void send_accel_scaled(struct transport_tx *trans, struct link_device *dev)
void ins_vectornav_propagate()
Propagate the received states into the vehicle state machine.
Vectornav VN-200 INS module.
#define INS_VN_BODY_TO_IMU_PHI
struct NedCoor_f ltp_accel_f
struct NedCoor_i ltp_accel_i
struct LlaCoor_f lla_pos
struct Int32Vect3 accel_i
struct VNData vn_data
Data struct.
struct VNPacket vn_packet
Packet struct.
float baro_z
z-position calculated from baro in meters (z-down)
struct OrientationReps body_to_imu
body_to_imu rotation
enum VNStatus vn_status
VN status.
struct NedCoor_i ltp_pos_i
#define INS_VN_BODY_TO_IMU_PSI
struct Int32Rates gyro_i
struct NedCoor_i ltp_speed_i
#define INS_VN_BODY_TO_IMU_THETA
uint16_t vn_rate
data frequency
struct LtpDef_i ltp_def
uint16_t foo
Definition main_demo5.c:58
float alt
in meters (normally above WGS84 reference ellipsoid)
float lon
in radians
float x
in meters
float lat
in radians
float y
in meters
vector in North East Down coordinates Units: meters
WGS-84 Geoid Heights.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
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
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
void vn200_read_message(struct VNPacket *vn_packet, struct VNData *vn_data)
Read received message and populate data struct with new measurements.
void vn200_event(struct VNPacket *vnp)
uint16_t framing_error
uint32_t hdr_error
uint8_t err
see page 122 of VN-200 datasheet
@ VNNotTracking
uint16_t overrun_error
struct FloatRates gyro
Rates in the imu frame m/s.
struct FloatEulers attitude
Attitude, float, [rad], yaw, pitch, roll.
struct FloatEulers ypr_u
Attitude uncertainty, 1sigma, float, [degrees], yaw, pitch, roll.
struct FloatVect3 accel
Acceleration in the imu frame, m/s.
uint8_t mode
0-not tracking, 1 - poor performance, 2- OK
float timestamp
Time since VN startup [s].
float pos_u[3]
The current GPS position uncertainty in the North East Down (NED) coordinate frame,...
@ VNMsgSync
double pos_lla[3]
float vel_u
NED velocity uncertainty [m/s].
uint8_t gps_fix
None|2D|3D.
uint8_t num_sv
number of visible satellites
struct FloatVect3 lin_accel
Linear acceleration in imu frame [m/s^2].
uint16_t counter
bool msg_available
struct NedCoor_f vel_ned
The estimated velocity in the North East Down (NED) frame, given in m/s.
uint16_t noise_error
uint32_t chksm_error
uint8_t msg_idx
enum VNMsgStatus status