16#ifndef EASYNAV_SEREST_CONTROLLER__SERESTCONTROLLER_HPP_
17#define EASYNAV_SEREST_CONTROLLER__SERESTCONTROLLER_HPP_
22#include "rclcpp/time.hpp"
23#include "nav_msgs/msg/odometry.hpp"
24#include "nav_msgs/msg/path.hpp"
25#include "geometry_msgs/msg/twist_stamped.hpp"
27#include "easynav_core/ControllerMethodBase.hpp"
28#include "easynav_common/types/NavState.hpp"
78 void update_rt(NavState & nav_state)
override;
108 std::vector<Vec2> pts;
109 std::vector<double> s_acc;
119 Vec2 closest{0.0, 0.0};
129 double kappa_hat{0.0};
137 PathData build_path_data(
const nav_msgs::msg::Path & path)
const;
145 Projection project_on_path(
const PathData & pd,
const Vec2 & p)
const;
154 RefKinematics ref_heading_and_curvature(
155 const PathData & pd,
const Projection & prj,
double v_prev)
const;
167 const Vec2 & robot_xy,
double robot_yaw,
168 const Projection & prj,
double psi_ref,
169 double & e_y,
double & e_theta)
const;
180 double closest_obstacle_distance(
181 const NavState & nav_state);
189 double v_safe_from_distance(
double d,
double slope_sin = 0.0)
const;
196 double v_curvature_limit(
double kappa_hat)
const;
199 double compute_dt_and_update_clock();
203 bool fetch_required_inputs(
204 NavState & nav_state,
205 nav_msgs::msg::Path & path,
206 nav_msgs::msg::Odometry & odom);
209 void robot_state_from_odom(
210 const nav_msgs::msg::Odometry & odom,
211 Vec2 & robot_xy,
double & yaw)
const;
214 void compute_goal_zone(
215 const nav_msgs::msg::Path & path,
216 const Vec2 & robot_xy,
double robot_yaw,
217 double & dist_xy_goal,
double & e_theta_goal,
218 double & stop_r,
double & slow_r,
double & gamma_slow,
219 Vec2 & goal_xy,
double & yaw_goal)
const;
223 const NavState & nav_state,
224 const RefKinematics & rk,
225 double & d_closest,
double & v_safe,
double & v_curv);
228 void apply_corner_guard(
229 const RefKinematics & rk,
double e_y,
double e_theta,
230 double & v_prog_ref,
double & omega_boost,
double & ey_apex_term)
const;
233 bool should_turn_in_place(
234 bool allow_reverse,
double e_theta,
double e_theta_goal,
235 double dist_to_end,
double turn_in_place_thr)
const;
238 bool maybe_final_align_and_publish(
239 NavState & nav_state,
const nav_msgs::msg::Path & path,
240 double dist_xy_goal,
double stop_r,
double e_theta_goal,
241 double gamma_slow,
double dt);
244 void rate_limit_and_saturate(
double dt,
double & vlin,
double & vrot);
247 void publish_cmd_and_debug(
248 NavState & nav_state,
const nav_msgs::msg::Path & path,
249 double vlin,
double vrot,
250 double e_y,
double e_theta,
double kappa_hat,
251 double d_closest,
double v_safe,
double v_curv,
double alpha,
252 bool allow_reverse,
double dist_to_end,
253 double dist_xy_goal,
double gamma_slow,
254 int in_final_align,
int arrived);
257 void publish_stop(NavState & nav_state,
const std::string & frame_id);
262 bool allow_reverse_{
false};
264 double v_progress_min_{0.05};
266 double k_s_share_max_{0.5};
269 double max_linear_speed_{0.6};
271 double max_angular_speed_{1.5};
273 double max_linear_acc_{0.8};
275 double max_angular_acc_{2.0};
278 double k_s_{0.8}, k_theta_{2.0}, k_y_{1.2}, ell_{0.3};
287 double a_brake_{1.2};
289 double a_lat_max_{1.5};
291 double d0_margin_{0.30};
293 double tau_latency_{0.10};
295 double d_hard_{0.20};
297 double t_emerg_{0.25};
300 double blend_base_{0.6};
302 double blend_k_per_v_{0.6};
304 double kappa_max_{2.5};
307 double dist_search_radius_{2.0};
310 double goal_pos_tol_{0.05};
312 double goal_yaw_tol_deg_{5.0};
314 double slow_radius_{0.60};
316 double slow_min_speed_{0.03};
319 double final_align_k_{2.0};
321 double final_align_wmax_{0.6};
324 bool corner_guard_enable_{
true};
326 double corner_gain_ey_{1.5};
328 double corner_gain_eth_{0.7};
330 double corner_gain_kappa_{0.4};
332 double corner_min_alpha_{0.35};
334 double corner_boost_omega_{0.8};
336 double apex_ey_des_{0.05};
338 double a_lat_soft_{1.1};
342 bool startup_anchor_active_{
true};
343 geometry_msgs::msg::Pose goal_pose_last_{};
345 bool tip_active_{
false};
348 double last_vlin_{0.0};
350 double last_vrot_{0.0};
352 rclcpp::Time last_update_ts_;
354 rclcpp::Time last_input_ts_;
356 geometry_msgs::msg::TwistStamped twist_stamped_;
375 return a.
x * b.
x + a.
y * b.
y;
386 return a.
x * b.
y - a.
y * b.
x;
void update_rt(NavState &nav_state) override
Real-time control update (called ~20–30 Hz).
Definition SerestController.cpp:626
SerestController()
Default constructor.
~SerestController() override
Destructor.
void on_initialize() override
Initialize parameters and internal state.
Definition SerestController.cpp:40
Provides a mapping for often used cost values.
Definition cost_values.hpp:41
SerestController::Vec2 v2(double x, double y)
Construct a 2D vector.
Definition SerestController.hpp:365
double crossz(const SerestController::Vec2 &a, const SerestController::Vec2 &b)
2D cross product Z component (a.x*b.y - a.y*b.x).
Definition SerestController.hpp:384
double dot(const SerestController::Vec2 &a, const SerestController::Vec2 &b)
Dot product between two 2D vectors.
Definition SerestController.hpp:373
SerestController::Vec2 normalize(const SerestController::Vec2 &a)
Normalize a 2D vector, with a safe fallback for very small norms.
Definition SerestController.hpp:401
double norm(const SerestController::Vec2 &a)
Euclidean norm (length) of a 2D vector.
Definition SerestController.hpp:394
Simple 2D vector utility type.
Definition SerestController.hpp:87
Vec2 operator+(const Vec2 &b) const
Vector addition.
Definition SerestController.hpp:92
Vec2 operator*(double s) const
Scalar multiplication (vector * scalar).
Definition SerestController.hpp:96
Vec2 operator-(const Vec2 &b) const
Vector subtraction.
Definition SerestController.hpp:94
friend Vec2 operator*(double s, const Vec2 &a)
Scalar multiplication (scalar * vector).
Definition SerestController.hpp:99
double y
Y component.
Definition SerestController.hpp:89
double x
X component.
Definition SerestController.hpp:88