environment_visualizer.cpp
Go to the documentation of this file.
1 
18 #include "environment_visualizer.h"
19 #include "marker_helper.h"
20 #include <visualization_msgs/MarkerArray.h>
21 
22 namespace visualization_server {
23 
25 
26  double marker_lifetime;
27  std::string dome_config_path;
28  std::string mild_config_path;
29  nh_.getParam("marker_lifetime", marker_lifetime);
30  nh_.getParam("dome_config_path", dome_config_path);
31  nh_.getParam("mild_config_path", mild_config_path);
32  marker_helper_ = MarkerHelper(marker_lifetime, dome_config_path, mild_config_path);
33 
34  nh_.getParam("output_topic", output_models_topic_);
35 
44 
45  double timer_duration = 0.5;
46  nh_.getParam("publish_rate", timer_duration);
48 
49  model_pub_ = nh_.advertise<visualization_msgs::MarkerArray>(output_models_topic_, 1);
50 }
51 
53  ROS_DEBUG_STREAM("Publishing environment models");
54 
55  std::string dome_marker_names = "[ ";
56  for (visualization_msgs::Marker m : dome_markers_.markers) {
57  dome_marker_names += m.ns + " ";
58  }
59  dome_marker_names += "]";
60  ROS_DEBUG_STREAM(dome_markers_.markers.size() << " dome markers are published " << dome_marker_names);
62 
63  std::string mild_marker_names = "[ ";
64  for (visualization_msgs::Marker m : mild_markers_.markers) {
65  mild_marker_names += m.ns + " ";
66  }
67  mild_marker_names += "]";
68  ROS_DEBUG_STREAM(mild_markers_.markers.size() << " mild markers are published " << mild_marker_names << std::endl);
70 
71 }
72 
73 bool EnvironmentVisualizer::processDrawAllModelsDomeRequest(DrawAllModelsDome::Request &req, DrawAllModelsDome::Response &res) {
75  return true;
76 }
77 
78 bool EnvironmentVisualizer::processDrawAllModelsMildRequest(DrawAllModelsMild::Request &req, DrawAllModelsMild::Response &res) {
80  return true;
81 }
82 
83 bool EnvironmentVisualizer::processClearAllModelsRequest(ClearAllModels::Request &req, ClearAllModels::Response &res) {
84  dome_markers_ = visualization_msgs::MarkerArray();
85  mild_markers_ = visualization_msgs::MarkerArray();
86  return true;
87 }
88 
89 bool EnvironmentVisualizer::processDrawModelDomeRequest(DrawModelDome::Request &req, DrawModelDome::Response &res) {
90  std::string name = req.name;
91  for (visualization_msgs::Marker m : dome_markers_.markers) {
92  if (name == m.ns) {
93  ROS_WARN_STREAM("A marker with the name " << name << " is already being published");
94  return true;
95  }
96  }
97  visualization_msgs::MarkerArray marker_array = marker_helper_.getAllMarkersDome();
98  bool marker_found = false;
99  for (visualization_msgs::Marker m : marker_array.markers) {
100  if (name == m.ns) {
101  dome_markers_.markers.push_back(m);
102  marker_found = true;
103  break;
104  }
105  }
106  if (!marker_found) {
107  ROS_WARN_STREAM("There is no available marker with the name " << name);
108  }
109  return true;
110 }
111 
112 bool EnvironmentVisualizer::processDrawModelMildRequest(DrawModelMild::Request &req, DrawModelMild::Response &res) {
113  std::string name = req.name;
114  for (visualization_msgs::Marker m : mild_markers_.markers) {
115  if (name == m.ns) {
116  ROS_WARN_STREAM("A marker with the name " << name << " is already being published");
117  return true;
118  }
119  }
120  visualization_msgs::MarkerArray marker_array = marker_helper_.getAllMarkersMild();
121  bool marker_found = false;
122  for (visualization_msgs::Marker m : marker_array.markers) {
123  if (name == m.ns) {
124  mild_markers_.markers.push_back(m);
125  marker_found = true;
126  break;
127  }
128  }
129  if (!marker_found) {
130  ROS_WARN_STREAM("There is no available marker with the name " << name);
131  }
132  return true;
133 }
134 
135 bool EnvironmentVisualizer::processClearModelDomeRequest(ClearModelDome::Request &req, ClearModelDome::Response &res) {
136  std::string name = req.name;
137  for (std::vector<visualization_msgs::Marker>::iterator iter = dome_markers_.markers.begin(); iter != dome_markers_.markers.end(); ++iter) {
138  if (iter->ns == name) {
139  dome_markers_.markers.erase(iter);
140  break;
141  }
142  }
143  return true;
144 }
145 
146 bool EnvironmentVisualizer::processClearModelMildRequest(ClearModelMild::Request &req, ClearModelMild::Response &res) {
147  std::string name = req.name;
148  for (std::vector<visualization_msgs::Marker>::iterator iter = mild_markers_.markers.begin(); iter != mild_markers_.markers.end(); ++iter) {
149  if (iter->ns == name) {
150  mild_markers_.markers.erase(iter);
151  break;
152  }
153  }
154  return true;
155 }
156 
157 bool EnvironmentVisualizer::processShowAvailableModelsRequest(ShowAvailableModels::Request &req, ShowAvailableModels::Response &res) {
158  visualization_msgs::MarkerArray dome_markers = marker_helper_.getAllMarkersDome();
159  visualization_msgs::MarkerArray mild_markers = marker_helper_.getAllMarkersMild();
160 
161  std::vector<std::string> dome_marker_names;
162  for (visualization_msgs::Marker m : dome_markers.markers) {
163  dome_marker_names.push_back(m.ns);
164  }
165 
166  std::vector<std::string> mild_marker_names;
167  for (visualization_msgs::Marker m : mild_markers.markers) {
168  mild_marker_names.push_back(m.ns);
169  }
170 
171  res.dome_markers = dome_marker_names;
172  res.mild_markers = mild_marker_names;
173 
174  return true;
175 }
176 
177 }
178 
179 int main(int argc, char** argv) {
180 
181  ros::init(argc, argv, "visualization");
182 
184 
185  ros::spin();
186 
187  return 0;
188 }
static const std::string CLEAR_MODEL_DOME_SERVICE_NAME("clear_model_dome")
bool processClearAllModelsRequest(ClearAllModels::Request &req, ClearAllModels::Response &res)
visualization_msgs::MarkerArray getAllMarkersMild()
void publish(const boost::shared_ptr< M > &message) const
static const std::string DRAW_MODEL_MILD_SERVICE_NAME("draw_model_mild")
bool processDrawModelDomeRequest(DrawModelDome::Request &req, DrawModelDome::Response &res)
visualization_msgs::MarkerArray mild_markers_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool processDrawAllModelsMildRequest(DrawAllModelsMild::Request &req, DrawAllModelsMild::Response &res)
int main(int argc, char **argv)
bool processDrawModelMildRequest(DrawModelMild::Request &req, DrawModelMild::Response &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool processDrawAllModelsDomeRequest(DrawAllModelsDome::Request &req, DrawAllModelsDome::Response &res)
static const std::string DRAW_ALL_DOME_SERVICE_NAME("draw_all_models_dome")
visualization_msgs::MarkerArray getAllMarkersDome()
bool processClearModelDomeRequest(ClearModelDome::Request &req, ClearModelDome::Response &res)
visualization_msgs::MarkerArray dome_markers_
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
static const std::string SHOW_AVAILABLE_MODELS_SERVICE_NAME("show_available_models")
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
static const std::string CLEAR_MODEL_MILD_SERVICE_NAME("clear_model_mild")
static const std::string DRAW_MODEL_DOME_SERVICE_NAME("draw_model_dome")
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
bool processShowAvailableModelsRequest(ShowAvailableModels::Request &req, ShowAvailableModels::Response &res)
static const std::string DRAW_ALL_MILD_SERVICE_NAME("draw_all_models_mild")
static const std::string NODE_NAME("visualization")
bool getParam(const std::string &key, std::string &s) const
bool processClearModelMildRequest(ClearModelMild::Request &req, ClearModelMild::Response &res)
static const std::string CLEAR_ALL_MODELS_SERVICE_NAME("clear_all_models")


asr_visualization_server
Author(s): Allgeyer Tobias, Braun Kai, Heller Florian, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:45:13