waypoint_provider.cpp
Go to the documentation of this file.
1 /*
2  Way point Provider
3 
4  inspired by yocs_waypoints_navi
5 
6  LICENSE : BSD - https://raw.github.com/yujinrobot/yujin_ocs/license/LICENSE
7 
8  Author : Jihoon Lee
9  Date : Dec 2013
10  */
11 
13 
14 namespace yocs {
16  yocs_msgs::WaypointList& wps,
17  yocs_msgs::TrajectoryList& trajs) : nh_(n)
18  {
19 
20  // setup pub
21  waypoints_pub_ = nh_.advertise<yocs_msgs::WaypointList>("waypoints", 5, true);
22  trajectories_pub_ = nh_.advertise<yocs_msgs::TrajectoryList>("trajectories", 5, true);
23  waypoints_marker_pub_ = nh_.advertise<visualization_msgs::MarkerArray>("waypoint_markers", 5, true);
24  trajectory_marker_pub_ = nh_.advertise<visualization_msgs::MarkerArray>("trajectory_markers", 5, true);
25  // setup srv server
27 
28  waypoints_ = wps;
29  trajectories_ = trajs;
32 
33  marker_index_ = 1000;
34  label_index_ = 2000;
35  }
36 
37 
39 
40  bool WaypointProvider::processWaypointsService(yocs_msgs::WaypointListService::Request& request,
41  yocs_msgs::WaypointListService::Response& response)
42  {
43  ROS_INFO("Waypoint Manager : Received request");
44  if(!initialized_) // return false if node is not initialized with points
45  {
46  response.success = false;
47  }
48  else {
49  response.waypoints = this->waypoints_;
50  response.success = true;
51  }
52  return true;
53  }
54 
55  void WaypointProvider::generateWaypointMarkers(const yocs_msgs::WaypointList& wps,
56  visualization_msgs::MarkerArray& wp_viz)
57  {
58  wp_viz.markers.clear();
59 
60  unsigned int i;
61 
62  for(i = 0; i < wps.waypoints.size(); i++)
63  {
64  visualization_msgs::Marker marker;
65  visualization_msgs::Marker label;
66 
67  createMarkerArrow(i, wps.waypoints[i], marker);
68  createMarkerLabel(wps.waypoints[i].header.frame_id,
69  i,
70  "waypoint_labels",
71  wps.waypoints[i].name,
72  wps.waypoints[i].pose,
73  label);
74 
75  wp_viz.markers.push_back(marker);
76  wp_viz.markers.push_back(label);
77  }
78  }
79 
80  void WaypointProvider::generateTrajectoryMarkers(const yocs_msgs::TrajectoryList& trajs,
81  visualization_msgs::MarkerArray& traj_markers)
82  {
83  traj_markers.markers.clear();
84  for(unsigned int traj = 0; traj < trajs.trajectories.size(); ++traj)
85  {
86  visualization_msgs::Marker marker;
87  createMarkerLineStrip(traj, trajs.trajectories[traj], marker);
88  traj_markers.markers.push_back(marker);
89  // no label, since way points with labels are already generated by for the waypoint marker publisher
90  }
91  }
92 
94  const yocs_msgs::Waypoint& wp,
95  visualization_msgs::Marker& marker)
96  {
97  marker.header.frame_id = wp.header.frame_id;
98  marker.header.stamp = ros::Time();
99  marker.ns = "waypoints";
100  marker.id = i + marker_index_;
101  marker.pose = wp.pose;
102  marker.type = visualization_msgs::Marker::ARROW;
103  marker.action = visualization_msgs::Marker::ADD;
104  marker.color.r = 0.0f;
105  marker.color.g = 1.0f;
106  marker.color.b = 0.0f;
107  marker.color.a = 1.0f;
108  marker.scale.x = 0.1;
109  marker.scale.y = 0.1;
110  marker.scale.z = 0.1;
111 
112  }
113 
114  void WaypointProvider::createMarkerLabel(const std::string frame_id,
115  const int id,
116  const std::string ns,
117  const std::string wp_name,
118  const geometry_msgs::Pose wp_pose,
119  visualization_msgs::Marker& marker)
120  {
121  marker.header.frame_id = frame_id;
122  marker.header.stamp = ros::Time();
123  marker.ns = ns;
124  marker.id = id + label_index_;
125  marker.scale.x = 0.1;
126  marker.scale.y = 0.1;
127  marker.scale.z = 0.1;
128  marker.color.r = 1.0f;
129  marker.color.g = 1.0f;
130  marker.color.b = 1.0f;
131  marker.color.a = 1.0f;
132  marker.pose = wp_pose;
133  marker.pose.position.z = marker.pose.position.z + marker.scale.z / 2.0 + 0.05; // just above the marker
134  marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
135  marker.action = visualization_msgs::Marker::ADD;
136  marker.text = wp_name;
137  }
138 
140  const yocs_msgs::Trajectory& traj,
141  visualization_msgs::Marker& marker)
142  {
143  marker.header.frame_id = traj.waypoints[0].header.frame_id;
144  marker.header.stamp = ros::Time();
145  marker.ns = "trajectories";
146  marker.id = i + marker_index_;
147  marker.pose = geometry_msgs::Pose();
148  marker.type = visualization_msgs::Marker::LINE_STRIP;
149  marker.action = visualization_msgs::Marker::ADD;
150  marker.color.r = 0.0f;
151  marker.color.g = 0.0f;
152  marker.color.b = 1.0f;
153  marker.color.a = 1.0f;
154  marker.scale.x = 0.1;
155  marker.scale.y = 0.1;
156  marker.scale.z = 0.1;
157  for(unsigned int wp = 0; wp < traj.waypoints.size(); ++wp)
158  {
159  marker.points.push_back(traj.waypoints[wp].pose.position);
160  marker.colors.push_back(marker.color);
161  }
162  }
163 
169  initialized_ = true;
170  ros::spin();
171  }
172 }
ros::Publisher waypoints_marker_pub_
void publish(const boost::shared_ptr< M > &message) const
yocs_msgs::WaypointList waypoints_
bool processWaypointsService(yocs_msgs::WaypointListService::Request &request, yocs_msgs::WaypointListService::Response &response)
ros::Publisher trajectories_pub_
yocs_msgs::TrajectoryList trajectories_
void createMarkerLineStrip(const int i, const yocs_msgs::Trajectory &traj, visualization_msgs::Marker &marker)
void generateTrajectoryMarkers(const yocs_msgs::TrajectoryList &trajs, visualization_msgs::MarkerArray &traj_markers)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void createMarkerLabel(const std::string frame_id, const int id, const std::string ns, const std::string wp_name, const geometry_msgs::Pose wp_pose, visualization_msgs::Marker &marker)
visualization_msgs::MarkerArray waypoint_markers_
#define ROS_INFO(...)
ros::Publisher trajectory_marker_pub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
WaypointProvider(ros::NodeHandle &n, yocs_msgs::WaypointList &wps, yocs_msgs::TrajectoryList &trajs)
ros::ServiceServer waypoints_srv_
void createMarkerArrow(const int i, const yocs_msgs::Waypoint &wp, visualization_msgs::Marker &marker)
visualization_msgs::MarkerArray trajectory_markers_
void generateWaypointMarkers(const yocs_msgs::WaypointList &wps, visualization_msgs::MarkerArray &wp_markers)


yocs_waypoint_provider
Author(s): Jihoon Lee
autogenerated on Mon Jun 10 2019 15:54:09