FreePositioning.cpp
Go to the documentation of this file.
00001 #include <remote_manipulation_markers/FreePositioning.h>
00002 
00003 using namespace std;
00004 
00005 FreePositioning::FreePositioning() :
00006         pnh("~"), specifiedGraspServer(pnh, "execute_grasp", boost::bind(&FreePositioning::executeGraspCallback, this, _1), false)
00007 {
00008   //read in parameters
00009   string graspTopic;
00010   pnh.param<string>("base_link", baseLink, "base_link");
00011   pnh.param<string>("eef_link", eefLink, "eef_link");
00012   pnh.param<string>("grasp_topic", graspTopic, "grasp");
00013 
00014   //messages
00015   markerPosePublisher = pnh.advertise<geometry_msgs::PoseStamped>("gripper_marker_pose", 1);
00016 
00017   //services
00018   resetMarkerPoseServer = pnh.advertiseService("reset_marker_pose", &FreePositioning::resetMarkerPoseCallback, this);
00019 
00020   //actionlib
00021   graspClient = new actionlib::SimpleActionClient<rail_manipulation_msgs::PickupAction>(graspTopic);
00022 
00023   imServer.reset(
00024       new interactive_markers::InteractiveMarkerServer("free_positioning", "free_positioning", false));
00025 
00026   ros::Duration(0.1).sleep();
00027 
00028   //set up marker
00029   tf::StampedTransform currentEefTransform;
00030   tfListener.waitForTransform(eefLink, baseLink, ros::Time::now(), ros::Duration(1.0));
00031   tfListener.lookupTransform(baseLink, eefLink, ros::Time(0), currentEefTransform);
00032   geometry_msgs::PoseStamped pose;
00033   pose.pose.position.x = currentEefTransform.getOrigin().x();
00034   pose.pose.position.y = currentEefTransform.getOrigin().y();
00035   pose.pose.position.z = currentEefTransform.getOrigin().z();
00036   pose.pose.orientation.x = currentEefTransform.getRotation().x();
00037   pose.pose.orientation.y = currentEefTransform.getRotation().y();
00038   pose.pose.orientation.z = currentEefTransform.getRotation().z();
00039   pose.pose.orientation.w = currentEefTransform.getRotation().w();
00040   visualization_msgs::InteractiveMarker iMarker = Common::makeGripperMarker(pose);
00041   iMarker.header.frame_id = baseLink;
00042 
00043   //add 6-DOF controls
00044   visualization_msgs::InteractiveMarkerControl control;
00045 
00046   control.orientation.w = 1;
00047   control.orientation.x = 1;
00048   control.orientation.y = 0;
00049   control.orientation.z = 0;
00050   control.name = "rotate_x";
00051   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00052   iMarker.controls.push_back(control);
00053   control.name = "move_x";
00054   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00055   iMarker.controls.push_back(control);
00056 
00057   control.orientation.w = 1;
00058   control.orientation.x = 0;
00059   control.orientation.y = 1;
00060   control.orientation.z = 0;
00061   control.name = "rotate_y";
00062   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00063   iMarker.controls.push_back(control);
00064   control.name = "move_y";
00065   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00066   iMarker.controls.push_back(control);
00067 
00068   control.orientation.w = 1;
00069   control.orientation.x = 0;
00070   control.orientation.y = 0;
00071   control.orientation.z = 1;
00072   control.name = "rotate_z";
00073   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00074   iMarker.controls.push_back(control);
00075   control.name = "move_z";
00076   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00077   iMarker.controls.push_back(control);
00078 
00079   imServer->insert(iMarker);
00080   imServer->applyChanges();
00081 
00082   specifiedGraspServer.start();
00083 }
00084 
00085 FreePositioning::~FreePositioning()
00086 {
00087   delete graspClient;
00088 }
00089 
00090 void FreePositioning::executeGraspCallback(const remote_manipulation_markers::SpecifiedGraspGoalConstPtr &goal)
00091 {
00092   remote_manipulation_markers::SpecifiedGraspFeedback feedback;
00093   remote_manipulation_markers::SpecifiedGraspResult result;
00094 
00095   feedback.message = "Moving arm to your set position...";
00096   specifiedGraspServer.publishFeedback(feedback);
00097 
00098   visualization_msgs::InteractiveMarker poseMarker;
00099   imServer->get("gripper", poseMarker);
00100 
00101   rail_manipulation_msgs::PickupGoal graspGoal;
00102   graspGoal.pose.header = poseMarker.header;
00103   graspGoal.pose.pose = poseMarker.pose;
00104   graspGoal.lift = false;
00105   graspGoal.verify = false;
00106   graspClient->sendGoal(graspGoal);
00107   graspClient->waitForResult(ros::Duration(30.0));
00108   rail_manipulation_msgs::PickupResultConstPtr graspResult = graspClient->getResult();
00109   result.success = graspResult->success;
00110   result.executionSuccess = graspResult->executionSuccess;
00111   if (!graspResult->executionSuccess)
00112   {
00113     ROS_INFO("Grasp failed!");
00114     feedback.message = "Failed to plan to your grasp. Try a different start or end pose, and watch out for collisions.";
00115   }
00116   else
00117   {
00118     ROS_INFO("Grasp succeeded.");
00119     feedback.message = "Success!";
00120   }
00121   specifiedGraspServer.publishFeedback(feedback);
00122   specifiedGraspServer.setSucceeded(result);
00123 }
00124 
00125 bool FreePositioning::resetMarkerPoseCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
00126 {
00127   tf::StampedTransform currentEefTransform;
00128   tfListener.waitForTransform(eefLink, baseLink, ros::Time::now(), ros::Duration(1.0));
00129   tfListener.lookupTransform(baseLink, eefLink, ros::Time(0), currentEefTransform);
00130   geometry_msgs::Pose pose;
00131   pose.position.x = currentEefTransform.getOrigin().x();
00132   pose.position.y = currentEefTransform.getOrigin().y();
00133   pose.position.z = currentEefTransform.getOrigin().z();
00134   pose.orientation.x = currentEefTransform.getRotation().x();
00135   pose.orientation.y = currentEefTransform.getRotation().y();
00136   pose.orientation.z = currentEefTransform.getRotation().z();
00137   pose.orientation.w = currentEefTransform.getRotation().w();
00138   imServer->setPose("gripper", pose);
00139   imServer->applyChanges();
00140 
00141   return true;
00142 }
00143 
00144 void FreePositioning::publishMarkerPose()
00145 {
00146   visualization_msgs::InteractiveMarker poseMarker;
00147   imServer->get("gripper", poseMarker);
00148 
00149   geometry_msgs::PoseStamped pose;
00150   pose.header = poseMarker.header;
00151   pose.pose = poseMarker.pose;
00152 
00153   markerPosePublisher.publish(pose);
00154 }
00155 
00156 int main(int argc, char **argv)
00157 {
00158   ros::init(argc, argv, "free_positioning");
00159 
00160   FreePositioning fp;
00161 
00162   ros::Rate loopRate(30);
00163   while (ros::ok())
00164   {
00165     fp.publishMarkerPose();
00166     ros::spinOnce();
00167     loopRate.sleep();
00168   }
00169 }


remote_manipulation_markers
Author(s): David Kent
autogenerated on Thu Jun 6 2019 22:05:39