Quantcast

Question about using Python embedded with C++

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

Question about using Python embedded with C++

kenley
I been working with the robovero python library and was wanted to embed it into C++ program that my group has, is it possible with the overo host using a tobi board expansion board? I have been working for this with multiple libraries and not sure if it's possible
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using Python embedded with C++

kenley
I found the solution to my problem, if any one is having a hard time trying with robovero in C++ code, you can use the keep the python code and use the embed python features in C++

First in console you have to set the python path so you can use robovero code
export PYTHONPATH=$PYTHONPATH (my robovero code was in the base of the directory so I didn't have to add file path)

Then compile in terminal
gcc -o  name code.cpp -lpython2.6(or what your python version is)
 to run it in terminal type:
./name

To make the C++ file create a file code.cpp (The Py_initilize and Py_finailize is the python code stuff, so before and after you can type your regular c++ code) I was able run the servo.py code in the robovero python library

I still new at this stuff and my first time posting code
 (note in the code no need to put py in python file)

#include <stdio.h>
#include </usr/include/python2.6/Python.h>

int main(int, char ** )

{

Py_Initialize();
PyRun_SimpleString("import pythonfile");  
Py_Finalize();

return 0;

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using Python embedded with C++

Andrew Gottemoller
If it's useful, you can also just communicate directly with the Robovero using C.  This will allow you to avoid the python client library altogether!  A short example program which demonstrates this can be found here:

http://www.agottem.com/pages/robovero_sensors/robocomm.c

Good luck!

On Mon, Nov 19, 2012 at 9:38 AM, kenley <[hidden email]> wrote:
and use the
embed python features in C++


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using Python embedded with C++

David Rebbe-4
In reply to this post by kenley
Kenley,

I'm guessing you used this code as an example but just incase you shouldn't hardcode paths in #includes and you weren't checking the return value for SimpleString func:

$ gcc -o  name code.cpp -L/usr/include/python2.6 -lpython2.6

#include <stdio.h>
#include <Python.h>

int main(int, char ** )

{
        int result;
        Py_Initialize();
        result = PyRun_SimpleString("import pythonfile");
        Py_Finalize();

        return result;
}


Also http://docs.python.org/2/c-api/intro.html#embedding-python shows how to set the path in code so you don't have to set the env var.


On 11/19/2012 10:38 AM, kenley wrote:

> I found the solution to my problem, if any one is having a hard time trying
> with robovero in C++ code, you can use the keep the python code and use the
> embed python features in C++
>
> First in console you have to set the python path so you can use robovero
> code
> export PYTHONPATH=$PYTHONPATH (my robovero code was in the base of the
> directory so I didn't have to add file path)
>
> Then compile in terminal
> gcc -o  name code.cpp -lpython2.6(or what your python version is)
>   to run it in terminal type:
> ./name
>
> To make the C++ file create a file code.cpp (The Py_initilize and
> Py_finailize is the python code stuff, so before and after you can type your
> regular c++ code) I was able run the servo.py code in the robovero python
> library
>
> I still new at this stuff and my first time posting code
>   (note in the code no need to put py in python file)
>
> #include <stdio.h>
> #include </usr/include/python2.6/Python.h>
>
> int main(int, char ** )
>
> {
>
> Py_Initialize();
> PyRun_SimpleString("import pythonfile");
> Py_Finalize();
>
> return 0;
>
> }
>
>
>
>
> --
> View this message in context: http://gumstix.8.n6.nabble.com/Question-about-using-Python-embedded-with-C-tp4966050p4966096.html
> Sent from the Gumstix mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> gumstix-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gumstix-users


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using Python embedded with C++

Jeff L
In reply to this post by Andrew Gottemoller
I installed the precompiled patched firmware from agottem.com/robovero_sensors, then compiled robocomm.c and ran it from an overo, however running the program just returns "Unexpected data received".  

The python examples work.  If I run one of those, and then try robocomm again, it returns "It has taken an unreasonable amount of time to receive data"

My kernel version is 3.2.0 if that helps.

Another question; does the new firmware also increase the speed at which the ADCs and serial data can be read?

Thanks,
Jeff




On Sat, Dec 8, 2012 at 4:38 PM, Andrew Gottemoller <[hidden email]> wrote:
If it's useful, you can also just communicate directly with the Robovero using C.  This will allow you to avoid the python client library altogether!  A short example program which demonstrates this can be found here:

http://www.agottem.com/pages/robovero_sensors/robocomm.c

Good luck!


On Mon, Nov 19, 2012 at 9:38 AM, kenley <[hidden email]> wrote:
and use the
embed python features in C++


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users



------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using Python embedded with C++

Jeff L
I did some further checking.  If I connect the robovero to my desktop, and do "./robocomm /dev/ttyACM0", it works just fine.  Also, from my desktop, if I use the robovero command line interface, i can issue commands and receive data as in agottem.com/pages/robovero_sensors/rs_config.png, so it seems as though the firmware is functioning just fine.

When connected the overo and trying from there, again, it does not work (robocomm returns "Unexpected data received").  /dev/ttyACM0 exists.  I tried using the robovero command line interface from the overo (i am connected over bluetooth), by doing "screen /dev/ttyACM0 115200", however there is no response.

This leads me to suspect that there is something wrong with the overo - robovero communication, but the python examples still work!  
I also tried connecting the overo to a tobi expansion board, then connecting the robovero to the tobi via usb, but it gives the same result.
I cross-compiled with arm-angstrom-linux-gnueabi-gcc, but I think that's fine since I've written other programs with that.  Not sure what I am missing here... very confusing...

Again, any help is very much appreciated.


On Sat, Dec 15, 2012 at 6:48 PM, Jeffrey Laut <[hidden email]> wrote:
I installed the precompiled patched firmware from agottem.com/robovero_sensors, then compiled robocomm.c and ran it from an overo, however running the program just returns "Unexpected data received".  

The python examples work.  If I run one of those, and then try robocomm again, it returns "It has taken an unreasonable amount of time to receive data"

My kernel version is 3.2.0 if that helps.

Another question; does the new firmware also increase the speed at which the ADCs and serial data can be read?

Thanks,
Jeff




On Sat, Dec 8, 2012 at 4:38 PM, Andrew Gottemoller <[hidden email]> wrote:
If it's useful, you can also just communicate directly with the Robovero using C.  This will allow you to avoid the python client library altogether!  A short example program which demonstrates this can be found here:

http://www.agottem.com/pages/robovero_sensors/robocomm.c

Good luck!


On Mon, Nov 19, 2012 at 9:38 AM, kenley <[hidden email]> wrote:
and use the
embed python features in C++


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users




------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using Python embedded with C++

Jeff L
got it working... had to do "chmod 666 /dev/ttyACM0"
don't know how that wasn't the first thing I checked...


On Sun, Dec 16, 2012 at 5:58 PM, Jeffrey Laut <[hidden email]> wrote:
I did some further checking.  If I connect the robovero to my desktop, and do "./robocomm /dev/ttyACM0", it works just fine.  Also, from my desktop, if I use the robovero command line interface, i can issue commands and receive data as in agottem.com/pages/robovero_sensors/rs_config.png, so it seems as though the firmware is functioning just fine.

When connected the overo and trying from there, again, it does not work (robocomm returns "Unexpected data received").  /dev/ttyACM0 exists.  I tried using the robovero command line interface from the overo (i am connected over bluetooth), by doing "screen /dev/ttyACM0 115200", however there is no response.

This leads me to suspect that there is something wrong with the overo - robovero communication, but the python examples still work!  
I also tried connecting the overo to a tobi expansion board, then connecting the robovero to the tobi via usb, but it gives the same result.
I cross-compiled with arm-angstrom-linux-gnueabi-gcc, but I think that's fine since I've written other programs with that.  Not sure what I am missing here... very confusing...

Again, any help is very much appreciated.


On Sat, Dec 15, 2012 at 6:48 PM, Jeffrey Laut <[hidden email]> wrote:
I installed the precompiled patched firmware from agottem.com/robovero_sensors, then compiled robocomm.c and ran it from an overo, however running the program just returns "Unexpected data received".  

The python examples work.  If I run one of those, and then try robocomm again, it returns "It has taken an unreasonable amount of time to receive data"

My kernel version is 3.2.0 if that helps.

Another question; does the new firmware also increase the speed at which the ADCs and serial data can be read?

Thanks,
Jeff




On Sat, Dec 8, 2012 at 4:38 PM, Andrew Gottemoller <[hidden email]> wrote:
If it's useful, you can also just communicate directly with the Robovero using C.  This will allow you to avoid the python client library altogether!  A short example program which demonstrates this can be found here:

http://www.agottem.com/pages/robovero_sensors/robocomm.c

Good luck!


On Mon, Nov 19, 2012 at 9:38 AM, kenley <[hidden email]> wrote:
and use the
embed python features in C++


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users





------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Loading...