Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "yocs_waypoint_manager/waypoint_manager.hpp"
00013
00014 namespace yocs {
00015 WaypointManager::WaypointManager(ros::NodeHandle& n, yocs_msgs::WaypointList& wp) : nh_(n)
00016 {
00017
00018
00019 waypoints_pub_ = nh_.advertise<yocs_msgs::WaypointList>("waypoints", 5, true);
00020 waypoints_viz_pub_ = nh_.advertise<visualization_msgs::MarkerArray>("waypoints_viz", 5, true);
00021
00022 waypoints_srv_ = nh_.advertiseService("request_waypoints", &WaypointManager::processWaypointsService, this);
00023
00024 waypoints_ = wp;
00025 generateVizmarkers(waypoints_, waypoints_viz_);
00026
00027 marker_index_ = 1000;
00028 label_index_ = 2000;
00029 }
00030
00031
00032 WaypointManager::~WaypointManager() {}
00033
00034 bool WaypointManager::processWaypointsService(yocs_msgs::WaypointListService::Request& request, yocs_msgs::WaypointListService::Response& response)
00035 {
00036 ROS_INFO("Waypoint Manager : Received request");
00037 if(!initialized_)
00038 {
00039 response.success = false;
00040 }
00041 else {
00042 response.waypoints = this->waypoints_;
00043 response.success = true;
00044 }
00045 return true;
00046 }
00047
00048 void WaypointManager::generateVizmarkers(const yocs_msgs::WaypointList& wps, visualization_msgs::MarkerArray& wp_viz)
00049 {
00050 wp_viz.markers.clear();
00051
00052 unsigned int i;
00053
00054 for(i = 0; i < wps.waypoints.size(); i++)
00055 {
00056 visualization_msgs::Marker marker;
00057 visualization_msgs::Marker label;
00058
00059 createArrowMarker(i, wps.waypoints[i], marker);
00060 createLabelMarker(i, wps.waypoints[i], label);
00061
00062 wp_viz.markers.push_back(marker);
00063 wp_viz.markers.push_back(label);
00064 }
00065 }
00066
00067 void WaypointManager::createArrowMarker(const int i,const yocs_msgs::Waypoint& wp, visualization_msgs::Marker& marker)
00068 {
00069 marker.header.frame_id = wp.header.frame_id;
00070 marker.header.stamp = ros::Time::now();
00071 marker.ns = "waypoints";
00072 marker.id = i + marker_index_;
00073 marker.pose = wp.pose;
00074 marker.type = visualization_msgs::Marker::ARROW;
00075 marker.action = visualization_msgs::Marker::ADD;
00076 marker.color.r = 0.0f;
00077 marker.color.g = 1.0f;
00078 marker.color.b = 0.0f;
00079 marker.color.a = 1.0f;
00080 marker.scale.x = 0.1;
00081 marker.scale.y = 0.1;
00082 marker.scale.z = 0.1;
00083
00084 }
00085
00086 void WaypointManager::createLabelMarker(const int i,const yocs_msgs::Waypoint& wp, visualization_msgs::Marker& marker)
00087 {
00088 marker.header.frame_id = wp.header.frame_id;
00089 marker.header.stamp = ros::Time::now();
00090 marker.ns = "waypoints_label";
00091 marker.id = i + label_index_;
00092 marker.scale.x = 0.1;
00093 marker.scale.y = 0.1;
00094 marker.scale.z = 0.1;
00095 marker.color.r = 1.0f;
00096 marker.color.g = 1.0f;
00097 marker.color.b = 1.0f;
00098 marker.color.a = 1.0f;
00099 marker.pose = wp.pose;
00100 marker.pose.position.z = marker.pose.position.z + marker.scale.z / 2.0 + 0.05;
00101 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00102 marker.action = visualization_msgs::Marker::ADD;
00103 marker.text = wp.name;
00104 }
00105
00106 void WaypointManager::spin() {
00107 waypoints_pub_.publish(waypoints_);
00108 waypoints_viz_pub_.publish(waypoints_viz_);
00109 initialized_ = true;
00110 ros::spin();
00111 }
00112 }