mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-29 19:17:28 +08:00
[ins] refactor xsens700
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
ap.CFLAGS += -DUSE_IMU
|
||||
ap.CFLAGS += -DIMU_TYPE_H=\"modules/ins/imu_xsens.h\"
|
||||
ap.srcs += $(SRC_MODULES)/ins/xsens.c
|
||||
ap.srcs += $(SRC_MODULES)/ins/xsens_common.c
|
||||
ap.srcs += $(SRC_MODULES)/ins/imu_xsens.c
|
||||
ap.srcs += $(SRC_SUBSYSTEMS)/imu.c
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ ap.CFLAGS += -DXSENS_LINK=uart$(XSENS_UART_NR)
|
||||
ap.CFLAGS += -DUART$(XSENS_UART_NR)_BAUD=$(XSENS_UART_BAUD)
|
||||
ap.CFLAGS += -DXSENS_OUTPUT_MODE=0x1836
|
||||
ap.srcs += $(SRC_MODULES)/ins/xsens.c
|
||||
ap.srcs += $(SRC_MODULES)/ins/xsens_common.c
|
||||
ap.srcs += $(SRC_SUBSYSTEMS)/ins.c
|
||||
ap.srcs += $(SRC_MODULES)/ins/ins_xsens.c
|
||||
ap.CFLAGS += -DAHRS_TRIGGERED_ATTITUDE_LOOP
|
||||
|
||||
@@ -11,19 +11,19 @@
|
||||
#########################################
|
||||
## ATTITUDE
|
||||
|
||||
ap.CFLAGS += -DUSE_INS_MODULE
|
||||
|
||||
# AHRS Results
|
||||
ap.CFLAGS += -DINS_TYPE_H=\"modules/ins/ins_xsens.h\"
|
||||
ap.CFLAGS += -DINS_TYPE_H=\"modules/ins/ins_xsens700.h\"
|
||||
|
||||
ifndef XSENS_UART_BAUD
|
||||
XSENS_UART_BAUD = B115200
|
||||
endif
|
||||
|
||||
ap.CFLAGS += -DUSE_UART$(XSENS_UART_NR)
|
||||
ap.CFLAGS += -DINS_LINK=uart$(XSENS_UART_NR)
|
||||
ap.CFLAGS += -DXSENS_LINK=uart$(XSENS_UART_NR)
|
||||
ap.CFLAGS += -DUART$(XSENS_UART_NR)_BAUD=$(XSENS_UART_BAUD)
|
||||
ap.CFLAGS += -DXSENS_OUTPUT_MODE=0x1836
|
||||
ap.srcs += $(SRC_MODULES)/ins/xsens700.c
|
||||
ap.srcs += $(SRC_MODULES)/ins/xsens_common.c
|
||||
ap.srcs += $(SRC_SUBSYSTEMS)/ins.c
|
||||
ap.srcs += $(SRC_MODULES)/ins/ins_xsens700.c
|
||||
ap.CFLAGS += -DAHRS_TRIGGERED_ATTITUDE_LOOP
|
||||
@@ -35,7 +35,7 @@ ap.CFLAGS += -DAHRS_TRIGGERED_ATTITUDE_LOOP
|
||||
ap.CFLAGS += -DUSE_GPS_XSENS
|
||||
ap.CFLAGS += -DGPS_NB_CHANNELS=50
|
||||
ap.CFLAGS += -DUSE_GPS
|
||||
ap.CFLAGS += -DGPS_TYPE_H=\"modules/ins/ins_xsens.h\"
|
||||
ap.CFLAGS += -DGPS_TYPE_H=\"modules/ins/ins_xsens700.h\"
|
||||
ap.srcs += $(SRC_SUBSYSTEMS)/gps.c
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "imu_xsens.h"
|
||||
#include "xsens.h"
|
||||
#include "xsens_common.h"
|
||||
|
||||
#include "generated/airframe.h"
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "ins_xsens.h"
|
||||
#include "xsens_common.h"
|
||||
#include "subsystems/ins.h"
|
||||
|
||||
#include "generated/airframe.h"
|
||||
@@ -110,7 +111,7 @@ static void gps_cb(uint8_t sender_id __attribute__((unused)),
|
||||
#if USE_GPS_XSENS
|
||||
void gps_xsens_init(void)
|
||||
{
|
||||
gps.nb_channels = 0;
|
||||
xsens.gps.nb_channels = 0;
|
||||
}
|
||||
|
||||
static void gps_xsens_publish(void)
|
||||
@@ -123,8 +124,6 @@ static void gps_xsens_publish(void)
|
||||
xsens.gps.last_3dfix_ticks = sys_time.nb_sec_rem;
|
||||
xsens.gps.last_3dfix_time = sys_time.nb_sec;
|
||||
}
|
||||
// still update the global gps struct for now
|
||||
gps = xsens.gps;
|
||||
AbiSendMsgGPS(GPS_XSENS_ID, now_ts, &xsens.gps);
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ENAC
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file modules/ins/ins_xsens700.h
|
||||
* Xsens700 as a full INS solution
|
||||
*/
|
||||
|
||||
#ifndef INS_XSENS700_H
|
||||
#define INS_XSENS700_H
|
||||
|
||||
#include "std.h"
|
||||
|
||||
#include "xsens700.h"
|
||||
|
||||
#ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
|
||||
extern volatile uint8_t new_ins_attitude;
|
||||
#endif
|
||||
|
||||
extern float ins_pitch_neutral;
|
||||
extern float ins_roll_neutral;
|
||||
|
||||
#define DefaultInsImpl ins_xsens700
|
||||
#define InsPeriodic xsens700_periodic
|
||||
#define InsEvent ins_xsens700_event
|
||||
extern void ins_xsens700_init(void);
|
||||
extern void ins_xsens700_register(void);
|
||||
extern void ins_xsens700_event(void);
|
||||
|
||||
#if USE_GPS_XSENS
|
||||
#ifndef PRIMARY_GPS
|
||||
#define PRIMARY_GPS gps_xsens700
|
||||
#endif
|
||||
extern void gps_xsens700_init(void);
|
||||
extern void gps_xsens700_register(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,9 @@
|
||||
*/
|
||||
|
||||
#include "xsens.h"
|
||||
#include "xsens_common.h"
|
||||
|
||||
#include "generated/airframe.h"
|
||||
|
||||
#if USE_GPS_XSENS
|
||||
#include "math/pprz_geodetic_wgs84.h"
|
||||
@@ -34,34 +37,6 @@
|
||||
#include "pprzlink/messages.h"
|
||||
#include "subsystems/datalink/downlink.h"
|
||||
|
||||
volatile uint8_t xsens_msg_received;
|
||||
|
||||
#define XsensLinkDevice (&((XSENS_LINK).device))
|
||||
|
||||
#define XsensInitCheksum() { send_ck = 0; }
|
||||
#define XsensUpdateChecksum(c) { send_ck += c; }
|
||||
|
||||
#define XsensUartSend1(c) XsensLinkDevice->put_byte(XsensLinkDevice->periph, c)
|
||||
#define XsensSend1(c) { uint8_t i8=c; XsensUartSend1(i8); XsensUpdateChecksum(i8); }
|
||||
#define XsensSend1ByAddr(x) { XsensSend1(*x); }
|
||||
#define XsensSend2ByAddr(x) { XsensSend1(*(x+1)); XsensSend1(*x); }
|
||||
#define XsensSend4ByAddr(x) { XsensSend1(*(x+3)); XsensSend1(*(x+2)); XsensSend1(*(x+1)); XsensSend1(*x); }
|
||||
|
||||
#define XsensHeader(msg_id, len) { \
|
||||
XsensUartSend1(XSENS_START); \
|
||||
XsensInitCheksum(); \
|
||||
XsensSend1(XSENS_BID); \
|
||||
XsensSend1(msg_id); \
|
||||
XsensSend1(len); \
|
||||
}
|
||||
#define XsensTrailer() { uint8_t i8=0x100-send_ck; XsensUartSend1(i8); }
|
||||
|
||||
/** Includes macros generated from xsens_MTi-G.xml */
|
||||
#include "xsens_protocol.h"
|
||||
|
||||
|
||||
#define XSENS_MAX_PAYLOAD 254
|
||||
uint8_t xsens_msg_buf[XSENS_MAX_PAYLOAD];
|
||||
|
||||
/* output mode : calibrated, orientation, position, velocity, status
|
||||
* -----------
|
||||
@@ -117,15 +92,6 @@ uint8_t xsens_msg_buf[XSENS_MAX_PAYLOAD];
|
||||
#define XSENS_OUTPUT_SETTINGS 0x80000C05
|
||||
#endif
|
||||
|
||||
#define UNINIT 0
|
||||
#define GOT_START 1
|
||||
#define GOT_BID 2
|
||||
#define GOT_MID 3
|
||||
#define GOT_LEN 4
|
||||
#define GOT_DATA 5
|
||||
#define GOT_CHECKSUM 6
|
||||
|
||||
|
||||
uint8_t xsens_errorcode;
|
||||
uint8_t xsens_msg_status;
|
||||
uint16_t xsens_time_stamp;
|
||||
@@ -138,13 +104,6 @@ float xsens_gps_arm_x = 0;
|
||||
float xsens_gps_arm_y = 0;
|
||||
float xsens_gps_arm_z = 0;
|
||||
|
||||
static uint8_t xsens_id;
|
||||
static uint8_t xsens_status;
|
||||
static uint8_t xsens_len;
|
||||
static uint8_t xsens_msg_idx;
|
||||
static uint8_t ck;
|
||||
uint8_t send_ck;
|
||||
|
||||
volatile int xsens_configured = 0;
|
||||
|
||||
struct Xsens xsens;
|
||||
@@ -162,16 +121,6 @@ void xsens_init(void)
|
||||
xsens_output_settings = XSENS_OUTPUT_SETTINGS;
|
||||
}
|
||||
|
||||
void xsens_event(void)
|
||||
{
|
||||
struct link_device *dev = &((XSENS_LINK).device);
|
||||
if (dev->char_available(dev->periph)) {
|
||||
while (dev->char_available(dev->periph) && !xsens_msg_received) {
|
||||
parse_xsens_buffer(dev->get_byte(dev->periph));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void xsens_periodic(void)
|
||||
{
|
||||
if (xsens_configured > 0) {
|
||||
@@ -422,57 +371,3 @@ void parse_xsens_msg(void)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void parse_xsens_buffer(uint8_t c)
|
||||
{
|
||||
ck += c;
|
||||
switch (xsens_status) {
|
||||
case UNINIT:
|
||||
if (c != XSENS_START) {
|
||||
goto error;
|
||||
}
|
||||
xsens_status++;
|
||||
ck = 0;
|
||||
break;
|
||||
case GOT_START:
|
||||
if (c != XSENS_BID) {
|
||||
goto error;
|
||||
}
|
||||
xsens_status++;
|
||||
break;
|
||||
case GOT_BID:
|
||||
xsens_id = c;
|
||||
xsens_status++;
|
||||
break;
|
||||
case GOT_MID:
|
||||
xsens_len = c;
|
||||
if (xsens_len > XSENS_MAX_PAYLOAD) {
|
||||
goto error;
|
||||
}
|
||||
xsens_msg_idx = 0;
|
||||
xsens_status++;
|
||||
break;
|
||||
case GOT_LEN:
|
||||
xsens_msg_buf[xsens_msg_idx] = c;
|
||||
xsens_msg_idx++;
|
||||
if (xsens_msg_idx >= xsens_len) {
|
||||
xsens_status++;
|
||||
}
|
||||
break;
|
||||
case GOT_DATA:
|
||||
if (ck != 0) {
|
||||
goto error;
|
||||
}
|
||||
xsens_msg_received = TRUE;
|
||||
goto restart;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
restart:
|
||||
xsens_status = UNINIT;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ extern struct Xsens xsens;
|
||||
|
||||
extern void xsens_init(void);
|
||||
extern void xsens_periodic(void);
|
||||
extern void xsens_event(void);
|
||||
extern void parse_xsens_msg(void);
|
||||
|
||||
#endif /* XSENS_H */
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Christophe De Wagter
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file modules/ins/xsens700.c
|
||||
* Parser for the Xsens700 protocol.
|
||||
*/
|
||||
|
||||
#include "xsens700.h"
|
||||
#include "xsens_common.h"
|
||||
|
||||
#include "generated/airframe.h"
|
||||
|
||||
#if USE_GPS_XSENS
|
||||
#include "math/pprz_geodetic_wgs84.h"
|
||||
#endif
|
||||
|
||||
// FIXME Debugging Only
|
||||
#include "mcu_periph/uart.h"
|
||||
#include "pprzlink/messages.h"
|
||||
#include "subsystems/datalink/downlink.h"
|
||||
|
||||
|
||||
uint8_t xsens_errorcode;
|
||||
uint32_t xsens_msg_statusword;
|
||||
uint16_t xsens_time_stamp;
|
||||
uint16_t xsens_output_mode;
|
||||
uint32_t xsens_output_settings;
|
||||
|
||||
float xsens_gps_arm_x = 0;
|
||||
float xsens_gps_arm_y = 0;
|
||||
float xsens_gps_arm_z = 0;
|
||||
|
||||
struct Xsens xsens700;
|
||||
|
||||
volatile int xsens_configured = 0;
|
||||
|
||||
void xsens700_init(void)
|
||||
{
|
||||
xsens_status = UNINIT;
|
||||
xsens_configured = 30;
|
||||
|
||||
xsens_msg_statusword = 0;
|
||||
xsens_time_stamp = 0;
|
||||
}
|
||||
|
||||
static void xsens_ask_message_rate(uint8_t c1, uint8_t c2, uint8_t freq)
|
||||
{
|
||||
uint8_t foo = 0;
|
||||
XsensSend1ByAddr(&c1);
|
||||
XsensSend1ByAddr(&c2);
|
||||
XsensSend1ByAddr(&foo);
|
||||
XsensSend1ByAddr(&freq);
|
||||
}
|
||||
|
||||
void xsens700_periodic(void)
|
||||
{
|
||||
if (xsens_configured > 0) {
|
||||
switch (xsens_configured) {
|
||||
case 25:
|
||||
/* send mode and settings to MT */
|
||||
XSENS_GoToConfig();
|
||||
//XSENS_SetOutputMode(xsens_output_mode);
|
||||
//XSENS_SetOutputSettings(xsens_output_settings);
|
||||
break;
|
||||
case 18:
|
||||
// Give pulses on SyncOut
|
||||
//XSENS_SetSyncOutSettings(0,0x0002);
|
||||
break;
|
||||
case 17:
|
||||
|
||||
XsensHeader(XSENS_SetOutputConfiguration_ID, 44);
|
||||
xsens_ask_message_rate(0x10, 0x10, 4); // UTC
|
||||
xsens_ask_message_rate(0x20, 0x30, 100); // Attitude Euler
|
||||
xsens_ask_message_rate(0x40, 0x10, 100); // Delta-V
|
||||
xsens_ask_message_rate(0x80, 0x20, 100); // Rate of turn
|
||||
xsens_ask_message_rate(0xE0, 0x20, 50); // Status
|
||||
xsens_ask_message_rate(0x30, 0x10, 50); // Baro Pressure
|
||||
xsens_ask_message_rate(0x88, 0x40, 1); // NavSol
|
||||
xsens_ask_message_rate(0x88, 0xA0, 1); // SV Info
|
||||
xsens_ask_message_rate(0x50, 0x20, 50); // GPS Altitude Ellipsiod
|
||||
xsens_ask_message_rate(0x50, 0x40, 50); // GPS Position
|
||||
xsens_ask_message_rate(0xD0, 0x10, 50); // GPS Speed
|
||||
XsensTrailer();
|
||||
break;
|
||||
case 2:
|
||||
//XSENS_ReqLeverArmGps();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
//XSENS_ReqMagneticDeclination();
|
||||
break;
|
||||
|
||||
case 13:
|
||||
//#ifdef AHRS_H_X
|
||||
//#pragma message "Sending XSens Magnetic Declination."
|
||||
//xsens_declination = atan2(AHRS_H_Y, AHRS_H_X);
|
||||
//XSENS_SetMagneticDeclination(xsens_declination);
|
||||
//#endif
|
||||
break;
|
||||
case 12:
|
||||
#ifdef GPS_IMU_LEVER_ARM_X
|
||||
#pragma message "Sending XSens GPS Arm."
|
||||
XSENS_SetLeverArmGps(GPS_IMU_LEVER_ARM_X, GPS_IMU_LEVER_ARM_Y, GPS_IMU_LEVER_ARM_Z);
|
||||
#endif
|
||||
break;
|
||||
case 10: {
|
||||
uint8_t baud = 1;
|
||||
XSENS_SetBaudrate(baud);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
XSENS_GoToMeasurment();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
xsens_configured--;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void parse_xsens700_msg(void)
|
||||
{
|
||||
uint8_t offset = 0;
|
||||
if (xsens_id == XSENS_ReqLeverArmGpsAck_ID) {
|
||||
xsens_gps_arm_x = XSENS_ReqLeverArmGpsAck_x(xsens_msg_buf);
|
||||
xsens_gps_arm_y = XSENS_ReqLeverArmGpsAck_y(xsens_msg_buf);
|
||||
xsens_gps_arm_z = XSENS_ReqLeverArmGpsAck_z(xsens_msg_buf);
|
||||
} else if (xsens_id == XSENS_Error_ID) {
|
||||
xsens_errorcode = XSENS_Error_errorcode(xsens_msg_buf);
|
||||
} else if (xsens_id == XSENS_MTData2_ID) {
|
||||
for (offset = 0; offset < xsens_len;) {
|
||||
uint8_t code1 = xsens_msg_buf[offset];
|
||||
uint8_t code2 = xsens_msg_buf[offset + 1];
|
||||
int subpacklen = (int)xsens_msg_buf[offset + 2];
|
||||
offset += 3;
|
||||
|
||||
if (code1 == 0x10) {
|
||||
if (code2 == 0x10) {
|
||||
// UTC
|
||||
} else if (code2 == 0x20) {
|
||||
// Packet Counter
|
||||
}
|
||||
if (code2 == 0x30) {
|
||||
// ITOW
|
||||
}
|
||||
} else if (code1 == 0x20) {
|
||||
if (code2 == 0x30) {
|
||||
// Attitude Euler
|
||||
xsens700.euler.phi = XSENS_DATA_Euler_roll(xsens_msg_buf, offset) * M_PI / 180;
|
||||
xsens700.euler.theta = XSENS_DATA_Euler_pitch(xsens_msg_buf, offset) * M_PI / 180;
|
||||
xsens700.euler.psi = XSENS_DATA_Euler_yaw(xsens_msg_buf, offset) * M_PI / 180;
|
||||
|
||||
xsens700.new_attitude = TRUE;
|
||||
}
|
||||
} else if (code1 == 0x40) {
|
||||
if (code2 == 0x10) {
|
||||
// Delta-V
|
||||
xsens700.accel.x = XSENS_DATA_Acceleration_x(xsens_msg_buf, offset) * 100.0f;
|
||||
xsens700.accel.y = XSENS_DATA_Acceleration_y(xsens_msg_buf, offset) * 100.0f;
|
||||
xsens700.accel.z = XSENS_DATA_Acceleration_z(xsens_msg_buf, offset) * 100.0f;
|
||||
}
|
||||
} else if (code1 == 0x80) {
|
||||
if (code2 == 0x20) {
|
||||
// Rate Of Turn
|
||||
xsens700.gyro.p = XSENS_DATA_RateOfTurn_x(xsens_msg_buf, offset) * M_PI / 180;
|
||||
xsens700.gyro.q = XSENS_DATA_RateOfTurn_y(xsens_msg_buf, offset) * M_PI / 180;
|
||||
xsens700.gyro.r = XSENS_DATA_RateOfTurn_z(xsens_msg_buf, offset) * M_PI / 180;
|
||||
}
|
||||
} else if (code1 == 0x30) {
|
||||
if (code2 == 0x10) {
|
||||
// Baro Pressure
|
||||
}
|
||||
} else if (code1 == 0xE0) {
|
||||
if (code2 == 0x20) {
|
||||
// Status Word
|
||||
xsens_msg_statusword = XSENS_DATA_StatusWord_status(xsens_msg_buf, offset);
|
||||
//xsens700.gps.tow = xsens_msg_statusword;
|
||||
#if USE_GPS_XSENS
|
||||
if (bit_is_set(xsens_msg_statusword, 2) && bit_is_set(xsens_msg_statusword, 1)) {
|
||||
if (bit_is_set(xsens_msg_statusword, 23) && bit_is_set(xsens_msg_statusword, 24)) {
|
||||
xsens700.gps.fix = GPS_FIX_3D;
|
||||
} else {
|
||||
xsens700.gps.fix = GPS_FIX_2D;
|
||||
}
|
||||
} else { xsens700.gps.fix = GPS_FIX_NONE; }
|
||||
#endif
|
||||
}
|
||||
} else if (code1 == 0x88) {
|
||||
if (code2 == 0x40) {
|
||||
xsens700.gps.week = XSENS_DATA_GpsSol_week(xsens_msg_buf, offset);
|
||||
xsens700.gps.num_sv = XSENS_DATA_GpsSol_numSv(xsens_msg_buf, offset);
|
||||
xsens700.gps.pacc = XSENS_DATA_GpsSol_pAcc(xsens_msg_buf, offset);
|
||||
xsens700.gps.sacc = XSENS_DATA_GpsSol_sAcc(xsens_msg_buf, offset);
|
||||
xsens700.gps.pdop = XSENS_DATA_GpsSol_pDop(xsens_msg_buf, offset);
|
||||
} else if (code2 == 0xA0) {
|
||||
// SVINFO
|
||||
xsens700.gps.tow = XSENS_XDI_GpsSvInfo_iTOW(xsens_msg_buf + offset);
|
||||
|
||||
#if USE_GPS_XSENS
|
||||
xsens700.gps.nb_channels = XSENS_XDI_GpsSvInfo_nch(xsens_msg_buf + offset);
|
||||
|
||||
xsens700.gps.last_3dfix_ticks = sys_time.nb_sec_rem;
|
||||
xsens700.gps.last_3dfix_time = sys_time.nb_sec;
|
||||
|
||||
uint8_t i;
|
||||
// Do not write outside buffer
|
||||
for (i = 0; i < Min(xsens700.gps.nb_channels, GPS_NB_CHANNELS); i++) {
|
||||
uint8_t ch = XSENS_XDI_GpsSvInfo_chn(xsens_msg_buf + offset, i);
|
||||
if (ch > xsens700.gps.nb_channels) { continue; }
|
||||
xsens700.gps.svinfos[ch].svid = XSENS_XDI_GpsSvInfo_svid(xsens_msg_buf + offset, i);
|
||||
xsens700.gps.svinfos[ch].flags = XSENS_XDI_GpsSvInfo_bitmask(xsens_msg_buf + offset, i);
|
||||
xsens700.gps.svinfos[ch].qi = XSENS_XDI_GpsSvInfo_qi(xsens_msg_buf + offset, i);
|
||||
xsens700.gps.svinfos[ch].cno = XSENS_XDI_GpsSvInfo_cnr(xsens_msg_buf + offset, i);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else if (code1 == 0x50) {
|
||||
if (code2 == 0x10) {
|
||||
//xsens700.gps.hmsl = XSENS_DATA_Altitude_h(xsens_msg_buf,offset)* 1000.0f;
|
||||
} else if (code2 == 0x20) {
|
||||
// Altitude Elipsoid
|
||||
xsens700.gps.lla_pos.alt = XSENS_DATA_Altitude_h(xsens_msg_buf, offset) * 1000.0f;
|
||||
|
||||
// Compute geoid (MSL) height
|
||||
float geoid_h = wgs84_ellipsoid_to_geoid(xsens700.lla_f.lat, xsens700.lla_f.lon);
|
||||
xsens700.gps.hmsl = xsens700.gps.lla_pos.alt - (geoid_h * 1000.0f);
|
||||
SetBit(xsens700.gps.valid_fields, GPS_VALID_HMSL_BIT);
|
||||
|
||||
//xsens700.gps.tow = geoid_h * 1000.0f; //xsens700.gps.utm_pos.alt;
|
||||
} else if (code2 == 0x40) {
|
||||
// LatLong
|
||||
#ifdef GPS_LED
|
||||
LED_TOGGLE(GPS_LED);
|
||||
#endif
|
||||
xsens700.gps.last_3dfix_ticks = sys_time.nb_sec_rem;
|
||||
xsens700.gps.last_3dfix_time = sys_time.nb_sec;
|
||||
xsens700.gps.week = 0; // FIXME
|
||||
|
||||
xsens700.lla_f.lat = RadOfDeg(XSENS_DATA_LatLon_lat(xsens_msg_buf, offset));
|
||||
xsens700.lla_f.lon = RadOfDeg(XSENS_DATA_LatLon_lon(xsens_msg_buf, offset));
|
||||
}
|
||||
} else if (code1 == 0xD0) {
|
||||
if (code2 == 0x10) {
|
||||
// Velocity
|
||||
xsens700.vel.x = XSENS_DATA_VelocityXYZ_x(xsens_msg_buf, offset);
|
||||
xsens700.vel.y = XSENS_DATA_VelocityXYZ_y(xsens_msg_buf, offset);
|
||||
xsens700.vel.z = XSENS_DATA_VelocityXYZ_z(xsens_msg_buf, offset);
|
||||
xsens700.gps.ned_vel.x = xsens700.vel.x;
|
||||
xsens700.gps.ned_vel.y = xsens700.vel.y;
|
||||
xsens700.gps.ned_vel.z = xsens700.vel.x;
|
||||
SetBit(xsens700.gps.valid_fields, GPS_VALID_VEL_NED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
if (subpacklen < 0) {
|
||||
subpacklen = 0;
|
||||
}
|
||||
offset += subpacklen;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ENAC
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @file modules/ins/xsens_700.h
|
||||
* Parser for the Xsens protocol.
|
||||
*/
|
||||
|
||||
#ifndef XSENS700_H
|
||||
#define XSENS700_H
|
||||
|
||||
#include "std.h"
|
||||
#include "math/pprz_algebra_float.h"
|
||||
#include "math/pprz_geodetic_float.h"
|
||||
#include "math/pprz_geodetic_int.h"
|
||||
|
||||
#if USE_GPS_XSENS
|
||||
#include "subsystems/gps.h"
|
||||
#endif
|
||||
|
||||
struct XsensTime {
|
||||
int8_t hour;
|
||||
int8_t min;
|
||||
int8_t sec;
|
||||
int32_t nanosec;
|
||||
int16_t year;
|
||||
int8_t month;
|
||||
int8_t day;
|
||||
};
|
||||
|
||||
struct Xsens {
|
||||
struct XsensTime time;
|
||||
uint16_t time_stamp;
|
||||
|
||||
struct FloatRates gyro;
|
||||
struct FloatVect3 accel;
|
||||
struct FloatVect3 mag;
|
||||
|
||||
struct LlaCoor_f lla_f;
|
||||
struct FloatVect3 vel; ///< NED velocity in m/s
|
||||
|
||||
struct FloatQuat quat;
|
||||
struct FloatEulers euler;
|
||||
|
||||
volatile bool_t msg_received;
|
||||
volatile bool_t new_attitude;
|
||||
|
||||
bool_t gyro_available;
|
||||
bool_t accel_available;
|
||||
bool_t mag_available;
|
||||
|
||||
#if USE_GPS_XSENS
|
||||
struct GpsState gps;
|
||||
bool_t gps_available;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern struct Xsens xsens700;
|
||||
|
||||
extern void xsens700_init(void);
|
||||
extern void xsens700_periodic(void);
|
||||
extern void parse_xsens700_msg(void);
|
||||
|
||||
#endif /* XSENS700_H */
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2003 Pascal Brisset, Antoine Drouin
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/** @file modules/ins/xsens_common.c
|
||||
* Parser for the Xsens protocol.
|
||||
*/
|
||||
|
||||
#include "xsens_common.h"
|
||||
|
||||
#include "pprzlink/pprzlink_device.h"
|
||||
#include "mcu_periph/uart.h"
|
||||
|
||||
volatile uint8_t xsens_msg_received;
|
||||
|
||||
uint8_t xsens_id;
|
||||
uint8_t xsens_status;
|
||||
uint8_t xsens_len;
|
||||
uint8_t xsens_msg_idx;
|
||||
uint8_t ck;
|
||||
uint8_t send_ck;
|
||||
|
||||
uint8_t xsens_msg_buf[XSENS_MAX_PAYLOAD];
|
||||
|
||||
void parse_xsens_buffer(uint8_t c);
|
||||
|
||||
void xsens_event(void)
|
||||
{
|
||||
struct link_device *dev = &((XSENS_LINK).device);
|
||||
if (dev->char_available(dev->periph)) {
|
||||
while (dev->char_available(dev->periph) && !xsens_msg_received) {
|
||||
parse_xsens_buffer(dev->get_byte(dev->periph));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse_xsens_buffer(uint8_t c)
|
||||
{
|
||||
ck += c;
|
||||
switch (xsens_status) {
|
||||
case UNINIT:
|
||||
if (c != XSENS_START) {
|
||||
goto error;
|
||||
}
|
||||
xsens_status++;
|
||||
ck = 0;
|
||||
break;
|
||||
case GOT_START:
|
||||
if (c != XSENS_BID) {
|
||||
goto error;
|
||||
}
|
||||
xsens_status++;
|
||||
break;
|
||||
case GOT_BID:
|
||||
xsens_id = c;
|
||||
xsens_status++;
|
||||
break;
|
||||
case GOT_MID:
|
||||
xsens_len = c;
|
||||
if (xsens_len > XSENS_MAX_PAYLOAD) {
|
||||
goto error;
|
||||
}
|
||||
xsens_msg_idx = 0;
|
||||
xsens_status++;
|
||||
break;
|
||||
case GOT_LEN:
|
||||
xsens_msg_buf[xsens_msg_idx] = c;
|
||||
xsens_msg_idx++;
|
||||
if (xsens_msg_idx >= xsens_len) {
|
||||
xsens_status++;
|
||||
}
|
||||
break;
|
||||
case GOT_DATA:
|
||||
if (ck != 0) {
|
||||
goto error;
|
||||
}
|
||||
xsens_msg_received = TRUE;
|
||||
goto restart;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
restart:
|
||||
xsens_status = UNINIT;
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2003 Pascal Brisset, Antoine Drouin
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/** @file modules/ins/xsens_common.h
|
||||
* Parser for the Xsens protocol.
|
||||
*/
|
||||
|
||||
#ifndef XSENS_COMMON_H
|
||||
#define XSENS_COMMON_H
|
||||
|
||||
#include "std.h"
|
||||
|
||||
/** Includes macros generated from xsens_MTi-G.xml */
|
||||
#include "xsens_protocol.h"
|
||||
|
||||
extern uint8_t xsens_id;
|
||||
extern uint8_t xsens_status;
|
||||
extern uint8_t xsens_len;
|
||||
extern uint8_t xsens_msg_idx;
|
||||
extern uint8_t ck;
|
||||
extern uint8_t send_ck;
|
||||
|
||||
#define XsensLinkDevice (&((XSENS_LINK).device))
|
||||
|
||||
#define XsensInitCheksum() { send_ck = 0; }
|
||||
#define XsensUpdateChecksum(c) { send_ck += c; }
|
||||
|
||||
#define XsensUartSend1(c) XsensLinkDevice->put_byte(XsensLinkDevice->periph, c)
|
||||
#define XsensSend1(c) { uint8_t i8=c; XsensUartSend1(i8); XsensUpdateChecksum(i8); }
|
||||
#define XsensSend1ByAddr(x) { XsensSend1(*x); }
|
||||
#define XsensSend2ByAddr(x) { XsensSend1(*(x+1)); XsensSend1(*x); }
|
||||
#define XsensSend4ByAddr(x) { XsensSend1(*(x+3)); XsensSend1(*(x+2)); XsensSend1(*(x+1)); XsensSend1(*x); }
|
||||
|
||||
#define XsensHeader(msg_id, len) { \
|
||||
XsensUartSend1(XSENS_START); \
|
||||
XsensInitCheksum(); \
|
||||
XsensSend1(XSENS_BID); \
|
||||
XsensSend1(msg_id); \
|
||||
XsensSend1(len); \
|
||||
}
|
||||
#define XsensTrailer() { uint8_t i8=0x100-send_ck; XsensUartSend1(i8); }
|
||||
|
||||
|
||||
#define XSENS_MAX_PAYLOAD 254
|
||||
extern uint8_t xsens_msg_buf[XSENS_MAX_PAYLOAD];
|
||||
|
||||
#define UNINIT 0
|
||||
#define GOT_START 1
|
||||
#define GOT_BID 2
|
||||
#define GOT_MID 3
|
||||
#define GOT_LEN 4
|
||||
#define GOT_DATA 5
|
||||
#define GOT_CHECKSUM 6
|
||||
|
||||
extern void xsens_event(void);
|
||||
|
||||
#endif /* XSENS_COMMON_H */
|
||||
Reference in New Issue
Block a user