Backgroundtask Logging

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


      • you can connect to the controller to read it.

      • you can send (TCP/UDP) the log to a different device

      • you send (TCP/UDP) the log message to a different device to display it there

  • 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:

    Quote

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

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


    Code
    public static ITaskLogger Logger;
    initialize() {
        this.Logger = getLogger();
    }


    and simply use it on your backgroundTask

    Code
    ITaskLogger logger;
    run() {
        logger = YourApplication.Logger;
    }


    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.

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

    Code
            System.out.println( "test" );



    3. Use anonymousLogger - you try.

    Code
            Logger.getAnonymousLogger().info( "test" );
  • 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.. :smiling_face:

  • 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!:thumbs_up:


    However, it is a bit hard to run, since it needs the main application to run first otherwise the background task does not start:

    1. After I upload the program, the robot is still in T1 operation mode. The background task wants to start running now, but it shows red as an error, clearly because it can't get the public variable from the main application, since this main application is not yet running. By pressing on the background task (in the menu "Applications") I can stop and restart the background application. However as said it always gets an error, because the main application is not running yet.
    2. Then I change into AUT mode which starts our main application. From the moment I change into the AUT operation mode I cannot change the background application to running or not running. So if the background task was running when I change into the AUT mode, it will now still run but also still show red as error, since it was not restarted after the main application was started. If the background task was not running, when I change into the AUT mode, the background task cannot be started.
    3. So next thing is I change into the T1 mode again. The main application is finished. However when I stop and restart the background task (or just start it if it wasn't started) then the background task works :thumbs_up:
    4. If I change again into the AUT mode also the main application is running, and everything works as it should.


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


    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 );

    RoboticsAPI.data.xml file>

    Code
    // 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).

    Edited 4 times, last by Seulki ().

Advertising from our partners