environment_visualizer.cpp
Go to the documentation of this file.
00001 
00018 #include "environment_visualizer.h"
00019 #include "marker_helper.h"
00020 #include <visualization_msgs/MarkerArray.h>
00021 
00022 namespace visualization_server {
00023 
00024 EnvironmentVisualizer::EnvironmentVisualizer() : nh_(NODE_NAME) {
00025 
00026     double marker_lifetime;
00027     std::string dome_config_path;
00028     std::string mild_config_path;
00029     nh_.getParam("marker_lifetime", marker_lifetime);
00030     nh_.getParam("dome_config_path", dome_config_path);
00031     nh_.getParam("mild_config_path", mild_config_path);
00032     marker_helper_ = MarkerHelper(marker_lifetime, dome_config_path, mild_config_path);
00033 
00034     nh_.getParam("output_topic", output_models_topic_);
00035 
00036     draw_all_dome_service_ = nh_.advertiseService(DRAW_ALL_DOME_SERVICE_NAME, &EnvironmentVisualizer::processDrawAllModelsDomeRequest, this);
00037     draw_all_mild_service_ = nh_.advertiseService(DRAW_ALL_MILD_SERVICE_NAME, &EnvironmentVisualizer::processDrawAllModelsMildRequest, this);
00038     clear_all_service_ = nh_.advertiseService(CLEAR_ALL_MODELS_SERVICE_NAME, &EnvironmentVisualizer::processClearAllModelsRequest, this);
00039     draw_model_dome_service_ = nh_.advertiseService(DRAW_MODEL_DOME_SERVICE_NAME, &EnvironmentVisualizer::processDrawModelDomeRequest, this);
00040     draw_model_mild_service_ = nh_.advertiseService(DRAW_MODEL_MILD_SERVICE_NAME, &EnvironmentVisualizer::processDrawModelMildRequest, this);
00041     clear_model_dome_service_ = nh_.advertiseService(CLEAR_MODEL_DOME_SERVICE_NAME, &EnvironmentVisualizer::processClearModelDomeRequest, this);
00042     clear_model_mild_service_ = nh_.advertiseService(CLEAR_MODEL_MILD_SERVICE_NAME, &EnvironmentVisualizer::processClearModelMildRequest, this);
00043     show_available_models_service_ = nh_.advertiseService(SHOW_AVAILABLE_MODELS_SERVICE_NAME, &EnvironmentVisualizer::processShowAvailableModelsRequest, this);
00044 
00045     double timer_duration = 0.5;
00046     nh_.getParam("publish_rate", timer_duration);
00047     publish_timer_ = nh_.createTimer(ros::Duration(timer_duration), &EnvironmentVisualizer::timerCallback, this);
00048 
00049     model_pub_ = nh_.advertise<visualization_msgs::MarkerArray>(output_models_topic_, 1);
00050 }
00051 
00052 void EnvironmentVisualizer::timerCallback(const ros::TimerEvent &e) {
00053     ROS_DEBUG_STREAM("Publishing environment models");
00054 
00055     std::string dome_marker_names = "[ ";
00056     for (visualization_msgs::Marker m : dome_markers_.markers) {
00057         dome_marker_names += m.ns + " ";
00058     }
00059     dome_marker_names += "]";
00060     ROS_DEBUG_STREAM(dome_markers_.markers.size() << " dome markers are published " << dome_marker_names);
00061     model_pub_.publish(dome_markers_);
00062 
00063     std::string mild_marker_names = "[ ";
00064     for (visualization_msgs::Marker m : mild_markers_.markers) {
00065         mild_marker_names += m.ns + " ";
00066     }
00067     mild_marker_names += "]";
00068     ROS_DEBUG_STREAM(mild_markers_.markers.size() << " mild markers are published " << mild_marker_names << std::endl);
00069     model_pub_.publish(mild_markers_);
00070 
00071 }
00072 
00073 bool EnvironmentVisualizer::processDrawAllModelsDomeRequest(DrawAllModelsDome::Request &req, DrawAllModelsDome::Response &res) {
00074     dome_markers_ = marker_helper_.getAllMarkersDome();
00075     return true;
00076 }
00077 
00078 bool EnvironmentVisualizer::processDrawAllModelsMildRequest(DrawAllModelsMild::Request &req, DrawAllModelsMild::Response &res) {
00079     mild_markers_ = marker_helper_.getAllMarkersMild();
00080     return true;
00081 }
00082 
00083 bool EnvironmentVisualizer::processClearAllModelsRequest(ClearAllModels::Request &req, ClearAllModels::Response &res) {
00084     dome_markers_ = visualization_msgs::MarkerArray();
00085     mild_markers_ = visualization_msgs::MarkerArray();
00086     return true;
00087 }
00088 
00089 bool EnvironmentVisualizer::processDrawModelDomeRequest(DrawModelDome::Request &req, DrawModelDome::Response &res) {
00090     std::string name = req.name;
00091     for (visualization_msgs::Marker m : dome_markers_.markers) {
00092         if (name == m.ns) {
00093             ROS_WARN_STREAM("A marker with the name " << name << " is already being published");
00094             return true;
00095         }
00096     }
00097     visualization_msgs::MarkerArray marker_array = marker_helper_.getAllMarkersDome();
00098     bool marker_found = false;
00099     for (visualization_msgs::Marker m : marker_array.markers) {
00100         if (name == m.ns) {
00101             dome_markers_.markers.push_back(m);
00102             marker_found = true;
00103             break;
00104         }
00105     }
00106     if (!marker_found) {
00107         ROS_WARN_STREAM("There is no available marker with the name " << name);
00108     }
00109     return true;
00110 }
00111 
00112 bool EnvironmentVisualizer::processDrawModelMildRequest(DrawModelMild::Request &req, DrawModelMild::Response &res) {
00113     std::string name = req.name;
00114     for (visualization_msgs::Marker m : mild_markers_.markers) {
00115         if (name == m.ns) {
00116             ROS_WARN_STREAM("A marker with the name " << name << " is already being published");
00117             return true;
00118         }
00119     }
00120     visualization_msgs::MarkerArray marker_array = marker_helper_.getAllMarkersMild();
00121     bool marker_found = false;
00122     for (visualization_msgs::Marker m : marker_array.markers) {
00123         if (name == m.ns) {
00124             mild_markers_.markers.push_back(m);
00125             marker_found = true;
00126             break;
00127         }
00128     }
00129     if (!marker_found) {
00130         ROS_WARN_STREAM("There is no available marker with the name " << name);
00131     }
00132     return true;
00133 }
00134 
00135 bool EnvironmentVisualizer::processClearModelDomeRequest(ClearModelDome::Request &req, ClearModelDome::Response &res) {
00136     std::string name = req.name;
00137     for (std::vector<visualization_msgs::Marker>::iterator iter = dome_markers_.markers.begin(); iter != dome_markers_.markers.end(); ++iter) {
00138         if (iter->ns == name) {
00139             dome_markers_.markers.erase(iter);
00140             break;
00141         }
00142     }
00143     return true;
00144 }
00145 
00146 bool EnvironmentVisualizer::processClearModelMildRequest(ClearModelMild::Request &req, ClearModelMild::Response &res) {
00147     std::string name = req.name;
00148     for (std::vector<visualization_msgs::Marker>::iterator iter = mild_markers_.markers.begin(); iter != mild_markers_.markers.end(); ++iter) {
00149         if (iter->ns == name) {
00150             mild_markers_.markers.erase(iter);
00151             break;
00152         }
00153     }
00154     return true;
00155 }
00156 
00157 bool EnvironmentVisualizer::processShowAvailableModelsRequest(ShowAvailableModels::Request &req, ShowAvailableModels::Response &res) {
00158     visualization_msgs::MarkerArray dome_markers = marker_helper_.getAllMarkersDome();
00159     visualization_msgs::MarkerArray mild_markers = marker_helper_.getAllMarkersMild();
00160 
00161     std::vector<std::string> dome_marker_names;
00162     for (visualization_msgs::Marker m : dome_markers.markers) {
00163         dome_marker_names.push_back(m.ns);
00164     }
00165 
00166     std::vector<std::string> mild_marker_names;
00167     for (visualization_msgs::Marker m : mild_markers.markers) {
00168         mild_marker_names.push_back(m.ns);
00169     }
00170 
00171     res.dome_markers = dome_marker_names;
00172     res.mild_markers = mild_marker_names;
00173 
00174     return true;
00175 }
00176 
00177 }
00178 
00179 int main(int argc, char** argv) {
00180 
00181     ros::init(argc, argv, "visualization");
00182 
00183     visualization_server::EnvironmentVisualizer env_vis;
00184 
00185     ros::spin();
00186 
00187     return 0;
00188 }


asr_visualization_server
Author(s): Allgeyer Tobias, Braun Kai, Heller Florian, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Wittenbeck Valerij
autogenerated on Thu Jun 6 2019 21:15:28