30#include "pprzlink/messages.h"
36#include "generated/flight_plan.h"
37#include "generated/airframe.h"
43#ifndef UWB_POSITIONING_USE_AS_LOCAL_POS
44#define UWB_POSITIONING_USE_AS_LOCAL_POS TRUE
48#ifndef UWB_POSITIONING_USE_AS_GPS
49#define UWB_POSITIONING_USE_AS_GPS FALSE
53#ifndef UWB_POSITIONING_USE_EKF
54#define UWB_POSITIONING_USE_EKF TRUE
63#ifndef UWB_POSITIONING_NB_ANCHORS
64#define UWB_POSITIONING_NB_ANCHORS 3
68#ifndef UWB_POSITIONING_RANGE_OFFSET
69#define UWB_POSITIONING_RANGE_OFFSET { 0.f, 0.f, 0.f }
73#ifndef UWB_POSITIONING_RANGE_SCALE
74#define UWB_POSITIONING_RANGE_SCALE { 1.f, 1.f, 1.f }
78#ifndef UWB_POSITIONING_TAG_ID
79#define UWB_POSITIONING_TAG_ID 0
83#ifndef UWB_POSITIONING_INITIAL_HEADING
84#define UWB_POSITIONING_INITIAL_HEADING 0.f
88#ifndef UWB_POSITIONING_TIMEOUT
89#define UWB_POSITIONING_TIMEOUT 500
93#ifndef UWB_POSITIONING_NOISE_X
94#define UWB_POSITIONING_NOISE_X 0.1f
97#ifndef UWB_POSITIONING_NOISE_Y
98#define UWB_POSITIONING_NOISE_Y 0.1f
101#ifndef UWB_POSITIONING_NOISE_Z
102#define UWB_POSITIONING_NOISE_Z 0.1f
105#ifndef UWB_POSITIONING_VEL_NOISE_X
106#define UWB_POSITIONING_VEL_NOISE_X 0.1f
109#ifndef UWB_POSITIONING_VEL_NOISE_Y
110#define UWB_POSITIONING_VEL_NOISE_Y 0.1f
113#ifndef UWB_POSITIONING_VEL_NOISE_Z
114#define UWB_POSITIONING_VEL_NOISE_Z 0.1f
117#if UWB_POSITIONING_USE_EKF
121#define UWB_POSITIONING_EKF_UNINIT 0
122#define UWB_POSITIONING_EKF_POS_INIT 1
123#define UWB_POSITIONING_EKF_RUNNING 2
125#ifndef UWB_POSITIONING_EKF_P0_POS
126#define UWB_POSITIONING_EKF_P0_POS 1.0f
129#ifndef UWB_POSITIONING_EKF_P0_SPEED
130#define UWB_POSITIONING_EKF_P0_SPEED 1.0f
133#ifndef UWB_POSITIONING_EKF_Q
134#define UWB_POSITIONING_EKF_Q 4.0f
137#ifndef UWB_POSITIONING_EKF_R_DIST
138#define UWB_POSITIONING_EKF_R_DIST 0.1f
141#ifndef UWB_POSITIONING_EKF_R_SPEED
142#define UWB_POSITIONING_EKF_R_SPEED 0.1f
150#ifndef UWB_POSITIONING_ANCHOR_SIM_WP
151#define UWB_POSITIONING_ANCHOR_SIM_WP { WP_ANCHOR_1, WP_ANCHOR_2, WP_ANCHOR_3 }
156#if UWB_POSITIONING_LOG
224#if UWB_POSITIONING_USE_AS_GPS
261#if defined(SECONDARY_GPS) && AHRS_USE_GPS_HEADING
267 uwb->gps_uwb.num_sv = 7;
283#if UWB_POSITIONING_USE_AS_LOCAL_POS
294 uwb->speed.x,
uwb->speed.y,
uwb->speed.z,
323 if (
uwb->ekf_running) {
327 uwb->ekf_running =
false;
332 if (
uwb->anchors[i].updated) {
334 uwb->anchors[i].pos);
335 uwb->anchors[i].updated =
false;
351 struct EnuCoor_f speed = { 0.f, 0.f, 0.f };
353 uwb->ekf_running =
true;
374#if UWB_POSITIONING_USE_AS_GPS
378#if UWB_POSITIONING_USE_AS_LOCAL_POS
383#if UWB_POSITIONING_LOG
411 uwb->updated =
false;
425#define UWB_POSITIONING_SITL_SYNC FALSE
429#if !UWB_POSITIONING_SITL_SYNC
436#if UWB_POSITIONING_SITL_SYNC
448 uwb->anchors[i].updated =
true;
452#if UWB_POSITIONING_SITL_SYNC
537#if UWB_POSITIONING_USE_AS_GPS
541#if UWB_POSITIONING_LOG
545 "d1 t1 d2 t2 d3 t3 x y z gps_x gps_y gps_z vx vy vz omega\n");
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Event structure to store callbacks in a linked list.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
#define WaypointAlt(_wp)
waypoint altitude in m above MSL
Common code for AP and FBW telemetry.
void ekf_range_update_noise(struct EKFRange *ekf_range, float Q_sigma2, float R_dist, float R_speed)
Update process and measurement noises.
void ekf_range_set_state(struct EKFRange *ekf_range, struct EnuCoor_f pos, struct EnuCoor_f speed)
Set initial state vector.
struct EnuCoor_f ekf_range_get_speed(struct EKFRange *ekf_range)
Get current speed.
void ekf_range_update_dist(struct EKFRange *ekf_range, float dist, struct EnuCoor_f anchor)
correction step
struct EnuCoor_f ekf_range_get_pos(struct EKFRange *ekf_range)
Get current pos.
void ekf_range_init(struct EKFRange *ekf_range, float P0_pos, float P0_speed, float Q_sigma2, float R_dist, float R_speed, float dt)
Init EKF_range internal struct.
void ekf_range_predict(struct EKFRange *ekf_range)
propagate dynamic model
void gps_periodic_check(struct GpsState *gps_s)
Periodic GPS check.
Device independent GPS code (interface)
uint32_t sacc
speed accuracy in cm/s
uint32_t cacc
course accuracy in rad*1e7
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
#define GPS_VALID_VEL_ECEF_BIT
#define GPS_VALID_VEL_NED_BIT
#define GPS_VALID_POS_LLA_BIT
uint16_t pdop
position dilution of precision scaled by 100
#define GPS_FIX_NONE
No GPS fix.
#define GPS_VALID_POS_ECEF_BIT
#define GPS_VALID_HMSL_BIT
uint32_t pacc
position accuracy in cm
uint8_t comp_id
id of current gps
#define GPS_FIX_3D
3D GPS fix
data structure for GPS information
struct GpsState gps_datalink
static float float_vect3_norm(const struct FloatVect3 *v)
#define FLOAT_VECT3_NORM(_v)
#define FLOAT_VECT2_NORM(_v)
#define VECT3_DIFF(_c, _a, _b)
#define MAT33_ELMT(_m, _row, _col)
int32_t lat
in degrees*1e7
void ecef_of_enu_vect_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct EnuCoor_i *enu)
Rotate a vector from ENU to ECEF.
#define VECT3_NED_OF_ENU(_o, _i)
void ecef_of_enu_point_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct EnuCoor_i *enu)
Convert a point in local ENU to ECEF.
void lla_of_ecef_i(struct LlaCoor_i *out, struct EcefCoor_i *in)
Convert a ECEF to LLA.
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
vector in East North Up coordinates
vector in Latitude, Longitude and Altitude
definition of the local (flat earth) coordinate system
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
static FILE * pprzLogFile
vector in East North Up coordinates Units: meters
API to get/set the generic vehicle states.
volatile uint32_t nb_sec
full seconds since startup
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
static float get_sys_time_float(void)
Get the time in seconds since startup.
int trilateration_init(struct Anchor *anchors)
Init internal trilateration structures.
int trilateration_compute(struct Anchor *anchors, struct EnuCoor_f *pos)
Compute trilateration based on the latest measurments.
float distance
last measured distance
struct EnuCoor_f pos
position of the anchor
bool updated
new data available
float time
time of the last received data
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define UWB_POSITIONING_VEL_NOISE_Z
struct EKFRange ekf_range
EKF filter.
float initial_heading
initial heading correction
#define UWB_POSITIONING_NOISE_Y
void WEAK uwb_range(uint16_t id)
Weak empty implementation.
void uwb_positioning_report(void)
struct LtpDef_i ltp_def
ltp reference
#define UWB_POSITIONING_TIMEOUT
default timeout (in ms)
static void process_data(struct UwbPositioning *uwb)
#define UWB_POSITIONING_RANGE_SCALE
default scale factor, applied to individual distances
static bool check_anchor_timeout(struct UwbPositioning *uwb, float timeout)
check timeout for each anchor
void uwb_positioning_update_ekf_q(float v)
settings handler
void uwb_positioning_update_ekf_r_dist(float v)
bool uwb_positioning_use_ekf
enable EKF filtering
#define UWB_POSITIONING_INITIAL_HEADING
default initial heading correction between anchors frame and global frame
#define UWB_POSITIONING_TAG_ID
My UWB tag id.
void uwb_positioning_init(void)
static bool check_and_compute_data(struct UwbPositioning *uwb)
check new data and compute with the proper algorithm
#define UWB_POSITIONING_VEL_NOISE_Y
bool updated
new anchor data available
struct EnuCoor_f speed
local speed in anchors frame
static const float pos_z[]
void uwb_positioning_update_ekf_r_speed(float v)
float uwb_positioning_ekf_r_speed
void uwb_positioning_reset_heading_ref(void)
Reset reference heading to current heading AHRS/INS should be aligned before calling this function.
struct Anchor anchors[UWB_POSITIONING_NB_ANCHORS]
anchors data
#define UWB_POSITIONING_NOISE_Z
#define UWB_POSITIONING_VEL_NOISE_X
struct EnuCoor_f pos
local pos in anchors frame
static abi_event uwb_ranging_ev
static const float offset[]
void uwb_positioning_range_periodic(void)
float uwb_positioning_ekf_r_dist
static const uint16_t ids[]
init arrays from airframe file
uint8_t anchor_ranging_idx
Next anchor index (in the anchors array) to be ranged.
static const float scale[]
struct GpsState gps_uwb
"fake" gps structure
#define UWB_POSITIONING_RANGE_OFFSET
default offset, applied to individual distances
float raw_dist[UWB_POSITIONING_NB_ANCHORS]
raw distance from anchors
#define UWB_POSITIONING_NOISE_X
UWB positioning output noise.
bool ekf_running
EKF logic status.
static void uwb_ranging_cb(uint8_t sender_id, uint32_t stamp, uint16_t src_id, uint16_t dst_id, float range)
#define UWB_POSITIONING_NB_ANCHORS
Number of anchors.
struct MedianFilterFloat mf[UWB_POSITIONING_NB_ANCHORS]
median filter for EKF input data
static const float pos_y[]
static const float pos_x[]
float uwb_positioning_ekf_q
process and measurements noise
void uwb_positioning_periodic(void)
static struct UwbPositioning uwb_positioning
#define UWB_POSITIONING_USE_EKF
TRUE if EKF range filter is use.
waypoints to use as anchors in simulation
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.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.