Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
tag_tracking.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
32 #include "generated/modules.h"
33 #include "state.h"
34 #include "modules/core/abi.h"
35 #include <math.h>
37 
38 #include "generated/flight_plan.h"
39 
40 
41 // use WP_TARGET by default for simulation
42 #if !(defined TAG_TRACKING_SIM_WP) && (defined WP_TARGET)
43 #define TAG_TRACKING_SIM_WP WP_TARGET
44 #endif
45 
46 #if defined SITL && defined TAG_TRACKING_SIM_WP
47 static void tag_tracking_sim(void);
48 static void tag_motion_sim(void);
49 
50 // select print function for debug
51 #include <stdio.h>
52 #define PRINTF printf
53 // #define PRINTF(...) {}
54 
55 #define TAG_MOTION_NONE 0
56 #define TAG_MOTION_LINE 1
57 #define TAG_MOTION_CIRCLE 2
58 
59 #define TAG_MOTION_SPEED_X 0.25f //0.5f
60 #define TAG_MOTION_SPEED_Y 0.f
61 #define TAG_MOTION_RANGE_X 4.f
62 #define TAG_MOTION_RANGE_Y 4.f
63 
64 static uint8_t tag_motion_sim_type = TAG_MOTION_NONE;
65 static struct FloatVect3 tag_motion_speed = { TAG_MOTION_SPEED_X, TAG_MOTION_SPEED_Y, 0.f };
66 
67 // variables for circle
68 int time_circle = 0;
69 float time_circle_corrected;
70 float speed_circle = 0.03;
71 
72 #endif // SITL
73 
74 // Default parameters
75 // Camera is looking down and is placed at the center of the frame
76 // With cam X axis pointing to the right, Y down and Z forward of image frame,
77 // the camera is just rotated of pi/2 around body Z axis
78 
79 #ifndef TAG_TRACKING_BODY_TO_CAM_PHI
80 #define TAG_TRACKING_BODY_TO_CAM_PHI 0.f
81 #endif
82 
83 #ifndef TAG_TRACKING_BODY_TO_CAM_THETA
84 #define TAG_TRACKING_BODY_TO_CAM_THETA 0.f
85 #endif
86 
87 #ifndef TAG_TRACKING_BODY_TO_CAM_PSI
88 #define TAG_TRACKING_BODY_TO_CAM_PSI M_PI_2
89 #endif
90 
91 #ifndef TAG_TRACKING_CAM_POS_X
92 #define TAG_TRACKING_CAM_POS_X 0.f
93 #endif
94 
95 #ifndef TAG_TRACKING_CAM_POS_Y
96 #define TAG_TRACKING_CAM_POS_Y 0.f
97 #endif
98 
99 #ifndef TAG_TRACKING_CAM_POS_Z
100 #define TAG_TRACKING_CAM_POS_Z 0.f
101 #endif
102 
103 #ifndef TAG_TRACKING_COORD_TO_M
104 #define TAG_TRACKING_COORD_TO_M (1.f / 1000.f)
105 #endif
106 
107 #ifndef TAG_TRACKING_R
108 #define TAG_TRACKING_R 1.f
109 #endif
110 
111 #ifndef TAG_TRACKING_Q_SIGMA2
112 #define TAG_TRACKING_Q_SIGMA2 1.f
113 #endif
114 
115 #ifndef TAG_TRACKING_P0_POS
116 #define TAG_TRACKING_P0_POS 10.f
117 #endif
118 
119 #ifndef TAG_TRACKING_P0_SPEED
120 #define TAG_TRACKING_P0_SPEED 10.f
121 #endif
122 
123 #ifndef TAG_TRACKING_TIMEOUT
124 #define TAG_TRACKING_TIMEOUT 5.f
125 #endif
126 
127 #ifndef TAG_TRACKING_PREDICT_TIME
128 #define TAG_TRACKING_PREDICT_TIME 1.f
129 #endif
130 
131 #ifndef TAG_TRACKING_MAX_OFFSET
132 #define TAG_TRACKING_MAX_OFFSET 2.0f
133 #endif
134 
135 #ifndef TAG_TRACKING_KP
136 #define TAG_TRACKING_KP 0.5f
137 #endif
138 
139 #ifndef TAG_TRACKING_KPZ
140 #define TAG_TRACKING_KPZ 0.2f
141 #endif
142 
143 #ifndef TAG_TRACKING_MAX_SPEED
144 #define TAG_TRACKING_MAX_SPEED 4.f
145 #endif
146 
147 #ifndef TAG_TRACKING_MAX_VZ
148 #define TAG_TRACKING_MAX_VZ 2.f
149 #endif
150 
151 
152 #define TAG_UNUSED_ID -1
153 
154 // generated in modules.h
155 static const float tag_track_dt = TAG_TRACKING_PROPAGATE_PERIOD;
156 
157 // global state structure
158 struct tag_tracking {
159  struct FloatVect3 meas;
160  struct FloatQuat cam_to_tag_quat;
161 
162  struct FloatRMat body_to_cam;
163  struct FloatQuat body_to_cam_quat;
164  struct FloatVect3 cam_pos;
165 
166  float timeout;
167  bool updated;
168 
170 };
171 
172 
173 
174 struct tag_info {
179 };
180 
181 struct wp_tracking {
184 };
185 
186 
187 #if (defined TAG_TRACKING_WPS)
188 struct wp_tracking wp_track[] = TAG_TRACKING_WPS;
189 const uint8_t tag_tracking_wps_len = sizeof(wp_track) / sizeof(struct wp_tracking);
190 #else
191 struct wp_tracking wp_track[] = {};
193 #endif
194 
195 
197 
198 struct tag_tracking_public dummy = {0};
199 
200 struct FloatQuat rot_x_quat; // quaternion to rotate tag to have Z down
201 
202 // Abi bindings
203 #ifndef TAG_TRACKING_ID
204 #define TAG_TRACKING_ID ABI_BROADCAST
205 #endif
206 
208 
210 
212  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
213  if(tag_infos[i].tag_track_private.id == tag_id) {
214  return &tag_infos[i].tag_tracking;
215  }
216 
217  // tag_id == TAG_TRACKING_ANY, returns the first running tag.
218  if(tag_id == TAG_TRACKING_ANY && tag_infos[i].tag_tracking.status == TAG_TRACKING_RUNNING) {
219  return &tag_infos[i].tag_tracking;
220  }
221  }
222 
225  return &dummy;
226 }
227 
229  struct tag_tracking_public* tag = tag_tracking_get(tag_id);
230  struct FloatEulers e;
232  return DegOfRad(e.psi);
233 }
234 
235 // update measure vect before calling
237 {
238  struct FloatVect3 target_pos_ned, target_pos_body;
239  // compute target position in body frame (rotate and translate)
241  VECT3_ADD(target_pos_body, tag_info->tag_track_private.cam_pos);
242  // rotate to ltp frame
243  struct FloatRMat *ltp_to_body_rmat = stateGetNedToBodyRMat_f();
244  float_rmat_transp_vmult(&target_pos_ned, ltp_to_body_rmat, &target_pos_body);
245  // compute absolute position of tag in earth frame
246  struct NedCoor_f * pos_ned = stateGetPositionNed_f();
247  VECT3_ADD(target_pos_ned, *pos_ned);
248 
249  // TODO filter in kalman ?
252 
254  // don't run kalman, just update pos, set speed to zero
255  tag_info->tag_tracking.pos = target_pos_ned;
257  } else {
258  // update state and status
260  // reset state after first detection or lost tag
261  struct FloatVect3 speed = { 0.f, 0.f, 0.f };
262  simple_kinematic_kalman_set_state(&tag_info->kalman, target_pos_ned, speed);
264  }
265  else {
266  // RUNNING state, call correction step
268  }
269  // update public structure
271  }
272 }
273 
274 static void tag_track_cb(uint8_t sender_id UNUSED,
275  uint8_t type, char * id,
276  uint8_t nb UNUSED, int16_t * coord, uint16_t * dim UNUSED,
277  struct FloatQuat quat UNUSED, char * extra UNUSED)
278 {
279  if (type == JEVOIS_MSG_D3) {
280  int16_t tag_id = (int16_t)jevois_extract_nb(id);
281  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
282  // free slot, store tag ID
283  if(tag_infos[i].tag_track_private.id == TAG_UNUSED_ID) {
284  tag_infos[i].tag_track_private.id = tag_id;
285  }
286 
287  if(tag_infos[i].tag_track_private.id == tag_id) {
288  // store data from Jevois detection
292 
293  float_quat_normalize(&quat);
294  // rotate the quaternion so Z is down
295  float_quat_comp(&tag_infos[i].tag_track_private.cam_to_tag_quat, &quat, &rot_x_quat);
296  // update filter
298  // reset timeout and status
301  break;
302  }
303  }
304  }
305 }
306 
308 {
309  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
310  // update x,y,z position from lat,lon,alt fields
311  tag_infos[i].tag_track_private.meas.x = DL_TARGET_POS_lat(buf) * TAG_TRACKING_COORD_TO_M;
312  tag_infos[i].tag_track_private.meas.y = DL_TARGET_POS_lon(buf) * TAG_TRACKING_COORD_TO_M;
313  tag_infos[i].tag_track_private.meas.z = DL_TARGET_POS_alt(buf) * TAG_TRACKING_COORD_TO_M;
314  // update filter
316  // store tag ID
317  tag_infos[i].tag_track_private.id = DL_TARGET_POS_target_id(buf);
318  // reset timeout and status
321  }
322 }
323 
324 // Update and display tracking WP
325 static void update_wp(struct tag_info* tag_info UNUSED, bool report UNUSED)
326 {
327 #ifdef TAG_TRACKING_WPS
328 
329  if(tag_info->wp_id == 0) {
330  // not associated with any WP
331  return;
332  }
333 
334  struct FloatVect3 target_pos_enu, target_pos_pred;
335  ENU_OF_TO_NED(target_pos_enu, tag_info->tag_tracking.pos); // convert local target pos to ENU
337  // when moving mode, predict tag position
338  ENU_OF_TO_NED(target_pos_pred, tag_info->tag_tracking.speed);
339  VECT2_SMUL(target_pos_pred, target_pos_pred, tag_info->tag_tracking.predict_time); // pos offset at predict_time
340  VECT2_STRIM(target_pos_pred, -TAG_TRACKING_MAX_OFFSET, TAG_TRACKING_MAX_OFFSET); // trim max offset
341  VECT3_ADD(target_pos_enu, target_pos_pred); // add prediction offset
342  }
343  struct EnuCoor_i pos_i;
344  ENU_BFP_OF_REAL(pos_i, target_pos_enu);
345  if (report) {
346  // move is a set + downlink report
348  } else {
350  }
351 
352 #endif
353 }
354 
355 // Init function
357 {
358  struct FloatEulers rot_x = { M_PI, 0, 0};
360 
361  // Init structure
362  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
363  FLOAT_VECT3_ZERO(tag_infos[i].tag_track_private.meas);
367  float_quat_identity(&tag_infos[i].tag_tracking.ned_to_tag_quat);
368  struct FloatEulers euler = {
372  };
373  float_rmat_of_eulers(&tag_infos[i].tag_track_private.body_to_cam, &euler);
374  float_quat_of_eulers(&tag_infos[i].tag_track_private.body_to_cam_quat, &euler);
375  VECT3_ASSIGN(tag_infos[i].tag_track_private.cam_pos,
381 
388  }
389 
390  // reserve slots for tag_ids we are looking for, and associate wp_ids.
391  for(int i=0; i<Min(tag_tracking_wps_len, TAG_TRACKING_NB_MAX); i++) {
393  tag_infos[i].wp_id = wp_track[i].wp_id;
394  }
395 
396  // Bind to ABI message
397  AbiBindMsgJEVOIS_MSG(TAG_TRACKING_ID, &tag_track_ev, tag_track_cb);
398 }
399 
400 
401 // Propagation function
403 {
404 #if defined SITL && defined TAG_TRACKING_SIM_WP
405  if (tag_motion_sim_type != TAG_MOTION_NONE) {
406  tag_motion_sim();
407  }
408  tag_tracking_sim();
409 #endif
410  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
411  switch (tag_infos[i].tag_tracking.status) {
413  // don't propagate, wait for first detection
414  break;
416  // call kalman propagation step
418  // force speed to zero for fixed tag
419  if (tag_infos[i].tag_tracking.motion_type == TAG_TRACKING_FIXED_POS) {
420  struct FloatVect3 zero = { 0.f, 0.f, 0.f };
422  }
423  // update public structure
425  // update WP
426  update_wp(&tag_infos[i], false);
427  // increment timeout counter
429  if (tag_infos[i].tag_track_private.timeout > TAG_TRACKING_TIMEOUT) {
431  }
432  break;
433  case TAG_TRACKING_LOST:
434  // tag is lost, restart filter and wait for a new detection
436  break;
437  default:
438  break;
439  }
440  }
441 }
442 
443 // Propagation start function (called at each start state)
445 {
449 }
450 
452  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
454  }
455 }
456 
457 // Report function
459 {
460  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
461  if(tag_infos[i].tag_track_private.id == TAG_UNUSED_ID) {
462  continue;
463  }
464 #if TAG_TRACKING_DEBUG
465  float msg[] = {
466  tag_infos[i].kalman.state[0],
467  tag_infos[i].kalman.state[1],
468  tag_infos[i].kalman.state[2],
469  tag_infos[i].kalman.state[3],
470  tag_infos[i].kalman.state[4],
471  tag_infos[i].kalman.state[5],
472  (float)tag_infos[i].tag_tracking.status
473  };
474  DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, 7, msg);
475 #endif
476 
478  // compute absolute position
479  struct LlaCoor_f tag_lla;
480  struct EcefCoor_f tag_ecef;
482  lla_of_ecef_f(&tag_lla, &tag_ecef);
483  float lat_deg = DegOfRad(tag_lla.lat);
484  float lon_deg = DegOfRad(tag_lla.lon);
485  uint8_t id =(uint8_t)tag_infos[i].tag_track_private.id;
486  DOWNLINK_SEND_MARK(DefaultChannel, DefaultDevice, &id, &lat_deg, &lon_deg);
487  update_wp(&tag_infos[i], true);
489  }
490  }
491 }
492 
500 {
501  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
502  if (tag_infos[i].tag_tracking.status == TAG_TRACKING_RUNNING) {
503  // compute speed command as estimated tag speed + gain * position error
504  struct NedCoor_f pos = *stateGetPositionNed_f();
508  VECT2_STRIM(tag_infos[i].tag_tracking.speed_cmd, -TAG_TRACKING_MAX_SPEED, TAG_TRACKING_MAX_SPEED); // trim max horizontal speed
509  BoundAbs(tag_infos[i].tag_tracking.speed_cmd.z, TAG_TRACKING_MAX_VZ); // tim max vertical speed
510  }
511  else {
512  // filter is not runing, set speed command to zero
514  }
515  }
516 }
517 
518 // Simulate detection using a WP coordinate
519 #if defined SITL && defined TAG_TRACKING_SIM_WP
520 static void tag_tracking_sim(void)
521 {
522  // Compute image coordinates of a WP given fake camera parameters
523  struct FloatRMat *ltp_to_body_rmat = stateGetNedToBodyRMat_f();
524  struct FloatRMat ltp_to_cam_rmat;
525  float_rmat_comp(&ltp_to_cam_rmat, ltp_to_body_rmat, &tag_infos[0].tag_track_private.body_to_cam);
526  // Prepare cam world position
527  // C_w = P_w + R_w2b * C_b
528  struct FloatVect3 cam_pos_ltp;
529  float_rmat_vmult(&cam_pos_ltp, ltp_to_body_rmat, &tag_infos[0].tag_track_private.cam_pos);
530  VECT3_ADD(cam_pos_ltp, *stateGetPositionNed_f());
531  // Target
532  struct NedCoor_f target_ltp;
533  ENU_OF_TO_NED(target_ltp, waypoints[TAG_TRACKING_SIM_WP].enu_f);
534  target_ltp.z = 0.f; // force on the ground
535  // Compute target in camera frame Pc = R * (Pw - C)
536  struct FloatVect3 target_cam, tmp;
537  VECT3_DIFF(tmp, target_ltp, cam_pos_ltp);
538  float_rmat_vmult(&target_cam, &ltp_to_cam_rmat, &tmp);
539  if (fabsf(target_cam.z) > 1.) {
540  // If we are not too close from target
541  // Compute target in image frame x = X/Z, y = X/Z
542  if (fabsf(target_cam.x / target_cam.z) < 0.3f &&
543  fabsf(target_cam.y / target_cam.z) < 0.3f) {
544  // If in field of view (~tan(60)/2)
545  // send coordinates in millimeter
546  int16_t coord[3] = {
547  (int16_t) (target_cam.x * 1000.f),
548  (int16_t) (target_cam.y * 1000.f),
549  (int16_t) (target_cam.z * 1000.f)
550  };
551  uint16_t dim[3] = { 100, 100, 0 };
552  struct FloatQuat quat; // TODO
553  float_quat_identity(&quat);
554  AbiSendMsgJEVOIS_MSG(42, JEVOIS_MSG_D3, "1", 3, coord, dim, quat, "");
555  }
556  }
557 }
558 
559 static void tag_motion_sim(void)
560 {
561  switch (tag_motion_sim_type) {
562  case TAG_MOTION_LINE:
563  {
564  struct EnuCoor_f pos = waypoints[TAG_TRACKING_SIM_WP].enu_f;
565  struct FloatVect3 speed_dt = tag_motion_speed;
566  VECT2_SMUL(speed_dt, speed_dt, tag_track_dt);
567  if (pos.x < -TAG_MOTION_RANGE_X || pos.x > TAG_MOTION_RANGE_X ||
568  pos.y < -TAG_MOTION_RANGE_Y || pos.y > TAG_MOTION_RANGE_Y) {
569  tag_motion_speed.x = -tag_motion_speed.x;
570  tag_motion_speed.y = -tag_motion_speed.y;
571  speed_dt.x = -speed_dt.x;
572  speed_dt.y = -speed_dt.y;
573  }
574  VECT2_ADD(pos, speed_dt);
575  struct EnuCoor_i pos_i;
576  ENU_BFP_OF_REAL(pos_i, pos);
577  waypoint_move_enu_i(TAG_TRACKING_SIM_WP, &pos_i);
578  break;
579  }
580  case TAG_MOTION_CIRCLE:
581  {
582  time_circle += 1;
583  time_circle_corrected = time_circle * 0.02;
584  struct EnuCoor_f pos = waypoints[TAG_TRACKING_SIM_WP].enu_f;
585  struct FloatVect3 speed_dt = tag_motion_speed;
586  VECT2_SMUL(speed_dt, speed_dt, tag_track_dt);
587  tag_motion_speed.x = speed_circle * cos(time_circle_corrected);
588  tag_motion_speed.y = speed_circle * sin(time_circle_corrected);
589  speed_dt.x = speed_circle * cos(time_circle_corrected);;
590  speed_dt.y = speed_circle * sin(time_circle_corrected);
591  VECT2_ADD(pos, speed_dt);
592  struct EnuCoor_i pos_i;
593  ENU_BFP_OF_REAL(pos_i, pos);
594  waypoint_move_enu_i(TAG_TRACKING_SIM_WP, &pos_i);
595  }
596  default:
597  break;
598  }
599 }
600 
601 #endif
602 
603 
604 
605 
611 
612 
613 void tag_tracking_set_motion_type(float motion_type) {
614  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
615  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
616  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
617  tag_infos[i].tag_tracking.motion_type = (uint8_t)motion_type;
618  tag_tracking_motion_type = (uint8_t)motion_type;;
619  }
620  }
621 }
622 
623 void tag_tracking_set_predict_time(float predict_time) {
624  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
625  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
626  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
627  tag_infos[i].tag_tracking.predict_time = predict_time;
628  tag_tracking_predict_time = predict_time;
629  }
630  }
631 }
632 
633 void tag_tracking_set_kp(float kp) {
634  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
635  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
636  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
637  tag_infos[i].tag_tracking.kp = kp;
638  tag_tracking_kp = kp;
639  }
640  }
641 }
642 
643 void tag_tracking_set_kpz(float kpz) {
644  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
645  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
646  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
647  tag_infos[i].tag_tracking.kpz = kpz;
648  tag_tracking_kpz = kpz;
649  }
650  }
651 }
652 
654  tag_tracking_setting_id = (int)id;
655  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
656  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
657  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
662  }
663  }
664 }
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition: abi_common.h:67
uint8_t last_wp UNUSED
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:39
#define Min(x, y)
Definition: esc_dshot.c:109
float psi
in radians
static void float_quat_normalize(struct FloatQuat *q)
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
#define FLOAT_VECT3_ZERO(_v)
#define float_rmat_of_eulers
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.
void float_eulers_of_quat(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'ZYX'
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
void float_rmat_vmult(struct FloatVect3 *vb, struct FloatRMat *m_a2b, struct FloatVect3 *va)
rotate 3D vector by rotation matrix.
euler angles
Roation quaternion.
rotation matrix
#define VECT2_ADD(_a, _b)
Definition: pprz_algebra.h:74
#define VECT2_SMUL(_vo, _vi, _s)
Definition: pprz_algebra.h:98
#define VECT2_STRIM(_v, _min, _max)
Definition: pprz_algebra.h:110
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
#define VECT3_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:182
#define VECT3_ADD(_a, _b)
Definition: pprz_algebra.h:147
#define ENU_OF_TO_NED(_po, _pi)
Definition: pprz_geodetic.h:41
#define ENU_BFP_OF_REAL(_o, _i)
vector in East North Up coordinates
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
Definition: state.h:1137
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
Definition: state.h:1131
struct State state
Definition: state.c:36
struct LtpDef_f ned_origin_f
Definition of the local (flat earth) coordinate system.
Definition: state.h:220
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
Definition: state.h:710
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
int jevois_extract_nb(char *in)
Extract a number from jevoid ID field.
Definition: jevois.c:130
#define JEVOIS_MSG_D3
Definition: jevois.h:41
void waypoint_move_enu_i(uint8_t wp_id, struct EnuCoor_i *new_pos)
Definition: waypoints.c:189
void waypoint_set_enu_i(uint8_t wp_id, struct EnuCoor_i *enu)
Definition: waypoints.c:165
void ecef_of_ned_point_f(struct EcefCoor_f *ecef, struct LtpDef_f *def, struct NedCoor_f *ned)
void lla_of_ecef_f(struct LlaCoor_f *out, struct EcefCoor_f *in)
float y
in meters
float x
in meters
float lon
in radians
float z
in meters
float x
in meters
float lat
in radians
float y
in meters
vector in EarthCenteredEarthFixed coordinates
vector in East North Up coordinates Units: meters
vector in Latitude, Longitude and Altitude
vector in North East Down coordinates Units: meters
void simple_kinematic_kalman_get_state(struct SimpleKinematicKalman *kalman, struct FloatVect3 *pos, struct FloatVect3 *speed)
Get current state.
void simple_kinematic_kalman_predict(struct SimpleKinematicKalman *kalman)
propagate dynamic model
void simple_kinematic_kalman_set_state(struct SimpleKinematicKalman *kalman, struct FloatVect3 pos, struct FloatVect3 speed)
Set initial state vector.
void simple_kinematic_kalman_update_pos(struct SimpleKinematicKalman *kalman, struct FloatVect3 pos)
correction step for position
void simple_kinematic_kalman_init(struct SimpleKinematicKalman *kalman, float P0_pos, float P0_speed, float Q_sigma2, float r, float dt)
Init SimpleKinematicKalman internal struct.
void simple_kinematic_kalman_update_speed(struct SimpleKinematicKalman *kalman, struct FloatVect3 speed, uint8_t type)
correction step for speed
#define SIMPLE_KINEMATIC_KALMAN_SPEED_3D
float state[SIMPLE_KINEMATIC_KALMAN_DIM]
state vector
API to get/set the generic vehicle states.
struct tag_tracking_public tag_tracking
Definition: tag_tracking.c:176
void tag_tracking_propagate_start()
Definition: tag_tracking.c:451
void tag_tracking_set_kpz(float kpz)
Definition: tag_tracking.c:643
static void update_tag_position(struct tag_info *tag_info)
Definition: tag_tracking.c:236
int tag_tracking_setting_id
Definition: tag_tracking.c:606
static abi_event tag_track_ev
Definition: tag_tracking.c:207
static void tag_track_cb(uint8_t sender_id UNUSED, uint8_t type, char *id, uint8_t nb UNUSED, int16_t *coord, uint16_t *dim UNUSED, struct FloatQuat quat UNUSED, char *extra UNUSED)
Definition: tag_tracking.c:274
static const float tag_track_dt
Definition: tag_tracking.c:155
#define TAG_TRACKING_TIMEOUT
Definition: tag_tracking.c:124
#define TAG_TRACKING_KP
Definition: tag_tracking.c:136
void tag_tracking_init()
Definition: tag_tracking.c:356
struct FloatVect3 meas
measured position
Definition: tag_tracking.c:159
void tag_tracking_set_kp(float kp)
Definition: tag_tracking.c:633
#define TAG_TRACKING_MAX_VZ
Definition: tag_tracking.c:148
#define TAG_TRACKING_CAM_POS_Z
Definition: tag_tracking.c:100
#define TAG_TRACKING_CAM_POS_Y
Definition: tag_tracking.c:96
struct tag_tracking_public * tag_tracking_get(int16_t tag_id)
Definition: tag_tracking.c:211
float tag_tracking_predict_time
Definition: tag_tracking.c:608
#define TAG_TRACKING_BODY_TO_CAM_THETA
Definition: tag_tracking.c:84
void tag_tracking_propagate()
Definition: tag_tracking.c:402
#define TAG_TRACKING_PREDICT_TIME
Definition: tag_tracking.c:128
#define TAG_TRACKING_Q_SIGMA2
Definition: tag_tracking.c:112
float tag_tracking_motion_type
Definition: tag_tracking.c:607
#define TAG_TRACKING_BODY_TO_CAM_PSI
Definition: tag_tracking.c:88
float timeout
timeout for lost flag [sec]
Definition: tag_tracking.c:166
void tag_tracking_set_setting_id(float id)
Definition: tag_tracking.c:653
#define TAG_TRACKING_KPZ
Definition: tag_tracking.c:140
struct FloatVect3 cam_pos
Position of camera in body frame.
Definition: tag_tracking.c:164
#define TAG_TRACKING_BODY_TO_CAM_PHI
Definition: tag_tracking.c:80
bool updated
updated state
Definition: tag_tracking.c:167
struct tag_tracking_public dummy
Definition: tag_tracking.c:198
#define TAG_TRACKING_COORD_TO_M
Definition: tag_tracking.c:104
uint8_t wp_id
Definition: tag_tracking.c:182
void tag_tracking_report()
Definition: tag_tracking.c:458
void tag_tracking_parse_target_pos(uint8_t *buf)
Definition: tag_tracking.c:307
const uint8_t tag_tracking_wps_len
Definition: tag_tracking.c:192
static void tag_tracking_propagate_start_tag(struct tag_info *tag_info)
Definition: tag_tracking.c:444
static void update_wp(struct tag_info *tag_info UNUSED, bool report UNUSED)
Definition: tag_tracking.c:325
struct FloatQuat body_to_cam_quat
Body to camera rotation in quaternion.
Definition: tag_tracking.c:163
struct tag_tracking tag_track_private
Definition: tag_tracking.c:175
void tag_tracking_set_predict_time(float predict_time)
Definition: tag_tracking.c:623
float tag_tracking_kpz
Definition: tag_tracking.c:610
#define TAG_TRACKING_P0_POS
Definition: tag_tracking.c:116
uint8_t tag_id
Definition: tag_tracking.c:183
struct tag_info tag_infos[TAG_TRACKING_NB_MAX]
Definition: tag_tracking.c:196
#define TAG_TRACKING_MAX_SPEED
Definition: tag_tracking.c:144
struct FloatRMat body_to_cam
Body to camera rotation.
Definition: tag_tracking.c:162
#define TAG_UNUSED_ID
Definition: tag_tracking.c:152
struct SimpleKinematicKalman kalman
Definition: tag_tracking.c:177
uint8_t wp_id
Definition: tag_tracking.c:178
float tag_tracking_kp
Definition: tag_tracking.c:609
#define TAG_TRACKING_CAM_POS_X
Definition: tag_tracking.c:92
#define TAG_TRACKING_MAX_OFFSET
Definition: tag_tracking.c:132
int16_t id
ID of detected tag.
Definition: tag_tracking.c:169
void tag_tracking_set_motion_type(float motion_type)
Definition: tag_tracking.c:613
#define TAG_TRACKING_P0_SPEED
Definition: tag_tracking.c:120
struct FloatQuat rot_x_quat
Definition: tag_tracking.c:200
struct wp_tracking wp_track[]
Definition: tag_tracking.c:191
#define TAG_TRACKING_ID
Definition: tag_tracking.c:204
void tag_tracking_compute_speed(void)
Control function.
Definition: tag_tracking.c:499
#define TAG_TRACKING_R
Definition: tag_tracking.c:108
float tag_tracking_get_heading(int16_t tag_id)
Definition: tag_tracking.c:228
struct FloatQuat cam_to_tag_quat
measured quat
Definition: tag_tracking.c:160
struct FloatQuat ned_to_tag_quat
estimated attitude in NED frame
Definition: tag_tracking.h:58
#define TAG_TRACKING_MOVING
Definition: tag_tracking.h:52
float kpz
vertical tracking command gain
Definition: tag_tracking.h:64
#define TAG_TRACKING_ANY
Definition: tag_tracking.h:41
#define TAG_TRACKING_DISABLE
Definition: tag_tracking.h:47
struct FloatVect3 pos
estimated position
Definition: tag_tracking.h:55
#define TAG_TRACKING_RUNNING
Definition: tag_tracking.h:45
uint8_t status
tracking status flag
Definition: tag_tracking.h:59
#define TAG_TRACKING_FIXED_POS
Definition: tag_tracking.h:51
float predict_time
prediction time for WP tag
Definition: tag_tracking.h:61
struct NedCoor_f speed_cmd
speed command to track the tag position
Definition: tag_tracking.h:62
#define TAG_TRACKING_NB_MAX
Definition: tag_tracking.h:37
#define TAG_TRACKING_SEARCHING
Definition: tag_tracking.h:44
struct FloatQuat body_to_tag_quat
estimated attitude in body frame
Definition: tag_tracking.h:57
#define TAG_TRACKING_LOST
Definition: tag_tracking.h:46
uint8_t motion_type
type of tag motion
Definition: tag_tracking.h:60
struct FloatVect3 speed
estimated speed
Definition: tag_tracking.h:56
float kp
horizontal tracking command gain
Definition: tag_tracking.h:63
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98