50 #ifndef FASTRACK_PLANNING_PLANNER_MANAGER_H 51 #define FASTRACK_PLANNING_PLANNER_MANAGER_H 57 #include <fastrack_msgs/ReplanRequest.h> 60 #include <visualization_msgs/Marker.h> 61 #include <std_msgs/Empty.h> 62 #include <geometry_msgs/Vector3.h> 63 #include <geometry_msgs/TransformStamped.h> 64 #include <tf2_ros/transform_broadcaster.h> 69 using trajectory::Trajectory;
108 if (msg->states.empty() || msg->times.empty()) {
109 ROS_WARN_THROTTLE(1.0,
"%s: Received empty trajectory.",
name_.c_str());
114 traj_ = Trajectory<S>(msg);
186 name_ = ros::names::append(n.getNamespace(),
"PlannerManager");
190 ROS_ERROR(
"%s: Failed to load parameters.",
name_.c_str());
196 ROS_ERROR(
"%s: Failed to register callbacks.",
name_.c_str());
207 ros::NodeHandle nl(n);
210 if (!nl.getParam(
"topic/ready",
ready_topic_))
return false;
211 if (!nl.getParam(
"topic/traj",
traj_topic_))
return false;
212 if (!nl.getParam(
"topic/ref",
ref_topic_))
return false;
216 if (!nl.getParam(
"vis/goal",
goal_topic_))
return false;
219 if (!nl.getParam(
"frame/fixed",
fixed_frame_))
return false;
223 if (!nl.getParam(
"time_step",
time_step_))
return false;
227 if (!nl.getParam(
"start",
start_.x))
return false;
228 if (!nl.getParam(
"goal",
goal_.x))
return false;
236 ros::NodeHandle nl(n);
254 goal_pub_ = nl.advertise<visualization_msgs::Marker>(
281 fastrack_msgs::ReplanRequest msg;
289 if (
traj_.Size() > 0) {
291 if (
traj_.LastTime() < msg.start_time) {
292 ROS_ERROR(
"%s: Current trajectory is too short. Cannot interpolate.",
294 msg.start =
traj_.LastState().ToRos();
296 msg.start =
traj_.Interpolate(msg.start_time).ToRos();
312 if (
traj_.Size() == 0) {
316 ROS_WARN_THROTTLE(1.0,
"%s: Waiting for trajectory.",
name_.c_str());
318 ROS_INFO_THROTTLE(1.0,
"%s: Servicing old updated environment callback.",
324 const S planner_x =
traj_.Interpolate(ros::Time::now().toSec());
327 ref_pub_.publish(planner_x.ToRos());
330 geometry_msgs::TransformStamped tf;
332 tf.header.stamp = ros::Time::now();
335 tf.transform.translation.x = planner_x.X();
336 tf.transform.translation.y = planner_x.Y();
337 tf.transform.translation.z = planner_x.Z();
338 tf.transform.rotation.x = 0;
339 tf.transform.rotation.y = 0;
340 tf.transform.rotation.z = 0;
341 tf.transform.rotation.w = 1;
350 visualization_msgs::Marker sphere;
351 sphere.ns =
"sphere";
353 sphere.header.stamp = ros::Time::now();
355 sphere.type = visualization_msgs::Marker::SPHERE;
356 sphere.action = visualization_msgs::Marker::ADD;
357 sphere.color.a = 1.0;
358 sphere.color.r = 0.3;
359 sphere.color.g = 0.7;
360 sphere.color.b = 0.7;
362 geometry_msgs::Point center;
365 sphere.scale.x = 0.1;
366 center.x =
goal_.x[0];
368 sphere.scale.y = 0.1;
369 center.y =
goal_.x[1];
371 sphere.scale.z = 0.1;
372 center.z =
goal_.x[2];
374 sphere.pose.position = center;
375 sphere.pose.orientation.x = 0.0;
376 sphere.pose.orientation.y = 0.0;
377 sphere.pose.orientation.z = 0.0;
378 sphere.pose.orientation.w = 1.0;
virtual bool RegisterCallbacks(const ros::NodeHandle &n)
virtual void VisualizeGoal() const
void TrajectoryCallback(const fastrack_msgs::Trajectory::ConstPtr &msg)
virtual ~PlannerManager()
std::string planner_frame_
fastrack_msgs::State start_
ros::Subscriber updated_env_sub_
virtual bool LoadParameters(const ros::NodeHandle &n)
tf2_ros::TransformBroadcaster tf_broadcaster_
bool serviced_updated_env_
fastrack_msgs::State goal_
std::string replan_request_topic_
ros::Subscriber traj_sub_
void ReadyCallback(const std_msgs::Empty::ConstPtr &msg)
std::string updated_env_topic_
std::string traj_vis_topic_
ros::Publisher traj_vis_pub_
bool Initialize(const ros::NodeHandle &n)
virtual void TimerCallback(const ros::TimerEvent &e)
ros::Publisher replan_request_pub_
virtual void MaybeRequestTrajectory()
ros::Subscriber ready_sub_
void UpdatedEnvironmentCallback(const std_msgs::Empty::ConstPtr &msg)