Author Topic: Accessing IIWA media flange using a thread in Sunrise workbench  (Read 1810 times)

UofM FABLab

  • FABLab Manager
  • Robots in Architecture Members
  • Forum User
  • *
  • Posts: 8
  • Jason was here.
    • View Profile
    • FAUM \\ FABLab
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

Johannes @ Robots in Architecture

  • Lead Developer
  • Administrator
  • Forum User
  • *****
  • Posts: 1224
    • View Profile
    • Robots in Architecture
Re: Accessing IIWA media flange using a thread in Sunrise workbench
« Reply #1 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:
Code: [Select]
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

UofM FABLab

  • FABLab Manager
  • Robots in Architecture Members
  • Forum User
  • *
  • Posts: 8
  • Jason was here.
    • View Profile
    • FAUM \\ FABLab
Re: Accessing IIWA media flange using a thread in Sunrise workbench
« Reply #2 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

Johannes @ Robots in Architecture

  • Lead Developer
  • Administrator
  • Forum User
  • *****
  • Posts: 1224
    • View Profile
    • Robots in Architecture
Re: Accessing IIWA media flange using a thread in Sunrise workbench
« Reply #3 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)

Code: [Select]
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

UofM FABLab

  • FABLab Manager
  • Robots in Architecture Members
  • Forum User
  • *
  • Posts: 8
  • Jason was here.
    • View Profile
    • FAUM \\ FABLab
Re: Accessing IIWA media flange using a thread in Sunrise workbench
« Reply #4 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

Johannes @ Robots in Architecture

  • Lead Developer
  • Administrator
  • Forum User
  • *****
  • Posts: 1224
    • View Profile
    • Robots in Architecture
Re: Accessing IIWA media flange using a thread in Sunrise workbench
« Reply #5 on: April 14, 2021, 07:12:15 PM »
Awesome, glad that it worked!

Best,
Johannes