Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The URScript topic #162

Closed
tianxiang84 opened this issue Mar 1, 2018 · 14 comments
Closed

The URScript topic #162

tianxiang84 opened this issue Mar 1, 2018 · 14 comments

Comments

@tianxiang84
Copy link

Hi Thomas and all,

I am trying to use the URScript topic to control a Robotiq gripper, but somehow cannot make it work. If anyone has suggestion, please kindly let me know.

The following script works on the UR teach pad, when it is run, the gripper can be activated and then close as expected.

  • socket_set_var(“ACT”, 0, “1”) # Deactivate gripper 1
  • sleep(0.5) # Wait for 0.5 sec to write the registration “ACT”
  • socket_set_var(“ATR”, 0, “1”) # Set the gripper as normal
  • sleep(0.5) # Wait for 0.5 sec to write the registration “ATR”
  • socket_set_var(“ACT”, 1, “1”) # Activate the gripper
  • sleep(3.0) # Wait for 3 sec because the gripper will move in activation
  • socket_set_var(“GTO”, 0, “1”) # Stop, don’t move
  • sleep(0.5) # Wait for 0.5 sec to write the registration “GTO”
  • socket_set_var(“POS”, 255, “1”) # Set the gripper position (0 is fully open, 255 is fully close)
  • sleep(0.5) # Wait for 0.5 sec to write the registration “POS”
  • socket_set_var(“GTO”, 1, “1”) # Move according to the POS setting
  • sleep(5.0) # Wait for 5 sec for the gripper to move
  • socket_set_var(“GTO”, 0, “1”) # Reset, don’t move when it is activated again next time
  • sleep(0.5) # Wait for 0.5 sec to write the registration “GTO”
  • socket_set_var(“POS”, 0, “1”) # Reset to fully open position
  • sleep(0.5) # Wait for 0.5 sec to write the registration “POS”
  • socket_set_var(“ACT”, 0, “1”) # Deactivate gripper 1
  • sleep(0.5) # Wait for 0.5 sec to write the registration “ACT”
  • socket_set_var(“ATR”, 0, “1”) # Set the gripper as normal
  • sleep(0.5) # Wait for 0.5 sec to write the registration “ATR”
  • socket_set_var(“ACT”, 1, “1”) # Activate the gripper
  • sleep(3.0) # Wait for 3 sec because the gripper will move in activation
  • socket_set_var(“GTO”, 0, “1”) # Stop, don’t move
  • sleep(0.5) # Wait for 0.5 sec to write the registration “GTO”
  • socket_set_var(“POS”, 255, “1”) # Set the gripper position (0 is fully open, 255 is fully close)
  • sleep(0.5) # Wait for 0.5 sec to write the registration “POS”
  • socket_set_var(“GTO”, 1, “1”) # Move according to the POS setting
  • sleep(5.0) # Wait for 5 sec for the gripper to move
  • socket_set_var(“GTO”, 0, “1”) # Reset, don’t move when it is activated again next time
  • sleep(0.5) # Wait for 0.5 sec to write the registration “GTO”
  • socket_set_var(“POS”, 0, “1”) # Reset to fully open position
  • sleep(0.5) # Wait for 0.5 sec to write the registration “POS”_

Then I was trying to publish these line by line to the ur_driver/URScript topic. The gripper does not do anything.... I tried to publish a simple "power off" to the topic, and it works, the power is turned off, so seems to me topic is good.

I checked the log on the teach pad, whenever I send the "socket..." message, there is a "Program socket_set_var started", immediately followed by a "Program socket_set_var stopped". So I guess it is the timing issue? In order for it to work, it should not stop so quickly?

I am fairly new to ROS, so I could be doing something totally wrong, if anyone has any idea, please let me know.

Thanks.

Tianxiang

@gavanderhoorn
Copy link
Member

gavanderhoorn commented Mar 2, 2018

Sending a msg to the urscript topic essentially causes a new program to be started on the controller. Sending N individual statements, as you are doing, thus causes N programs to be started, one after the other.

You'll probably have to put all statements in a single program and send that in one message.

Question: can you use socket_set_var(..) without some statement to open the socket first?

I am fairly new to ROS, so I could be doing something totally wrong, if anyone has any idea, please let me know.

this is not really ROS-related: try sending the same script lines using ncat to port 30002 or 30003 manually, it will probably result in the same behaviour. If it doesn't, then we'd have to see what the difference is between these two approaches.

@haisongdong-harrison
Copy link

haisongdong-harrison commented Mar 2, 2018

@gavanderhoorn I think sending the whole program at once could work here. But I have a related question that what if I do have to send the program line by line in order to be able to stop sending the script under certain conditions? I happen to be implementing an action that can do exactly this where I hope to give users the freedom to cancel the script at any moment.

But it seems to me that when using the URScript topic, you never know the when the command you send will be finished because there is no feedback. So you have no idea if it is a good timing to insert a stopj command. If this is a service that can return true when the script is finished, there should not be any problem sending it line by line.

@carlosjoserg
Copy link

Hi @tiangxiang84, just saw your post on dof and here as well. Yes, you need to send a string containing all your script at once. If you use std::string you can use the + to add new lines and keep the code readible, and the filling the data in std msgs/String as defined in that topic.

@hansondon You can always set/unset IOs on the robot via the script you send, which are already exposed by the driver, so you can sync/communicate to the ROS side that your script did something or not

@haisongdong-harrison
Copy link

@carlosjoserg Ah! That's a good workaround. I'll need to set/unset IOs before and after every actual command, though. But it solves my problem. Thanks!

@gavanderhoorn
Copy link
Member

There's no way to detect whether "the script" has finished. That is a limitation of the infrastructure provided by UR, not of the driver btw.

@tianxiang84
Copy link
Author

tianxiang84 commented Mar 2, 2018

Thanks everyone for the response. It is helpful.

So I tried to put these lines in a talker.cpp:

/////////////////////////////////////////////////
std_msgs::String msg;
std::string cmd_str;
int count = 1;

while(count <= 2){
  ROS_INFO("Begin to send a message");
  //cmd_str = "power on";
  cmd_str = "socket_set_var(\"ACT\", 0, \"1\")";
  
  //cmd_str += "socket_set_var(\"ATR\", 0, \"1\")\n";
  //cmd_str += "sleep(0.5)\n";
  //cmd_str += "socket_set_var(\"ACT\", 1, \"1\")\n";
  //cmd_str += "sleep(3.0)\n";
  //cmd_str += "socket_set_var(\"GTO\", 0, \"1\")\n";
  //cmd_str += "sleep(0.5)\n";
  //cmd_str += "socket_set_var(\"POS\", 255, \"1\")\n";
  //cmd_str += "sleep(0.5)\n";
  //cmd_str += "socket_set_var(\"GTO\", 1, \"1\")\n";
  //cmd_str += "sleep(5.0)\n";
  //cmd_str += "socket_set_var(\"GTO\", 0, \"1\")\n";
  //cmd_str += "sleep(0.5)\n";
  //cmd_str += "socket_set_var(\"POS\", 0, \"1\")\n";
  //cmd_str += "sleep(0.5)\n";

  msg.data = cmd_str;
  chatter_pub.publish(msg);
  ROS_INFO("Message is: %s", msg.data.c_str());
  count++;

  ROS_INFO("End of sending this message");

  ros::spinOnce();
  loop_rate.sleep();
}

//////////////////////////////////////////////////////////////////////////////////////

On the console, I received:
[ INFO] [1519997892.221843195]: Begin to send a message
[ INFO] [1519997892.221955734]: Message is: socket_set_var("ACT", 0, "1")
[ INFO] [1519997892.221986258]: End of sending this message
[ INFO] [1519997902.221929296]: Begin to send a message
[ INFO] [1519997902.222048838]: Message is: socket_set_var("ACT", 0, "1")
[ INFO] [1519997902.222106172]: End of sending this message

On another terminal where I used rostopic echo ur_driver/URScript, I received:

sdrwcs@ia3:~$ rostopic echo ur_driver/URScript
data: "socket_set_var(\"ACT\", 0, \"1\")"

So the problems are:

  1. I tried running "socket_set_var("ACT", 0, "1")" alone on the UR teach pad (just this single line in a brand new program file), this successfully deactivated my gripper. Then I activated my gripper again from the teach pad, and sent the message to the ur_drive/URScript using the above c++ script, the gripper remains activated. If even this single command does not work, I feel sending the entire script will not work either?

  2. In the C++ script, I looped twice, so I saw in the console there are 2 [Begin to send a message].....[end of sending messages], which makes sense. But on the rostopic echo terminal, I only got 1 response:
    data: socket_set_var("ACT", 0, "1") ...
    and this output is from the 2nd one. What did I do wrong that I don't get the first published string?

  3. This is pretty stupid but I just want to confirm, what I want to send is "socket_set_var("ACT", 0, "1")", but on the rostopic echo terminal, I got the display of
    "socket_set_var( \"ACT \", 0, \"1\")"
    So the double quote become \", will this be a problem? I guess it is OK right?

Just to diagnose the problem, I tried the same script to publish the message "power off". If I loop twice, the power was successfully turned off the 2nd time. So I think the script can successfully publish messages to the URScript topic. But still here the problem is if I loop only once, there is no power off response.

I feel I may be making some simple mistake that I cannot see. Please let me know where I did wrong.

Thanks.

Regards,
Tianxiang

@tianxiang84
Copy link
Author

I can now make it work by directly communicating between my PC and robot without using the ur_driver/URScript topic.

The commands I sent to the UR are:
socket_close("gripper_socket")
socket_open("127.0.0.1",63352,"gripper_socket")
set_analog_inputrange(0,0)
set_analog_inputrange(1,0)
set_analog_inputrange(2,0)
set_analog_inputrange(3,0)
set_analog_outputdomain(0,0)
set_analog_outputdomain(1,0)
set_tool_voltage(0)
set_runstate_outputs([])
set_payload(0.85)
socket_set_var("SPE",255,"gripper_socket")
sync()
socket_set_var("FOR",50,"gripper_socket")
sync()
socket_set_var("ACT",1,"gripper_socket")
sync()
socket_set_var("GTO",1,"gripper_socket")
sync()
sleep(0.1)
socket_set_var("POS",0,"gripper_socket")
sync()
sleep(2.0)

Thanks everyone for the help.

But the issue of using URScript topic is still there (my previous posts). I still cannot make it work using the ROS topic. If anyone knows where I did wrong, please let me know. I am curious.

Tianxiang

@felixvd
Copy link

felixvd commented Aug 9, 2018

Not a very qualified comment because I haven't used URScript a lot, but I know that I sent this example program to the /robot_name/URScript topic successfully. Note the wrapping function definition, which might be required:

def move_forward_10cm():
    start_pos=get_forward_kin()
    target_pos=pose_trans(start_pos,p[0.0, 0.0, 100.0, 0.0, 0.0, 0.0])
    movel(pose_trans(p[0.0,0.0,0.0,0.0,0.0,0.0], target_pos), a=1.2, v=0.25)
end

@ctaipuj
Copy link

ctaipuj commented Sep 11, 2018

Hi, @tianxiang84 I saw your post a few days ago and based on your comments and @carlosjoserg 's suggestions, I developed this C++ class to control the Robotiq's 85 Gripper through UR3 controller using URScript ROS topic. I 've tested it in a sample node and the gripper moves and works fine... You can find the source code/package here. Notice that the robotiq URcap must be installed in the controller and that @felixvd comment is valid, it is required to use the def/end statement (Almost every time). I'm not expert neither in ROS nor C++ so if anyone has any suggestion/recommendation please let me know.

@DavidYaonanZhu
Copy link

@ctaipuj can you provide the link to your program again? Now it's 404 :)

@felixvd
Copy link

felixvd commented Apr 4, 2019

This is a popular google result, so in case someone can use it, I'll just link this header file that waits for the UR controller to complete a program. It will work as soon as #247 is merged.

As it says, the ur_modern_driver script does not stop, so can only check if your own URScripts that you sent to the urscript topic have completed, but it might be useful for someone.

@Giessen
Copy link

Giessen commented Apr 15, 2019

@ctaipuj could you give a valid link please~~~ the old is dead. Thanks (:

@ctaipuj
Copy link

ctaipuj commented May 23, 2019

Hello @Giessen @DavidYaonanZhu, sorry for the delayed response. I just fixed the link to the repo. Sorry but currently this package doesn't have a readme file. Please check the doc directory where you can find the class documentation.

@gavanderhoorn
Copy link
Member

Seeing as this issue has gone somewhat off-topic (from "how to use urscript topic" to "how to control robotiq grippers") I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants