SMACC
Loading...
Searching...
No Matches
cb_navigate_backward.cpp
Go to the documentation of this file.
3#include <tf/tf.h>
4#include <thread>
5
6namespace cl_move_base_z
7{
8using namespace ::cl_move_base_z::odom_tracker;
9
11{
12 if (backwardDistance < 0)
13 {
14 ROS_ERROR("cb backward: distance must be greater or equal than 0");
15 this->backwardDistance = 0;
16 }
17 this->backwardDistance = backwardDistance;
18}
19
21{
22}
23
25{
26 // straight motion distance
27 double dist;
28
30 {
31 this->getCurrentState()->param("straight_motion_distance", dist, 3.5);
32 }
33 else
34 {
35 dist = *backwardDistance;
36 }
37
38 ROS_INFO_STREAM("[CbNavigateBackwards] Straight backwards motion distance: " << dist);
39
41 auto referenceFrame = p->getReferenceFrame();
42 auto currentPoseMsg = p->toPoseMsg();
43
44 tf::Transform currentPose;
45 tf::poseMsgToTF(currentPoseMsg, currentPose);
46 tf::Transform forwardDeltaTransform;
47 forwardDeltaTransform.setIdentity();
48 forwardDeltaTransform.setOrigin(tf::Vector3(-dist, 0, 0));
49 tf::Transform targetPose = currentPose * forwardDeltaTransform;
50 ClMoveBaseZ::Goal goal;
51 goal.target_pose.header.frame_id = referenceFrame;
52 goal.target_pose.header.stamp = ros::Time::now();
53 tf::poseTFToMsg(targetPose, goal.target_pose.pose);
54 ROS_INFO_STREAM("[CbNavigateBackwards] TARGET POSE BACKWARDS: " << goal.target_pose);
55
57 if (odomTracker_ != nullptr)
58 {
59 this->odomTracker_->clearPath();
60 this->odomTracker_->setStartPoint(currentPoseMsg);
61 this->odomTracker_->setWorkingMode(WorkingMode::RECORD_PATH);
62 }
63
64 auto plannerSwitcher = moveBaseClient_->getComponent<PlannerSwitcher>();
65 plannerSwitcher->setBackwardPlanner();
66 // this wait might be needed to let the backward planner receive the last forward message from the odom tracker
67 ros::Duration(0.5).sleep();
68
70}
71
73{
74 if (odomTracker_)
75 {
76 this->odomTracker_->setWorkingMode(WorkingMode::IDLE);
77 }
78}
79
80} // namespace cl_move_base_z
cl_move_base_z::odom_tracker::OdomTracker * odomTracker_
boost::optional< float > backwardDistance
const std::string & getReferenceFrame() const
Definition: cp_pose.h:39
void setStartPoint(const geometry_msgs::PoseStamped &pose)
void setWorkingMode(WorkingMode workingMode)
TComponent * getComponent()
bool param(std::string param_name, T &param_val, const T &default_val) const