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
00033
00034
00035
00036
00037
00038
00039 #include <eband_local_planner/eband_visualization.h>
00040
00041
00042 namespace eband_local_planner{
00043
00044
00045 EBandVisualization::EBandVisualization() : initialized_(false) {}
00046
00047
00048 EBandVisualization::EBandVisualization(ros::NodeHandle& pn, costmap_2d::Costmap2DROS* costmap_ros)
00049 {
00050 initialize(pn, costmap_ros);
00051 }
00052
00053
00054 EBandVisualization::~EBandVisualization() {}
00055
00056
00057 void EBandVisualization::initialize(ros::NodeHandle& pn, costmap_2d::Costmap2DROS* costmap_ros)
00058 {
00059
00060 if(!initialized_)
00061 {
00062
00063 pn.param("marker_lifetime", marker_lifetime_, 0.5);
00064
00065
00066 one_bubble_pub_ = pn.advertise<visualization_msgs::Marker>("eband_visualization", 1);
00067
00068 bubble_pub_ = pn.advertise<visualization_msgs::MarkerArray>("eband_visualization_array", 1);
00069
00070
00071 costmap_ros_ = costmap_ros;
00072
00073 initialized_ = true;
00074 }
00075 else
00076 {
00077 ROS_WARN("Trying to initialize already initialized visualization, doing nothing.");
00078 }
00079 }
00080
00081
00082 void EBandVisualization::reconfigure(
00083 eband_local_planner::EBandPlannerConfig& config)
00084 {
00085 marker_lifetime_ = config.marker_lifetime;
00086 }
00087
00088
00089 void EBandVisualization::publishBand(std::string marker_name_space, std::vector<Bubble> band)
00090 {
00091
00092 if(!initialized_)
00093 {
00094 ROS_ERROR("Visualization not yet initialized, please call initialize() before using visualization");
00095 return;
00096 }
00097
00098 visualization_msgs::MarkerArray eband_msg;
00099 eband_msg.markers.resize(band.size());
00100
00101 visualization_msgs::MarkerArray eband_heading_msg;
00102 eband_heading_msg.markers.resize(band.size());
00103 std::string marker_heading_name_space = marker_name_space;
00104 marker_heading_name_space.append("_heading");
00105
00106
00107 for(int i = 0; i < ((int) band.size()); i++)
00108 {
00109
00110 bubbleToMarker(band[i], eband_msg.markers[i], marker_name_space, i, green);
00111
00112
00113
00114 }
00115
00116
00117 bubble_pub_.publish(eband_msg);
00118
00119 }
00120
00121
00122 void EBandVisualization::publishBubble(std::string marker_name_space, int marker_id, Bubble bubble)
00123 {
00124
00125 if(!initialized_)
00126 {
00127 ROS_ERROR("Visualization not yet initialized, please call initialize() before using visualization");
00128 return;
00129 }
00130
00131 visualization_msgs::Marker bubble_msg;
00132
00133
00134 bubbleToMarker(bubble, bubble_msg, marker_name_space, marker_id, green);
00135
00136
00137 one_bubble_pub_.publish(bubble_msg);
00138 }
00139
00140
00141 void EBandVisualization::publishBubble(std::string marker_name_space, int marker_id, Color marker_color, Bubble bubble)
00142 {
00143
00144 if(!initialized_)
00145 {
00146 ROS_ERROR("Visualization not yet initialized, please call initialize() before using visualization");
00147 return;
00148 }
00149
00150 visualization_msgs::Marker bubble_msg;
00151
00152
00153 bubbleToMarker(bubble, bubble_msg, marker_name_space, marker_id, marker_color);
00154
00155
00156 one_bubble_pub_.publish(bubble_msg);
00157 }
00158
00159
00160 void EBandVisualization::publishForceList(std::string marker_name_space, std::vector<geometry_msgs::WrenchStamped> forces, std::vector<Bubble> band)
00161 {
00162
00163 if(!initialized_)
00164 {
00165 ROS_ERROR("Visualization not yet initialized, please call initialize() before using visualization");
00166 return;
00167 }
00168
00169 visualization_msgs::MarkerArray forces_msg;
00170 forces_msg.markers.resize(forces.size());
00171
00172
00173 Color marker_color = green;
00174 if(marker_name_space.compare("internal_forces") == 0)
00175 marker_color = blue;
00176
00177 if(marker_name_space.compare("external_forces") == 0)
00178 marker_color = red;
00179
00180 if(marker_name_space.compare("resulting_forces") == 0)
00181 marker_color = green;
00182
00183 for(int i = 0; i < ((int) forces.size()); i++)
00184 {
00185
00186 forceToMarker(forces[i], band[i].center.pose, forces_msg.markers[i], marker_name_space, i, marker_color);
00187 }
00188
00189
00190 bubble_pub_.publish(forces_msg);
00191 }
00192
00193 void EBandVisualization::publishForce(std::string marker_name_space, int id, Color marker_color, geometry_msgs::WrenchStamped force, Bubble bubble)
00194 {
00195
00196 if(!initialized_)
00197 {
00198 ROS_ERROR("Visualization not yet initialized, please call initialize() before using visualization");
00199 return;
00200 }
00201
00202 visualization_msgs::Marker force_msg;
00203
00204
00205 forceToMarker(force, bubble.center.pose, force_msg, marker_name_space, id, marker_color);
00206
00207
00208 one_bubble_pub_.publish(force_msg);
00209 }
00210
00211
00212 void EBandVisualization::bubbleToMarker(Bubble bubble, visualization_msgs::Marker& marker, std::string marker_name_space, int marker_id, Color marker_color)
00213 {
00214 geometry_msgs::Pose2D tmp_pose2d;
00215
00216
00217 marker.header.stamp = ros::Time::now();
00218 marker.header.frame_id = bubble.center.header.frame_id;
00219
00220
00221 marker.ns = marker_name_space;
00222 marker.id = marker_id;
00223 marker.type = visualization_msgs::Marker::SPHERE;
00224 marker.action = visualization_msgs::Marker::ADD;
00225
00226
00227 marker.pose = bubble.center.pose;
00228
00229 PoseToPose2D(bubble.center.pose, tmp_pose2d);
00230 marker.pose.position.z = 0;
00231
00232 marker.scale.x = 2.0*bubble.expansion;
00233 marker.scale.y = 2.0*bubble.expansion;
00234 marker.scale.z = 2.0*bubble.expansion;
00235
00236
00237 marker.color.r = 0.0f;
00238 marker.color.g = 0.0f;
00239 marker.color.b = 0.0f;
00240 switch(marker_color)
00241 {
00242 case red: { marker.color.r = 1.0f; break; }
00243 case green: { marker.color.g = 1.0f; break; }
00244 case blue: { marker.color.b = 1.0f; break; }
00245 }
00246
00247 marker.color.a = 0.75;
00248
00249
00250 marker.lifetime = ros::Duration(marker_lifetime_);
00251 }
00252
00253
00254 void EBandVisualization::bubbleHeadingToMarker(Bubble bubble, visualization_msgs::Marker& marker, std::string marker_name_space, int marker_id, Color marker_color)
00255 {
00256 geometry_msgs::Pose2D tmp_pose2d;
00257
00258
00259 marker.header.stamp = ros::Time::now();
00260 marker.header.frame_id = bubble.center.header.frame_id;
00261
00262
00263 marker.ns = marker_name_space;
00264 marker.id = marker_id;
00265 marker.type = visualization_msgs::Marker::ARROW;
00266 marker.action = visualization_msgs::Marker::ADD;
00267
00268
00269 marker.pose = bubble.center.pose;
00270
00271 PoseToPose2D(bubble.center.pose, tmp_pose2d);
00272 marker.pose.position.z = tmp_pose2d.theta * getCircumscribedRadius(*costmap_ros_);
00273
00274 marker.scale.x = 0.9;
00275 marker.scale.y = 0.45;
00276 marker.scale.z = 0.45;
00277
00278
00279 marker.color.r = 0.0f;
00280 marker.color.g = 0.0f;
00281 marker.color.b = 0.0f;
00282 switch(marker_color)
00283 {
00284 case red: { marker.color.r = 1.0f; break; }
00285 case green: { marker.color.g = 1.0f; break; }
00286 case blue: { marker.color.b = 1.0f; break; }
00287 }
00288
00289 marker.color.a = 1.0;
00290
00291
00292 marker.lifetime = ros::Duration(marker_lifetime_);
00293 }
00294
00295
00296 void EBandVisualization::forceToMarker(geometry_msgs::WrenchStamped wrench, geometry_msgs::Pose wrench_origin, visualization_msgs::Marker& marker, std::string marker_name_space, int marker_id, Color marker_color)
00297 {
00298 geometry_msgs::Pose2D tmp_pose2d;
00299
00300
00301 marker.header.stamp = ros::Time::now();
00302 marker.header.frame_id = wrench.header.frame_id;
00303
00304
00305 marker.ns = marker_name_space;
00306 marker.id = marker_id;
00307 marker.type = visualization_msgs::Marker::ARROW;
00308 marker.action = visualization_msgs::Marker::ADD;
00309
00310
00311 marker.pose.position = wrench_origin.position;
00312
00313 PoseToPose2D(wrench_origin, tmp_pose2d);
00314 marker.pose.position.z = tmp_pose2d.theta * getCircumscribedRadius(*costmap_ros_);
00315
00316
00317
00318 if( (wrench.wrench.force.x != 0) || (wrench.wrench.force.y != 0) || (wrench.wrench.torque.z != 0) )
00319 {
00320
00321
00322 Eigen::Vector3d x_axis(1.0, 0.0, 0.0);
00323 Eigen::Vector3d target_vec( wrench.wrench.force.x, wrench.wrench.force.y, wrench.wrench.torque.z / getCircumscribedRadius(*costmap_ros_) );
00324 Eigen::Vector3d rotation_axis(1.0, 0.0, 0.0);
00325 double rotation_angle = 0.0;
00326
00327 x_axis.normalize();
00328 target_vec.normalize();
00329 if(!(x_axis == target_vec))
00330 {
00331
00332 rotation_axis = x_axis.cross(target_vec);
00333 rotation_angle = x_axis.dot(target_vec);
00334 rotation_angle = acos(rotation_angle);
00335 }
00336
00337 rotation_axis.normalize();
00338 const double s = sin(rotation_angle/2);
00339 const double c = cos(rotation_angle/2);
00340 Eigen::Quaterniond rotate_quat(c, s*rotation_axis.x(), s*rotation_axis.y(), s*rotation_axis.z());
00341
00342
00343 tf::Quaternion orientation_tf;
00344 geometry_msgs::Quaternion orientation_msg;
00345 tf::quaternionEigenToTF(rotate_quat, orientation_tf);
00346 tf::quaternionTFToMsg(orientation_tf, orientation_msg);
00347
00348
00349 marker.pose.orientation = orientation_msg;
00350
00351
00352 double scale = sqrt( (wrench.wrench.force.x * wrench.wrench.force.x) + (wrench.wrench.force.y * wrench.wrench.force.y) +
00353 ( (wrench.wrench.torque.z/getCircumscribedRadius(*costmap_ros_))*(wrench.wrench.torque.z/getCircumscribedRadius(*costmap_ros_)) ) );
00354 marker.scale.x = scale;
00355 marker.scale.y = scale;
00356 marker.scale.z = scale;
00357
00358
00359 marker.color.r = 0.0f;
00360 marker.color.g = 0.0f;
00361 marker.color.b = 0.0f;
00362 switch(marker_color)
00363 {
00364 case red: { marker.color.r = 1.0f; break; }
00365 case green: { marker.color.g = 1.0f; break; }
00366 case blue: { marker.color.b = 1.0f; break; }
00367 }
00368
00369 marker.color.a = 1.25;
00370 }
00371 else
00372 {
00373
00374 marker.pose.orientation = wrench_origin.orientation;
00375
00376
00377 marker.scale.x = 0.0;
00378 marker.scale.y = 0.0;
00379 marker.scale.z = 0.0;
00380
00381
00382 marker.color.r = 0.0f;
00383 marker.color.g = 0.0f;
00384 marker.color.b = 0.0f;
00385
00386
00387 marker.color.a = 0.0;
00388 }
00389
00390
00391 marker.lifetime = ros::Duration(marker_lifetime_);
00392 }
00393
00394 };
00395