state_validation_service_capability.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
42 
43 namespace move_group
44 {
45 MoveGroupStateValidationService::MoveGroupStateValidationService() : MoveGroupCapability("StateValidationService")
46 {
47 }
48 
50 {
53 }
54 
55 bool MoveGroupStateValidationService::computeService(moveit_msgs::GetStateValidity::Request& req,
56  moveit_msgs::GetStateValidity::Response& res)
57 {
58  planning_scene_monitor::LockedPlanningSceneRO ls(context_->planning_scene_monitor_);
59  moveit::core::RobotState rs = ls->getCurrentState();
60  moveit::core::robotStateMsgToRobotState(req.robot_state, rs);
61 
62  res.valid = true;
63 
64  // configure collision request
66  creq.group_name = req.group_name;
67  creq.cost = true;
68  creq.contacts = true;
69  creq.max_contacts = ls->getWorld()->size() + ls->getRobotModel()->getLinkModelsWithCollisionGeometry().size();
70  creq.max_cost_sources = creq.max_contacts;
71  creq.max_contacts *= creq.max_contacts;
73 
74  // check collision
75  ls->checkCollision(creq, cres, rs);
76 
77  // copy contacts if any
78  if (cres.collision)
79  {
80  ros::Time time_now = ros::Time::now();
81  res.contacts.reserve(cres.contact_count);
82  res.valid = false;
83  for (collision_detection::CollisionResult::ContactMap::const_iterator it = cres.contacts.begin();
84  it != cres.contacts.end(); ++it)
85  for (const collision_detection::Contact& contact : it->second)
86  {
87  res.contacts.resize(res.contacts.size() + 1);
88  collision_detection::contactToMsg(contact, res.contacts.back());
89  res.contacts.back().header.frame_id = ls->getPlanningFrame();
90  res.contacts.back().header.stamp = time_now;
91  }
92  }
93 
94  // copy cost sources
95  res.cost_sources.reserve(cres.cost_sources.size());
96  for (const collision_detection::CostSource& cost_source : cres.cost_sources)
97  {
98  res.cost_sources.resize(res.cost_sources.size() + 1);
99  collision_detection::costSourceToMsg(cost_source, res.cost_sources.back());
100  }
101 
102  // evaluate constraints
103  if (!moveit::core::isEmpty(req.constraints))
104  {
105  kinematic_constraints::KinematicConstraintSet kset(ls->getRobotModel());
106  kset.add(req.constraints, ls->getTransforms());
107  std::vector<kinematic_constraints::ConstraintEvaluationResult> kres;
108  kinematic_constraints::ConstraintEvaluationResult total_result = kset.decide(rs, kres);
109  if (!total_result.satisfied)
110  res.valid = false;
111 
112  // copy constraint results
113  res.constraint_result.resize(kres.size());
114  for (std::size_t k = 0; k < kres.size(); ++k)
115  {
116  res.constraint_result[k].result = kres[k].satisfied;
117  res.constraint_result[k].distance = kres[k].distance;
118  }
119  }
120 
121  return true;
122 }
123 } // namespace move_group
124 
move_group::MoveGroupStateValidationService
Definition: state_validation_service_capability.h:76
collision_detection::CollisionRequest::cost
bool cost
move_group::MoveGroupCapability
Definition: move_group_capability.h:89
move_group::MoveGroupCapability::context_
MoveGroupContextPtr context_
Definition: move_group_capability.h:132
collision_tools.h
collision_detection::costSourceToMsg
void costSourceToMsg(const CostSource &cost_source, moveit_msgs::CostSource &msg)
collision_detection::contactToMsg
void contactToMsg(const Contact &contact, moveit_msgs::ContactInformation &msg)
ros::NodeHandle::advertiseService
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
move_group::MoveGroupStateValidationService::validity_service_
ros::ServiceServer validity_service_
Definition: state_validation_service_capability.h:118
moveit::core::RobotState
kinematic_constraints::ConstraintEvaluationResult::satisfied
bool satisfied
collision_detection::Contact
collision_detection::CollisionRequest
collision_detection::CostSource
message_checks.h
moveit::core::isEmpty
bool isEmpty(const geometry_msgs::Pose &msg)
move_group::MoveGroupCapability::root_node_handle_
ros::NodeHandle root_node_handle_
Definition: move_group_capability.h:129
state_validation_service_capability.h
collision_detection::CollisionResult
collision_detection::CollisionRequest::max_contacts
std::size_t max_contacts
move_group::STATE_VALIDITY_SERVICE_NAME
static const std::string STATE_VALIDITY_SERVICE_NAME
Definition: capability_names.h:87
collision_detection::CollisionRequest::group_name
std::string group_name
kinematic_constraints::KinematicConstraintSet
move_group
Definition: capability_names.h:41
class_loader.hpp
move_group::MoveGroupStateValidationService::initialize
void initialize() override
Definition: state_validation_service_capability.cpp:81
collision_detection::CollisionResult::contacts
ContactMap contacts
move_group::MoveGroupStateValidationService::MoveGroupStateValidationService
MoveGroupStateValidationService()
Definition: state_validation_service_capability.cpp:77
ros::Time
planning_scene_monitor::LockedPlanningSceneRO
collision_detection::CollisionRequest::contacts
bool contacts
collision_detection::CollisionRequest::max_cost_sources
std::size_t max_cost_sources
collision_detection::CollisionResult::collision
bool collision
conversions.h
collision_detection::CollisionResult::cost_sources
std::set< CostSource > cost_sources
CLASS_LOADER_REGISTER_CLASS
CLASS_LOADER_REGISTER_CLASS(default_planner_request_adapters::AddIterativeSplineParameterization, planning_request_adapter::PlanningRequestAdapter)
collision_detection::CollisionResult::contact_count
std::size_t contact_count
capability_names.h
moveit::core::robotStateMsgToRobotState
bool robotStateMsgToRobotState(const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
ros::Time::now
static Time now()
kinematic_constraints::ConstraintEvaluationResult
move_group::MoveGroupStateValidationService::computeService
bool computeService(moveit_msgs::GetStateValidity::Request &req, moveit_msgs::GetStateValidity::Response &res)
Definition: state_validation_service_capability.cpp:87


move_group
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Sun Mar 3 2024 03:24:41