diff --git a/conf/modules/tag_tracking.xml b/conf/modules/tag_tracking.xml
index 1c9f7172a0..c45b88d415 100644
--- a/conf/modules/tag_tracking.xml
+++ b/conf/modules/tag_tracking.xml
@@ -22,6 +22,10 @@
+
+
+
+
@@ -29,6 +33,8 @@
+
+
diff --git a/sw/airborne/modules/computer_vision/tag_tracking.c b/sw/airborne/modules/computer_vision/tag_tracking.c
index 526982e95f..96cfeccfa1 100644
--- a/sw/airborne/modules/computer_vision/tag_tracking.c
+++ b/sw/airborne/modules/computer_vision/tag_tracking.c
@@ -127,13 +127,29 @@ float speed_circle = 0.03;
#endif
#ifndef TAG_TRACKING_PREDICT_TIME
-#define TAG_TRACKING_PREDICT_TIME 1.5f
+#define TAG_TRACKING_PREDICT_TIME 1.f
#endif
#ifndef TAG_TRACKING_MAX_OFFSET
#define TAG_TRACKING_MAX_OFFSET 2.0f
#endif
+#ifndef TAG_TRACKING_KP
+#define TAG_TRACKING_KP 0.5f
+#endif
+
+#ifndef TAG_TRACKING_KPZ
+#define TAG_TRACKING_KPZ 0.2f
+#endif
+
+#ifndef TAG_TRACKING_MAX_SPEED
+#define TAG_TRACKING_MAX_SPEED 4.f
+#endif
+
+#ifndef TAG_TRACKING_MAX_VZ
+#define TAG_TRACKING_MAX_VZ 2.f
+#endif
+
// generated in modules.h
static const float tag_track_dt = TAG_TRACKING_PROPAGATE_PERIOD;
@@ -233,7 +249,7 @@ void tag_tracking_parse_target_pos(uint8_t *buf)
}
// Update and display tracking WP
-static void update_wp(bool report)
+static void update_wp(bool report UNUSED)
{
#ifdef TAG_TRACKING_WP
struct FloatVect3 target_pos_enu, target_pos_pred;
@@ -263,6 +279,7 @@ void tag_tracking_init()
FLOAT_VECT3_ZERO(tag_track_private.meas);
FLOAT_VECT3_ZERO(tag_tracking.pos);
FLOAT_VECT3_ZERO(tag_tracking.speed);
+ FLOAT_VECT3_ZERO(tag_tracking.speed_cmd);
struct FloatEulers euler = {
TAG_TRACKING_BODY_TO_CAM_PHI,
TAG_TRACKING_BODY_TO_CAM_THETA,
@@ -273,6 +290,8 @@ void tag_tracking_init()
TAG_TRACKING_CAM_POS_X,
TAG_TRACKING_CAM_POS_Y,
TAG_TRACKING_CAM_POS_Z);
+ tag_tracking.kp = TAG_TRACKING_KP;
+ tag_tracking.kpz = TAG_TRACKING_KPZ;
// Bind to ABI message
AbiBindMsgJEVOIS_MSG(TAG_TRACKING_ID, &tag_track_ev, tag_track_cb);
@@ -365,6 +384,28 @@ void tag_tracking_report()
}
}
+/** Control function
+ *
+ * calling this function only updates the command vector
+ * it can be applied to the guidance control using the guided mode
+ * or from the flight plan with 'guided' instruction
+ */
+void tag_tracking_compute_speed(void)
+{
+ if (tag_tracking.status == TAG_TRACKING_RUNNING) {
+ // compute speed command as estimated tag speed + gain * position error
+ struct NedCoor_f pos = *stateGetPositionNed_f();
+ tag_tracking.speed_cmd.x = tag_tracking.speed.x + tag_tracking.kp * (tag_tracking.pos.x - pos.x);
+ tag_tracking.speed_cmd.y = tag_tracking.speed.y + tag_tracking.kp * (tag_tracking.pos.y - pos.y);
+ tag_tracking.speed_cmd.z = tag_tracking.speed.z + tag_tracking.kpz * (tag_tracking.pos.z - pos.z);
+ VECT2_STRIM(tag_tracking.speed_cmd, -TAG_TRACKING_MAX_SPEED, TAG_TRACKING_MAX_SPEED); // trim max horizontal speed
+ BoundAbs(tag_tracking.speed_cmd.z, TAG_TRACKING_MAX_VZ); // tim max vertical speed
+ }
+ else {
+ // filter is not runing, set speed command to zero
+ FLOAT_VECT3_ZERO(tag_tracking.speed_cmd);
+ }
+}
// Simulate detection using a WP coordinate
#if defined SITL && defined TAG_TRACKING_SIM_WP
diff --git a/sw/airborne/modules/computer_vision/tag_tracking.h b/sw/airborne/modules/computer_vision/tag_tracking.h
index 2c895606cb..be0a80faca 100644
--- a/sw/airborne/modules/computer_vision/tag_tracking.h
+++ b/sw/airborne/modules/computer_vision/tag_tracking.h
@@ -31,6 +31,7 @@
#include "std.h"
#include "math/pprz_algebra_float.h"
+#include "math/pprz_geodetic_float.h"
// Searching status
#define TAG_TRACKING_SEARCHING 0
@@ -49,6 +50,9 @@ struct tag_tracking_public {
uint8_t status; ///< tracking status flag
uint8_t motion_type; ///< type of tag motion
float predict_time; ///< prediction time for WP tag
+ struct NedCoor_f speed_cmd; ///< speed command to track the tag position
+ float kp; ///< horizontal tracking command gain
+ float kpz; ///< vertical tracking command gain
};
extern struct tag_tracking_public tag_tracking;
@@ -58,6 +62,7 @@ extern void tag_tracking_propagate(void);
extern void tag_tracking_propagate_start(void);
extern void tag_tracking_report(void);
extern void tag_tracking_parse_target_pos(uint8_t *buf);
+extern void tag_tracking_compute_speed(void);
#endif // TAG_TRACKING_H