SMACC2
cb_undo_path_backwards.cpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
26
27namespace cl_nav2z
28{
29using ::cl_nav2z::odom_tracker::OdomTracker;
31
32using namespace std::chrono_literals;
33
35{
36 listener = std::make_shared<tf2_ros::Buffer>(this->getNode()->get_clock());
37 auto * odomTracker = moveBaseClient_->getComponent<OdomTracker>();
38
39 auto plannerSwitcher = moveBaseClient_->getComponent<PlannerSwitcher>();
40
41 nav_msgs::msg::Path forwardpath = odomTracker->getPath();
42 // RCLCPP_INFO_STREAM(getLogger(),"[UndoPathBackward] Current path backwards: " << forwardpath);
43
44 odomTracker->setWorkingMode(WorkingMode::CLEAR_PATH);
45
46 ClNav2Z::Goal goal;
47
48 auto goalCheckerSwitcher = moveBaseClient_->getComponent<GoalCheckerSwitcher>();
49 goalCheckerSwitcher->setGoalCheckerId("undo_path_backwards_goal_checker");
50
51 // WARNING: There might be some race condition with the remote undo global planner were the global path was not received yet
52 rclcpp::sleep_for(1s);
53
54 // this line is used to flush/reset backward planner in the case it were already there
55 // plannerSwitcher->setDefaultPlanners();
56 if (forwardpath.poses.size() > 0)
57 {
58 goal.pose = forwardpath.poses.front();
59 goal.pose.header.stamp = getNode()->now();
60 plannerSwitcher->setUndoPathBackwardPlanner();
62 }
63}
64
66{
67 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Exiting: undo navigation ");
68
69 if (this->navigationResult_ == rclcpp_action::ResultCode::SUCCEEDED)
70 {
71 RCLCPP_INFO_STREAM(
72 getLogger(),
73 getName() << " - Exiting: undo navigation successful, popping odom tracker path");
74 auto * odomTracker = moveBaseClient_->getComponent<OdomTracker>();
75 odomTracker->popPath();
76 }
77 else
78 {
79 // navigation interrupted or aborted. The path may be not totally undone.
80 // We keep the odom tracker in its current state, probably in the middle of the undoing process.
81 // Could you try to repeat the behavior?
82 }
83}
84
85} // namespace cl_nav2z
std::shared_ptr< tf2_ros::Buffer > listener
void setGoalCheckerId(std::string goal_checker_id)
void popPath(int pathCount=1, bool keepPreviousPath=false)
virtual rclcpp::Node::SharedPtr getNode()
TComponent * getComponent()
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal)