[POC] python and ev3

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

[POC] python and ev3

Postby topikachu » Tue Oct 01, 2013 3:47 pm

Hi, all
I create a poc to demonstrate drive ev3 in python. You can see at http://www.tudou.com/v/rzZ629cvWlY/&rpi ... 5_99/v.swf
I use Andy 0.4.0-alpha lejos and python 2.7.
A github project is setup to continue develop python driver. https://github.com/topikachu/python-ev3

Many thanks to lejos team.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby fuzzycow » Tue Oct 01, 2013 8:42 pm

I think you can cross-compile using regular GCC for ARM.
Worked for CMU flite, with GCC 4.7.x (gcc-4.7-arm-linux-gnueabi) on Debian . Don't know which version of gcc will produce better results.

Disclaimer: excuse me if this is obvious ;)
fuzzycow
New User
 
Posts: 20
Joined: Sun Sep 08, 2013 4:33 pm

Re: [POC] python and ev3

Postby pepijndevos » Tue Oct 08, 2013 10:38 am

Nice one!

I have been playing with this myself. I compiled Python 3.3 with working NumPy and pip. I got the C api from BricxCC to work using ctypes, but that's missing sensor support.

I gave up on writing pure Python drivers myself because after mmap'ing the driver files, I could not easily extract the data from it.

I did try h2py, which converted all the defines, but not the types. Your use of ctypesgen looks very promising.

I'm currently experimenting with SWIG on a C++ API that someone is writing, but if your API is close to working, I might just contribute to yours.
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: [POC] python and ev3

Postby topikachu » Tue Oct 08, 2013 11:56 am

Hi, pepijndevos
I use python 2.7 and implement in pure python.
The low level Uart, AD, LCD, Button and Sound drivers are almost done with python OS and mmap module.
The data struct is generated from lms2012.h by ctypesgen. Only _IO/R/W macro is missing.

^^
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby pepijndevos » Tue Oct 08, 2013 4:34 pm

Cool. let me know if I can do anything to help. I could have a look at I2C if you want. I have some NXT sensors to play with :)
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: [POC] python and ev3

Postby topikachu » Wed Oct 09, 2013 1:39 am

Hi, pepijndevos
Yes please.
You are welcome.
You can fork my project, or if you'd like, send me your git account and I will add you as collaborator.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby topikachu » Wed Oct 09, 2013 1:40 am

Hi, pepijndevos
Yes please.
You are welcome.
You can fork my project, or if you'd like, send me your git account and I will add you as collaborator.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby pepijndevos » Thu Oct 10, 2013 10:12 am

Now I see what you mean by _IORW. It's defined in extra/linux-03.20.00.13/include/asm-generic/ioctl.h, would that help?

I found it expands to the following for the IIC constants.

Code: Select all
(((2U|1U) << (((0 +8)+8)+14)) | ((('i')) << (0 +8)) | (((2)) << 0) | ((((sizeof(DEVCON)))) << ((0 +8)+8)))
(((2U|1U) << (((0 +8)+8)+14)) | ((('i')) << (0 +8)) | (((3)) << 0) | ((((sizeof(IICCTL)))) << ((0 +8)+8)))
(((2U|1U) << (((0 +8)+8)+14)) | ((('i')) << (0 +8)) | (((5)) << 0) | ((((sizeof(IICDAT)))) << ((0 +8)+8)))
(((2U|1U) << (((0 +8)+8)+14)) | ((('i')) << (0 +8)) | (((6)) << 0) | ((((sizeof(IICSTR)))) << ((0 +8)+8)))


Maybe we can build a Python function out of that with a bit of magic? I foresee problems with the 'i' char and 2U unsigned numbers, but it should work...

[edit] it does!
Code: Select all
((3 << 30) | (ord('u') << 8) | 0 | (sizeof(lms2012.DEVCON) << 16))


[edit]
I2C is not working yet. I'm looking at DEVCON now. I think we might need one global devcon?

[edit]
Still meh. I got some data back, but not the data I wanted. https://www.refheap.com/19606

Some resource:
https://sourceforge.net/p/lejos/ev3/ci/ ... t.java#l96
http://robotnav.wordpress.com/i2c_devices/
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: [POC] python and ev3

Postby topikachu » Thu Oct 10, 2013 10:11 pm

devcon should be shared between IIC and UART. However I haven't fix it.
All port should be reset and clear change before use or when DCM detect a change. https://github.com/mindboards/ev3source ... ut.c#L1085
Try to clear the mmap file status field &= ~IIC_DATA_READY

There are two ioctl command for IIC in ev3
see below post. too may URLs :(
Last edited by topikachu on Fri Oct 11, 2013 1:59 am, edited 1 time in total.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby topikachu » Fri Oct 11, 2013 1:51 am

IIC_SET. This one set a setup string (optional) and a polling string. The ev3 kernel will poll the IIC data and copy the value to the device file. See https://github.com/mindboards/ev3source ... ic.c#L1245
The IIC string is at here
lego's https://raw.github.com/mindboards/ev3so ... pedata.rcf
HT's https://raw.github.com/mindboards/ev3so ... data50.rcf
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby topikachu » Fri Oct 11, 2013 1:52 am

IIC_SETUP. This one is used in lejos. It's a one time transaction. https://github.com/mindboards/ev3source ... ic.c#L1245

That's all I know about IIC :D
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby pepijndevos » Sat Oct 26, 2013 8:40 am

Any progress on your side?

I'm a bit busy these days, so I did not try to fix the IIC code yet.
pepijndevos
New User
 
Posts: 24
Joined: Fri May 14, 2010 8:56 am

Re: [POC] python and ev3

Postby topikachu » Mon Oct 28, 2013 1:40 am

I get some IIC sensors and make some test.
Please see the latest code. and try the IICtest under test folder.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [POC] python and ev3

Postby GeekDude » Wed Nov 20, 2013 5:33 am

DISCLAIMER: I am very much a novice on these matters. I might be doing everything fundamentally wrong.

Somewhat amusingly, I've managed to get nxt-python running on the EV3. It only took a few hours of trying to figure out how to get it to fit together!

I did something like this

First I downloaded nxt-python
then downloaded pyusb
then downloaded libusb 1.0

I extracted nxt-python and pyusb onto the EV3, and ran
Code: Select all
$ python setup.py install

on them.


Then I extracted libusb, and ran this series of commands on it to cross compile for ARM
Code: Select all
$ RANLIB=/usr/bin/ranlib
$ ./configure --prefix=/usr/local/arm-linux-gcc --host=arm-linux
$ make



I copied the contents of the new libusb-1.0/libusb/.lib folder into the /lib folder on the EV3


then, in ~/python2/lib/python2.7/site-packages/usb/backend/libusb10.py, I changed some lines around
Code: Select all
def _load_library():
    if sys.platform != 'cygwin':
        libname = 'libusb-1.0.so.0'
        # candidates = ('usb-1.0', 'libusb-1.0', 'usb')
        # for candidate in candidates:
            # libname = ctypes.util.find_library(candidate)
            # if libname is not None: break

because for some reason ctypes.util.find_library doesn't work on the EV3


When I ran some test code, (something like this)
Code: Select all
import nxt.locator

brick = nxt.locator.find_one_brick()
print "NXT found with name: " + brick.get_device_info()[0].rstrip('\0')

it worked fine. Motors seem to be working fine, but I didn't really test them much at all.
GeekDude
New User
 
Posts: 9
Joined: Wed Nov 13, 2013 12:50 pm

Re: [POC] python and ev3

Postby topikachu » Sun Nov 24, 2013 5:29 am

@GeekDude
Greate job.
Please continue your investigation.
BTW, do you run this nxt-python on Lego in stock firmware or Lejos image?
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Next

Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff