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 #ifndef TAG_TRACKING_SIM_ID
65 #define TAG_TRACKING_SIM_ID "U1"
66 #endif
67 
68 static uint8_t tag_motion_sim_type = TAG_MOTION_NONE;
69 static struct FloatVect3 tag_motion_speed = { TAG_MOTION_SPEED_X, TAG_MOTION_SPEED_Y, 0.f };
70 
71 // variables for circle
72 int time_circle = 0;
73 float time_circle_corrected;
74 float speed_circle = 0.03;
75 
76 #endif // SITL
77 
78 // Default parameters
79 // Camera is looking down and is placed at the center of the frame
80 // With cam X axis pointing to the right, Y down and Z forward of image frame,
81 // the camera is just rotated of pi/2 around body Z axis
82 
83 #ifndef TAG_TRACKING_BODY_TO_CAM_PHI
84 #define TAG_TRACKING_BODY_TO_CAM_PHI 0.f
85 #endif
86 
87 #ifndef TAG_TRACKING_BODY_TO_CAM_THETA
88 #define TAG_TRACKING_BODY_TO_CAM_THETA 0.f
89 #endif
90 
91 #ifndef TAG_TRACKING_BODY_TO_CAM_PSI
92 #define TAG_TRACKING_BODY_TO_CAM_PSI M_PI_2
93 #endif
94 
95 #ifndef TAG_TRACKING_CAM_POS_X
96 #define TAG_TRACKING_CAM_POS_X 0.f
97 #endif
98 
99 #ifndef TAG_TRACKING_CAM_POS_Y
100 #define TAG_TRACKING_CAM_POS_Y 0.f
101 #endif
102 
103 #ifndef TAG_TRACKING_CAM_POS_Z
104 #define TAG_TRACKING_CAM_POS_Z 0.f
105 #endif
106 
107 #ifndef TAG_TRACKING_COORD_TO_M
108 #define TAG_TRACKING_COORD_TO_M (1.f / 1000.f)
109 #endif
110 
111 #ifndef TAG_TRACKING_R
112 #define TAG_TRACKING_R 1.f
113 #endif
114 
115 #ifndef TAG_TRACKING_Q_SIGMA2
116 #define TAG_TRACKING_Q_SIGMA2 1.f
117 #endif
118 
119 #ifndef TAG_TRACKING_P0_POS
120 #define TAG_TRACKING_P0_POS 10.f
121 #endif
122 
123 #ifndef TAG_TRACKING_P0_SPEED
124 #define TAG_TRACKING_P0_SPEED 10.f
125 #endif
126 
127 #ifndef TAG_TRACKING_TIMEOUT
128 #define TAG_TRACKING_TIMEOUT 5.f
129 #endif
130 
131 #ifndef TAG_TRACKING_PREDICT_TIME
132 #define TAG_TRACKING_PREDICT_TIME 1.f
133 #endif
134 
135 #ifndef TAG_TRACKING_MAX_OFFSET
136 #define TAG_TRACKING_MAX_OFFSET 2.0f
137 #endif
138 
139 #ifndef TAG_TRACKING_KP
140 #define TAG_TRACKING_KP 0.5f
141 #endif
142 
143 #ifndef TAG_TRACKING_KPZ
144 #define TAG_TRACKING_KPZ 0.2f
145 #endif
146 
147 #ifndef TAG_TRACKING_MAX_SPEED
148 #define TAG_TRACKING_MAX_SPEED 4.f
149 #endif
150 
151 #ifndef TAG_TRACKING_MAX_VZ
152 #define TAG_TRACKING_MAX_VZ 2.f
153 #endif
154 
155 
156 #define TAG_UNUSED_ID -1
157 
158 // generated in modules.h
159 static const float tag_track_dt = TAG_TRACKING_PROPAGATE_PERIOD;
160 
161 // global state structure
162 struct tag_tracking {
163  struct FloatVect3 meas;
164  struct FloatQuat cam_to_tag_quat;
165 
166  struct FloatRMat body_to_cam;
167  struct FloatQuat body_to_cam_quat;
168  struct FloatVect3 cam_pos;
169 
170  float timeout;
171  bool updated;
172 
174 };
175 
176 
177 
178 struct tag_info {
183 };
184 
185 struct wp_tracking {
188 };
189 
190 
191 #if (defined TAG_TRACKING_WPS)
192 struct wp_tracking wp_track[] = TAG_TRACKING_WPS;
193 const uint8_t tag_tracking_wps_len = sizeof(wp_track) / sizeof(struct wp_tracking);
194 #else
195 struct wp_tracking wp_track[] = {};
197 #endif
198 
199 
201 
202 struct tag_tracking_public dummy = {0};
203 
204 struct FloatQuat rot_x_quat; // quaternion to rotate tag to have Z down
205 
206 // Abi bindings
207 #ifndef TAG_TRACKING_ID
208 #define TAG_TRACKING_ID ABI_BROADCAST
209 #endif
210 
212 
214 
216  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
217  if(tag_infos[i].tag_track_private.id == tag_id) {
218  return &tag_infos[i].tag_tracking;
219  }
220 
221  // tag_id == TAG_TRACKING_ANY, returns the first running tag.
222  if (tag_id == TAG_TRACKING_ANY && tag_infos[i].tag_tracking.status == TAG_TRACKING_RUNNING) {
223  return &tag_infos[i].tag_tracking;
224  }
225  }
226 
229  return &dummy;
230 }
231 
233 {
234  return tag_tracking_get(tag_id)->status;
235 }
236 
238 {
239  return tag_tracking_get(tag_id)->motion_type;
240 }
241 
243  struct tag_tracking_public* tag = tag_tracking_get(tag_id);
244  struct FloatEulers e;
246  return DegOfRad(e.psi);
247 }
248 
249 // update measure vect before calling
251 {
252  struct FloatVect3 target_pos_ned, target_pos_body;
253  // compute target position in body frame (rotate and translate)
255  VECT3_ADD(target_pos_body, tag_info->tag_track_private.cam_pos);
256  // rotate to ltp frame
257  struct FloatRMat *ltp_to_body_rmat = stateGetNedToBodyRMat_f();
258  float_rmat_transp_vmult(&target_pos_ned, ltp_to_body_rmat, &target_pos_body);
259  // compute absolute position of tag in earth frame
260  struct NedCoor_f * pos_ned = stateGetPositionNed_f();
261  VECT3_ADD(target_pos_ned, *pos_ned);
262 
263  // TODO filter in kalman ?
266 
268  // don't run kalman, just update pos, set speed to zero
269  tag_info->tag_tracking.pos = target_pos_ned;
271  } else {
272  // update state and status
274  // reset state after first detection or lost tag
275  struct FloatVect3 speed = { 0.f, 0.f, 0.f };
276  simple_kinematic_kalman_set_state(&tag_info->kalman, target_pos_ned, speed);
278  }
279  else {
280  // RUNNING state, call correction step
282  }
283  // update public structure
285  }
286 }
287 
288 static void tag_track_cb(uint8_t sender_id UNUSED,
289  uint8_t type, char * id,
290  uint8_t nb UNUSED, int16_t * coord, uint16_t * dim UNUSED,
291  struct FloatQuat quat UNUSED, char * extra UNUSED)
292 {
293  if (type == JEVOIS_MSG_D3) {
294  int16_t tag_id = (int16_t)jevois_extract_nb(id);
295  for (int i=0; i<TAG_TRACKING_NB_MAX; i++) {
296  // free slot, store tag ID
297  if (tag_infos[i].tag_track_private.id == TAG_UNUSED_ID) {
298  tag_infos[i].tag_track_private.id = tag_id;
299  }
300 
301  if (tag_infos[i].tag_track_private.id == tag_id) {
302  // store data from Jevois detection
306 
307  float_quat_normalize(&quat);
308  // rotate the quaternion so Z is down
309  float_quat_comp(&tag_infos[i].tag_track_private.cam_to_tag_quat, &quat, &rot_x_quat);
310  // update filter
312  // reset timeout and status
315  break;
316  }
317  }
318  }
319 }
320 
322 {
323  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
324  // update x,y,z position from lat,lon,alt fields
325  tag_infos[i].tag_track_private.meas.x = DL_TARGET_POS_lat(buf) * TAG_TRACKING_COORD_TO_M;
326  tag_infos[i].tag_track_private.meas.y = DL_TARGET_POS_lon(buf) * TAG_TRACKING_COORD_TO_M;
327  tag_infos[i].tag_track_private.meas.z = DL_TARGET_POS_alt(buf) * TAG_TRACKING_COORD_TO_M;
328  // update filter
330  // store tag ID
331  tag_infos[i].tag_track_private.id = DL_TARGET_POS_target_id(buf);
332  // reset timeout and status
335  }
336 }
337 
338 // Update and display tracking WP
339 static void update_wp(struct tag_info* tag_info UNUSED, bool report UNUSED)
340 {
341  if (tag_info->wp_id == 0) {
342  // not associated with any WP
343  return;
344  }
345 
346  struct FloatVect3 target_pos_enu, target_pos_pred;
347  ENU_OF_TO_NED(target_pos_enu, tag_info->tag_tracking.pos); // convert local target pos to ENU
349  // when moving mode, predict tag position
350  ENU_OF_TO_NED(target_pos_pred, tag_info->tag_tracking.speed);
351  VECT2_SMUL(target_pos_pred, target_pos_pred, tag_info->tag_tracking.predict_time); // pos offset at predict_time
352  VECT2_STRIM(target_pos_pred, -TAG_TRACKING_MAX_OFFSET, TAG_TRACKING_MAX_OFFSET); // trim max offset
353  VECT3_ADD(target_pos_enu, target_pos_pred); // add prediction offset
354  }
355  struct EnuCoor_i pos_i;
356  ENU_BFP_OF_REAL(pos_i, target_pos_enu);
357  if (report) {
358  // move is a set + downlink report
360  } else {
362  }
363 }
364 
365 // Init function
367 {
368  struct FloatEulers rot_x = { M_PI, 0, 0};
370 
371  // Init structure
372  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
373  FLOAT_VECT3_ZERO(tag_infos[i].tag_track_private.meas);
377  float_quat_identity(&tag_infos[i].tag_tracking.ned_to_tag_quat);
378  struct FloatEulers euler = {
382  };
383  float_rmat_of_eulers(&tag_infos[i].tag_track_private.body_to_cam, &euler);
384  float_quat_of_eulers(&tag_infos[i].tag_track_private.body_to_cam_quat, &euler);
385  VECT3_ASSIGN(tag_infos[i].tag_track_private.cam_pos,
391 
398  }
399 
400  // reserve slots for tag_ids we are looking for, and associate wp_ids.
401  for(int i=0; i<Min(tag_tracking_wps_len, TAG_TRACKING_NB_MAX); i++) {
403  tag_infos[i].wp_id = wp_track[i].wp_id;
404  }
405 
406  // Bind to ABI message
407  AbiBindMsgJEVOIS_MSG(TAG_TRACKING_ID, &tag_track_ev, tag_track_cb);
408 }
409 
410 
411 // Propagation function
413 {
414 #if defined SITL && defined TAG_TRACKING_SIM_WP
415  if (tag_motion_sim_type != TAG_MOTION_NONE) {
416  tag_motion_sim();
417  }
418  tag_tracking_sim();
419 #endif
420  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
421  switch (tag_infos[i].tag_tracking.status) {
423  // don't propagate, wait for first detection
424  break;
426  // call kalman propagation step
428  // force speed to zero for fixed tag
429  if (tag_infos[i].tag_tracking.motion_type == TAG_TRACKING_FIXED_POS) {
430  struct FloatVect3 zero = { 0.f, 0.f, 0.f };
432  }
433  // update public structure
435  // update WP
436  update_wp(&tag_infos[i], false);
437  // increment timeout counter
439  if (tag_infos[i].tag_track_private.timeout > TAG_TRACKING_TIMEOUT) {
441  }
442  break;
443  case TAG_TRACKING_LOST:
444  // tag is lost, restart filter and wait for a new detection
446  break;
447  default:
448  break;
449  }
450  }
451 }
452 
453 // Propagation start function (called at each start state)
455 {
459 }
460 
462  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
464  }
465 }
466 
467 // Report function
469 {
470  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
471  if(tag_infos[i].tag_track_private.id == TAG_UNUSED_ID) {
472  continue;
473  }
474 #if TAG_TRACKING_DEBUG
475  float msg[] = {
476  tag_infos[i].kalman.state[0],
477  tag_infos[i].kalman.state[1],
478  tag_infos[i].kalman.state[2],
479  tag_infos[i].kalman.state[3],
480  tag_infos[i].kalman.state[4],
481  tag_infos[i].kalman.state[5],
482  (float)tag_infos[i].tag_tracking.status
483  };
484  DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, 7, msg);
485 #endif
486 
488  // compute absolute position
489  struct LlaCoor_f tag_lla;
490  struct EcefCoor_f tag_ecef;
491  ecef_of_ned_point_f(&tag_ecef, stateGetNedOrigin_f(), (struct NedCoor_f *)(&tag_infos[i].tag_tracking.pos));
492  lla_of_ecef_f(&tag_lla, &tag_ecef);
493  float lat_deg = DegOfRad(tag_lla.lat);
494  float lon_deg = DegOfRad(tag_lla.lon);
495  uint8_t id =(uint8_t)tag_infos[i].tag_track_private.id;
496  DOWNLINK_SEND_MARK(DefaultChannel, DefaultDevice, &id, &lat_deg, &lon_deg);
497  update_wp(&tag_infos[i], true);
499  }
500  }
501 }
502 
510 {
511  for (int i = 0; i < TAG_TRACKING_NB_MAX; i++) {
512  if (tag_infos[i].tag_tracking.status == TAG_TRACKING_RUNNING) {
513  // compute speed command as estimated tag speed + gain * position error
514  struct NedCoor_f pos = *stateGetPositionNed_f();
518  VECT2_STRIM(tag_infos[i].tag_tracking.speed_cmd, -TAG_TRACKING_MAX_SPEED, TAG_TRACKING_MAX_SPEED); // trim max horizontal speed
519  BoundAbs(tag_infos[i].tag_tracking.speed_cmd.z, TAG_TRACKING_MAX_VZ); // tim max vertical speed
520  }
521  else {
522  // filter is not runing, set speed command to zero
524  }
525  }
526 }
527 
529 {
530  for (int i = 0; i < TAG_TRACKING_NB_MAX; i++) {
531  if (tag_infos[i].tag_track_private.id == TAG_UNUSED_ID || tag_infos[i].tag_track_private.id == tag_id) {
532  tag_infos[i].tag_track_private.id = tag_id;
533  tag_infos[i].wp_id = wp_id;
534  return true;
535  }
536  }
537  return false; // fail to set tracker id
538 }
539 
540 // Simulate detection using a WP coordinate
541 #if defined SITL && defined TAG_TRACKING_SIM_WP
542 static void tag_tracking_sim(void)
543 {
544  // Compute image coordinates of a WP given fake camera parameters
545  struct FloatRMat *ltp_to_body_rmat = stateGetNedToBodyRMat_f();
546  struct FloatRMat ltp_to_cam_rmat;
547  float_rmat_comp(&ltp_to_cam_rmat, ltp_to_body_rmat, &tag_infos[0].tag_track_private.body_to_cam);
548  // Prepare cam world position
549  // C_w = P_w + R_w2b * C_b
550  struct FloatVect3 cam_pos_ltp;
551  float_rmat_vmult(&cam_pos_ltp, ltp_to_body_rmat, &tag_infos[0].tag_track_private.cam_pos);
552  VECT3_ADD(cam_pos_ltp, *stateGetPositionNed_f());
553  // Target
554  struct NedCoor_f target_ltp;
555  ENU_OF_TO_NED(target_ltp, waypoints[TAG_TRACKING_SIM_WP].enu_f);
556  target_ltp.z = 0.f; // force on the ground
557  // Compute target in camera frame Pc = R * (Pw - C)
558  struct FloatVect3 target_cam, tmp;
559  VECT3_DIFF(tmp, target_ltp, cam_pos_ltp);
560  float_rmat_vmult(&target_cam, &ltp_to_cam_rmat, &tmp);
561  if (fabsf(target_cam.z) > 1.) {
562  // If we are not too close from target
563  // Compute target in image frame x = X/Z, y = X/Z
564  if (fabsf(target_cam.x / target_cam.z) < 0.3f &&
565  fabsf(target_cam.y / target_cam.z) < 0.3f) {
566  // If in field of view (~tan(60)/2)
567  // send coordinates in millimeter
568  int16_t coord[3] = {
569  (int16_t) (target_cam.x * 1000.f),
570  (int16_t) (target_cam.y * 1000.f),
571  (int16_t) (target_cam.z * 1000.f)
572  };
573  uint16_t dim[3] = { 100, 100, 0 };
574  struct FloatQuat quat; // TODO
575  float_quat_identity(&quat);
576  AbiSendMsgJEVOIS_MSG(42, JEVOIS_MSG_D3, TAG_TRACKING_SIM_ID, 3, coord, dim, quat, "");
577  }
578  }
579 }
580 
581 static void tag_motion_sim(void)
582 {
583  switch (tag_motion_sim_type) {
584  case TAG_MOTION_LINE:
585  {
586  struct EnuCoor_f pos = waypoints[TAG_TRACKING_SIM_WP].enu_f;
587  struct FloatVect3 speed_dt = tag_motion_speed;
588  VECT2_SMUL(speed_dt, speed_dt, tag_track_dt);
589  if (pos.x < -TAG_MOTION_RANGE_X || pos.x > TAG_MOTION_RANGE_X ||
590  pos.y < -TAG_MOTION_RANGE_Y || pos.y > TAG_MOTION_RANGE_Y) {
591  tag_motion_speed.x = -tag_motion_speed.x;
592  tag_motion_speed.y = -tag_motion_speed.y;
593  speed_dt.x = -speed_dt.x;
594  speed_dt.y = -speed_dt.y;
595  }
596  VECT2_ADD(pos, speed_dt);
597  struct EnuCoor_i pos_i;
598  ENU_BFP_OF_REAL(pos_i, pos);
599  waypoint_move_enu_i(TAG_TRACKING_SIM_WP, &pos_i);
600  break;
601  }
602  case TAG_MOTION_CIRCLE:
603  {
604  time_circle += 1;
605  time_circle_corrected = time_circle * 0.02;
606  struct EnuCoor_f pos = waypoints[TAG_TRACKING_SIM_WP].enu_f;
607  struct FloatVect3 speed_dt = tag_motion_speed;
608  VECT2_SMUL(speed_dt, speed_dt, tag_track_dt);
609  tag_motion_speed.x = speed_circle * cos(time_circle_corrected);
610  tag_motion_speed.y = speed_circle * sin(time_circle_corrected);
611  speed_dt.x = speed_circle * cos(time_circle_corrected);;
612  speed_dt.y = speed_circle * sin(time_circle_corrected);
613  VECT2_ADD(pos, speed_dt);
614  struct EnuCoor_i pos_i;
615  ENU_BFP_OF_REAL(pos_i, pos);
616  waypoint_move_enu_i(TAG_TRACKING_SIM_WP, &pos_i);
617  }
618  default:
619  break;
620  }
621 }
622 
623 #endif
624 
625 
626 
627 
633 
634 
635 void tag_tracking_set_motion_type(float motion_type) {
636  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
637  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
638  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
639  tag_infos[i].tag_tracking.motion_type = (uint8_t)motion_type;
640  tag_tracking_motion_type = (uint8_t)motion_type;;
641  }
642  }
643 }
644 
645 void tag_tracking_set_predict_time(float predict_time) {
646  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
647  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
648  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
649  tag_infos[i].tag_tracking.predict_time = predict_time;
650  tag_tracking_predict_time = predict_time;
651  }
652  }
653 }
654 
655 void tag_tracking_set_kp(float kp) {
656  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
657  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
658  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
659  tag_infos[i].tag_tracking.kp = kp;
660  tag_tracking_kp = kp;
661  }
662  }
663 }
664 
665 void tag_tracking_set_kpz(float kpz) {
666  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
667  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
668  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
669  tag_infos[i].tag_tracking.kpz = kpz;
670  tag_tracking_kpz = kpz;
671  }
672  }
673 }
674 
676  tag_tracking_setting_id = (int)id;
677  for(int i=0; i<TAG_TRACKING_NB_MAX; i++) {
678  bool joker = (tag_tracking_setting_id == -1) && (tag_infos[i].tag_track_private.id != TAG_UNUSED_ID);
679  if(tag_infos[i].tag_track_private.id == tag_tracking_setting_id || joker) {
684  }
685  }
686 }
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:44
#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:1300
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
Definition: state.h:1294
static struct LtpDef_f * stateGetNedOrigin_f(void)
Get the coordinate NED frame origin (float)
Definition: state.h:566
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
Definition: state.h:839
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:180
int16_t tag_id
Definition: tag_tracking.c:186
void tag_tracking_propagate_start()
Definition: tag_tracking.c:461
void tag_tracking_set_kpz(float kpz)
Definition: tag_tracking.c:665
static void update_tag_position(struct tag_info *tag_info)
Definition: tag_tracking.c:250
int tag_tracking_setting_id
Definition: tag_tracking.c:628
static abi_event tag_track_ev
Definition: tag_tracking.c:211
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:288
static const float tag_track_dt
Definition: tag_tracking.c:159
#define TAG_TRACKING_TIMEOUT
Definition: tag_tracking.c:128
#define TAG_TRACKING_KP
Definition: tag_tracking.c:140
void tag_tracking_init()
Definition: tag_tracking.c:366
bool tag_tracking_set_tracker_id(int16_t tag_id, uint8_t wp_id)
Definition: tag_tracking.c:528
struct FloatVect3 meas
measured position
Definition: tag_tracking.c:163
void tag_tracking_set_kp(float kp)
Definition: tag_tracking.c:655
#define TAG_TRACKING_MAX_VZ
Definition: tag_tracking.c:152
#define TAG_TRACKING_CAM_POS_Z
Definition: tag_tracking.c:104
#define TAG_TRACKING_CAM_POS_Y
Definition: tag_tracking.c:100
struct tag_tracking_public * tag_tracking_get(int16_t tag_id)
Definition: tag_tracking.c:215
float tag_tracking_predict_time
Definition: tag_tracking.c:630
#define TAG_TRACKING_BODY_TO_CAM_THETA
Definition: tag_tracking.c:88
uint8_t tag_tracking_get_motion_type(int16_t tag_id)
Definition: tag_tracking.c:237
void tag_tracking_propagate()
Definition: tag_tracking.c:412
#define TAG_TRACKING_PREDICT_TIME
Definition: tag_tracking.c:132
#define TAG_TRACKING_Q_SIGMA2
Definition: tag_tracking.c:116
float tag_tracking_motion_type
Definition: tag_tracking.c:629
#define TAG_TRACKING_BODY_TO_CAM_PSI
Definition: tag_tracking.c:92
float timeout
timeout for lost flag [sec]
Definition: tag_tracking.c:170
void tag_tracking_set_setting_id(float id)
Definition: tag_tracking.c:675
#define TAG_TRACKING_KPZ
Definition: tag_tracking.c:144
struct FloatVect3 cam_pos
Position of camera in body frame.
Definition: tag_tracking.c:168
#define TAG_TRACKING_BODY_TO_CAM_PHI
Definition: tag_tracking.c:84
bool updated
updated state
Definition: tag_tracking.c:171
struct tag_tracking_public dummy
Definition: tag_tracking.c:202
#define TAG_TRACKING_COORD_TO_M
Definition: tag_tracking.c:108
uint8_t wp_id
Definition: tag_tracking.c:187
void tag_tracking_report()
Definition: tag_tracking.c:468
void tag_tracking_parse_target_pos(uint8_t *buf)
Definition: tag_tracking.c:321
const uint8_t tag_tracking_wps_len
Definition: tag_tracking.c:196
static void tag_tracking_propagate_start_tag(struct tag_info *tag_info)
Definition: tag_tracking.c:454
static void update_wp(struct tag_info *tag_info UNUSED, bool report UNUSED)
Definition: tag_tracking.c:339
struct FloatQuat body_to_cam_quat
Body to camera rotation in quaternion.
Definition: tag_tracking.c:167
struct tag_tracking tag_track_private
Definition: tag_tracking.c:179
void tag_tracking_set_predict_time(float predict_time)
Definition: tag_tracking.c:645
float tag_tracking_kpz
Definition: tag_tracking.c:632
#define TAG_TRACKING_P0_POS
Definition: tag_tracking.c:120
struct tag_info tag_infos[TAG_TRACKING_NB_MAX]
Definition: tag_tracking.c:200
#define TAG_TRACKING_MAX_SPEED
Definition: tag_tracking.c:148
struct FloatRMat body_to_cam
Body to camera rotation.
Definition: tag_tracking.c:166
#define TAG_UNUSED_ID
Definition: tag_tracking.c:156
struct SimpleKinematicKalman kalman
Definition: tag_tracking.c:181
uint8_t wp_id
Definition: tag_tracking.c:182
float tag_tracking_kp
Definition: tag_tracking.c:631
#define TAG_TRACKING_CAM_POS_X
Definition: tag_tracking.c:96
uint8_t tag_tracking_get_status(int16_t tag_id)
Definition: tag_tracking.c:232
#define TAG_TRACKING_MAX_OFFSET
Definition: tag_tracking.c:136
int16_t id
ID of detected tag.
Definition: tag_tracking.c:173
void tag_tracking_set_motion_type(float motion_type)
Definition: tag_tracking.c:635
#define TAG_TRACKING_P0_SPEED
Definition: tag_tracking.c:124
struct FloatQuat rot_x_quat
Definition: tag_tracking.c:204
struct wp_tracking wp_track[]
Definition: tag_tracking.c:195
#define TAG_TRACKING_ID
Definition: tag_tracking.c:208
void tag_tracking_compute_speed(void)
Control function.
Definition: tag_tracking.c:509
#define TAG_TRACKING_R
Definition: tag_tracking.c:112
float tag_tracking_get_heading(int16_t tag_id)
Definition: tag_tracking.c:242
struct FloatQuat cam_to_tag_quat
measured quat
Definition: tag_tracking.c:164
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