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
00033
00034
00035
00036
00037
00038 #include <ros/ros.h>
00039
00040
00041 #include <moveit/robot_model_loader/robot_model_loader.h>
00042 #include <moveit/planning_scene/planning_scene.h>
00043
00044 #include <moveit/kinematic_constraints/utils.h>
00045 #include <eigen_conversions/eigen_msg.h>
00046
00047 bool userCallback(const robot_state::RobotState &kinematic_state, bool verbose)
00048 {
00049
00050 const std::vector<double>& joint_state_values = kinematic_state.getJointState("r_shoulder_pan_joint")->getVariableValues();
00051 return (joint_state_values.front() > 0.0);
00052 }
00053
00054 int main(int argc, char **argv)
00055 {
00056 ros::init (argc, argv, "right_arm_kinematics");
00057 ros::AsyncSpinner spinner(1);
00058 spinner.start();
00059
00060
00061 robot_model_loader::RobotModelLoader robot_model_loader("robot_description");
00062
00063
00064 robot_model::RobotModelPtr kinematic_model = robot_model_loader.getModel();
00065
00066
00067
00068
00069 planning_scene::PlanningScene planning_scene(kinematic_model);
00070
00071
00072
00073 robot_state::RobotState& current_state = planning_scene.getCurrentStateNonConst();
00074
00075
00076
00077
00078 collision_detection::CollisionRequest collision_request;
00079 collision_detection::CollisionResult collision_result;
00080 planning_scene.checkSelfCollision(collision_request, collision_result);
00081 ROS_INFO_STREAM("Test 1 : Current state is " << (collision_result.collision ? "in" : "not in") << " self collision");
00082
00083
00084 current_state.setToRandomValues();
00085 collision_result.clear();
00086 planning_scene.checkSelfCollision(collision_request, collision_result);
00087 ROS_INFO_STREAM("Test 2 : Current state is " << (collision_result.collision ? "in" : "not in") << " self collision");
00088
00089
00090
00091 collision_request.group_name = "right_arm";
00092 current_state.setToRandomValues();
00093 collision_result.clear();
00094 planning_scene.checkSelfCollision(collision_request, collision_result);
00095 ROS_INFO_STREAM("Test 3: Current state is " << (collision_result.collision ? "in" : "not in") << " self collision");
00096
00097
00098
00099 std::vector<double> joint_values;
00100 robot_state::JointStateGroup* joint_state_group = current_state.getJointStateGroup("right_arm");
00101 joint_state_group->getVariableValues(joint_values);
00102 joint_values[0] = 1.57;
00103 joint_state_group->setVariableValues(joint_values);
00104
00105
00106 ROS_INFO_STREAM("Current state is " << (current_state.satisfiesBounds() ? "valid" : "not valid"));
00107
00108
00109
00110 collision_request.contacts = true;
00111 collision_request.max_contacts = 1000;
00112
00113 collision_result.clear();
00114 planning_scene.checkSelfCollision(collision_request, collision_result);
00115 ROS_INFO_STREAM("Test 4: Current state is " << (collision_result.collision ? "in" : "not in") << " self collision");
00116 for(collision_detection::CollisionResult::ContactMap::const_iterator it = collision_result.contacts.begin();
00117 it != collision_result.contacts.end();
00118 ++it)
00119 {
00120 ROS_INFO("Contact between: %s and %s", it->first.first.c_str(), it->first.second.c_str());
00121 }
00122
00123
00124 collision_detection::AllowedCollisionMatrix acm = planning_scene.getAllowedCollisionMatrix();
00125 robot_state::RobotState copied_state = planning_scene.getCurrentState();
00126
00127 for(collision_detection::CollisionResult::ContactMap::const_iterator it = collision_result.contacts.begin();
00128 it != collision_result.contacts.end();
00129 ++it)
00130 {
00131 acm.setEntry(it->first.first, it->first.second, true);
00132 }
00133 collision_result.clear();
00134 planning_scene.checkSelfCollision(collision_request, collision_result, copied_state, acm);
00135 ROS_INFO_STREAM("Test 5: Current state is " << (collision_result.collision ? "in" : "not in") << " self collision");
00136
00137
00138
00139
00140
00141
00142 collision_result.clear();
00143 planning_scene.checkCollision(collision_request, collision_result, copied_state, acm);
00144 ROS_INFO_STREAM("Test 6: Current state is " << (collision_result.collision ? "in" : "not in") << " self collision");
00145
00146
00147
00148
00149 const robot_model::JointModelGroup* joint_model_group = kinematic_model->getJointModelGroup("right_arm");
00150 std::string end_effector_name = joint_model_group->getLinkModelNames().back();
00151
00152 geometry_msgs::PoseStamped desired_pose;
00153 desired_pose.pose.orientation.w = 1.0;
00154 desired_pose.pose.position.x = 0.75;
00155 desired_pose.pose.position.y = -0.185;
00156 desired_pose.pose.position.z = 1.3;
00157 desired_pose.header.frame_id = "base_footprint";
00158
00159 moveit_msgs::Constraints goal_constraint = kinematic_constraints::constructGoalConstraints(end_effector_name, desired_pose);
00160
00161
00162 copied_state.setToRandomValues();
00163 bool state_constrained = planning_scene.isStateConstrained(copied_state, goal_constraint);
00164 ROS_INFO_STREAM("Test 7: Random state is " << (state_constrained ? "constrained" : "not constrained"));
00165
00166
00167
00168
00169 kinematic_constraints::KinematicConstraintSet kinematic_constraint_set(kinematic_model);
00170 kinematic_constraint_set.add(goal_constraint, planning_scene.getTransforms());
00171
00172 bool state_constrained_2 = planning_scene.isStateConstrained(copied_state, kinematic_constraint_set);
00173 ROS_INFO_STREAM("Test 8: Random state is " << (state_constrained_2 ? "constrained" : "not constrained"));
00174
00175
00176 kinematic_constraints::ConstraintEvaluationResult constraint_eval_result = kinematic_constraint_set.decide(copied_state);
00177 ROS_INFO_STREAM("Test 9: Random state is " << (constraint_eval_result.satisfied ? "constrained" : "not constrained"));
00178
00179
00180
00181
00182 planning_scene.setStateFeasibilityPredicate(userCallback);
00183 bool state_feasible = planning_scene.isStateFeasible(copied_state);
00184 ROS_INFO_STREAM("Test 10: Random state is " << (state_feasible ? "feasible" : "not feasible"));
00185
00186
00187
00188 bool state_valid = planning_scene.isStateValid(copied_state, kinematic_constraint_set, "right_arm");
00189 ROS_INFO_STREAM("Test 10: Random state is " << (state_valid ? "valid" : "not valid"));
00190
00191 ros::shutdown();
00192 return 0;
00193 }