28#include <rclcpp/parameter_client.hpp>
37 if (yaw_goal_tolerance >= 0)
48 RCLCPP_INFO_STREAM(
getLogger(),
"[CbAbsoluteRotate] Absolute yaw Angle:" << goal_angle);
60 plannerSwitcher->setDefaultPlanners();
67 auto currentPoseMsg = p->toPoseMsg();
70 goal.pose.header.frame_id = referenceFrame;
73 auto targetAngle = goal_angle * M_PI / 180.0;
74 goal.pose.pose.position = currentPoseMsg.position;
76 q.setRPY(0, 0, targetAngle);
77 goal.pose.pose.orientation = tf2::toMsg(q);
80 if (odomTracker_ !=
nullptr)
83 odomTracker_->pushPath(pathname);
84 odomTracker_->setStartPoint(p->toPoseStampedMsg());
93 "[" <<
getName() <<
"] current pose yaw: " << tf2::getYaw(currentPoseMsg.orientation));
96 "[" <<
getName() <<
"] goal pose yaw: " << tf2::getYaw(goal.pose.pose.orientation));
104 std::string nodename =
"/controller_server";
106 auto parameters_client =
107 std::make_shared<rclcpp::AsyncParametersClient>(this->
getNode(), nodename);
110 log,
"[" <<
getName() <<
"] using a parameter client to update some controller parameters: "
111 << nodename <<
". Waiting service.");
112 parameters_client->wait_for_service();
114 RCLCPP_INFO_STREAM(log,
"[" <<
getName() <<
"] Service found: " << nodename <<
".");
116 std::string localPlannerName;
117 std::vector<rclcpp::Parameter> parameters;
120 rclcpp::Parameter yaw_goal_tolerance(
"goal_checker.yaw_goal_tolerance");
122 rclcpp::Parameter max_vel_theta, min_vel_theta;
128 if (isPureSpinningPlanner)
130 localPlannerName =
"PureSpinningLocalPlanner";
131 max_vel_theta = rclcpp::Parameter(localPlannerName +
".max_angular_z_speed");
132 min_vel_theta = rclcpp::Parameter(localPlannerName +
".min_vel_theta");
134 else if (isRosBasePlanner)
136 localPlannerName =
"FollowPath";
137 max_vel_theta = rclcpp::Parameter(localPlannerName +
".max_vel_theta");
138 min_vel_theta = rclcpp::Parameter(localPlannerName +
".min_vel_theta");
146 auto fut = parameters_client->get_parameters(
147 {localPlannerName +
".yaw_goal_tolerance"},
148 [&](
auto futureParameters)
150 auto params = futureParameters.get();
157 yaw_goal_tolerance = rclcpp::Parameter(
"goal_checker.yaw_goal_tolerance", *
yawGoalTolerance);
158 parameters.push_back(yaw_goal_tolerance);
167 if (isRosBasePlanner)
173 auto fut = parameters_client->get_parameters(
174 {localPlannerName +
".max_vel_theta"},
175 [&](
auto futureParameters)
177 auto params = futureParameters.get();
185 max_vel_theta = rclcpp::Parameter(localPlannerName +
".max_vel_theta", *
maxVelTheta);
186 min_vel_theta = rclcpp::Parameter(localPlannerName +
".min_vel_theta", -*
maxVelTheta);
187 parameters.push_back(max_vel_theta);
188 parameters.push_back(min_vel_theta);
191 log,
"[" <<
getName() <<
"] updating max vel theta local planner to: " << *
maxVelTheta
194 log,
"[" <<
getName() <<
"] updating min vel theta local planner to: " << -*
maxVelTheta
202 yaw_goal_tolerance = rclcpp::Parameter(
"goal_checker.yaw_goal_tolerance",
oldYawTolerance);
204 log,
"[" <<
getName() <<
"] restoring yaw tolerance local planner from: "
210 if (isRosBasePlanner)
212 max_vel_theta = rclcpp::Parameter(localPlannerName +
".max_vel_theta",
oldMaxVelTheta);
213 min_vel_theta = rclcpp::Parameter(localPlannerName +
".max_vel_theta",
oldMinVelTheta);
216 parameters.push_back(max_vel_theta);
217 parameters.push_back(min_vel_theta);
219 log,
"[" <<
getName() <<
"] restoring max vel theta local planner from: " << *
maxVelTheta
222 log,
"[" <<
getName() <<
"] restoring min vel theta local planner from: " << -(*
maxVelTheta)
227 if (parameters.size())
229 std::stringstream ss;
230 ss <<
"Executing asynchronous request. Parameters to update: " << std::endl;
231 for (
auto & p : parameters)
233 ss << p.get_name() <<
" - " << p.value_to_string() << std::endl;
236 RCLCPP_INFO_STREAM(
getLogger(),
"[CbAbsoluteRotate] " << ss.str());
238 auto futureResults = parameters_client->set_parameters(parameters);
241 for (
auto & res : futureResults.get())
244 getLogger(),
"[" <<
getName() <<
"] parameter result: " << parameters[i].get_name() <<
"="
245 << parameters[i].as_string() <<
". Result: " << res.successful);
249 RCLCPP_INFO_STREAM(log,
"[" <<
getName() <<
"] parameters updated");
253 RCLCPP_INFO_STREAM(log,
"[" <<
getName() <<
"] skipping parameters update");
std::optional< float > maxVelTheta
std::optional< SpinningPlanner > spinningPlanner
void updateTemporalBehaviorParameters(bool undo)
float absoluteGoalAngleDegree
std::shared_ptr< tf2_ros::Buffer > listener
std::optional< float > yawGoalTolerance
void sendGoal(ClNav2Z::Goal &goal)
cl_nav2z::ClNav2Z * nav2zClient_
void setGoalCheckerId(std::string goal_checker_id)
void setPureSpinningPlanner(bool commit=true)
const std::string & getReferenceFrame() const
ISmaccState * getCurrentState()
std::string getName() const
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
TComponent * getComponent()
virtual std::string getName()=0
typename ActionClient::Goal Goal