PyEV3 (peeve?)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

PyEV3 (peeve?)

Post by pepijndevos »

Some people have mentioned the idea of running Python on the EV3, but I haven't actually seen it happen. So here you are:

https://www.dropbox.com/s/jmz4wqfbm7lmzqw/ev3.tar.gz

Just extract that somewhere and run the python3.3 binary. I'm using the LejOS image, but you don't need to.

There are currently no drivers, so you can't do anything cool, but I plan to remedy that soon. I will also compile NumPy, for all your mathy A.I. needs

I have not yet decided if I should expose John's C API, or port it... I'm leaning towards exposing because things are young and evolving rapidly, so concentrating effort is preferred in these early days.

HOWTO: This is roughly what I did:

Code: Select all

wget https://sourcery.mentor.com/GNUToolchain/package4573/public/arm-none-linux-gnueabi/arm-2009q1-203-arm-none-linux-gnueabi.bin
chmod +x arm-2009q1-203-arm-none-linux-gnueabi.bin
sudo apt-get install openjdk-7-jre
sudo apt-get install lib32 # on 64 bit systems
sudo dpkg-reconfigure -plow dash # installer needs real bash
./arm-2009q1-203-arm-none-linux-gnueabi.bin -i console # swing did not work for me
export PATH="/home/parallels/CodeSourcery/Sourcery_G++_Lite/bin:$PATH"
wget http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2
tar -xjf Python-3.3.2.tar.bz2
./configure # first we need to install python3.3 on the host system
make
sudo make altinstall
make clean # remove all the stuff and start the real deal
vim config.site # copy-paste from that link above
CONFIG_SITE=config.site ./configure --build=x86_64-ubuntu-linux --host=arm-none-linux-gnueabi --prefix=/home/parallels/ev3/ --disable-ipv6
make
make install
You might try older Python versions, but be advised that cross-compiling them requires more work.
-- Pepijn
http://studl.es Mindstorms Building Instructions
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: PyEV3 (peeve?)

Post by pepijndevos »

NumPy is there!

https://www.dropbox.com/s/jmz4wqfbm7lmzqw/ev3.tar.gz

It was actually harder to compile than Python itself.

Code: Select all

CFLAGS="-g -O3 -I$HOME/ev3/include/python3.3m/" LDFLAGS="-shared -L$HOME/ev3/lib/python3.3/" CC=/home/parallels/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc LDSHARED=/home/parallels/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc LD=/home/parallels/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-ld python3.3 setup.py install --prefix /home/parallels/ev3/
Next I might add pip and start working on API bindings.
-- Pepijn
http://studl.es Mindstorms Building Instructions
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: PyEV3 (peeve?)

Post by pepijndevos »

Actually, you can just upload the libev3.so and do

Code: Select all

import ctypes
ev3 = ctypes.cdll.LoadLibrary("./libev3.so")
ev3.SoundInit()
ev3.PlaySound(1)
I have one feature request though: a KILL OFF STOP QUIT HALT TERMINATE button. Like - you know - that nice back button. I don't know at which level this should be implemented, but it's important.

I'm currently using the LejOS image. It can't be turned off. I can't stop programs. And when I ran this program the SSH connection dies and I had to remove the batteries.

Code: Select all

>>> ev3.RotateMotorEx(1, 100, 45, 1,1,1)Write failed: Host is down
-- Pepijn
http://studl.es Mindstorms Building Instructions
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: PyEV3 (peeve?)

Post by gloomyandy »

If the connection is being dropped that suggests that the EV3 has crashed (or the batteries are flat). You can shutdown a healthy leJOS image using the standard linux halt command.
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: PyEV3 (peeve?)

Post by pepijndevos »

I know about halt, but it's very annoying when the wifi doesn't work or your program hangs. Maybe I should write a daemon that listens for a back button press and halts the system.

If it did crash, what is "it", and did it write a stacktrace or memory dump or something? I can reproduce it...
-- Pepijn
http://studl.es Mindstorms Building Instructions
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: PyEV3 (peeve?)

Post by gloomyandy »

"It" in this case, is the Linux kernel. My guess is something you asked the Lego motor control module to do caused the problem. Remember that the Lego module code runs inside of the kernel, so if anything goes wrong your system is toast. I've never seen the network stop working unless the system crashes. No amount of daemons will rescue you from this situation. Look at the serial connection on sensor port one to see if there is a kernel panic of some sort, you may see it, you may not I can't remember if the panic code resets the serial port device. Welcome to the fun world of debugging embedded systems...
quarryman
Posts: 1
Joined: 07 Aug 2013, 08:57

Re: PyEV3 (peeve?)

Post by quarryman »

Very interesting. I've been planning on doing something like this too, but I didn't get my EV3 until this Monday, so I haven't had time to do anything with it yet, seems you're way ahead of me. I did grab the name "ev3" on PyPi though to use for the project, could that be interesting perhaps? (at least to me being able to do pip install -U ev3 on the EV3 to get the latest version sounds very appealing)
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: PyEV3 (peeve?)

Post by pepijndevos »

Installing libs is still a pain, because pip requires zlib, which I neglected to compile. Working on a better Python with zlib, readline and pip.

Currently there is no library. I just use the C API directly. I do want to add a Pythonic layer to it eventually. I'll put some things on Github as soon as I have something.
-- Pepijn
http://studl.es Mindstorms Building Instructions
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: PyEV3 (peeve?)

Post by pepijndevos »

Ok here is a python with pip included:

https://www.dropbox.com/s/irb0hvnb771ob ... hon.tar.gz

You need to use rdate to set the time correctly, otherwise SSL does not work. Then you can just say

Code: Select all

./ev3python/bin/pip install awesometuff
-- Pepijn
http://studl.es Mindstorms Building Instructions
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: PyEV3 (peeve?)

Post by tcwan »

pepijndevos wrote:Ok here is a python with pip included:

https://www.dropbox.com/s/irb0hvnb771ob ... hon.tar.gz

You need to use rdate to set the time correctly, otherwise SSL does not work. Then you can just say

Code: Select all

./ev3python/bin/pip install awesometuff

It would be great if there is a Sticky Post or a page somewhere on the Mindboards site with links to all the Language(s) and tools being developed for the EV3 to make it easier to look for info. So far we have LeJOS and now Python.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest