|
| 1 | +#ifndef REFERENCE_FILTER_DP_QUAT__LIB__WAYPOINT_FOLLOWER_HPP_ |
| 2 | +#define REFERENCE_FILTER_DP_QUAT__LIB__WAYPOINT_FOLLOWER_HPP_ |
| 3 | + |
| 4 | +#include <mutex> |
| 5 | +#include <vortex/utils/types.hpp> |
| 6 | +#include "reference_filter_dp_quat/lib/eigen_typedefs.hpp" |
| 7 | +#include "reference_filter_dp_quat/lib/reference_filter.hpp" |
| 8 | +#include "reference_filter_dp_quat/lib/waypoint_types.hpp" |
| 9 | + |
| 10 | +namespace vortex::guidance { |
| 11 | + |
| 12 | +using vortex::utils::types::PoseEuler; |
| 13 | +using vortex::utils::types::Twist; |
| 14 | + |
| 15 | +/** |
| 16 | + * @brief Manages reference filter state and waypoint following logic. |
| 17 | + * |
| 18 | + * Thread-safe: all public methods acquire a mutex. |
| 19 | + */ |
| 20 | +class WaypointFollower { |
| 21 | + public: |
| 22 | + WaypointFollower(const ReferenceFilterParams& params, double dt_seconds); |
| 23 | + |
| 24 | + /** |
| 25 | + * @brief Initialize the follower with the current vehicle state and target. |
| 26 | + * @param pose Current vehicle pose. |
| 27 | + * @param twist Current vehicle twist (body frame). |
| 28 | + * @param waypoint Target waypoint with mode. |
| 29 | + * @param convergence_threshold Max error norm to consider target reached. |
| 30 | + */ |
| 31 | + void start(const PoseEuler& pose, |
| 32 | + const Twist& twist, |
| 33 | + const Waypoint& waypoint, |
| 34 | + double convergence_threshold); |
| 35 | + |
| 36 | + /** |
| 37 | + * @brief Advance the filter by one time step. |
| 38 | + * @return The updated filter state. |
| 39 | + */ |
| 40 | + Eigen::Vector18d step(); |
| 41 | + |
| 42 | + /** |
| 43 | + * @brief Check if the measured pose has converged to the reference goal. |
| 44 | + * @param measured_pose Current measured pose. |
| 45 | + * @return True if the error norm is within the convergence threshold. |
| 46 | + */ |
| 47 | + bool within_convergance(const Eigen::Vector6d& measured_pose) const; |
| 48 | + |
| 49 | + /** |
| 50 | + * @brief Update the reference goal pose mid-sequence. |
| 51 | + * @param reference_goal_pose The new reference pose. |
| 52 | + */ |
| 53 | + void set_reference(const PoseEuler& reference_goal_pose); |
| 54 | + |
| 55 | + /** |
| 56 | + * @brief Snap the position component of the filter state to the reference. |
| 57 | + * |
| 58 | + * Useful after convergence to eliminate any remaining steady-state offset |
| 59 | + */ |
| 60 | + void snap_state_to_reference(); |
| 61 | + |
| 62 | + /// @brief Get the current 18D filter state. |
| 63 | + Eigen::Vector18d state() const; |
| 64 | + |
| 65 | + /// @brief Get the current 6D reference goal pose. |
| 66 | + Eigen::Vector6d reference() const; |
| 67 | + |
| 68 | + private: |
| 69 | + Eigen::Vector18d compute_initial_state(const PoseEuler& pose, |
| 70 | + const Twist& twist); |
| 71 | + |
| 72 | + mutable std::mutex mutex_; |
| 73 | + ReferenceFilter filter_; |
| 74 | + double dt_seconds_{0.01}; |
| 75 | + Eigen::Vector18d state_ = Eigen::Vector18d::Zero(); |
| 76 | + Eigen::Vector6d reference_goal_ = Eigen::Vector6d::Zero(); |
| 77 | + WaypointMode waypoint_mode_{WaypointMode::FULL_POSE}; |
| 78 | + double convergence_threshold_{0.1}; |
| 79 | +}; |
| 80 | + |
| 81 | +} // namespace vortex::guidance |
| 82 | + |
| 83 | +#endif // REFERENCE_FILTER_DP_QUAT__LIB__WAYPOINT_FOLLOWER_HPP_ |
0 commit comments