0

Rosanswers logo

I need to open and close the gripper of PR2. I did not find any option to do that in python. From this tutorial, I found these functions:

void openGripper(trajectory_msgs::JointTrajectory& posture)
{
  // BEGIN_SUB_TUTORIAL open_gripper
  /* Add both finger joints of panda robot. */
  posture.joint_names.resize(2);
  posture.joint_names[0] = "panda_finger_joint1";
  posture.joint_names[1] = "panda_finger_joint2";

/* Set them as open, wide enough for the object to fit. */ posture.points.resize(1); posture.points[0].positions.resize(2); posture.points[0].positions[0] = 0.04; posture.points[0].positions[1] = 0.04; posture.points[0].time_from_start = ros::Duration(0.5); // END_SUB_TUTORIAL }

void closedGripper(trajectory_msgs::JointTrajectory& posture) { // BEGIN_SUB_TUTORIAL closed_gripper /* Add both finger joints of panda robot. */ posture.joint_names.resize(2); posture.joint_names[0] = "panda_finger_joint1"; posture.joint_names[1] = "panda_finger_joint2";

/* Set them as closed. */ posture.points.resize(1); posture.points[0].positions.resize(2); posture.points[0].positions[0] = 0.00; posture.points[0].positions[1] = 0.00; posture.points[0].time_from_start = ros::Duration(0.5); // END_SUB_TUTORIAL }

Could anyone provide a simple example of how to call these functions from python? I do not how to wrap python with C++ and I did not find any straightforward tutorial for ROS. The panda_finger_joint1 should be replaced by PR2's joint though which I think is _gripper_joint.


Originally posted by Tawfiq Chowdhury on ROS Answers with karma: 137 on 2019-07-20

Post score: 1

1 Answers1

0

Rosanswers logo

Hi,

You can control PR2's grippers by calling the gripper action server. For example, the right gripper provides the action r_gripper_controller/gripper_action which you can call as

$ rosrun actionlib axclient.py /r_gripper_controller/gripper_action

To do it from a python script, you can adapt this tutorial to call the gripper action.


Originally posted by diogoa with karma: 16 on 2019-07-22

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Tawfiq Chowdhury on 2019-07-22:
@diogoa Can you please elaborate a bit more, how to open and close the gripper? In C++, there are functions such as openGripper and closeGripper.

Comment by diogoa on 2019-07-22:
I understood that you want to open and close the gripper from Python. In that case, the best you can do is call the appropriate action service that allows you to open and close the gripper, and that is the gripper action service.

If you run the command I listed above, you should see a GUI pop up and allow you to command the gripper. Once you are confident the gripper can open and close that way, it is easy to create a python script which calls it programmatically. I suggested adapting the action lib tutorial I linking in my answer, but of course you can then integrate it on your code.

Comment by Madcreator on 2020-02-07:
I think that OP wants to control the gripper at a joint level in order to use the moveit pick place pipeline. I am also trying to find a solution now. The gripper action server isn't adapted to the moveit pick place pipeline as it only accept command whereas the pipeline needs joints values...