Quantcast

Python YARP samples

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Python YARP samples

Jackie Kay
Greetings,

I'm learning the iCub simulator for a class project and I'm wondering if anyone can point me to some good examples of YARP/iCub Python code besides what's on the iCub wiki. I understand that with SWIG all of the C++ classes should just exist with the same function names, etc. but it does not appear to be that straightforward.

For example, I want to use the RateThread class to set off a thread that will collect trajectory data as the main thread controls the robot. However, it appears that the RateThread class does not exist but the Thread class does. So, I wrote a new CollectThread class that extends Thread, but I am having some difficulty calling start() on the new thread. It looks like the SWIG bindings expect start to receive a Thread object, but really it's receiving a CollectThread object, and so is unable to proceed.

Thanks for your help,

Jackie Kay
Swarthmore College

------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Robotcub-hackers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/robotcub-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Python YARP samples

paulfitz
Administrator
Hi Jackie,

Thanks for reporting this.  Your understanding of SWIG is basically
correct, what you discovered were mistakes on my part. If you have the
yarp source code, and look at bindings/yarp.i, you'll see a big list of
classes a little way down in it. RateThread is simply missing from that
list.  I've now added it. Also, for performance reasons, SWIG doesn't
automatically support inheritance/extension for all translated classes,
you need to tell it specifically which ones you want to support
inheritance for. This is controlled by the lines that look like this:
   %feature("director") yarp::os::RFModule;
I think (though have not checked) that the problem you hit with Thread
is that we haven't enabled inheritance for it.  I've now done that.

You can find the two fixes here:
   https://github.com/robotology/yarp/commit/d04b460488
To try them out yourself, either update your version of YARP, or make
the changes manually by adding:
   %feature("director") yarp::os::Thread;
   %include <yarp/os/RateThread.h>
in bindings/yarp.i in about the locations shown, then rebuild the bindings.

Hope this helps,
Paul

On 04/26/2014 01:27 AM, Jackie Kay wrote:

> Greetings,
>
> I'm learning the iCub simulator for a class project and I'm wondering
> if anyone can point me to some good examples of YARP/iCub Python code
> besides what's on the iCub wiki. I understand that with SWIG all of
> the C++ classes should just exist with the same function names, etc.
> but it does not appear to be that straightforward.
>
> For example, I want to use the RateThread class to set off a thread
> that will collect trajectory data as the main thread controls the
> robot. However, it appears that the RateThread class does not exist
> but the Thread class does. So, I wrote a new CollectThread class that
> extends Thread, but I am having some difficulty calling start() on the
> new thread. It looks like the SWIG bindings expect start to receive a
> Thread object, but really it's receiving a CollectThread object, and
> so is unable to proceed.
>
> Thanks for your help,
>
> Jackie Kay
> Swarthmore College
>


------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Robotcub-hackers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/robotcub-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Python YARP samples

Jackie Kay
Thanks Paul! Much appreciated.

Another Python iCub question:

I'm having difficulty getting the cartesiancontrollerclient module working from Python. At first I thought it was because I installed iCub from pre-compiled binaries and maybe the flag to enable the cartesian interface wasn't set, but I think the issue is actually coming from translating instructions from C++ to Python. The cartesian interface tutorial says that I should include the macro "YARP_DECLARE_DEVICES(icubmod)" with includes and "YARP_REGISTER_DEVICES(icubmod)" in main(). How does this work in Python? Does the cartesian interface work with Python/SWIG bindings? It seems feasible that I could look at the source code and then translate the macros into Python YARP commands. Is this recommended?

Jackie


On Fri, Apr 25, 2014 at 10:08 PM, Paul Fitzpatrick <[hidden email]> wrote:
Hi Jackie,

Thanks for reporting this.  Your understanding of SWIG is basically
correct, what you discovered were mistakes on my part. If you have the
yarp source code, and look at bindings/yarp.i, you'll see a big list of
classes a little way down in it. RateThread is simply missing from that
list.  I've now added it. Also, for performance reasons, SWIG doesn't
automatically support inheritance/extension for all translated classes,
you need to tell it specifically which ones you want to support
inheritance for. This is controlled by the lines that look like this:
   %feature("director") yarp::os::RFModule;
I think (though have not checked) that the problem you hit with Thread
is that we haven't enabled inheritance for it.  I've now done that.

You can find the two fixes here:
   https://github.com/robotology/yarp/commit/d04b460488
To try them out yourself, either update your version of YARP, or make
the changes manually by adding:
   %feature("director") yarp::os::Thread;
   %include <yarp/os/RateThread.h>
in bindings/yarp.i in about the locations shown, then rebuild the bindings.

Hope this helps,
Paul

On 04/26/2014 01:27 AM, Jackie Kay wrote:
> Greetings,
>
> I'm learning the iCub simulator for a class project and I'm wondering
> if anyone can point me to some good examples of YARP/iCub Python code
> besides what's on the iCub wiki. I understand that with SWIG all of
> the C++ classes should just exist with the same function names, etc.
> but it does not appear to be that straightforward.
>
> For example, I want to use the RateThread class to set off a thread
> that will collect trajectory data as the main thread controls the
> robot. However, it appears that the RateThread class does not exist
> but the Thread class does. So, I wrote a new CollectThread class that
> extends Thread, but I am having some difficulty calling start() on the
> new thread. It looks like the SWIG bindings expect start to receive a
> Thread object, but really it's receiving a CollectThread object, and
> so is unable to proceed.
>
> Thanks for your help,
>
> Jackie Kay
> Swarthmore College
>


------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Robotcub-hackers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/robotcub-hackers


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.  Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Robotcub-hackers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/robotcub-hackers
Loading...