Threading in IOIO

120 views
Skip to first unread message

Shantanu Gore

unread,
Apr 5, 2015, 11:39:02 PM4/5/15
to ioio-...@googlegroups.com
Hey everyone,

I would like to spawn multiple IOIO threads, one for each motor+potentiometer pair I have. I have been looking for how to do this for a few days now, but everything I find seems to be outdated (using the deprecated method AbstractIOIOActivity).

Basically, I would like to be able to move each motor simultaneously, concurrently, and independently. The best way that I can think of to do this is through separate threads for each motor+pot pair, rather than an event loop like many of the examples I am able to find seem to be doing.

Is there a reason why BaseIOIOLooper seems to be replacing IOIOThread, or am I missing something?

Thanks in advance for your help!

Shantanu

Ytai Ben-Tsvi

unread,
Apr 6, 2015, 6:50:05 PM4/6/15
to ioio-...@googlegroups.com
Multiple threads are indeed the recommended way of doing what you want. Do not confuse that with having multiple IOIOThreads, which is not what you want.
A thread is automatically created by the IOIO framework for every possible IOIO connection. This is some internal bookkeeping that is not immediately relevant for you, but in short, this will be the thread on which your setup() / loop() / disconnected() methods will run, should a session to the IOIO be established on that particular possible connection. The deprecated stuff is indeed, er, deprecated and I would strongly recommend that you don't use it.
From the setup() method (which is called once you have a live IOIO session) you can do whatever you want. Specifically, you can create multiple Threads (just normal Java threads), passing them the IOIO instance of some more specific interfaces or whatever and do real work. The IOIO API is completely thread-safe, you don't need to worry about synchronizing access yourself.
For clean closing, make sure that all these threads exit quickly after the IOIO connection drops (e.g. in response to ConnectionLostException), and that your disconnect() method join()s all threads, i.e. waits for them to exit.
That's pretty much it. The IOIO codebase contains an app called IOIOTorture test which uses a similar pattern. In that case, it is exercising all the peripherals concurrently to validate the IOIO software / firmware under concurrent load.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Ranu Gupta

unread,
Oct 30, 2015, 2:30:49 AM10/30/15
to ioio-...@googlegroups.com
Hello,

 I'm also attempting to run multiple (e.g. 4 )motor+potentiometer pair using multithreading, however not able  to implement it sucessfully.
If you have worked out a way to acheive the parallel motor control, I request your kind help in this regard. 
Can you share your code  to  allow me testing the same for my requirement?
Waiting earnestly for your reply. 

Thank you.


Ytai Ben-Tsvi

unread,
Nov 2, 2015, 2:02:47 PM11/2/15
to ioio-...@googlegroups.com
In the IOIO codebase, there's an app called IOIOTortureTest which uses the IOIO in a multi-threaded environment. It is a little complicated, though, so I'm not sure if that's what you're asking for.

What is the actual problem you're having? Can you send some small piece of code that you're having trouble with?

Reply all
Reply to author
Forward
0 new messages