Hello
Will there be any possibility to use Python instead of Aseba with Thymio II in the future?
Hello
Will there be any possibility to use Python instead of Aseba with Thymio II in the future?
No, the memory footprint of Python is orders of magnitude heavier than what the Thymio II's microcontroller provides.
Thanks for the reply. Did you have a look at http://wiki.python.org/moin/PyMite also? It's a subset of the language from what I understand.
Thank you for the link, I was not aware of this project, it looks interesting, I have to look a bit deeper into it. Note that according to the feature list in http://code.google.com/p/python-on-a-chip/, the "hello world" needs 5KB of RAM, while our microcontroller has 16 KB for everything, including communication buffer, etc. Therefore, PyMite is probably too heavy for the Thymio. One thing that I would be interested in is a tiny embedded language with Pythonish syntax, static typing, and type inference. But this is a significant project for which I do not have time now.
What about python on the PC side in order to "remote control" and program the ThymioII over USB serial port as e.g. mentioned in Labview interface?
If someone wants to contribute Python bindings for Aseba, for instance using boost::python, we would warmly welcome them.
Ohh… - it must be a misunderstanding; I did not want to claim that python-dbus does not work - I simply was not able to test it because of a lack in ready-to-use resp. working python-dbus package for win. Or do you know one?
The following example uses pyserial which works on win and unix/linux and exists as ready-to-use packages.
Meanwhile I a wrote a dirty and hacky script basing on all hints I got so far and my findings (cf. the Labview Interface also):
port = 'COM4' # COM4 (win)
#port = '/dev/ttyS1' # ttyS1 (unix/linux)
ASEBA_MESSAGE_GET_DESCRIPTION = 0xA000
MESSAGE = "\x04\x00"
import serial # http://pyserial.sourceforge.net/
import struct
try:
# open serial port with thymio2 connected
ser = serial.Serial(port,
baudrate=115200,
bytesize=8,
parity='N',
stopbits=1,
xonxoff=0, rtscts=0)
# check which port was really used
print "port:", ser.portstr
# serialize and send MESSAGE
#print '%r' % struct.pack('<H', len(MESSAGE))
#print '%r' % struct.pack('<H', 0)
#print '%r' % struct.pack('<H', ASEBA_MESSAGE_GET_DESCRIPTION)
#print '%r' % MESSAGE
# header
ser.write(struct.pack('<H', len(MESSAGE))) # length of message (word)
ser.write(struct.pack('<H', 0)) # source id of message (word)
ser.write(struct.pack('<H', ASEBA_MESSAGE_GET_DESCRIPTION)) # type of message (word)
# payload
ser.write(MESSAGE) # the message ...
# receive answer and check for thymio signature
s = ser.read(20) # read some bytes (no timeout)
print "device:", s[7:16]
if s[7:16] == "thymio-II":
print "\nThymioII found."
## # receive and deserialize answer
## # header
## while True:
## length = struct.unpack('<H', ser.read(2))[0]
## print '%04x' % length, length
## if length and (length > 0):
## sid = struct.unpack('<H', ser.read(2))[0]
## styp = struct.unpack('<H', ser.read(2))[0]
## msg = ser.read(length)
## print msg
## else:
## break
except serial.serialutil.SerialException:
print "ERROR: port could not be opened!"
Open here is what 04 00 means and how exactly to de-serialize and interpret the received answer afterwards…
Then we can start to implement a python-serial module for ThymioII.
The correct way to implement a pure-Python interface is to use a similar architecture as in common/msg, with an abstract class for all messages and sub-classes for every message type, as explained in this thread. I do not see the point of going any other way.
Yes of course - you are right - for python this is possible. According to that advice I implemented python-serial, resp. the aseba-thymio2.py example. Attention please do not confuse 'python-serial' with the very well known, good old 'pyserial'.
Thanks for all your support!!