Hi.
I'm working with a LBR iiwa 7 together with the roboticsAPI 1.15.1.7.
Since a long time I'm searching for a possibility to use the ITaskLogger within a background task.
Does someone know how to use it?
Cheers,
Tammo
Hi.
I'm working with a LBR iiwa 7 together with the roboticsAPI 1.15.1.7.
Since a long time I'm searching for a possibility to use the ITaskLogger within a background task.
Does someone know how to use it?
Cheers,
Tammo
Hi Tammoj,
use the "Injection" mechanism, and you should be fine:
In your class BackgroundTask (-> BackgroundTask.java) have the following stuff:
class BackgroundTask extends RoboticsAPIBackgroundTask {
@Inject
private ITaskLogger _logger;
}
As you use the eclipse mechanisms to insert the code,
the Import Statements are resolved automatically, then you should find a list of imports, like the following
import javax.inject.Inject;
import com.kuka.task.ITaskLogger;
After that, you can use the logger, as you already are used to it from the RoboticsAPIApplication:
_logger.info("Hello World");
Greetings,
DrG
You can log with the ITaskLogger but it will not be displayed on the SmartHMI.
But there are some possibility to make readable.
Hi razzo.
Sending the message from the background task over udp to another device (i.e. my laptop) is what I'm already doing. But this not what I'm looking for because I need to print/forward the message on/to the SmartHMI.
What do you mean with:
Quoteyou can connect to the controller to read it.
Is this a possibility to do so?
Greetings,
Tammo
What do you mean with:
This means a remote desktop connection which is provided by windows.
Afaik you can only log on the SmartHMI what is in the TaskContext of your robot application.
I do not know how it is if you start the server thread within your robot application which receives the messages from your background task, but I think this will then be a different TaskContext.
I am not sure if you can pass the logger as a parameter of a method to log with it, but you could try that.
No context is required for the task logger, it can be injected in any class.
It can be injected, but it will not be displayed on the SmartHMI, afaik.
If I got time I will try it on Friday. Which version do you got?
It can be injected, but it will not be displayed on the SmartHMI, afaik.
If I got time I will try it on Friday. Which version do you got?
1.14. I've never tried it in a background task though
Hi, there was something I tried before, though I can't remember if it worked or not.
make a static ITaskLogger variable and initialize it on your RoboticsAPIApplication.
and simply use it on your backgroundTask
Of course you need to use try-catch or whatever way to prevent your backgroundTask to be jammed when YourApplication's Logger is not yet initialized.
It will only log when YourApplication is initialized, otherwise it won't.
Hi, there was something I tried before, though I can't remember if it worked or not.
make a static ITaskLogger variable and initialize it on your RoboticsAPIApplication.and simply use it on your backgroundTask
Of course you need to use try-catch or whatever way to prevent your backgroundTask to be jammed when YourApplication's Logger is not yet initialized.
It will only log when YourApplication is initialized, otherwise it won't.
Has anyone tried this approach? I would like to output logg message from a background task to the SmartHMI. Did anyone find a solution?
Has anyone tried this approach? I would like to output logg message from a background task to the SmartHMI. Did anyone find a solution?
I think it should work. You could try it. I'd like to test it but I don't have a robot to test.
Or other options,
1. If you use Sunrise OS higher than 1.11, you can directly inject logger in backgroundTask.
// where your class variables are declared
@Inject
private ITaskLogger logger;
// inside run()
logger.info("test");
It definitely works when you have an active application view.
2. Simply use 'syso' - not sure if it works. you can try.
3. Use anonymousLogger - you try.
Thanks a lot, Seulki for the fast response! I will try out the different options tomorrow, when I have access to the robot.
At the moment we use 'sys' for normal output in the main robot application instead of the KUKA ITaskLogger class. Mainly because you can use that in any class outside of a robot task / application, I think..
Similarly, I trie to use sys in the background task, but on the SmartHMI I get no log messages from the background task. Also on the SmartHMI I cannot open something as a separate window with the output for the background task..
I will first try the ITaskLogger normally, since I never tried and the manual said it should work both in applications and all sorts of tasks. I will try both the injection method and the public static variable.
Let's see if I manage to get a result..
So I quickly tried the following two approaches:
* Inject ITaskLogger
* As said in the manual with: getLogger().info("test");
Everything compiles and loads onto the controller. However, I do not see any message on the smartPAD. Honestly, I cannot imagine where it would show. Because it seems unlikely that the message is shown in the log window of the main application. However I cannot change into a log window of the background task, since clicking on the background task on the smartPad doesn't do anything.
As said, I already tested "syso" and I get the same (no) results.
I will now try the public static variable.
The suggested method by Seulki with the public static variable does work!
However, it is a bit hard to run, since it needs the main application to run first otherwise the background task does not start:
Unfortunately, we need an autonomous background task which will work also when the main application is not running, since this was the whole reason why we want to add a background task.
If someone manages to make it work otherwise or does now if the log messages of the background task can be shown separately on the smartPAD, I would be very thankful for a hint!
1. You need to use try-catch. I've already stated about the problem you have on my first comment.
2. Yes backgroundTask itself doesn't have a place to print out its logger. And all the options you have as syso, static logger and inject as well, they all need an active main application since they are 'borrowing' the logging place of the main application.
3. I am not really sure what you are trying to display specifically on SmartHMI. There are few more options for you to display things from backgroundTasks.
a> UserKey : Use UserKey name. What you can display is limited to 'String', and has to be short like 5-6 characters. (Not recommended)
b> ProcessData : You can make use of ProcessData as a kind of system variable(global var) because it uses a file(RoboticsAPI.data.xml) to store values and we can use it as an interface between Tasks no matter they are RobotApplications or BackgroundTasks. (recommended)
You probably need to review your manual regarding processData.
backgroundTask> - Please note I didn't use Cyclic one, and made an infinite loop inside. It probably is better with Cyclic one if you have a designed duty cycle.
-> getApplicationData().getProcessData( "visionData" ).setValue( msg );
// example [this backgroundTask gets a message from UDP comm. and updates value to processData where you can always see it on Station-ProcessData]
public class VisionComm extends RoboticsAPIBackgroundTask {
// vision
private int lhPort;
...
@Override
public void initialize() {
receiver = new UdpReceiver( lhPort, 65545 );
...
}
@Override
public void run() {
while ( true ) {
try {
String msg = null;
msg = receiver.receiveString();
if ( msg != null ) {
getApplicationData().getProcessData( "visionData" ).setValue( msg );
}
} catch ( Exception e ) {
// ThreadUtil.milliSleep( 500 );
} // end of try-catch
} // end of while()
} // end of run()
@Override
public void dispose() {
try {
receiver.endComm();
} catch ( Exception e ) {
}
}
}
Display More
RoboticsAPI.data.xml file>
// this is where you can declare process data -RoboticsAPI.data.xml file
-<processDataContainer>
...
<processData value="" id="visionData" editableOnHmi="false" displayName="Vision Data" defaultValue="" dataType="java.lang.String"/>
</processDataContainer>
And you will see values displayed and updated on the second column of each names as below, (Sorry for Non-english, and Vision Data is now blank since communication is not yet made - try-catch is preventing the backgroundTask from being jammed)
c> [NOT RECOMMENDED] Remember that the system is using JAVA. Not a new language based on JAVA, the coding system itself is using Robotics library provided by manufacturer ENTIRELY IN JAVA system. Meaning, you can do whatever you may do in JAVA. You can make your own file to be written from your backgroundTASK and display it as a new swing window when you give an input(simply from UserKey, touching Robot, to even voice command).
Hello,
I was wondering whether someone was able to solve this problem and if so, which was the procedure.
Thank you before hand.