m3pi logo

m3pi logo

Import programm3pi_logo

Look for a LOGO (.LGO) file on the mbed and run the commands in it. Only supports a small subset of the LOGO commands.

The m3pi robot really does seem very similar to a logo turtle, so I thought it would be cool to get it to run logo code. Indeed all the functionality is there to get it moving all that's missing is a pen.

The idea was simply to have the code loaded on the m3pi and for it to detect logo programs on the file system. If a logo file exists, interpret it and move the robot as requested.

To start, I wrote the code to read the file system and open the logo file. It appeared that the ".LGO" extension was common for such files, so I simply wrote code that got the directory listing and looked for the latest file with this extension. Ideally I'd have liked to check the timestamp to ensure it was the latest file, but it appears that functionality is not implemented in the library.

Once this was done, I looked to get the commands working. I first defined the API - each Command class specialization would need a function to execute what was requested, and a pretty printer to help debug the code. Implementing the FORWARD command, showed this worked well.

Next I moved onto joining up the logo file with the commands. A tokenizer was written - there's only three types we care about:

  • Words
  • Integers
  • EOL

The parsing of the file is simple - when it's looking for a command, you expect a word, then pass code to a function that knows:

  • if any additional command parameters are expected, and
  • how to build the Command class for it.

Once it was all hooked up, it more or less worked. I wrote a "test.lgo" file and the robot happily moved forward the number of steps requested. One by one, I added support for the BACK, LEFT and RIGHT commands. The only issue seemed to be that the robot is not rotating as I expect - what I calculated as 90 degrees, doesn't actually work.

I've also added recognition of the PENDOWN and PENUP commands. They can't do anything, but perhaps we can hook it up to something later?

The code seems to mostly work, apart from:

  • Rotation does not work if the SPEED is adjusted.
  • Some memory corruption seems to be happening since after completing once, the mbed does not connect to my PC. If I turn on the m3pi, part of the logo program runs. When the program completes, only then the mbed is seen by the PC.

Plans:

  • I'd really like to do something meaningful with the PENDOWN and PENUP buttons.
  • Extend the command set to be more than what's currently available.


Please log in to post comments.