visualize_obstacle_distance_node.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <string.h>
19 #include <map>
20 #include <ros/ros.h>
21 #include <visualization_msgs/MarkerArray.h>
22 #include <cob_control_msgs/ObstacleDistances.h>
23 
24 
26 {
30 
31 public:
32 
33  int init()
34  {
35  marker_pub_ = this->nh_.advertise<visualization_msgs::MarkerArray>("obstacle_distance/distance_markers", 1, true);
36  obstacle_distances_sub_ = this->nh_.subscribe("obstacle_distances", 1, &DebugObstacleDistance::obstacleDistancesCallback, this);
37 
38  ros::Duration(1.0).sleep();
39  ROS_WARN("Debug initialized.");
40  return 0;
41  }
42 
43 
44  void obstacleDistancesCallback(const cob_control_msgs::ObstacleDistances::ConstPtr& msg)
45  {
46  visualization_msgs::MarkerArray marker_array;
47 
48  for(unsigned int i = 0; i < msg->distances.size(); i++)
49  {
50  cob_control_msgs::ObstacleDistance info = msg->distances[i];
51 
52  //show distance vector as arrow
53  visualization_msgs::Marker marker_vector;
54  marker_vector.type = visualization_msgs::Marker::ARROW;
55  marker_vector.lifetime = ros::Duration();
56  marker_vector.action = visualization_msgs::Marker::ADD;
57  marker_vector.ns = "arrows";
58  marker_vector.id = 2*i;
59  marker_vector.header.frame_id = info.header.frame_id;
60 
61  marker_vector.scale.x = 0.01;
62  marker_vector.scale.y = 0.05;
63 
64  geometry_msgs::Point start;
65  start.x = info.nearest_point_obstacle_vector.x;
66  start.y = info.nearest_point_obstacle_vector.y;
67  start.z = info.nearest_point_obstacle_vector.z;
68 
69  geometry_msgs::Point end;
70  end.x = info.nearest_point_frame_vector.x;
71  end.y = info.nearest_point_frame_vector.y;
72  end.z = info.nearest_point_frame_vector.z;
73 
74  marker_vector.color.a = 1.0;
75  marker_vector.color.g = 1.0;
76 
77  marker_vector.points.push_back(start);
78  marker_vector.points.push_back(end);
79  marker_array.markers.push_back(marker_vector);
80 
81 
82  //show distance as text
83  visualization_msgs::Marker marker_distance;
84  marker_distance.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
85  marker_distance.lifetime = ros::Duration();
86  marker_distance.action = visualization_msgs::Marker::ADD;
87  marker_distance.ns = "distances";
88  marker_distance.id = 2*i+1;
89  marker_distance.header.frame_id = info.header.frame_id;
90  std::stringstream sstream;
91  sstream << std::setprecision(3) << info.distance;
92  marker_distance.text = sstream.str();
93 
94  marker_distance.scale.x = 0.1;
95  marker_distance.scale.y = 0.1;
96  marker_distance.scale.z = 0.1;
97 
98  marker_distance.color.a = 1.0;
99  //marker_distance.color.r = 1.0;
100  //marker_distance.color.g = 1.0;
101  //marker_distance.color.b = 1.0;
102  marker_distance.color.r = 0.0;
103  marker_distance.color.g = 0.0;
104  marker_distance.color.b = 0.0;
105 
106  marker_distance.pose.position.x = info.nearest_point_frame_vector.x;
107  marker_distance.pose.position.y = info.nearest_point_frame_vector.y + 0.05;
108  marker_distance.pose.position.z = info.nearest_point_frame_vector.z;
109 
110  marker_array.markers.push_back(marker_distance);
111  }
112 
113  marker_pub_.publish(marker_array);
114  }
115 };
116 
117 int main(int argc, char** argv)
118 {
119  ros::init(argc, argv, "debug_obstacle_distance_node");
120 
122  if (dod.init() != 0)
123  {
124  ROS_ERROR("Failed to initialize DebugDistanceManager.");
125  return -1;
126  }
127 
128  ros::spin();
129 }
130 
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_WARN(...)
int main(int argc, char **argv)
ROSCPP_DECL void spin(Spinner &spinner)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_ERROR(...)
void obstacleDistancesCallback(const cob_control_msgs::ObstacleDistances::ConstPtr &msg)


cob_obstacle_distance_moveit
Author(s): Florian Koehler , Felix Messmer
autogenerated on Sun Dec 6 2020 03:26:02