Ask Your Question
0

How to call the openGripper functon from python

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

Tawfiq Chowdhury gravatar image

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

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

diogoa gravatar image

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.

edit flag offensive delete link more

Comments

@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 imageTawfiq Chowdhury ( 2019-07-22 14:50:32 -0500 )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 imagediogoa ( 2019-07-22 15:03:16 -0500 )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

1 follower

Stats

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

Seen: 99 times

Last updated: Jul 22