# Printf - like debugging in URCaps or any alternative?

**URL:** <https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214>\
**Category:** URCap Development\
**Created:** [September 2, 2016, 4:45pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214 "2016-09-02T16:45:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon2960714](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@anon2960714](https://forum.universal-robots.com/u/anon2960714)\
**Post date:** [September 2, 2016, 4:45pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/1 "2016-09-02T16:45:28Z")

</div>

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…

> writer.appendRaw(“textmsg(radius)”);

> …some code…  
> }

---

<div class="post-metadata">

**Author:** ![anon87661449](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@anon87661449](https://forum.universal-robots.com/u/anon87661449)\
**Post date:** [September 2, 2016, 9:35pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/2 "2016-09-02T21:35:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [September 3, 2016, 12:24pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/3 "2016-09-03T12:24:05Z")

</div>

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](http://forum.universal-robots.com/t/debugging-in-urscript/128) in this forum including what was suggested by @anon87661449

---

<div class="post-metadata">

**Author:** ![anon2960714](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@anon2960714](https://forum.universal-robots.com/u/anon2960714)\
**Post date:** [September 5, 2016, 8:34am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/4 "2016-09-05T08:34:07Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/708cc44ded8aa106a73b45ea82ff60c2ca225f05.jpg)

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?

@anon87661449  
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  
> writer.end()

Any idea?

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [September 5, 2016, 9:17am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/5 "2016-09-05T09:17:51Z")

</div>

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:

```auto
...
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:

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

```

---

<div class="post-metadata">

**Author:** ![anon2960714](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@anon2960714](https://forum.universal-robots.com/u/anon2960714)\
**Post date:** [September 5, 2016, 10:32am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/6 "2016-09-05T10:32:28Z")

</div>

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.

 ![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/a0226172faf692a4b47cef44a8ec4e41206e990e.jpg)

@jbm

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

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [September 5, 2016, 10:49am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/7 "2016-09-05T10:49:00Z")

</div>

Ahh, that solves the log-writer problem 🙂

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.

---

<div class="post-metadata">

**Author:** ![anon61101646](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@anon61101646](https://forum.universal-robots.com/u/anon61101646)\
**Post date:** [October 3, 2016, 1:56pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/8 "2016-10-03T13:56:37Z")

</div>

How can I access the terminal to see result of `System.out.println("Some debug string")` in URSim 3.3.0.145 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());
```

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [October 3, 2016, 2:18pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/9 "2016-10-03T14:18:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon61101646](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@anon61101646](https://forum.universal-robots.com/u/anon61101646)\
**Post date:** [October 3, 2016, 2:42pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/10 "2016-10-03T14:42:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sskuce](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@sskuce](https://forum.universal-robots.com/u/sskuce)\
**Post date:** [October 14, 2016, 6:57pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/11 "2016-10-14T18:57:05Z")

</div>

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")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
server = SimpleXMLRPCServer(("127.0.0.1", 40404))
server.register_function(set_title, "set_title")
server.register_function(get_title, "get_title")
server.register_function(get_message, "get_message")
server.serve_forever()

```

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!"
    else:
        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?

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [October 19, 2016, 7:10am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/12 "2016-10-19T07:10:43Z")

</div>

@sskuce

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.

---

<div class="post-metadata">

**Author:** ![anon68375071](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@anon68375071](https://forum.universal-robots.com/u/anon68375071)\
**Post date:** [August 2, 2017, 3:00pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/13 "2017-08-02T15:00:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon58863070](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon58863070](https://forum.universal-robots.com/u/anon58863070)\
**Post date:** [August 3, 2017, 9:28am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/14 "2017-08-03T09:28:16Z")

</div>

Hi,  
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\>”

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [August 3, 2017, 10:50am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/15 "2017-08-03T10:50:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon68375071](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@anon68375071](https://forum.universal-robots.com/u/anon68375071)\
**Post date:** [August 3, 2017, 3:35pm UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/16 "2017-08-03T15:35:53Z")

</div>

Wonderful thank you!!

---

<div class="post-metadata">

**Author:** ![anon27419989](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anon27419989](https://forum.universal-robots.com/u/anon27419989)\
**Post date:** [May 29, 2021, 3:10am UTC](https://forum.universal-robots.com/t/printf-like-debugging-in-urcaps-or-any-alternative/214/17 "2021-05-29T03:10:41Z")

</div>

Hi jbm, Thank you for the information…
