You are viewing an older revision! See the latest version

m3pi logo

An introduction to logo

Aims of the m3pi-logo project

This page will be devoted to the development and advancement of the m3pi robot for use with the logo functional programming language. The aim will be to control the full functionality of the m3pi robot through a text file that can be located on a flash/thumb drive. Users can simply write their code into the text file from a computer and then run it on the m3pi. I hope to keep what code is recognised and understood and indeed what is used as similar to the actual Logo language as possible so that it may be used as a more physical demonstration for those that studying or are looking to study the language. However there may be a few new additions...

Basic Logo language

The commands set forth are simple to understand and need nothing in the way of conventional programmers understanding. The object that is doing the actual moveing has become known as the Turtle through visualization and debugging software.

  • FORWARD 100
    • This makes the 'turtle' move forward 100 units (in this case, centimetres)
  • BACKWARD 100
    • This makes it move backward 100 units
  • RIGHT 90
    • A rotation to the right 90° although at present i have narrowed down the precise accuracy to within 5° to 10°
  • LEFT 20
    • A rotation to the left by 20°
  • REPEAT 4 [FORWARD 10 RIGHT 90]
    • This will repeat anything within the brackets the number of times stated outside (in this case, repeat the commands forward 10cm and right 90° four times)

Above is stated the commands that exist already in Logo, but we have some more things we can do, what with being a robot and all...

  • BUZZER 100
    • This will make the yet unused (and undisclosed) buzzer on the m3pi make a sound at the intended frequency.
    • NOTE there is no time limit to this, but your m3pi will not move or function whilst making the sound.
  • BUZZER 0
    • This will turn the buzzer off, and allow normal operation of the m3pi to resume
  • STOP 10
    • This will stop the m3pi from moving, but not stop the buzzer from sounding. can be used as a wait command to hold or pause the m3pi for a set duration. As of yet it is undecided if it will be in seconds or milliseconds

The concept

The idea whilst being simple in nature: to convert the logo visual programming language into a set of commands that the mbed and m3pi can recognise, isn't without it's difficulties. For starters, one must grab all of the content of a text document (there have also been suggestions of doing it through a hyper terminal) and then process it into it's components; the action, and the variable associated with it.

Getting started

First we need to insure everything is working properly for this we can use a simple code to read a text file on a memory stick called YourText.txt and print the first 8 characters of the document to the m3pi's LCD screen (8 characters because that is all that can fit on the first line of the display)

Hello_World

#include "mbed.h"
#include "m3pi.h"
#include "MSCFileSystem.h"

DigitalOut myled(LED1);
m3pi m3pi;
MSCFileSystem msc("usb");

//The m3pi can have a maximum of 8 charicters on a row of it's display, so logically that is all we need to accomedate
char YourText[8];

int main() {
    //set the file you want to open to /usb/YourFile.txt and we want to read it, so fopen needs 'r'
    FILE *YourFile = fopen("/usb/YourFile.txt", "r");
    if (YourFile == NULL) {
        //if your file isnt there, turn an led on and do nothing else
        myled = 1;
        while (1) {}
    }
    //scan untill you hit then end of the document and put everything in YourText as a string
    while (!feof(YourFile)) {
        fscanf (YourFile, "%s", YourText);
    }
    m3pi.cls();
    //and print your message!
    m3pi.printf("%s", YourText);
}

All wikipages