SMACC2
Loading...
Searching...
No Matches
cb_navigate_backward.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
21#include <tf2/utils.h>
22#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
23#include <geometry_msgs/msg/quaternion_stamped.hpp>
29
30namespace cl_nav2z
31{
32using namespace ::cl_nav2z::odom_tracker;
33
35{
36 if (backwardDistance < 0)
37 {
38 RCLCPP_ERROR(getLogger(), "[CbNavigateBackwards] distance must be greater or equal than 0");
39 this->backwardDistance = 0;
40 }
41 this->backwardDistance = backwardDistance;
42}
43
45{
46 // straight motion distance
47 double dist = backwardDistance;
48
49 RCLCPP_INFO_STREAM(
50 getLogger(), "[CbNavigateBackwards] Straight backwards motion distance: " << dist);
51
53 auto referenceFrame = p->getReferenceFrame();
54 auto currentPoseMsg = p->toPoseMsg();
55 tf2::Transform currentPose;
56 tf2::fromMsg(currentPoseMsg, currentPose);
57
58 tf2::Transform backwardDeltaTransform;
59 backwardDeltaTransform.setIdentity();
60 backwardDeltaTransform.setOrigin(tf2::Vector3(-dist, 0, 0));
61
62 tf2::Transform targetPose = currentPose * backwardDeltaTransform;
63
64 ClNav2Z::Goal goal;
65 goal.pose.header.frame_id = referenceFrame;
66 //goal.pose.header.stamp = getNode()->now();
67 tf2::toMsg(targetPose, goal.pose.pose);
68 RCLCPP_INFO_STREAM(getLogger(), "[CbNavigateBackwards] TARGET POSE BACKWARDS: " << goal.pose);
69
70 geometry_msgs::msg::PoseStamped currentStampedPoseMsg;
71 currentStampedPoseMsg.header.frame_id = referenceFrame;
72 currentStampedPoseMsg.header.stamp = getNode()->now();
73 tf2::toMsg(currentPose, currentStampedPoseMsg.pose);
74
76 if (odomTracker_ != nullptr)
77 {
78 this->odomTracker_->clearPath();
79 this->odomTracker_->setStartPoint(currentStampedPoseMsg);
80 this->odomTracker_->setWorkingMode(WorkingMode::RECORD_PATH);
81 }
82
83 auto plannerSwitcher = nav2zClient_->getComponent<PlannerSwitcher>();
84 plannerSwitcher->setBackwardPlanner();
85
86 auto goalCheckerSwitcher = nav2zClient_->getComponent<GoalCheckerSwitcher>();
87 goalCheckerSwitcher->setGoalCheckerId("backward_goal_checker");
88
89 this->sendGoal(goal);
90}
91
93{
94 if (odomTracker_)
95 {
96 this->odomTracker_->setWorkingMode(WorkingMode::IDLE);
97 }
98}
99
100} // namespace cl_nav2z
cl_nav2z::odom_tracker::OdomTracker * odomTracker_
CbNavigateBackwards(float backwardDistanceMeters)
void setGoalCheckerId(std::string goal_checker_id)
void setBackwardPlanner(bool commit=true)
const std::string & getReferenceFrame() const
Definition: cp_pose.hpp:76
void setWorkingMode(WorkingMode workingMode)
void setStartPoint(const geometry_msgs::msg::PoseStamped &pose)
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
TComponent * getComponent()