Go to the documentation of this file.00001 #include "rail_grasping/graspObject.h"
00002
00003 using namespace std;
00004
00005 graspObject::graspObject() :
00006 acPickup("jaco_arm/manipulation/pickup"),
00007 acGrasp("jaco_arm/manipulation/grasp"),
00008 acJointTrajectory("jaco_arm/joint_velocity_controller/trajectory"),
00009 acMoveArm("carl_moveit_wrapper/move_to_pose")
00010 {
00011 ROS_INFO("Starting rail grasping...");
00012 graspTransform.setOrigin(tf::Vector3(0.0, 0.0, 0.0));
00013 graspTransform.setRotation(tf::Quaternion(0, 0, 0, 1));
00014
00015 armJointSubscriber = n.subscribe("jaco_arm/joint_states", 1, &graspObject::armJointStatesCallback, this);
00016
00017 IKClient = n.serviceClient<carl_moveit::CallIK>("carl_moveit_wrapper/call_ik");
00018
00019 jointNamesSet = false;
00020 armJointPos.resize(NUM_JACO_JOINTS);
00021 armJointNames.resize(NUM_JACO_JOINTS);
00022
00023 while (!acPickup.waitForServer(ros::Duration(5.0)) &&
00024 !acGrasp.waitForServer(ros::Duration(5.0)) &&
00025 !acJointTrajectory.waitForServer(ros::Duration(5.0)))
00026 {
00027 ROS_INFO("Waiting for grasp, pickup, and arm trajectory action servers...");
00028 }
00029
00030 requestGraspServer = n.advertiseService("rail_grasping/request_grasp", &graspObject::requestGrasp, this);
00031
00032 ROS_INFO("Rail grasping started.");
00033 }
00034
00035 void graspObject::armJointStatesCallback(const sensor_msgs::JointState &msg)
00036 {
00037 for (unsigned int i = 0; i < NUM_JACO_JOINTS; i++)
00038 {
00039 armJointPos[i] = msg.position[i];
00040 }
00041
00042 if (!jointNamesSet)
00043 {
00044 for (unsigned int i = 0; i < NUM_JACO_JOINTS; i++)
00045 {
00046 armJointNames[i] = msg.name[i];
00047 }
00048 jointNamesSet = true;
00049 }
00050 }
00051
00052 bool graspObject::requestGrasp(rail_grasping::RequestGrasp::Request & req, rail_grasping::RequestGrasp::Response & res)
00053 {
00054 ROS_INFO("Received new grasp request...");
00055
00056 graspTransform.setOrigin(tf::Vector3(req.graspPose.position.x, req.graspPose.position.y, req.graspPose.position.z));
00057 graspTransform.setRotation(tf::Quaternion(req.graspPose.orientation.x, req.graspPose.orientation.y, req.graspPose.orientation.z, req.graspPose.orientation.w));
00058 tfBroadcaster.sendTransform(tf::StampedTransform(graspTransform, ros::Time::now(), "base_footprint", "grasp_frame"));
00059
00060 ros::Duration(1).sleep();
00061
00062 bool earlyFailureDetected;
00063 res.result = executeGrasp(&earlyFailureDetected);
00064 res.earlyFailureDetected = earlyFailureDetected;
00065
00066 return true;
00067 }
00068
00069 bool graspObject::executeGrasp(bool *earlyFailureFlag)
00070 {
00071 ROS_INFO("\nGrasp execution started");
00072
00073
00074 geometry_msgs::PoseStamped approachPose;
00075 geometry_msgs::PoseStamped poseOut;
00076
00077 approachPose.header.frame_id = "grasp_frame";
00078 approachPose.pose.position.x = 0.0;
00079 approachPose.pose.position.y = 0.0;
00080 approachPose.pose.position.z = 0.1;
00081 approachPose.pose.orientation.x = 0.0;
00082 approachPose.pose.orientation.y = 0.0;
00083 approachPose.pose.orientation.z = 0.0;
00084 approachPose.pose.orientation.w = 1.0;
00085
00086
00087 approachPose.pose.position.z += .19;
00088
00089 tfListener.transformPose("base_footprint", approachPose, poseOut);
00090
00091
00092 ROS_INFO("Moving to approach angle...");
00093 carl_moveit::MoveToPoseGoal movePoseGoal;
00094 movePoseGoal.pose = poseOut.pose;
00095 acMoveArm.sendGoal(movePoseGoal);
00096 ROS_INFO("Approach angle arm move iniated.");
00097 acMoveArm.waitForResult(ros::Duration(10.0));
00098 carl_moveit::MoveToPoseResultConstPtr movePoseResult = acMoveArm.getResult();
00099
00100 *earlyFailureFlag = !movePoseResult->success;
00101 if (*earlyFailureFlag)
00102 {
00103 ROS_INFO("Detected failure on moving to approach angle.");
00104 return false;
00105 }
00106
00107
00108
00109 ROS_INFO("Waiting for trajectory execution...");
00110 ros::Duration(10.0).sleep();
00111 ROS_INFO("Done waiting for trajectory execution.");
00112
00113
00114
00115 ROS_INFO("Fully opening gripper...");
00116 wpi_jaco_msgs::ExecuteGraspGoal openGripperGoal;
00117 openGripperGoal.closeGripper = false;
00118 openGripperGoal.limitFingerVelocity = false;
00119 acGrasp.sendGoal(openGripperGoal);
00120 acGrasp.waitForResult(ros::Duration(5.0));
00121 ROS_INFO("Gripper opened.");
00122
00123
00124 geometry_msgs::PoseStamped pickupPose;
00125 geometry_msgs::PoseStamped pickupPoseOut;
00126 pickupPoseOut.header.frame_id = "base_footprint";
00127
00128 pickupPose.header.frame_id = "grasp_frame";
00129 pickupPose.pose.position.x = 0.0;
00130 pickupPose.pose.position.y = 0.0;
00131 pickupPose.pose.position.z = 0.0;
00132 pickupPose.pose.orientation.x = 0.0;
00133 pickupPose.pose.orientation.y = 0.0;
00134 pickupPose.pose.orientation.z = 0.0;
00135 pickupPose.pose.orientation.w = 1.0;
00136
00137
00138 approachPose.pose.position.z += .19;
00139
00140 tfListener.transformPose("base_footprint", pickupPose, pickupPoseOut);
00141
00142 ROS_INFO("Moving arm to pickup pose...");
00143
00144 if (!moveArmToPose(pickupPoseOut))
00145 {
00146 ROS_INFO("Failed to move arm to pickup pose");
00147 *earlyFailureFlag = true;
00148 return false;
00149 }
00150 ROS_INFO("Arm at pickup pose.");
00151
00152
00153 ROS_INFO("Closing gripper...");
00154 wpi_jaco_msgs::ExecuteGraspGoal closeGripperGoal;
00155 closeGripperGoal.closeGripper = true;
00156 closeGripperGoal.limitFingerVelocity = false;
00157 acGrasp.sendGoal(closeGripperGoal);
00158 acGrasp.waitForResult(ros::Duration(5.0));
00159 ROS_INFO("Gripper closed.");
00160
00161
00162
00163
00164
00165 ROS_INFO("Lifting object...");
00166 wpi_jaco_msgs::ExecutePickupGoal pickupGoal;
00167 pickupGoal.limitFingerVelocity = false;
00168 pickupGoal.setLiftVelocity = false;
00169 acPickup.sendGoal(pickupGoal);
00170 acPickup.waitForResult(ros::Duration(10));
00171 ROS_INFO("Object lifting complete.");
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 return true;
00203 }
00204
00205 bool graspObject::moveArmToPose(geometry_msgs::PoseStamped poseGoal)
00206 {
00207
00208 carl_moveit::CallIK::Request ikReq;
00209 carl_moveit::CallIK::Response ikRes;
00210 ikReq.pose = poseGoal.pose;
00211 IKClient.call(ikReq, ikRes);
00212
00213 if (ikRes.success = false)
00214 {
00215 ROS_INFO("IK Server returned false");
00216 return false;
00217 }
00218
00219
00220
00221 if (!jointNamesSet)
00222 {
00223 ROS_INFO("Joint data from the arm has not been received");
00224 return false;
00225 }
00226
00227 trajectory_msgs::JointTrajectoryPoint startPoint;
00228 trajectory_msgs::JointTrajectoryPoint endPoint;
00229 startPoint.positions = armJointPos;
00230 endPoint.positions = ikRes.jointPositions;
00231 control_msgs::FollowJointTrajectoryGoal trajGoal;
00232 trajGoal.trajectory.joint_names = armJointNames;
00233 trajGoal.trajectory.points.clear();
00234 trajGoal.trajectory.points.push_back(startPoint);
00235 trajGoal.trajectory.points.push_back(endPoint);
00236
00237
00238
00239
00240 ROS_INFO("Sending trajectory goal directly to arm");
00241
00242 acJointTrajectory.sendGoal(trajGoal);
00243 acJointTrajectory.waitForResult(ros::Duration(10.0));
00244
00245
00246 return true;
00247 }
00248
00249 void graspObject::publishGraspFrame()
00250 {
00251 tfBroadcaster.sendTransform(tf::StampedTransform(graspTransform, ros::Time::now(), "base_footprint", "grasp_frame"));
00252 }
00253
00254 int main(int argc, char **argv)
00255 {
00256 ros::init(argc, argv, "rail_grasping");
00257
00258 graspObject go;
00259
00260 ros::Rate loop_rate(30);
00261 while (ros::ok())
00262 {
00263 ros::spinOnce();
00264 go.publishGraspFrame();
00265 loop_rate.sleep();
00266 }
00267
00268 return 0;
00269 }