2323#include < algorithm>
2424#include < limits>
2525#include < cmath>
26+ #include < numbers>
2627
2728#include " tf2/utils.hpp"
2829#include " tf2_geometry_msgs/tf2_geometry_msgs.hpp"
@@ -401,17 +402,16 @@ SerestController::compute_goal_zone(
401402 double & stop_r, double & slow_r, double & gamma_slow,
402403 Vec2 & goal_xy, double & yaw_goal) const
403404{
404- const double PI = 3.14159265358979323846 ;
405- const double goal_yaw_tol = goal_yaw_tol_deg_ * PI / 180.0 ; // (no se devuelve, pero útil si quieres)
406- (void )goal_yaw_tol;
407-
408405 const auto & pgoal = path.poses .back ().pose .position ;
409406 yaw_goal = tf2::getYaw (path.poses .back ().pose .orientation );
410407 goal_xy = Vec2{pgoal.x , pgoal.y };
411408
412409 dist_xy_goal = std::hypot (robot_xy.x - goal_xy.x , robot_xy.y - goal_xy.y );
413410 e_theta_goal = std::atan2 (std::sin (robot_yaw - yaw_goal), std::cos (robot_yaw - yaw_goal));
414411
412+ // Use externally provided goal position tolerance when available (via update_rt),
413+ // which stores it in goal_pos_tol_. Here we only shape the radial zone using
414+ // the current value of goal_pos_tol_ as stop radius.
415415 stop_r = std::max (0.0 , goal_pos_tol_);
416416 slow_r = std::max (slow_radius_, stop_r + 0.05 );
417417
@@ -482,8 +482,7 @@ SerestController::should_turn_in_place(
482482{
483483 // Mantenemos compatibilidad con la firma, pero ignoramos turn_in_place_thr
484484 // y usamos dos umbrales internos sin exponer parámetros.
485- const double PI = 3.14159265358979323846 ;
486- const double thr_enter = 60.0 * PI / 180.0 ; // entra a girar si |e_theta| > 60°
485+ const double thr_enter = 60.0 * std::numbers::pi / 180.0 ; // entra a girar si |e_theta| > 60°
487486 // const double thr_exit = 35.0 * PI / 180.0; // sale de girar si |e_theta| < 35°
488487
489488 // No permitimos “atajo” marcha atrás en esta decisión: si no permites reverse,
@@ -506,8 +505,7 @@ SerestController::maybe_final_align_and_publish(
506505 double dist_xy_goal, double stop_r, double e_theta_goal,
507506 double gamma_slow, double dt)
508507{
509- const double PI = 3.14159265358979323846 ;
510- const double goal_yaw_tol = goal_yaw_tol_deg_ * PI / 180.0 ;
508+ const double goal_yaw_tol = goal_yaw_tol_deg_ * std::numbers::pi / 180.0 ;
511509
512510 if (dist_xy_goal > stop_r) {
513511 return false ;
@@ -620,6 +618,16 @@ SerestController::update_rt(NavState & nav_state)
620618 nav_msgs::msg::Odometry odom;
621619 if (!fetch_required_inputs (nav_state, path, odom)) {return ;}
622620
621+ // 1.5) Goal tolerances: prefer shared GoalManager values, fallback to local params
622+ double goal_pos_tol = goal_pos_tol_;
623+ double goal_yaw_tol = goal_yaw_tol_deg_ * (std::numbers::pi / 180.0 );
624+ if (nav_state.has (" goal_tolerance.position" )) {
625+ goal_pos_tol = nav_state.get <double >(" goal_tolerance.position" );
626+ }
627+ if (nav_state.has (" goal_tolerance.yaw" )) {
628+ goal_yaw_tol = nav_state.get <double >(" goal_tolerance.yaw" );
629+ }
630+
623631 // 2) Robot state (position + yaw)
624632 Vec2 robot_xy; double yaw = 0.0 ;
625633 robot_state_from_odom (odom, robot_xy, yaw);
@@ -714,8 +722,7 @@ SerestController::update_rt(NavState & nav_state)
714722 double v_prog_ref = v_prog_ref_free * gamma_slow;
715723
716724 // Maintain a small cruising speed when roughly aligned and outside the stop zone (no reverse)
717- const double PI = 3.14159265358979323846 ;
718- const double align_thr = 30.0 * PI / 180.0 ;
725+ const double align_thr = 30.0 * std::numbers::pi / 180.0 ;
719726 if (!allow_reverse_ && (dist_xy_goal > stop_r) && std::fabs (e_theta) < align_thr) {
720727 v_prog_ref = std::max (v_prog_ref, std::min (slow_min_speed_, v_prog_ref_free));
721728 }
@@ -766,7 +773,7 @@ SerestController::update_rt(NavState & nav_state)
766773
767774 // Optional classic TiP safeguard using the same angular threshold
768775 {
769- const double turn_in_place_thr = (60.0 * PI / 180.0 );
776+ const double turn_in_place_thr = (60.0 * std::numbers::pi / 180.0 );
770777 const double s_total = pd.s_acc .back ();
771778 const double dist_to_end = s_total - prj.s_star ;
772779
0 commit comments