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