Universal Robots Forum

Printf - like debugging in URCaps or any alternative?

Can I call the textmsg(“myvariable or something”) script function with the writer to get some program status? I doesn’t work for me in the URSIM environment.

public void generateScript(ScriptWriter writer) { …some code…


…some code…

This should work (simu and real robot):

writer.appendLine("textmsg(\"varname is: \", varname)");

as executed, it puts the output into the logfile.
If you want to evaluate this from external, you should consider using another approach.

In your case, the “…Raw” may be the issue.
BTW the ursim behaves nearly the same as a real robot, the exceptions are documented by UR (which are obvious).
For developing URCaps, it is helpful (necessary) to have deeper knowledge of the script language.

1 Like

If you are running in the simulator, using System.out.println("Some debug string"); will print a line in the terminal, this is the simplest way of debugging your URCap code itself.

For the URScript debugging check out the debugging suggestions in this forum including what was suggested by @hch

The URSim is running on a Virtualbox Linux StarterPack, I use the Eclipse Mars Version.

I remember System.out.println(…) as a C++ command but I am stuck with the command using inside a generateScript line. Or do I have to use it in the Linux command line?

Didn´t consider the escape-Character ‘’ but unfortunately it doesn’t work yet.

So here is a part of the generateScript method(
…some code
writer.assign(“radius”, “radius + increment”);
writer.appendLine("textmsg("radius is: “, radius)”);
writer.appendLine(“System.out.println(“I am here”)”);
…some code

Any idea?

Hi Michael

System.out.println("Debug line") is Java code and should not be put in your script code but in the Java layer.

The generated script from your code would be:

radius = radius + increment           (OK, if increment is defined somewhere else)
textmsg("radius is: ",radius)         (OK)
System.out.println("I am here")       (illegal script code)
end                                   (not sure why this "end" is here)

Does the end end some if-statement or a while or why is the end there?

Hence, the System-print cannot be put in your script code, only in the Java for debugging your URCap Java code.
A use case would be:

private void setVariable(String var){
   model.set(VarName, var);
   System.out.println("Variable is set in DataModel to: "+var);

Somebody want to laugh?
I did not activate the Info Button in the log window, so I couldn’t see the textmessages created by writer.appendLine("textmsg("radius is: “, radius)”); Shame on me.


Does the end end some if-statement or a while or why is the end there?
Yes, the end is for a while loop comparing maxRadius with radius.

One more question regarding the System.out.println():
To compile my URCaps I still use the Linux console and just type mvn install and the file is created. When I want to use the System.out.println() I have to compile the application with Eclipse or not?
I am still confused about all these functional layers, Java, URScript, etc.

Ahh, that solves the log-writer problem :slight_smile:

To see the lines printed by System.out.println() just open the URSim using terminal, then the terminal you use to open the URSim will post these lines.

You don’t need to compile in eclipse, just use mvn install -P ursim or so to build and deploy to URSim.

1 Like

How can I access the terminal to see result of System.out.println("Some debug string") in URSim Starter - VMware Workstation 12 Player?
Is it impossible in VMware?

<codesnip> of MyDaemonInstallationNodeContribution.java

 17 import java.io.*;

 74         @Override
 75         public void openView() {
 76                 System.out.println("My Daemon\n");
 77                 enableDaemonButton.setText("Start Daemon");
 78                 disableDaemonButton.setText("Stop daemon");
 79                 popupTitleField.setText(getPopupTitle());

Instead of “clicking” the URSim icon on the desktop in your simulator, try to start the simulator by navigating to the ursim-3.3.x folder in home and start the simulator from terminal by executing start-ursim.sh.
If you wish to run a simulated UR3, simply write ./ start-ursim.sh UR3.
By default a UR5 will be started.

The terminal window that calls the simulator will then show the desired log messages + some additional generic messages from the simulator itself.

1 Like

Great Thanks Jbm,
It works and will be very helpful.

I noticed that the “hello-world.py” python script in the daemon example in the starter package doesn’t print to the terminal used to start the URSIM simulator. E.g. I changed the portion of the .py file which starts the server to include a print() statement as well as explicit calls to print to both stdout and stderr:

sys.stdout.write("MyDaemon daemon started")
sys.stderr.write("MyDaemon daemon started")
server = SimpleXMLRPCServer(("", 40404))
server.register_function(set_title, "set_title")
server.register_function(get_title, "get_title")
server.register_function(get_message, "get_message")

I also changed the code in the get_message() function to attempt to print whenever that function is called:

def get_message(name):
    print("Got a message request")
    if str(name):
        return "Hello " + str(name) + ", welcome to *modified* PolyScope!"
        return "No name set"
  • Note that I changed the return value to include the string "*modified*" so I can ensure that it is actually running my updated code when I call this function using the XMLRPCServer interface described in the getting started guide.

I then deploy the mydaemon-1.0-SNAPSHOT.jar to the URSIM directory, start URSIM from the terminal with ./start-ursim UR5 register the URCAP with the robot simulator, and restart the simulator using the terminal again, but the messages printed in the code above do not show up in the simulator’s terminal output, including when calling the “getmessage” RPC function.

For our application, most of the work will be in this Python script, or whatever we write to replace it, so it would be very useful to have printf debugging available from the resource executable embedded in the daemon URCAP package, since using breakpoints and an IDE is probably not going to be possible to debug the resource executable. Is using print statements from the embedded resource executable possible?

1 Like


PolyScope does not use either stdout or stderr.
If you would like to debug from a daemon, there is two options:

  1. Have the daemon write data to a log file or open a stream of custom setup.
    E.g. place the log file in home/.urcap-name/ or similar.
  2. When debugging, start the daemon manually (disable the start() method in Java, and open the daemon from a terminal to read the terminal trace. This only works while building up the code though.

Hate to dig up an old thread, but is there a way to see the console output from a URCap running on a physical robot? @jbm I’ve been debugging with println()'s which has worked well in the ursim, but when I tested it on the physical robot it’s not working I’m not sure how to debug it.

what you can do for testing on the robot is the same as for the daemon, writing all logs to a file, (make a printDebug() function for exemple, and in this, both display on the console and append the text a text file), and and you execute on the robot, you connect through ssh and you can read realtime the file with the command “tail -f <file>”

On a physical robot, you can use a USB keyboard and press CTRL + ALT + F9 to enter PolyScope terminal output.
Use CTRL + ALT + F7 to return to PolyScope GUI.


Wonderful thank you!!