Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "collvoid_local_planner/collvoid_publishers.h"
00033
00034 namespace collvoid {
00035
00036 void publishHoloSpeed(Vector2 pos, Vector2 vel, std::string base_frame, std::string name_space, ros::Publisher speed_pub) {
00037 visualization_msgs::Marker line_list;
00038 line_list.header.frame_id = base_frame;
00039 line_list.header.stamp = ros::Time::now();
00040 line_list.ns = name_space;
00041 line_list.action = visualization_msgs::Marker::ADD;
00042 line_list.pose.orientation.w = 1.0;
00043 line_list.type = visualization_msgs::Marker::LINE_LIST;
00044 line_list.scale.x = 0.02;
00045 line_list.color.r = 0.0;
00046 line_list.color.g = 1.0;
00047 line_list.color.a = 1.0;
00048 line_list.id = 0;
00049 geometry_msgs::Point p;
00050 p.x = pos.x();
00051 p.y = pos.y();
00052 p.z = 0.2;
00053 line_list.points.push_back(p);
00054 p.x = p.x + vel.x();
00055 p.y = p.y + vel.y();
00056 line_list.points.push_back(p);
00057
00058 speed_pub.publish(line_list);
00059 }
00060
00061
00062 void publishVOs(Vector2& pos, const std::vector<VO>& truncated_vos, bool use_truncation, std::string base_frame, std::string name_space, ros::Publisher vo_pub){
00063 visualization_msgs::Marker line_list;
00064 line_list.header.frame_id = base_frame;
00065 line_list.header.stamp = ros::Time::now();
00066 line_list.ns = name_space;
00067 line_list.action = visualization_msgs::Marker::ADD;
00068 line_list.pose.orientation.w = 1.0;
00069 line_list.type = visualization_msgs::Marker::LINE_LIST;
00070 line_list.scale.x = 0.015;
00071 line_list.color.r = 1.0;
00072 line_list.color.a = 1.0;
00073 line_list.id = 0;
00074 if (!use_truncation){
00075 for (int i=0;i< (int)truncated_vos.size();i++) {
00076 geometry_msgs::Point p;
00077
00078
00079 p.x = pos.x() + truncated_vos[i].point.x();
00080 p.y = pos.y() + truncated_vos[i].point.y();
00081
00082 line_list.points.push_back(p);
00083 p.x = p.x + 3 * truncated_vos[i].left_leg_dir.x();
00084 p.y = p.y + 3 * truncated_vos[i].left_leg_dir.y();
00085 line_list.points.push_back(p);
00086
00087
00088 p.x = pos.x() + truncated_vos[i].point.x();
00089 p.y = pos.y() + truncated_vos[i].point.y();
00090
00091 line_list.points.push_back(p);
00092 p.x = p.x + 3 * truncated_vos[i].right_leg_dir.x();
00093 p.y = p.y + 3 * truncated_vos[i].right_leg_dir.y();
00094 line_list.points.push_back(p);
00095
00096 }
00097 }
00098 else {
00099 for (int i=0;i< (int)truncated_vos.size();i++) {
00100 geometry_msgs::Point p;
00101
00102 p.x = pos.x() + truncated_vos[i].trunc_left.x();
00103 p.y = pos.y() + truncated_vos[i].trunc_left.y();
00104
00105 line_list.points.push_back(p);
00106 p.x = p.x + 3 * truncated_vos[i].left_leg_dir.x();
00107 p.y = p.y + 3 * truncated_vos[i].left_leg_dir.y();
00108 line_list.points.push_back(p);
00109
00110 p.x = pos.x() + truncated_vos[i].trunc_right.x();
00111 p.y = pos.y() + truncated_vos[i].trunc_right.y();
00112
00113 line_list.points.push_back(p);
00114 p.x = p.x + 3 * truncated_vos[i].right_leg_dir.x();
00115 p.y = p.y + 3 * truncated_vos[i].right_leg_dir.y();
00116 line_list.points.push_back(p);
00117
00118
00119 p.x = pos.x() + truncated_vos[i].trunc_left.x();
00120 p.y = pos.y() + truncated_vos[i].trunc_left.y();
00121 line_list.points.push_back(p);
00122
00123 p.x = pos.x() + truncated_vos[i].trunc_right.x();
00124 p.y = pos.y() + truncated_vos[i].trunc_right.y();
00125 line_list.points.push_back(p);
00126
00127
00128
00129 }
00130 }
00131 vo_pub.publish(line_list);
00132 }
00133
00134
00135 void publishPoints(Vector2& pos, const std::vector<VelocitySample>& points, std::string base_frame, std::string name_space, ros::Publisher samples_pub){
00136 visualization_msgs::MarkerArray point_array;
00137
00138
00139
00140 for (int i=0;i< (int)points.size();i++) {
00141
00142 visualization_msgs::Marker sphere;
00143
00144 sphere.header.frame_id = base_frame;
00145 sphere.header.stamp = ros::Time::now();
00146 sphere.ns = name_space;
00147 sphere.action = visualization_msgs::Marker::ADD;
00148 sphere.pose.orientation.w = 1.0;
00149 sphere.type = visualization_msgs::Marker::SPHERE;
00150 sphere.scale.x = 0.1;
00151 sphere.scale.y = 0.1;
00152 sphere.scale.z = 0.1;
00153 sphere.color.r = 0.5;
00154 sphere.color.a = 1.0;
00155 sphere.id = i;
00156 geometry_msgs::Point p;
00157 p.x = pos.x() + points[i].velocity.x();
00158 p.y = pos.y() + points[i].velocity.y();
00159 p.z = 0.1;
00160 sphere.points.push_back(p);
00161 sphere.pose.position.x = p.x;
00162 sphere.pose.position.y = p.y;
00163 sphere.pose.position.z = p.z;
00164 point_array.markers.push_back(sphere);
00165 }
00166
00167 for (int i=point_array.markers.size();i<MAX_POINTS_;i++) {
00168 visualization_msgs::Marker sphere_list;
00169 sphere_list.header.frame_id = base_frame;
00170 sphere_list.header.stamp = ros::Time::now();
00171 sphere_list.ns = name_space;
00172 sphere_list.action = visualization_msgs::Marker::DELETE;
00173 sphere_list.id = i;
00174 geometry_msgs::Point p;
00175 sphere_list.points.push_back(p);
00176 sphere_list.pose.position.x = p.x;
00177 sphere_list.pose.position.y = p.y;
00178 sphere_list.pose.position.z = p.z;
00179 point_array.markers.push_back(sphere_list);
00180
00181 }
00182 samples_pub.publish(point_array);
00183 }
00184
00185
00186
00187 void publishOrcaLines(const std::vector<Line>& orca_lines, Vector2& position, std::string base_frame, std::string name_space, ros::Publisher line_pub){
00188 visualization_msgs::Marker line_list;
00189 line_list.header.frame_id = base_frame;
00190 line_list.header.stamp = ros::Time::now();
00191 line_list.ns = name_space;
00192 line_list.action = visualization_msgs::Marker::ADD;
00193 line_list.pose.orientation.w = 1.0;
00194 line_list.type = visualization_msgs::Marker::LINE_LIST;
00195 line_list.scale.x = 0.015;
00196 line_list.color.r = 1.0;
00197 line_list.color.a = 1.0;
00198 line_list.id = 1;
00199 geometry_msgs::Point p;
00200 for (int i=0;i<(int) orca_lines.size();i++) {
00201 p.x = position.x() + orca_lines[i].point.x() - orca_lines[i].dir.x();
00202 p.y = position.y() + orca_lines[i].point.y() - orca_lines[i].dir.y();
00203
00204 line_list.points.push_back(p);
00205 p.x = p.x + 3 * orca_lines[i].dir.x();
00206 p.y = p.y + 3 * orca_lines[i].dir.y();
00207 line_list.points.push_back(p);
00208
00209 }
00210 line_pub.publish(line_list);
00211
00212 }
00213
00214 void publishObstacleLines(const std::vector<Obstacle>& obstacles_lines, std::string base_frame, std::string name_space, ros::Publisher line_pub){
00215 visualization_msgs::Marker line_list;
00216 line_list.header.frame_id = base_frame;
00217 line_list.header.stamp = ros::Time::now();
00218 line_list.ns = name_space;
00219 line_list.action = visualization_msgs::Marker::ADD;
00220 line_list.pose.orientation.w = 1.0;
00221 line_list.type = visualization_msgs::Marker::LINE_LIST;
00222 line_list.scale.x = 0.015;
00223 line_list.color.r = 1.0;
00224 line_list.color.a = 1.0;
00225 line_list.id = 1;
00226 geometry_msgs::Point p;
00227 for (int i=0;i<(int) obstacles_lines.size();i++) {
00228 if (obstacles_lines[i].point1 == obstacles_lines[i].point2) {
00229 continue;
00230 }
00231 p.x = obstacles_lines[i].point1.x();
00232 p.y = obstacles_lines[i].point1.y();
00233 line_list.points.push_back(p);
00234
00235 p.x = obstacles_lines[i].point2.x();
00236 p.y = obstacles_lines[i].point2.y();
00237 line_list.points.push_back(p);
00238
00239 }
00240 line_pub.publish(line_list);
00241
00242 }
00243
00244
00245 void publishMePosition(ROSAgent* me, std::string base_frame, std::string name_space, ros::Publisher me_pub){
00246 visualization_msgs::MarkerArray sphere_list;
00247 sphere_list.markers.clear();
00248 fillMarkerWithROSAgent(sphere_list, me, base_frame, name_space);
00249 me_pub.publish(sphere_list);
00250 }
00251
00252
00253 void publishNeighborPositions(std::vector<AgentPtr>& neighbors, std::string base_frame, std::string name_space, ros::Publisher neighbors_pub){
00254 visualization_msgs::MarkerArray sphere_list;
00255 sphere_list.markers.clear();
00256
00257 for (int i = 0; i<(int)neighbors.size(); i++){
00258 ROSAgentPtr agent = boost::dynamic_pointer_cast<ROSAgent>(neighbors[i]);
00259
00260 fillMarkerWithROSAgent(sphere_list, agent.get(), base_frame, name_space);
00261 }
00262 neighbors_pub.publish(sphere_list);
00263 }
00264
00265 void fillMarkerWithROSAgent(visualization_msgs::MarkerArray& marker, ROSAgent* agent, std::string base_frame, std::string name_space) {
00266 int id = (int)marker.markers.size();
00267 marker.markers.resize(marker.markers.size()+2);
00268 ros::Time timestamp = ros::Time::now();
00269
00270 marker.markers[id].header.frame_id = base_frame;
00271 marker.markers[id].header.stamp = ros::Time::now();
00272 marker.markers[id].ns = name_space;
00273 marker.markers[id].action = visualization_msgs::Marker::ADD;
00274 marker.markers[id].pose.orientation.w = 1.0;
00275 marker.markers[id].type = visualization_msgs::Marker::SPHERE;
00276 marker.markers[id].scale.x = 2.0*agent->getRadius();
00277 marker.markers[id].scale.y = 2.0*agent->getRadius();
00278 marker.markers[id].scale.z = 0.1;
00279 marker.markers[id].color.r = 1.0;
00280 marker.markers[id].color.a = 1.0;
00281 marker.markers[id].id = id;
00282
00283 double yaw, x_dif, y_dif, th_dif, time_dif;
00284 time_dif = (ros::Time::now() - agent->lastSeen()).toSec();
00285 yaw = tf::getYaw(agent->base_odom_.pose.pose.orientation);
00286
00287
00288
00289 th_dif = time_dif * agent->base_odom_.twist.twist.angular.z;
00290 if (agent->isHoloRobot()) {
00291 x_dif = time_dif * agent->base_odom_.twist.twist.linear.x;
00292 y_dif = time_dif * agent->base_odom_.twist.twist.linear.y;
00293 }
00294 else {
00295 x_dif = time_dif * agent->base_odom_.twist.twist.linear.x * cos(yaw + th_dif/2.0);
00296 y_dif = time_dif * agent->base_odom_.twist.twist.linear.x * sin(yaw + th_dif/2.0);
00297 }
00298 marker.markers[id].pose.position.x = agent->base_odom_.pose.pose.position.x + x_dif;
00299 marker.markers[id].pose.position.y = agent->base_odom_.pose.pose.position.y + y_dif;
00300 marker.markers[id].pose.position.z = 0.2;
00301
00302 id = id +1;
00303 marker.markers[id].header.frame_id = base_frame;
00304 marker.markers[id].header.stamp = ros::Time::now();
00305 marker.markers[id].ns = name_space;
00306 marker.markers[id].action = visualization_msgs::Marker::ADD;
00307 marker.markers[id].pose.orientation.w = 1.0;
00308 marker.markers[id].type = visualization_msgs::Marker::ARROW;
00309 marker.markers[id].scale.x = 0.1;
00310 marker.markers[id].scale.y = 0.2;
00311 marker.markers[id].scale.z = 0.1;
00312 marker.markers[id].color.r = 1.0;
00313 marker.markers[id].color.a = 1.0;
00314 marker.markers[id].id = id;
00315
00316 geometry_msgs::Point p;
00317 p.x = agent->base_odom_.pose.pose.position.x + x_dif;
00318 p.y = agent->base_odom_.pose.pose.position.y + y_dif;
00319 p.z = 0.1;
00320 marker.markers[id].points.push_back(p);
00321
00322 p.x += agent->getRadius() * 2.0 * cos(yaw + th_dif);
00323 p.y += agent->getRadius() * 2.0 * sin(yaw + th_dif);
00324 marker.markers[id].points.push_back(p);
00325 }
00326 }