Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
ins_xsens700.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Christophe De Wagter
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 
28 #include "ins_xsens700.h"
29 #include "subsystems/ins.h"
30 
31 #include "generated/airframe.h"
32 
33 #include "mcu_periph/sys_time.h"
35 #include "pprzlink/messages.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 "subsystems/gps.h"
42 #include "subsystems/abi.h"
45 #include "subsystems/navigation/common_nav.h" /* needed for nav_utm_zone0 */
46 #endif
47 
51 #ifndef INS_XSENS700_GPS_ID
52 #define INS_XSENS700_GPS_ID GPS_MULTI_ID
53 #endif
54 PRINT_CONFIG_VAR(INS_XSENS700_GPS_ID)
56 
59 
60 static void handle_ins_msg(void);
61 static void update_state_interface(void);
62 static void gps_cb(uint8_t sender_id __attribute__((unused)),
63  uint32_t stamp __attribute__((unused)),
64  struct GpsState *gps_s);
65 
67 {
68  xsens700_init();
69 
72 
73  struct UtmCoor_f utm0 = { nav_utm_north0, nav_utm_east0, 0., nav_utm_zone0 };
75  stateSetPositionUtm_f(&utm0);
76 
77  AbiBindMsgGPS(INS_XSENS700_GPS_ID, &gps_ev, gps_cb);
78 }
79 
81 {
87  }
88 }
89 
90 static void gps_cb(uint8_t sender_id __attribute__((unused)),
91  uint32_t stamp __attribute__((unused)),
92  struct GpsState *gps_s)
93 {
94  struct UtmCoor_f utm = utm_float_from_gps(gps_s, nav_utm_zone0);
95 
96  // set position
98 
99  struct NedCoor_f ned_vel = {
100  gps_s->ned_vel.x / 100.,
101  gps_s->ned_vel.y / 100.,
102  gps_s->ned_vel.z / 100.
103  };
104  // set velocity
105  stateSetSpeedNed_f(&ned_vel);
106 }
107 
108 
109 #if USE_GPS_XSENS
110 void gps_xsens700_init(void)
111 {
112  xsens700.gps.nb_channels = 0;
113 }
114 
115 static void gps_xsens700_publish(void)
116 {
117  // publish gps data
118  uint32_t now_ts = get_sys_time_usec();
119  xsens700.gps.last_msg_ticks = sys_time.nb_sec_rem;
120  xsens700.gps.last_msg_time = sys_time.nb_sec;
121  if (xsens700.gps.fix == GPS_FIX_3D) {
122  xsens700.gps.last_3dfix_ticks = sys_time.nb_sec_rem;
123  xsens700.gps.last_3dfix_time = sys_time.nb_sec;
124  }
125  AbiSendMsgGPS(GPS_XSENS_ID, now_ts, &xsens700.gps);
126 }
127 #endif
128 
129 
130 static void update_state_interface(void)
131 {
132  // Send to Estimator (Control)
133 #ifdef XSENS_BACKWARDS
134  struct FloatEulers att = {
137  -xsens700.euler.psi + RadOfDeg(180)
138  };
139  struct FloatEulerstRates rates = {
140  xsens700.gyro.p,
141  -xsens700.gyro.q,
142  -xsens700.gyro.r
143  };
144 #else
145  struct FloatEulers att = {
149  };
150  struct FloatRates rates = {
151  -xsens700.gyro.p,
152  xsens700.gyro.q,
153  -xsens700.gyro.r
154  };
155 #endif
157  stateSetBodyRates_f(&rates);
158 }
159 
160 
161 void handle_ins_msg(void)
162 {
163 
165 
166  if (xsens700.new_attitude) {
167 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
168  new_ins_attitude = true;
169 #endif
170  xsens700.new_attitude = false;
171  }
172 
173 #if USE_GPS_XSENS
174  if (xsens700.gps_available) {
175  // Horizontal speed
176  float fspeed = FLOAT_VECT2_NORM(xsens700.vel);
177  if (xsens700.gps.fix != GPS_FIX_3D) {
178  fspeed = 0;
179  }
180  xsens700.gps.gspeed = fspeed * 100.;
181  xsens700.gps.speed_3d = float_vect3_norm(&xsens700.vel) * 100;
182 
183  float fcourse = atan2f(xsens700.vel.y, xsens700.vel.x);
184  xsens700.gps.course = fcourse * 1e7;
185  SetBit(xsens700.gps.valid_fields, GPS_VALID_COURSE_BIT);
186 
187  gps_xsens700_publish();
188  xsens700.gps_available = false;
189  }
190 #endif // USE_GPS_XSENS
191 }
ins.h
NedCoor_f
vector in North East Down coordinates Units: meters
Definition: pprz_geodetic_float.h:63
Xsens::vel
struct FloatVect3 vel
NED velocity in m/s.
Definition: xsens.h:61
GPS_VALID_COURSE_BIT
#define GPS_VALID_COURSE_BIT
Definition: gps.h:54
xsens_parser_event
void xsens_parser_event(struct XsensParser *xsensparser)
Definition: xsens_parser.c:35
stateSetSpeedNed_f
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition: state.h:809
ins_xsens700_event
void ins_xsens700_event(void)
Definition: ins_xsens700.c:80
INS_PITCH_NEUTRAL_DEFAULT
#define INS_PITCH_NEUTRAL_DEFAULT
Definition: ahrs_sim.c:46
GPS_XSENS_ID
#define GPS_XSENS_ID
Definition: abi_sender_ids.h:236
abi.h
NedCoor_i::y
int32_t y
East.
Definition: pprz_geodetic_int.h:70
nav_utm_east0
int32_t nav_utm_east0
Definition: common_nav.c:42
Xsens::new_attitude
volatile bool new_attitude
Definition: xsens.h:67
Xsens::euler
struct FloatEulers euler
Definition: xsens.h:64
INS_ROLL_NEUTRAL_DEFAULT
#define INS_ROLL_NEUTRAL_DEFAULT
Definition: ahrs_sim.c:43
gps_ev
static abi_event gps_ev
Definition: ins_xsens700.c:55
GpsState
data structure for GPS information
Definition: gps.h:87
abi_struct
Event structure to store callbacks in a linked list.
Definition: abi_common.h:65
uint32_t
unsigned long uint32_t
Definition: types.h:18
common_nav.h
ins_roll_neutral
float ins_roll_neutral
Definition: ins_xsens700.c:58
stateSetPositionUtm_f
static void stateSetPositionUtm_f(struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
Definition: state.h:582
nav_utm_north0
int32_t nav_utm_north0
Definition: common_nav.c:43
GpsState::ned_vel
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:96
XsensParser::msg_received
volatile uint8_t msg_received
Definition: xsens_parser.h:47
FloatEulers::theta
float theta
in radians
Definition: pprz_algebra_float.h:86
NedCoor_i::z
int32_t z
Down.
Definition: pprz_geodetic_int.h:71
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
stateSetLocalUtmOrigin_f
static void stateSetLocalUtmOrigin_f(struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
Definition: state.h:477
pprz_geodetic_float.h
Paparazzi floating point math for geodetic calculations.
float_vect3_norm
static float float_vect3_norm(struct FloatVect3 *v)
Definition: pprz_algebra_float.h:171
gps.h
Device independent GPS code (interface)
FloatEulers::phi
float phi
in radians
Definition: pprz_algebra_float.h:85
ins_pitch_neutral
float ins_pitch_neutral
Definition: ins_xsens700.c:57
FLOAT_VECT2_NORM
#define FLOAT_VECT2_NORM(_v)
Definition: pprz_algebra_float.h:132
stateSetBodyRates_f
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Definition: state.h:1181
xsens700_init
void xsens700_init(void)
Definition: xsens700.c:53
sys_time.h
Architecture independent timing functions.
uint8_t
unsigned char uint8_t
Definition: types.h:14
handle_ins_msg
static void handle_ins_msg(void)
Definition: ins_xsens700.c:161
FloatRates::r
float r
in rad/s
Definition: pprz_algebra_float.h:96
Xsens::parser
struct XsensParser parser
Definition: xsens.h:66
parse_xsens700_msg
void parse_xsens700_msg(void)
Definition: xsens700.c:141
FloatVect3::y
float y
Definition: pprz_algebra_float.h:56
FloatRates::q
float q
in rad/s
Definition: pprz_algebra_float.h:95
utm_float_from_gps
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:390
Xsens::gyro
struct FloatRates gyro
Definition: xsens.h:56
xsens700
struct Xsens xsens700
Definition: xsens700.c:49
FloatVect3::x
float x
Definition: pprz_algebra_float.h:55
sys_time
Definition: sys_time.h:71
UtmCoor_f
position in UTM coordinates Units: meters
Definition: pprz_geodetic_float.h:81
sys_time::nb_sec_rem
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:73
nav_utm_zone0
uint8_t nav_utm_zone0
Definition: common_nav.c:44
stateSetNedToBodyEulers_f
static void stateSetNedToBodyEulers_f(struct FloatEulers *ned_to_body_eulers)
Set vehicle body attitude from euler angles (float).
Definition: state.h:1105
NedCoor_i::x
int32_t x
North.
Definition: pprz_geodetic_int.h:69
ins_xsens700.h
gps_cb
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
Definition: ins_xsens700.c:90
FloatEulers
euler angles
Definition: pprz_algebra_float.h:84
INS_XSENS700_GPS_ID
#define INS_XSENS700_GPS_ID
ABI binding for gps data.
Definition: ins_xsens700.c:52
FloatEulers::psi
float psi
in radians
Definition: pprz_algebra_float.h:87
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
ins_xsens700_init
void ins_xsens700_init(void)
Definition: ins_xsens700.c:66
new_ins_attitude
volatile uint8_t new_ins_attitude
update_state_interface
static void update_state_interface(void)
Definition: ins_xsens700.c:130
GPS_FIX_3D
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:39
FloatRates::p
float p
in rad/s
Definition: pprz_algebra_float.h:94
pprz_geodetic_wgs84.h
WGS-84 Geoid Heights.
FloatRates
angular rates
Definition: pprz_algebra_float.h:93