@@ -1057,6 +1057,33 @@ bool MoveItVisualTools::publishWorkspaceParameters(const moveit_msgs::WorkspaceP
1057
1057
" Planning_Workspace" , 1 );
1058
1058
}
1059
1059
1060
+ bool MoveItVisualTools::checkAndPublishCollision (const moveit::core::RobotState& robot_state,
1061
+ const planning_scene::PlanningScene* planning_scene,
1062
+ const rviz_visual_tools::colors& highlight_link_color,
1063
+ const rviz_visual_tools::colors& contact_point_color)
1064
+ {
1065
+ // Compute the contacts if any
1066
+ collision_detection::CollisionRequest c_req;
1067
+ collision_detection::CollisionResult c_res;
1068
+ c_req.contacts = true ;
1069
+ c_req.max_contacts = 10 ;
1070
+ c_req.max_contacts_per_pair = 3 ;
1071
+ c_req.verbose = true ;
1072
+
1073
+ // Check for collisions
1074
+ planning_scene->checkCollision (c_req, c_res, robot_state);
1075
+ std::vector<std::string> highlight_links;
1076
+ for (const auto & contact : c_res.contacts )
1077
+ {
1078
+ highlight_links.push_back (contact.first .first );
1079
+ highlight_links.push_back (contact.first .second );
1080
+ }
1081
+
1082
+ publishRobotState (robot_state, highlight_link_color, highlight_links);
1083
+ publishContactPoints (c_res.contacts , planning_scene, contact_point_color);
1084
+ return c_res.collision ;
1085
+ }
1086
+
1060
1087
bool MoveItVisualTools::publishContactPoints (const moveit::core::RobotState& robot_state,
1061
1088
const planning_scene::PlanningScene* planning_scene,
1062
1089
const rviz_visual_tools::colors& color)
@@ -1071,12 +1098,18 @@ bool MoveItVisualTools::publishContactPoints(const moveit::core::RobotState& rob
1071
1098
1072
1099
// Check for collisions
1073
1100
planning_scene->checkCollision (c_req, c_res, robot_state);
1101
+ return publishContactPoints (c_res.contacts , planning_scene, color);
1102
+ }
1074
1103
1104
+ bool MoveItVisualTools::publishContactPoints (const collision_detection::CollisionResult::ContactMap& contacts,
1105
+ const planning_scene::PlanningScene* planning_scene,
1106
+ const rviz_visual_tools::colors& color)
1107
+ {
1075
1108
// Display
1076
- if (c_res. contact_count > 0 )
1109
+ if (!contacts. empty () )
1077
1110
{
1078
1111
visualization_msgs::MarkerArray arr;
1079
- collision_detection::getCollisionMarkersFromContacts (arr, planning_scene->getPlanningFrame (), c_res. contacts );
1112
+ collision_detection::getCollisionMarkersFromContacts (arr, planning_scene->getPlanningFrame (), contacts);
1080
1113
ROS_INFO_STREAM_NAMED (LOGNAME, " Completed listing of explanations for invalid states." );
1081
1114
1082
1115
// Check for markers
@@ -1087,6 +1120,7 @@ bool MoveItVisualTools::publishContactPoints(const moveit::core::RobotState& rob
1087
1120
for (std::size_t i = 0 ; i < arr.markers .size (); ++i)
1088
1121
{
1089
1122
arr.markers [i].ns = " Collision" ;
1123
+ arr.markers [i].id = i;
1090
1124
arr.markers [i].scale .x = 0.04 ;
1091
1125
arr.markers [i].scale .y = 0.04 ;
1092
1126
arr.markers [i].scale .z = 0.04 ;
@@ -1395,26 +1429,34 @@ bool MoveItVisualTools::publishRobotState(const std::vector<double> joint_positi
1395
1429
}
1396
1430
1397
1431
bool MoveItVisualTools::publishRobotState (const robot_state::RobotStatePtr& robot_state,
1398
- const rviz_visual_tools::colors& color)
1432
+ const rviz_visual_tools::colors& color,
1433
+ const std::vector<std::string>& highlight_links)
1399
1434
{
1400
- return publishRobotState (*robot_state.get (), color);
1435
+ return publishRobotState (*robot_state.get (), color, highlight_links );
1401
1436
}
1402
1437
1403
1438
bool MoveItVisualTools::publishRobotState (const robot_state::RobotState& robot_state,
1404
- const rviz_visual_tools::colors& color)
1439
+ const rviz_visual_tools::colors& color,
1440
+ const std::vector<std::string>& highlight_links)
1405
1441
{
1442
+ // when only a subset of links should be colored, the default message is used rather than the cached solid robot messages
1443
+ rviz_visual_tools::colors base_color = color;
1444
+ if (!highlight_links.empty ())
1445
+ base_color = rviz_visual_tools::DEFAULT;
1446
+
1406
1447
// Reference to the correctly colored version of message (they are cached)
1407
1448
// May not exist yet but this will create it
1408
- moveit_msgs::DisplayRobotState& display_robot_msg = display_robot_msgs_[color ];
1449
+ moveit_msgs::DisplayRobotState& display_robot_msg = display_robot_msgs_[base_color ];
1409
1450
1410
1451
// Check if a robot state message already exists for this color
1411
1452
if (display_robot_msg.highlight_links .size () == 0 ) // has not been colored yet, lets create that
1412
1453
{
1413
1454
if (color != rviz_visual_tools::DEFAULT) // ignore color highlights when set to default
1414
1455
{
1415
1456
// Get links names
1416
- const std::vector<const moveit::core::LinkModel*>& link_names =
1417
- robot_state.getRobotModel ()->getLinkModelsWithCollisionGeometry ();
1457
+ const std::vector<std::string>& link_names =
1458
+ highlight_links.empty () ? robot_state.getRobotModel ()->getLinkModelNamesWithCollisionGeometry () :
1459
+ highlight_links;
1418
1460
display_robot_msg.highlight_links .resize (link_names.size ());
1419
1461
1420
1462
// Get color
@@ -1423,7 +1465,7 @@ bool MoveItVisualTools::publishRobotState(const robot_state::RobotState& robot_s
1423
1465
// Color every link
1424
1466
for (std::size_t i = 0 ; i < link_names.size (); ++i)
1425
1467
{
1426
- display_robot_msg.highlight_links [i].id = link_names[i]-> getName () ;
1468
+ display_robot_msg.highlight_links [i].id = link_names[i];
1427
1469
display_robot_msg.highlight_links [i].color = color_rgba;
1428
1470
}
1429
1471
}
@@ -1453,6 +1495,10 @@ bool MoveItVisualTools::publishRobotState(const robot_state::RobotState& robot_s
1453
1495
pub_robot_state_.publish (display_robot_msg);
1454
1496
ros::spinOnce ();
1455
1497
1498
+ // remove highlight links from default message
1499
+ if (!highlight_links.empty ())
1500
+ display_robot_msg.highlight_links .clear ();
1501
+
1456
1502
return true ;
1457
1503
}
1458
1504
0 commit comments