ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to call the openGripper functon from python

asked 2019-07-20 18:45:58 -0600

Tawfiq Chowdhury gravatar image

updated 2019-07-21 13:32:54 -0600

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[0] = "panda_finger_joint1";
  posture.joint_names[1] = "panda_finger_joint2";

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

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

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

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-07-22 09:12:55 -0600

diogoa gravatar image


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 /r_gripper_controller/gripper_action

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

edit flag offensive delete link more


@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.

Tawfiq Chowdhury gravatar image Tawfiq Chowdhury  ( 2019-07-22 14:50:32 -0600 )edit

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.

diogoa gravatar image diogoa  ( 2019-07-22 15:03:16 -0600 )edit

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...

Madcreator gravatar image Madcreator  ( 2020-02-07 02:59:49 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-07-20 18:45:58 -0600

Seen: 673 times

Last updated: Jul 22 '19