Robotics StackExchange | Archived questions

Using ROS Rviz to control the UR5 with OnRobot RG2 Gripper

Hello there!

My objective is to control the UR5 robotic arm with the RG2 Gripper from OnRobot (link here) using Rviz for both the simulated robot in Gazebo and the Real robot itself. My current setup is Ubuntu 16.04 >> ROS Kinetic >> Gazebo V7.0.0 Using the Universal Robot and urmoderndriver packages in my catkin workspace.

As of now, i have managed to edit the .urdf files to attach the RG2 gripper model onto the UR5 in Gazebo. However, i am unsure on how to proceed further from this point in order to control the real and simulated gripper from Rviz. The only other example that i could find, is from Sharathrjtr (link here) but his RG2 gripper model is one big static mesh which i assume means that it cannot grip objects in Gazebo since his gripper hands will never close. By using his example, i am able to control the RG2 Gripper by sending,

$ rosservice call /rg2gripper/controlwidth ur_control/RG2 110

and

$ rosservice call /rg2gripper/controlwidth ur_control/RG2 0

to open and close the RG2 Gripper respectively. However, on further inspection, i find that his code just uses ROS as a means of communication with the UR5's controller (Lines 395 onwards of ur_driver.cpp)(Found here)

The parts of code are found below. Basically, all of the code assigned to cmd_str is in URScript.

std::string cmd_str;

char buf[5000],buf_socket[5000];
sprintf(buf, "\ttarget_width=%f\n",target_width);
std::cout << "Reached service to control RG2 gripper" << std::endl;

cmd_str = "def rg2ProgOpen():\n";
cmd_str += "\ttextmsg(\"inside RG2 function called\")\n";

cmd_str += buf;
cmd_str += "\ttarget_force=40\n";
cmd_str += "\tpayload=1.0\n";
cmd_str += "\tset_payload1=False\n";
cmd_str += "\tdepth_compensation=False\n";
cmd_str += "\tslave=False\n";

cmd_str += "\ttimeout = 0\n";
cmd_str += "\twhile get_digital_in(9) == False:\n";
cmd_str += "\t\ttextmsg(\"inside while\")\n";
cmd_str += "\t\tif timeout > 400:\n";
cmd_str += "\t\t\tbreak\n";
cmd_str += "\t\tend\n";
cmd_str += "\t\ttimeout = timeout+1\n";
cmd_str += "\t\tsync()\n";
cmd_str += "\tend\n";
cmd_str += "\ttextmsg(\"outside while\")\n";

cmd_str += "\tdef bit(input):\n";
cmd_str += "\t\tmsb=65536\n";
cmd_str += "\t\tlocal i=0\n";
cmd_str += "\t\tlocal output=0\n";
cmd_str += "\t\twhile i<17:\n";
cmd_str += "\t\t\tset_digital_out(8,True)\n";
cmd_str += "\t\t\tif input>=msb:\n";
cmd_str += "\t\t\t\tinput=input-msb\n";
cmd_str += "\t\t\t\tset_digital_out(9,False)\n";
cmd_str += "\t\t\telse:\n";
cmd_str += "\t\t\t\tset_digital_out(9,True)\n";
cmd_str += "\t\t\tend\n";
cmd_str += "\t\t\tif get_digital_in(8):\n";
cmd_str += "\t\t\t\tout=1\n";
cmd_str += "\t\t\tend\n";
cmd_str += "\t\t\tsync()\n";
cmd_str += "\t\t\tset_digital_out(8,False)\n";
cmd_str += "\t\t\tsync()\n";
cmd_str += "\t\t\tinput=input*2\n";
cmd_str += "\t\t\toutput=output*2\n";
cmd_str += "\t\t\ti=i+1\n";
cmd_str += "\t\tend\n";
cmd_str += "\t\treturn output\n";
cmd_str += "\tend\n";
cmd_str += "\ttextmsg(\"outside bit definition\")\n";


cmd_str += "\ttarget_width=target_width+0.0\n";
cmd_str += "\tif target_force>40:\n";
cmd_str += "\t\ttarget_force=40\n";
cmd_str += "\tend\n";

cmd_str += "\tif target_force<4:\n";
cmd_str += "\t\ttarget_force=4\n";
cmd_str += "\tend\n";
cmd_str += "\tif target_width>110:\n";
cmd_str += "\t\ttarget_width=110\n";
cmd_str += "\tend\n";
cmd_str += "\tif target_width<0:\n";
cmd_str += "\t\ttarget_width=0\n";
cmd_str += "\tend\n";
cmd_str += "\trg_data=floor(target_width)*4\n";
cmd_str += "\trg_data=rg_data+floor(target_force/2)*4*111\n";
cmd_str += "\tif slave:\n";
cmd_str += "\t\trg_data=rg_data+16384\n";
cmd_str += "\tend\n";

cmd_str += "\ttextmsg(\"about to call bit\")\n";
cmd_str += "\tbit(rg_data)\n";
cmd_str += "\ttextmsg(\"called bit\")\n";

cmd_str += "\tif depth_compensation:\n";
cmd_str += "\t\tfinger_length = 55.0/1000\n";
cmd_str += "\t\tfinger_heigth_disp = 5.0/1000\n";
cmd_str += "\t\tcenter_displacement = 7.5/1000\n";

cmd_str += "\t\tstart_pose = get_forward_kin()\n";
cmd_str += "\t\tset_analog_inputrange(2, 1)\n";
cmd_str += "\t\tzscale = (get_analog_in(2)-0.026)/2.976\n";
cmd_str += "\t\tzangle = zscale*1.57079633-0.087266462\n";
cmd_str += "\t\tzwidth = 5+110*sin(zangle)\n";

cmd_str += "\t\tstart_depth = cos(zangle)*finger_length\n";


cmd_str += "\t\tsync()\n";
cmd_str += "\t\tsync()\n";
cmd_str += "\t\ttimeout = 0\n";

cmd_str += "\t\twhile get_digital_in(9) == True:\n";
cmd_str += "\t\t\ttimeout=timeout+1\n";
cmd_str += "\t\t\tsync()\n";
cmd_str += "\t\t\tif timeout > 20:\n";
cmd_str += "\t\t\t\tbreak\n";
cmd_str += "\t\t\tend\n";
cmd_str += "\t\tend\n";
cmd_str += "\t\ttimeout = 0\n";
cmd_str += "\t\twhile get_digital_in(9) == False:\n";
cmd_str += "\t\t\tzscale = (get_analog_in(2)-0.026)/2.976\n";
cmd_str += "\t\t\tzangle = zscale*1.57079633-0.087266462\n";
cmd_str += "\t\t\tzwidth = 5+110*sin(zangle)\n";
cmd_str += "\t\t\tmeasure_depth = cos(zangle)*finger_length\n";
cmd_str += "\t\t\tcompensation_depth = (measure_depth - start_depth)\n";
cmd_str += "\t\t\ttarget_pose = pose_trans(start_pose,p[0,0,-compensation_depth,0,0,0])\n";
cmd_str += "\t\t\tif timeout > 400:\n";
cmd_str += "\t\t\t\tbreak\n";
cmd_str += "\t\t\tend\n";
cmd_str += "\t\t\ttimeout=timeout+1\n";
cmd_str += "\t\t\tservoj(get_inverse_kin(target_pose),0,0,0.008,0.033,1700)\n";
cmd_str += "\t\tend\n";
cmd_str += "\t\tnspeed = norm(get_actual_tcp_speed())\n";
cmd_str += "\t\twhile nspeed > 0.001:\n";
cmd_str += "\t\t\tservoj(get_inverse_kin(target_pose),0,0,0.008,0.033,1700)\n";
cmd_str += "\t\t\tnspeed = norm(get_actual_tcp_speed())\n";
cmd_str += "\t\tend\n";
cmd_str += "\tend\n";
cmd_str += "\tif depth_compensation==False:\n";
cmd_str += "\t\ttimeout = 0\n";
cmd_str += "\t\twhile get_digital_in(9) == True:\n";
cmd_str += "\t\t\ttimeout = timeout+1\n";
cmd_str += "\t\t\tsync()\n";
cmd_str += "\t\t\tif timeout > 20:\n";
cmd_str += "\t\t\t\tbreak\n";
cmd_str += "\t\t\tend\n";
cmd_str += "\t\tend\n";
cmd_str += "\t\ttimeout = 0\n";
cmd_str += "\t\twhile get_digital_in(9) == False:\n";
cmd_str += "\t\t\ttimeout = timeout+1\n";
cmd_str += "\t\t\tsync()\n";
cmd_str += "\t\t\tif timeout > 400:\n";
cmd_str += "\t\t\t\tbreak\n";
cmd_str += "\t\t\tend\n";
cmd_str += "\t\tend\n";
cmd_str += "\tend\n";
cmd_str += "\tif set_payload1:\n";
    cmd_str += "\t\tif slave:\n";
    cmd_str += "\t\t\tif get_analog_in(3) < 2:\n";
    cmd_str += "\t\t\t\tzslam=0\n";
    cmd_str += "\t\t\telse:\n";
    cmd_str += "\t\t\t\tzslam=payload\n";
    cmd_str += "\t\t\tend\n";
    cmd_str += "\t\telse:\n";
    cmd_str += "\t\t\tif get_digital_in(8) == False:\n";
    cmd_str += "\t\t\t\tzmasm=0\n";
    cmd_str += "\t\t\telse:\n";
    cmd_str += "\t\t\t\tzmasm=payload\n";
    cmd_str += "\t\t\tend\n";
    cmd_str += "\t\tend\n";
    cmd_str += "\t\tzsysm=0.0\n";
cmd_str += "\t\tzload=zmasm+zslam+zsysm\n";
cmd_str += "\t\tset_payload(zload)\n";
cmd_str += "\tend\n";


cmd_str += "end\n";


rt_interface_->addCommandToQueue(cmd_str);
std::cout << cmd_str << std::endl;

If possible, i would like to control the RG2 Gripper solely using ROS.

Does anyone have any experience with the RG2 Gripper? Or can at at least point me in the right direction? Please let me know if you require any additional information.~

Thanks!

Asked by Fruitspunchsamurai on 2018-05-04 02:49:07 UTC

Comments

i find that his code just uses ROS as a means of communication with the UR5's teach pendant

Can you clarify what you mean by this? The UR controller doesn't 'run ROS', so I'm unsure how you feel things should work.

Asked by gvdhoorn on 2018-05-04 03:08:58 UTC

Thanks for the quick reply!!

I believe that he's using the URScript programming language as the foundation to control the robot. The rosservice calls that he makes through the terminal are just on the surface level, if my understanding is correct.

Asked by Fruitspunchsamurai on 2018-05-04 03:48:10 UTC

Can you please add some more direct links to the parts you are referring to? Your only link right now points to an entire .cpp file.

Asked by gvdhoorn on 2018-05-04 03:49:53 UTC

Edited the question.~ The comments field has a limited character count.

Asked by Fruitspunchsamurai on 2018-05-04 04:14:52 UTC

Edited the question.~ The comments field has a limited character count.

Great. Editing your question is always preferable over using comments.

Asked by gvdhoorn on 2018-05-04 04:20:12 UTC

If your gripper is connected to the controller, then I don't see a way around using URScript. Whether embedding it like this is the best approach, I don't know (the ur_modern_driver exposes a urscript topic that could potentially be used).

Asked by gvdhoorn on 2018-05-04 04:21:48 UTC

i find that his code just uses ROS as a means of communication with the UR5's teach pendant

note btw: this code does not 'communicate with the teach pendant', but with the controller. Those are two different things.

Asked by gvdhoorn on 2018-05-04 04:22:14 UTC

I see.~ My bad, yeah it's with the controller!

I understand where you're coming from. I'll look into the topic you mentioned. Thanks!!

Asked by Fruitspunchsamurai on 2018-05-04 04:41:21 UTC

Hi! How did you manage use those commands for controlling the opening and the closure of the RG2? When I try them for my UR5 it says: "ERROR: Service [/rg2_gripper/control_width] is not available." Have you also dealt with this problem?

Asked by enrico on 2018-10-12 05:01:34 UTC

@enrico I also faced the same problem, were you able to find a solution for that?

Asked by parth_v92 on 2019-03-13 18:34:53 UTC

Yes, in my case the problem was with Zagitta's ur_modern_driver. That pkg didn't rnu the service I needed. So instead I used the ur_modern_driver by sharathrjtr mentioned above

Asked by enrico on 2019-03-17 03:54:03 UTC

Answers

Controlling the RG2 gripper solely using the ROS (without URScript) might not be possible since the UR controller doesn't run on ROS which is provided in answer. As far as i know the driver from the UR controller only accepts commands using URScript.

I have come across some posts saying you can communicate with universal robot with C-api, but in the end it just points to the ROS's universal_robot and ur_modern_driver package.

"RG2 gripper model is one big static mesh". I had contacted the makers of RG2 gripper for providing the STEP/mesh file for the gripper body and its fingers. But they had provided me with just a single STEP file for the entire gripper. I can understand you will not able to simulate the finger motion without separate mesh for the fingers. If it's really needed then would suggest you to contact OnRobot requesting them to provide the gripper body and its fingers STEP/mesh files separately.

Asked by sharath on 2018-05-24 05:44:53 UTC

Comments

There is the possibility to use Weblogic to control the RG2 gripper. It's described in this post from the UR Forum. Nevertheless, this solutions is a bit complicated, because a signal has to be predefined for each width/force combination. Isn't there a better solution? I would be grateful for some help with a similar question: Control and read sensors of OnRobot RG2-FT gripper mounted to a UR5 robot arm using ROS2

Asked by benedikt on 2022-02-21 04:12:49 UTC

Comments