Skip to content

Commit d0add84

Browse files
Revert "Add goal pose to CriticData (#4812)" (#5527)
This reverts commit ad2f960.
1 parent 476d9e8 commit d0add84

23 files changed

+102
-177
lines changed

nav2_mppi_controller/include/nav2_mppi_controller/critic_data.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ namespace mppi
3232

3333
/**
3434
* @struct mppi::CriticData
35-
* @brief Data to pass to critics for scoring, including state, trajectories,
36-
* pruned path, global goal, costs, and important parameters to share
35+
* @brief Data to pass to critics for scoring, including state, trajectories, path, costs, and
36+
* important parameters to share
3737
*/
3838
struct CriticData
3939
{
4040
const models::State & state;
4141
const models::Trajectories & trajectories;
4242
const models::Path & path;
43-
const geometry_msgs::msg::Pose & goal;
4443

4544
xt::xtensor<float, 1> & costs;
4645
float & model_dt;

nav2_mppi_controller/include/nav2_mppi_controller/optimizer.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Optimizer
9090
geometry_msgs::msg::TwistStamped evalControl(
9191
const geometry_msgs::msg::PoseStamped & robot_pose,
9292
const geometry_msgs::msg::Twist & robot_speed, const nav_msgs::msg::Path & plan,
93-
const geometry_msgs::msg::Pose & goal, nav2_core::GoalChecker * goal_checker);
93+
nav2_core::GoalChecker * goal_checker);
9494

9595
/**
9696
* @brief Get the trajectories generated in a cycle for visualization
@@ -132,8 +132,7 @@ class Optimizer
132132
void prepare(
133133
const geometry_msgs::msg::PoseStamped & robot_pose,
134134
const geometry_msgs::msg::Twist & robot_speed,
135-
const nav_msgs::msg::Path & plan,
136-
const geometry_msgs::msg::Pose & goal, nav2_core::GoalChecker * goal_checker);
135+
const nav_msgs::msg::Path & plan, nav2_core::GoalChecker * goal_checker);
137136

138137
/**
139138
* @brief Obtain the main controller's parameters
@@ -251,12 +250,10 @@ class Optimizer
251250
std::array<mppi::models::Control, 4> control_history_;
252251
models::Trajectories generated_trajectories_;
253252
models::Path path_;
254-
geometry_msgs::msg::Pose goal_;
255253
xt::xtensor<float, 1> costs_;
256254

257-
CriticData critics_data_ = {
258-
state_, generated_trajectories_, path_, goal_,
259-
costs_, settings_.model_dt, false, nullptr, nullptr,
255+
CriticData critics_data_ =
256+
{state_, generated_trajectories_, path_, costs_, settings_.model_dt, false, nullptr, nullptr,
260257
std::nullopt, std::nullopt}; /// Caution, keep references
261258

262259
rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};

nav2_mppi_controller/include/nav2_mppi_controller/tools/path_handler.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ class PathHandler
8989
*/
9090
nav_msgs::msg::Path transformPath(const geometry_msgs::msg::PoseStamped & robot_pose);
9191

92-
/**
93-
* @brief Get the global goal pose transformed to the local frame
94-
* @param stamp Time to get the goal pose at
95-
* @return Transformed goal pose
96-
*/
97-
geometry_msgs::msg::PoseStamped getTransformedGoal(const builtin_interfaces::msg::Time & stamp);
98-
9992
protected:
10093
/**
10194
* @brief Transform a pose to another frame

nav2_mppi_controller/include/nav2_mppi_controller/tools/utils.hpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,27 @@ inline models::Path toTensor(const nav_msgs::msg::Path & path)
195195
* @brief Check if the robot pose is within the Goal Checker's tolerances to goal
196196
* @param global_checker Pointer to the goal checker
197197
* @param robot Pose of robot
198-
* @param goal Goal pose
198+
* @param path Path to retreive goal pose from
199199
* @return bool If robot is within goal checker tolerances to the goal
200200
*/
201201
inline bool withinPositionGoalTolerance(
202202
nav2_core::GoalChecker * goal_checker,
203203
const geometry_msgs::msg::Pose & robot,
204-
const geometry_msgs::msg::Pose & goal)
204+
const models::Path & path)
205205
{
206+
const auto goal_idx = path.x.shape(0) - 1;
207+
const auto goal_x = path.x(goal_idx);
208+
const auto goal_y = path.y(goal_idx);
209+
206210
if (goal_checker) {
207211
geometry_msgs::msg::Pose pose_tolerance;
208212
geometry_msgs::msg::Twist velocity_tolerance;
209213
goal_checker->getTolerances(pose_tolerance, velocity_tolerance);
210214

211215
const auto pose_tolerance_sq = pose_tolerance.position.x * pose_tolerance.position.x;
212216

213-
auto dx = robot.position.x - goal.position.x;
214-
auto dy = robot.position.y - goal.position.y;
217+
auto dx = robot.position.x - goal_x;
218+
auto dy = robot.position.y - goal_y;
215219

216220
auto dist_sq = dx * dx + dy * dy;
217221

@@ -227,19 +231,24 @@ inline bool withinPositionGoalTolerance(
227231
* @brief Check if the robot pose is within tolerance to the goal
228232
* @param pose_tolerance Pose tolerance to use
229233
* @param robot Pose of robot
230-
* @param goal Goal pose
234+
* @param path Path to retreive goal pose from
231235
* @return bool If robot is within tolerance to the goal
232236
*/
233237
inline bool withinPositionGoalTolerance(
234238
float pose_tolerance,
235239
const geometry_msgs::msg::Pose & robot,
236-
const geometry_msgs::msg::Pose & goal)
240+
const models::Path & path)
237241
{
238-
const double & dist_sq =
239-
std::pow(goal.position.x - robot.position.x, 2) +
240-
std::pow(goal.position.y - robot.position.y, 2);
242+
const auto goal_idx = path.x.shape(0) - 1;
243+
const auto goal_x = path.x(goal_idx);
244+
const auto goal_y = path.y(goal_idx);
245+
246+
const auto pose_tolerance_sq = pose_tolerance * pose_tolerance;
247+
248+
auto dx = robot.position.x - goal_x;
249+
auto dy = robot.position.y - goal_y;
241250

242-
const float pose_tolerance_sq = pose_tolerance * pose_tolerance;
251+
auto dist_sq = dx * dx + dy * dy;
243252

244253
if (dist_sq < pose_tolerance_sq) {
245254
return true;

nav2_mppi_controller/src/controller.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,13 @@ geometry_msgs::msg::TwistStamped MPPIController::computeVelocityCommands(
9292
last_time_called_ = clock_->now();
9393

9494
std::lock_guard<std::mutex> param_lock(*parameters_handler_->getLock());
95-
geometry_msgs::msg::Pose goal = path_handler_.getTransformedGoal(robot_pose.header.stamp).pose;
96-
9795
nav_msgs::msg::Path transformed_plan = path_handler_.transformPath(robot_pose);
9896

9997
nav2_costmap_2d::Costmap2D * costmap = costmap_ros_->getCostmap();
10098
std::unique_lock<nav2_costmap_2d::Costmap2D::mutex_t> costmap_lock(*(costmap->getMutex()));
10199

102100
geometry_msgs::msg::TwistStamped cmd =
103-
optimizer_.evalControl(robot_pose, robot_speed, transformed_plan, goal, goal_checker);
101+
optimizer_.evalControl(robot_pose, robot_speed, transformed_plan, goal_checker);
104102

105103
#ifdef BENCHMARK_TESTING
106104
auto end = std::chrono::system_clock::now();

nav2_mppi_controller/src/critics/cost_critic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void CostCritic::score(CriticData & data)
132132

133133
// If near the goal, don't apply the preferential term since the goal is near obstacles
134134
bool near_goal = false;
135-
if (utils::withinPositionGoalTolerance(near_goal_distance_, data.state.pose.pose, data.goal)) {
135+
if (utils::withinPositionGoalTolerance(near_goal_distance_, data.state.pose.pose, data.path)) {
136136
near_goal = true;
137137
}
138138

nav2_mppi_controller/src/critics/goal_angle_critic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void GoalAngleCritic::initialize()
3636
void GoalAngleCritic::score(CriticData & data)
3737
{
3838
if (!enabled_ || !utils::withinPositionGoalTolerance(
39-
threshold_to_consider_, data.state.pose.pose, data.goal))
39+
threshold_to_consider_, data.state.pose.pose, data.path))
4040
{
4141
return;
4242
}

nav2_mppi_controller/src/critics/goal_critic.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ void GoalCritic::initialize()
3636
void GoalCritic::score(CriticData & data)
3737
{
3838
if (!enabled_ || !utils::withinPositionGoalTolerance(
39-
threshold_to_consider_, data.state.pose.pose, data.goal))
39+
threshold_to_consider_, data.state.pose.pose, data.path))
4040
{
4141
return;
4242
}
4343

44-
const auto & goal_x = data.goal.position.x;
45-
const auto & goal_y = data.goal.position.y;
44+
const auto goal_idx = data.path.x.shape(0) - 1;
45+
46+
const auto goal_x = data.path.x(goal_idx);
47+
const auto goal_y = data.path.y(goal_idx);
4648

4749
const auto traj_x = xt::view(data.trajectories.x, xt::all(), xt::all());
4850
const auto traj_y = xt::view(data.trajectories.y, xt::all(), xt::all());

nav2_mppi_controller/src/critics/obstacles_critic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void ObstaclesCritic::score(CriticData & data)
138138

139139
// If near the goal, don't apply the preferential term since the goal is near obstacles
140140
bool near_goal = false;
141-
if (utils::withinPositionGoalTolerance(near_goal_distance_, data.state.pose.pose, data.goal)) {
141+
if (utils::withinPositionGoalTolerance(near_goal_distance_, data.state.pose.pose, data.path)) {
142142
near_goal = true;
143143
}
144144

nav2_mppi_controller/src/critics/path_align_critic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ void PathAlignCritic::initialize()
4646
void PathAlignCritic::score(CriticData & data)
4747
{
4848
// Don't apply close to goal, let the goal critics take over
49-
if (!enabled_ || utils::withinPositionGoalTolerance(
50-
threshold_to_consider_, data.state.pose.pose, data.goal))
49+
if (!enabled_ ||
50+
utils::withinPositionGoalTolerance(threshold_to_consider_, data.state.pose.pose, data.path))
5151
{
5252
return;
5353
}

0 commit comments

Comments
 (0)