SMACC
Loading...
Searching...
No Matches
cb_undo_path_backwards2.cpp
Go to the documentation of this file.
4
5namespace cl_move_base_z
6{
7template <typename T>
8int sgn(T val)
9{
10 return (T(0) < val) - (val < T(0));
11}
12
13using namespace ::cl_move_base_z::odom_tracker;
14
16{
17 triggerThreshold_ = 0.01; // 10 mm
18}
19
21{
23
24 auto plannerSwitcher = moveBaseClient_->getComponent<PlannerSwitcher>();
26
27 nav_msgs::Path forwardpath = odomTracker_->getPath();
28 // ROS_INFO_STREAM("[UndoPathBackward] Current path backwards: " << forwardpath);
29
30 odomTracker_->setWorkingMode(WorkingMode::CLEAR_PATH);
31
32 // this line is used to flush/reset backward planner in the case it were already there
33 // plannerSwitcher->setDefaultPlanners();
34 if (forwardpath.poses.size() > 0)
35 {
36 goal_.target_pose = forwardpath.poses.front();
38 plannerSwitcher->setUndoPathBackwardsPlannerConfiguration();
40 }
41}
42
43// bool points_on_same_side_of_line(const Vector2d &p1, const Vector2d &p2, const Vector2d &p_line, const Vector2d &normal)
44// {
45// return normal.dot(p1 - p_line)*normal.dot(p2 - p_line) > 0.0f;
46// }
47
48float CbUndoPathBackwards2::evalPlaneSide(const geometry_msgs::Pose& pose)
49{
50 // check the line was passed
51 // y = mx x + y0
52 // y = (sin(alpha)/cos(alpha)) (x -x0) + y0
53 // cos(alpha)(y - y0) - sin(alpha) (x -x0)= 0 // if greater one side if lower , the other
54 auto y = pose.position.y;
55 auto x = pose.position.x;
56 auto alpha = tf::getYaw(goal_.target_pose.pose.orientation);
57 auto y0 = goal_.target_pose.pose.position.y;
58 auto x0 = goal_.target_pose.pose.position.x;
59
60 auto evalimplicit = cos(alpha) * (y - y0) - sin (alpha) * (x - x0);
61 return evalimplicit;
62}
63
65{
66 auto pose = robotPose_->toPoseMsg();
67
68 float evalimplicit = evalPlaneSide(pose);
69 if (sgn(evalimplicit) != sgn(initial_plane_side_))
70 {
71 ROS_WARN_STREAM("[CbUndoPathBackwards2] goal_ line passed: "
72 << evalimplicit << "/" << this->initial_plane_side_);
73
74 if (fabs(evalimplicit) > triggerThreshold_ /*meters*/)
75 {
76 ROS_WARN_STREAM("[CbUndoPathBackwards2] virtual goal line passed, stopping behavior and success: "
77 << evalimplicit << "/" << this->initial_plane_side_);
79 // this->postSuccessEvent();
81 }
82 }
83 else
84 {
85 ROS_INFO_STREAM_THROTTLE(1.0, "[CbUndoPathBackwards2] goal_ line not passed yet: " << evalimplicit << "/"
86 << this->initial_plane_side_);
87 }
88}
89
91{
92 double phi = tf::getYaw(goal_.target_pose.pose.orientation);
93 visualization_msgs::Marker marker;
94 marker.header.frame_id = robotPose_->getReferenceFrame();
95
96 marker.header.stamp = ros::Time::now();
97 marker.ns = "my_namespace2";
98 marker.id = 0;
99 marker.type = visualization_msgs::Marker::SPHERE;
100 marker.action = visualization_msgs::Marker::ADD;
101 marker.scale.x = 3;
102 marker.scale.y = 3;
103 marker.scale.z = 3;
104 marker.color.a = 1.0;
105 marker.color.r = 1.0;
106 marker.color.g = 0.0;
107 marker.color.b = 0.0;
108
109 marker.pose = goal_.target_pose.pose;
110
111 // geometry_msgs::Point start, end;
112 // start.x = pose.position.x;
113 // start.y = pose.position.y;
114
115 // end.x = pose.position.x + 0.5 * cos(phi);
116 // end.y = pose.position.y + 0.5 * sin(phi);
117
118 // marker.points.push_back(start);
119 // marker.points.push_back(end);
120
121 visualization_msgs::MarkerArray ma;
122 ma.markers.push_back(marker);
123
124 this->visualizationMarkersPub_.publish(ma);
125}
126
128{
129 auto* odomTracker = moveBaseClient_->getComponent<OdomTracker>();
130 odomTracker->popPath();
131}
132
133} // namespace cl_move_base_z
odom_tracker::OdomTracker * odomTracker_
float evalPlaneSide(const geometry_msgs::Pose &pose)
geometry_msgs::Pose toPoseMsg()
Definition: cp_pose.h:27
const std::string & getReferenceFrame() const
Definition: cp_pose.h:39
void setWorkingMode(WorkingMode workingMode)
TComponent * getComponent()