Robots in Architecture Forum

Robots in Architecture, Art, and Design => General Discussion => Topic started by: UofM FABLab on April 12, 2021, 10:52:07 PM

Title: Accessing IIWA media flange using a thread in Sunrise workbench
Post by: UofM FABLab on April 12, 2021, 10:52:07 PM
Hello,

I am currently working on a project where a thread is used outside of the main application class in sunrise workbench to constantly cycle a stepper motor, while the main class goes about its functions.

I've run into a wall trying to access the media flange via the stepper thread in sunrise workbench. I am able to inject the media flange into the thread, but it throws an error when trying to set a pin.

Any advice/help would be greatly appreciated.

Jon
Title: Re: Accessing IIWA media flange using a thread in Sunrise workbench
Post by: Johannes @ Robots in Architecture on April 12, 2021, 10:56:52 PM
Hello Jon,
Attached is a thread example, the following snippet passes a reference of the BlockingQueue to the thread:
public UDPReceiver(BlockingQueue<PRC_CommandData> UDPInput) throws SocketException {
        socket = new DatagramSocket(30000);
        UDPQueue = UDPInput;
    }

I would pass a reference to the IO group containing the media flange the same way and then see what happens!
Best,
Johannes
Title: Re: Accessing IIWA media flange using a thread in Sunrise workbench
Post by: UofM FABLab on April 13, 2021, 11:01:52 PM
Thank you for your reply Johannes.

I've fidled around with the code you sent and I am still unsure on how to establish a relationship between the thread and the ioGroup/mediaFlange.

Would it look something like this?

public UDPReceiver(MediaFlangeIOGroup mediaFlangeIO) throws SocketException {
       socket = new DatagramSocket(30000);
        mediaFlange = mediaFlangeIO;
    }

I've essentially just changed the variable from your code to MediaFlangeIOGroup. How would I got about changing a pin status in this setup?

Thank you for your help.

Take care,
Jon
Title: Re: Accessing IIWA media flange using a thread in Sunrise workbench
Post by: Johannes @ Robots in Architecture on April 14, 2021, 07:18:08 AM
Hello Jon,

I would also get rid of the "throws SocketException" part and the socket object - unless you need socket communication. Don't forget to define your mediaFlange object where previously the socket was defined.
The naming of the IOs is not really standardized, but you should be able to do something like mediaFlange.SetOutput1(true)

public void run() {
        running = true;
        while (running) {
            mediaFlange.SetOutput1(true)
        }
    }

I haven't worked with Sunrise in quite a while, but Sunrise Workbench should suggest the possible options anyway.
The code above would constantly set your output 1 to true, which is not terribly exciting.
Best,
Johannes
Title: Re: Accessing IIWA media flange using a thread in Sunrise workbench
Post by: UofM FABLab on April 14, 2021, 05:31:56 PM
Hello Johannes,

This worked. To establish the connection, I had to include the MediaFlangeIOGroup in the constructor of the the thread and inject it.

Thank you very much for your help.

Jon
Title: Re: Accessing IIWA media flange using a thread in Sunrise workbench
Post by: Johannes @ Robots in Architecture on April 14, 2021, 07:12:15 PM
Awesome, glad that it worked!

Best,
Johannes