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
00039
00040 #include <moveit_simple_grasps/grasp_data.h>
00041
00042
00043 #include <Eigen/Core>
00044 #include <Eigen/Geometry>
00045 #include <eigen_conversions/eigen_msg.h>
00046
00047
00048 #include <math.h>
00049 #define _USE_MATH_DEFINES
00050
00051 namespace moveit_simple_grasps
00052 {
00053 GraspData::GraspData() :
00054
00055 base_link_("/base_link"),
00056 grasp_depth_(0.12),
00057 angle_resolution_(16),
00058 approach_retreat_desired_dist_(0.6),
00059 approach_retreat_min_dist_(0.4),
00060 object_size_(0.04)
00061 {}
00062
00063 bool GraspData::loadRobotGraspData(const ros::NodeHandle& nh, const std::string& end_effector)
00064 {
00065 std::vector<std::string> joint_names;
00066 std::vector<double> pre_grasp_posture;
00067 std::vector<double> grasp_posture;
00068 std::vector<double> grasp_pose_to_eef;
00069 std::vector<double> grasp_pose_to_eef_rotation;
00070 double pregrasp_time_from_start;
00071 double grasp_time_from_start;
00072 std::string end_effector_name;
00073 std::string end_effector_parent_link;
00074
00075
00076 if (!nh.hasParam("base_link"))
00077 {
00078 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `base_link` missing from rosparam server. Did you load your end effector's configuration yaml file? Searching in namespace: " << nh.getNamespace());
00079 return false;
00080 }
00081 nh.getParam("base_link", base_link_);
00082
00083
00084 ros::NodeHandle child_nh(nh, end_effector);
00085
00086
00087 if (!child_nh.hasParam("pregrasp_time_from_start"))
00088 {
00089 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `pregrasp_time_from_start` missing from rosparam server. Did you load your end effector's configuration yaml file? Searching in namespace: " << child_nh.getNamespace());
00090 return false;
00091 }
00092 child_nh.getParam("pregrasp_time_from_start", pregrasp_time_from_start);
00093
00094
00095 if (!child_nh.hasParam("grasp_time_from_start"))
00096 {
00097 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `grasp_time_from_start` missing from rosparam server. Did you load your end effector's configuration yaml file?");
00098 return false;
00099 }
00100 child_nh.getParam("grasp_time_from_start", grasp_time_from_start);
00101
00102
00103 if (!child_nh.hasParam("end_effector_name"))
00104 {
00105 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `end_effector_name` missing from rosparam server. Did you load your end effector's configuration yaml file?");
00106 return false;
00107 }
00108 child_nh.getParam("end_effector_name", end_effector_name);
00109
00110
00111 if (!child_nh.hasParam("end_effector_parent_link"))
00112 {
00113 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `end_effector_parent_link` missing from rosparam server. Did you load your end effector's configuration yaml file?");
00114 return false;
00115 }
00116 child_nh.getParam("end_effector_parent_link", end_effector_parent_link);
00117
00118
00119 if (!child_nh.hasParam("joints"))
00120 {
00121 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `joints` missing from rosparam server. Did you load your end effector's configuration yaml file?");
00122 return false;
00123 }
00124 XmlRpc::XmlRpcValue joint_list;
00125 child_nh.getParam("joints", joint_list);
00126 if (joint_list.getType() == XmlRpc::XmlRpcValue::TypeArray)
00127 for (int32_t i = 0; i < joint_list.size(); ++i)
00128 {
00129 ROS_ASSERT(joint_list[i].getType() == XmlRpc::XmlRpcValue::TypeString);
00130 joint_names.push_back(static_cast<std::string>(joint_list[i]));
00131 }
00132 else
00133 ROS_ERROR_STREAM_NAMED("temp","joint list type is not type array???");
00134
00135 if(child_nh.hasParam("pregrasp_posture"))
00136 {
00137 XmlRpc::XmlRpcValue preg_posture_list;
00138 child_nh.getParam("pregrasp_posture", preg_posture_list);
00139 ROS_ASSERT(preg_posture_list.getType() == XmlRpc::XmlRpcValue::TypeArray);
00140 for (int32_t i = 0; i < preg_posture_list.size(); ++i)
00141 {
00142 ROS_ASSERT(preg_posture_list[i].getType() == XmlRpc::XmlRpcValue::TypeDouble);
00143 pre_grasp_posture.push_back(static_cast<double>(preg_posture_list[i]));
00144 }
00145 }
00146
00147 ROS_ASSERT(child_nh.hasParam("grasp_posture"));
00148 XmlRpc::XmlRpcValue grasp_posture_list;
00149 child_nh.getParam("grasp_posture", grasp_posture_list);
00150 ROS_ASSERT(grasp_posture_list.getType() == XmlRpc::XmlRpcValue::TypeArray);
00151 for (int32_t i = 0; i < grasp_posture_list.size(); ++i)
00152 {
00153 ROS_ASSERT(grasp_posture_list[i].getType() == XmlRpc::XmlRpcValue::TypeDouble);
00154 grasp_posture.push_back(static_cast<double>(grasp_posture_list[i]));
00155 }
00156
00157 ROS_ASSERT(child_nh.hasParam("grasp_pose_to_eef"));
00158 XmlRpc::XmlRpcValue g_to_eef_list;
00159 child_nh.getParam("grasp_pose_to_eef", g_to_eef_list);
00160 ROS_ASSERT(g_to_eef_list.getType() == XmlRpc::XmlRpcValue::TypeArray);
00161 for (int32_t i = 0; i < g_to_eef_list.size(); ++i)
00162 {
00163
00164 if (g_to_eef_list[i].getType() != XmlRpc::XmlRpcValue::TypeDouble)
00165 {
00166 if (g_to_eef_list[i].getType() != XmlRpc::XmlRpcValue::TypeInt )
00167 {
00168 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `grasp_pose_to_eef` wrong data type - int or double required.");
00169 return false;
00170 }
00171 else
00172 grasp_pose_to_eef.push_back(static_cast<int>(g_to_eef_list[i]));
00173 }
00174 else
00175 grasp_pose_to_eef.push_back(static_cast<double>(g_to_eef_list[i]));
00176 }
00177
00178 ROS_ASSERT(child_nh.hasParam("grasp_pose_to_eef_rotation"));
00179 XmlRpc::XmlRpcValue g_to_eef_rotation_list;
00180 child_nh.getParam("grasp_pose_to_eef_rotation", g_to_eef_rotation_list);
00181 ROS_ASSERT(g_to_eef_rotation_list.getType() == XmlRpc::XmlRpcValue::TypeArray);
00182 for (int32_t i = 0; i < g_to_eef_rotation_list.size(); ++i)
00183 {
00184
00185 if (g_to_eef_rotation_list[i].getType() != XmlRpc::XmlRpcValue::TypeDouble)
00186 {
00187 if (g_to_eef_rotation_list[i].getType() != XmlRpc::XmlRpcValue::TypeInt )
00188 {
00189 ROS_ERROR_STREAM_NAMED("grasp_data_loader","Grasp configuration parameter `grasp_pose_to_eef_rotation` wrong data type - int or double required.");
00190 return false;
00191 }
00192 else
00193 grasp_pose_to_eef_rotation.push_back(static_cast<int>(g_to_eef_rotation_list[i]));
00194 }
00195 else
00196 grasp_pose_to_eef_rotation.push_back(static_cast<double>(g_to_eef_rotation_list[i]));
00197 }
00198
00199
00200
00201
00202
00203 ROS_ASSERT(grasp_pose_to_eef_rotation.size() == 3);
00204 Eigen::Quaterniond quat(Eigen::AngleAxis<double>(double(grasp_pose_to_eef_rotation[1]), Eigen::Vector3d::UnitY()));
00205
00206
00207 grasp_pose_to_eef_pose_.orientation.x = quat.x();
00208 grasp_pose_to_eef_pose_.orientation.y = quat.y();
00209 grasp_pose_to_eef_pose_.orientation.z = quat.z();
00210 grasp_pose_to_eef_pose_.orientation.w = quat.w();
00211
00212
00213 ROS_ASSERT(grasp_pose_to_eef.size() == 3);
00214 grasp_pose_to_eef_pose_.position.x = grasp_pose_to_eef[0];
00215 grasp_pose_to_eef_pose_.position.y = grasp_pose_to_eef[1];
00216 grasp_pose_to_eef_pose_.position.z = grasp_pose_to_eef[2];
00217
00218
00219
00220 if(!pre_grasp_posture.empty())
00221 {
00222 pre_grasp_posture_.header.frame_id = base_link_;
00223 pre_grasp_posture_.header.stamp = ros::Time::now();
00224
00225 pre_grasp_posture_.joint_names = joint_names;
00226
00227 pre_grasp_posture_.points.resize(1);
00228 pre_grasp_posture_.points[0].positions = pre_grasp_posture;
00229 pre_grasp_posture_.points[0].time_from_start = ros::Duration(pregrasp_time_from_start);
00230 }
00231
00232
00233 grasp_posture_.header.frame_id = base_link_;
00234 grasp_posture_.header.stamp = ros::Time::now();
00235
00236 grasp_posture_.joint_names = joint_names;
00237
00238 grasp_posture_.points.resize(1);
00239 grasp_posture_.points[0].positions = grasp_posture;
00240 grasp_posture_.points[0].time_from_start = ros::Duration(grasp_time_from_start);
00241
00242
00243
00244 ee_parent_link_ = end_effector_parent_link;
00245 ee_group_ = end_effector_name;
00246
00247
00248
00249 approach_retreat_desired_dist_ = 0.2;
00250 approach_retreat_min_dist_ = 0.06;
00251
00252 grasp_depth_ = 0.06;
00253
00254
00255 angle_resolution_ = 16;
00256
00257
00258
00259
00260 return true;
00261 }
00262
00263 bool GraspData::setRobotStatePreGrasp( robot_state::RobotStatePtr &robot_state )
00264 {
00265 return setRobotState( robot_state, pre_grasp_posture_ );
00266 }
00267 bool GraspData::setRobotStateGrasp( robot_state::RobotStatePtr &robot_state )
00268 {
00269 return setRobotState( robot_state, grasp_posture_ );
00270 }
00271
00272 bool GraspData::setRobotState( robot_state::RobotStatePtr &robot_state, const trajectory_msgs::JointTrajectory &posture )
00273 {
00274
00275 for (std::size_t i = 0; i < posture.joint_names.size(); ++i)
00276 {
00277
00278 std::cout << "Setting joint " << posture.joint_names[i] << " to value "
00279 << posture.points[i].positions[0] << std::endl;
00280
00281
00282 robot_state->setJointPositions( posture.joint_names[i],
00283 posture.points[i].positions );
00284 }
00285 }
00286
00287 void GraspData::print()
00288 {
00289 ROS_WARN_STREAM_NAMED("grasp_data","Debug Grasp Data variable values:");
00290 std::cout << "grasp_pose_to_eef_pose_: \n" <<grasp_pose_to_eef_pose_<<std::endl;
00291 std::cout << "pre_grasp_posture_: \n" <<pre_grasp_posture_<<std::endl;
00292 std::cout << "grasp_posture_: \n" <<grasp_posture_<<std::endl;
00293 std::cout << "base_link_: " <<base_link_<<std::endl;
00294 std::cout << "ee_parent_link_: " <<ee_parent_link_<<std::endl;
00295 std::cout << "ee_group_: " <<ee_group_<<std::endl;
00296 std::cout << "grasp_depth_: " <<grasp_depth_<<std::endl;
00297 std::cout << "angle_resolution_: " <<angle_resolution_<<std::endl;
00298 std::cout << "approach_retreat_desired_dist_: " <<approach_retreat_desired_dist_<<std::endl;
00299 std::cout << "approach_retreat_min_dist_: " <<approach_retreat_min_dist_<<std::endl;
00300 std::cout << "object_size_: " <<object_size_<<std::endl;
00301 }
00302
00303 }