[squeak-dev] [ANN] Physical Etoys 2.0 released!
richi.moran at gmail.com
Sun Apr 22 03:31:24 UTC 2012
On Sat, Apr 21, 2012 at 3:03 AM, Michael Haupt <mhaupt at gmail.com> wrote:
> Hi Ricardo,
> 1. We added a new programming mode that lets you compile your scripts
> and have them running inside the robot, in contrast to running them in the
> computer and communicate with the robot via bluetooth or usb. We believe
> this opens a lot of new posibilities for the Physical Etoys users.
> Can you give some details? I figure you'd have to compile the programs
> somehow to let them run in isolation. How do you do that for Arduino, and
> how for the NXT?
Yes, we're using the same mechanism for both Arduino and Lego Nxt. We made
a very simple Smalltalk to C translator, which takes a Smalltalk class and
generates a valid C/C++ program (C++ for Arduino and NXC for Lego Nxt,
actually). Then we talk to the compiler libraries for each platform
(avr-gcc/avrdude for Arduino and NBC for Lego Nxt) and let them compile and
program the robot.
The process is actually a little bit more complicated than that because to
translate the Etoys scripts, which can be represented by several different
Player subclasses, first we need to merge them in one class. This is a
restriction enforced by the translator which requires as input only one
class with one entry point (even though it will then generate code for all
the referred classes). Also, this one class representing the Etoys program
must simulate the script's ticking, for which I simply create an eternal
loop that constantly goes through the list of scripts and executes them if
they have to run at that time.
All in all, the C code generation is actually very simple, but it took us
quite some time to implement it. At first I started using Squeak's parser
but then Serge Stinckwich was kind enough to point me to the Refactoring
Browser's parser, which has a much simpler hierarchy of parse nodes IMHO.
That, combined with the visitor pattern, is all we needed to translate the
Currently, the translator only supports a very small subset of Smalltalk,
easily identifiable by the hierarchy of CObject and its subclasses. It's so
basic that it doesn't even support blocks (except as arguments of primitive
methods), polymorphism or dynamic typing (we use pragmas to specify the
variable types). So it's not actually very fun to write code for it (it's
more like C code disguised as smalltalk) but it's good enough for Etoys
scripts and it has seemed to work fine... at least on our lab, let's see
how it goes in the real world :)
When we started doing this for Lego Nxt we looked briefly at NXTalk but we
decided against it because we had as a requirement to be compatible with
the Lego standard firmware so that the kid could use both Physical Etoys
and the Lego software to program his robot. We think we made the right
choice, specially because the same code for the Lego Nxt was then used for
Arduino without too many changes.
If you want to have a look, all the code is available at the following
squeaksource repositories: CTranslator, Arduino and SqueakNxt. Look for the
packages that end with "Compiler" in the last two. Don't expect it to be
fully documented, though :)
> And also, I would like to announce that Physical Etoys 2.0 is going to
> be installed by default on all the laptops of the "Conectar igualdad"
> program, which is kind of like the argentinian version of OLPC (but for
> older students). So we are *really* excited about this!
> Congratulations! That is a great achievement.
Thanks, we believe that too and we're very happy about it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev