SMACC
Loading...
Searching...
No Matches
cb_absolute_rotate.cpp
Go to the documentation of this file.
1
5
6namespace cl_move_base_z
7{
9{
10}
11
12CbAbsoluteRotate::CbAbsoluteRotate(float absoluteGoalAngleDegree, float yaw_goal_tolerance)
13{
14 this->absoluteGoalAngleDegree = absoluteGoalAngleDegree;
15
16 if (yaw_goal_tolerance >= 0)
17 {
18 this->yawGoalTolerance = yaw_goal_tolerance;
19 }
20}
21
23{
24 dynamic_reconfigure::ReconfigureRequest srv_req;
25 dynamic_reconfigure::ReconfigureResponse srv_resp;
26 dynamic_reconfigure::Config conf;
27
28 ros::NodeHandle nh;
29 std::string nodename = "/move_base";
30 std::string localPlannerName;
31 dynamic_reconfigure::DoubleParameter yaw_goal_tolerance;
32 yaw_goal_tolerance.name = "yaw_goal_tolerance";
33
34 dynamic_reconfigure::DoubleParameter max_vel_theta;
35 dynamic_reconfigure::DoubleParameter min_vel_theta;
36 bool isRosBasePlanner = !spinningPlanner || *spinningPlanner == SpiningPlanner::Default;
37 bool isPureSpinningPlanner = spinningPlanner && *spinningPlanner == SpiningPlanner::PureSpinning;
38
39 if (isPureSpinningPlanner)
40 {
41 localPlannerName = "PureSpinningLocalPlanner";
42 max_vel_theta.name = "max_angular_z_speed";
43 min_vel_theta.name = "min_vel_theta";
44 }
45 else if (isRosBasePlanner)
46 {
47 localPlannerName = "TrajectoryPlannerROS";
48 max_vel_theta.name = "max_vel_theta";
49 min_vel_theta.name = "min_vel_theta";
50 }
51
52 if (!undo)
53 {
55 {
56 // save old yaw tolerance
57 nh.getParam(nodename + "/" + localPlannerName + "/yaw_goal_tolerance", oldYawTolerance);
58 yaw_goal_tolerance.value = *yawGoalTolerance;
59 conf.doubles.push_back(yaw_goal_tolerance);
60 ROS_INFO("[CbAbsoluteRotate] updating yaw tolerance local planner to: %lf, from previous value: %lf ",
62 }
63
64 if (maxVelTheta)
65 {
66 if (isRosBasePlanner)
67 {
68 // save old yaw tolerance
69 // nh.getParam(nodename + "/" + localPlannerName+"/min_vel_theta", oldMinVelTheta);
70 nh.getParam(nodename + "/" + localPlannerName + "/max_vel_theta", oldMaxVelTheta);
71 }
72 max_vel_theta.value = *maxVelTheta;
73 min_vel_theta.value = -*maxVelTheta;
74 conf.doubles.push_back(max_vel_theta);
75 conf.doubles.push_back(min_vel_theta);
76 ROS_INFO("[CbAbsoluteRotate] updating max vel theta local planner to: %lf, from previous value: %lf ",
78 ROS_INFO("[CbAbsoluteRotate] updating min vel theta local planner to: %lf, from previous value: %lf ",
80 }
81 }
82 else
83 {
85 {
86 yaw_goal_tolerance.value = oldYawTolerance;
87 conf.doubles.push_back(yaw_goal_tolerance);
88 ROS_INFO("[CbAbsoluteRotate] restoring yaw tolerance local planner from: %lf, to previous value: %lf ",
90 }
91
92 if (maxVelTheta)
93 {
94 if (isRosBasePlanner)
95 {
96 max_vel_theta.value = oldMaxVelTheta;
97 min_vel_theta.value = oldMinVelTheta;
98 }
99
100 conf.doubles.push_back(max_vel_theta);
101 conf.doubles.push_back(min_vel_theta);
102 ROS_INFO("[CbAbsoluteRotate] restoring max vel theta local planner from: %lf, to previous value: %lf ",
104 ROS_INFO("[CbAbsoluteRotate] restoring min vel theta local planner from: %lf, to previous value: %lf ",
105 -(*maxVelTheta), this->oldMinVelTheta);
106 }
107 }
108
109 srv_req.config = conf;
110 bool res;
111 do
112 {
113 std::string servername = nodename + "/" + localPlannerName + "/set_parameters";
114 res = ros::service::call(servername, srv_req, srv_resp);
115 ROS_INFO_STREAM("[CbAbsoluteRotate] dynamic configure call [" << servername << "]: " << res);
116 ros::spinOnce();
117 if (!res)
118 {
119 ros::Duration(0.1).sleep();
120 ROS_INFO("[CbAbsoluteRotate] Failed, retrtying call");
121 }
122 } while (!res);
123}
124
126{
128 {
129 }
130 else
131 {
132 }
133
135}
136
138{
139 double goal_angle;
140 ROS_INFO_STREAM("[CbAbsoluteRotate] Absolute yaw Angle:" << this->absoluteGoalAngleDegree);
141
142 if (!this->absoluteGoalAngleDegree)
143 {
144 this->getCurrentState()->param("goal_angle", goal_angle, 45.0);
145 }
146 else
147 {
148 goal_angle = *this->absoluteGoalAngleDegree;
149 }
150
151 auto plannerSwitcher = moveBaseClient_->getComponent<PlannerSwitcher>();
152 // this should work better with a coroutine and await
153 // this->plannerSwitcher_->setForwardPlanner();
154
156 plannerSwitcher->setPureSpinningPlanner();
157 else
158 plannerSwitcher->setDefaultPlanners();
159
161
163 auto referenceFrame = p->getReferenceFrame();
164 auto currentPoseMsg = p->toPoseMsg();
165
166 ClMoveBaseZ::Goal goal;
167 goal.target_pose.header.frame_id = referenceFrame;
168 goal.target_pose.header.stamp = ros::Time::now();
169
170 auto currentAngle = tf::getYaw(currentPoseMsg.orientation);
171 auto targetAngle = goal_angle * M_PI / 180.0;
172 goal.target_pose.pose.position = currentPoseMsg.position;
173 goal.target_pose.pose.orientation = tf::createQuaternionMsgFromYaw(targetAngle);
174
176 if (odomTracker_ != nullptr)
177 {
178 odomTracker_->pushPath("PureSpinningToAbsoluteGoalOrientation");
179 odomTracker_->setStartPoint(p->toPoseStampedMsg());
180 odomTracker_->setWorkingMode(odom_tracker::WorkingMode::RECORD_PATH);
181 }
182
183 ROS_INFO_STREAM("[CbAbsoluteRotate] current pose: " << currentPoseMsg);
184 ROS_INFO_STREAM("[CbAbsoluteRotate] goal pose: " << goal.target_pose.pose);
186}
187} // namespace cl_move_base_z
boost::optional< SpiningPlanner > spinningPlanner
boost::optional< float > yawGoalTolerance
boost::optional< float > maxVelTheta
boost::optional< float > absoluteGoalAngleDegree
const std::string & getReferenceFrame() const
Definition: cp_pose.h:39
This class track the required distance of the cord based on the external localization system.
Definition: odom_tracker.h:47
void pushPath(std::string newPathTagName="")
TComponent * getComponent()
bool param(std::string param_name, T &param_val, const T &default_val) const