Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ins_xsens.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2003 Pascal Brisset, Antoine Drouin
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, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
27#include "ins_xsens.h"
28#include "modules/ins/ins.h"
29
30#include "generated/airframe.h"
31#include "generated/modules.h"
32
33#include "mcu_periph/sys_time.h"
34#include "modules/core/abi.h"
35#include "state.h"
36
37#if USE_GPS_XSENS
38#if !USE_GPS
39#error "USE_GPS needs to be 1 to use the Xsens GPS!"
40#endif
41#include "modules/gps/gps.h"
43#include "modules/nav/common_nav.h" /* needed for nav_utm_zone0 */
44#endif
45
49#ifndef INS_XSENS_GPS_ID
50#define INS_XSENS_GPS_ID GPS_MULTI_ID
51#endif
54
57
58static void handle_ins_msg(void);
62 struct GpsState *gps_s);
63
77
87
88static void gps_cb(uint8_t sender_id __attribute__((unused)),
90 struct GpsState *gps_s)
91{
93 utm.alt = gps_s->hmsl / 1000.;
94
95 // set position
97
98 struct NedCoor_f ned_vel = ned_vel_float_from_gps(gps_s);
99 // set velocity
101}
102
103#if USE_GPS_XSENS
104void gps_xsens_init(void)
105{
106 xsens.gps.nb_channels = 0;
107}
108
109static void gps_xsens_publish(void)
110{
111 // publish gps data
113 xsens.gps.last_msg_ticks = sys_time.nb_sec_rem;
114 xsens.gps.last_msg_time = sys_time.nb_sec;
115 if (xsens.gps.fix == GPS_FIX_3D) {
116 xsens.gps.last_3dfix_ticks = sys_time.nb_sec_rem;
117 xsens.gps.last_3dfix_time = sys_time.nb_sec;
118 }
120}
121#endif
122
123
124static void update_state_interface(void)
125{
126 // Send to Estimator (Control)
127#ifdef XSENS_BACKWARDS
128 struct FloatEulers att = {
131 xsens.euler.psi + RadOfDeg(180)
132 };
133 struct FloatEulerstRates rates = {
134 -xsens.gyro.p,
135 -xsens.gyro.q,
136 xsens.gyro.r
137 };
138#else
139 struct FloatEulers att = {
143 };
144 struct FloatRates rates = xsens.gyro;
145#endif
148}
149
150
151static void handle_ins_msg(void)
152{
153
155
156 if (xsens.new_attitude) {
157#ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
158 new_ins_attitude = true;
159#endif
160 xsens.new_attitude = false;
161 }
162
163#if USE_GPS_XSENS
164 if (xsens.gps_available) {
165 // Horizontal speed
167 if (xsens.gps.fix != GPS_FIX_3D) {
168 fspeed = 0;
169 }
170 xsens.gps.gspeed = fspeed * 100.;
171 xsens.gps.speed_3d = float_vect3_norm(&xsens.vel) * 100;
172
173 float fcourse = atan2f(xsens.vel.y, xsens.vel.x);
174 xsens.gps.course = fcourse * 1e7;
175 SetBit(xsens.gps.valid_fields, GPS_VALID_COURSE_BIT);
176
178 xsens.gps_available = false;
179 }
180#endif // USE_GPS_XSENS
181}
182
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:68
#define GPS_XSENS_ID
#define INS_PITCH_NEUTRAL_DEFAULT
Definition ahrs_sim.c:46
#define INS_ROLL_NEUTRAL_DEFAULT
Definition ahrs_sim.c:43
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
int32_t nav_utm_east0
Definition common_nav.c:48
uint8_t nav_utm_zone0
Definition common_nav.c:50
int32_t nav_utm_north0
Definition common_nav.c:49
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
Definition gps.c:603
struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (float) Converted on the fly if not available.
Definition gps.c:570
Device independent GPS code (interface)
#define GPS_FIX_3D
3D GPS fix
Definition gps.h:44
#define GPS_VALID_COURSE_BIT
Definition gps.h:54
data structure for GPS information
Definition gps.h:90
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
static float float_vect3_norm(struct FloatVect3 *v)
#define FLOAT_VECT2_NORM(_v)
euler angles
angular rates
static void stateSetNedToBodyEulers_f(uint16_t id, struct FloatEulers *ned_to_body_eulers)
Set vehicle body attitude from euler angles (float).
Definition state.h:1267
static void stateSetPositionUtm_f(uint16_t id, struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
Definition state.h:698
static void stateSetLocalUtmOrigin_f(uint16_t id, struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
Definition state.h:541
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
Integrated Navigation System interface.
volatile uint8_t new_ins_attitude
static void handle_ins_msg(void)
Definition ins_xsens.c:151
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
Definition ins_xsens.c:88
void ins_xsens_init(void)
Definition ins_xsens.c:64
float ins_roll_neutral
Definition ins_xsens.c:56
static void update_state_interface(void)
Definition ins_xsens.c:124
void ins_xsens_event(void)
Definition ins_xsens.c:78
float ins_pitch_neutral
Definition ins_xsens.c:55
#define INS_XSENS_GPS_ID
ABI binding for gps data.
Definition ins_xsens.c:50
static abi_event gps_ev
Definition ins_xsens.c:53
Xsens as a full INS solution.
uint16_t foo
Definition main_demo5.c:58
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Paparazzi floating point math for geodetic calculations.
vector in North East Down coordinates Units: meters
position in UTM coordinates Units: meters
API to get/set the generic vehicle states.
#define FALSE
Definition std.h:5
Architecture independent timing functions.
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
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
struct XsensParser parser
Definition xsens.h:66
struct FloatEulers euler
Definition xsens.h:64
struct FloatVect3 vel
NED velocity in m/s.
Definition xsens.h:61
struct FloatRates gyro
Definition xsens.h:56
volatile bool new_attitude
Definition xsens.h:67
void xsens_init(void)
Definition xsens.c:113
void parse_xsens_msg(void)
Definition xsens.c:184
struct Xsens xsens
Definition xsens.c:109
void xsens_parser_event(struct XsensParser *xsensparser)
volatile uint8_t msg_received