Instructions as of May 2015

The RoboSlam robot is built in four stages. Each stage involves some circuit construction and programming to add a new feature to the robot.

Stage 1: Preparation

Step 1.1: Switch to Firefox

If you’re reading this in Internet Explorer, please switch to Firefox now. Copying and pasting the example programs from Internet Explorer does not work correctly.

Step 1.2: Download roboslam.zip

To use the example programs provided below to control your robot, you need a text editor called Notepad++ and a C compiler called mspgcc. We have created a zip file called "roboslam.zip" which contains both, together with some other useful tools. If you haven’t already downloaded this zip file, you should do so now:

Extract the contents of the zip file to "C:\RoboSlam\".

WARNING: If you decide to place your RoboSlam folder in a different location, the path to the folder must not contain any spaces. For example, "C:\Documents and Settings\users\Joe\RoboSlam" won’t work because there are spaces in the folder name "Documents and Settings".

Step 1.3: Preparing the components

To prevent accidental short circuits, we trim the legs of each component to just the right length.

  • Trim the legs of all five resistors to 10mm in length.
  • Trim the legs of both capacitors to 10mm in length.
  • Trim the legs of both LEDs to 8mm in length.

trim_components

A total of 22 wires are required. Each wire must be cut to the required length and then 5-6 mm of its plastic insulation must be stripped from each end. Every piece of wire in the circuit is one of four standard lengths:

  • Short: 30mm in length, including 5-6mm stripped at each end.
  • Medium: 50mm in length, including 5-6mm stripped at each end.
  • Long: 60mm in length, including 5-6mm stripped at each end.
  • Extra Long: 100mm in length, including 5-6mm stripped at each end.

The quantity of each length in each colour is:

  • BLACK: 3 short, 2 medium, 1 extra long
  • RED: 2 short, 2 medium
  • ORANGE: 2 medium
  • PURPLE: 2 medium, 2 long
  • BROWN: 1 short, 2 medium
  • GREY: 1 medium
  • YELLOW: 1 extra long
  • GREEN: 1 extra long

wire_lengths

Stage 2: Indicator LEDs

In this stage, we build a basic breadboard circuit and then load a short example program onto the MSP430 microcontroller to blink two light emitting diodes (LEDs) on and off. These LEDs are used as indicator lights.

Step 2.1: Connect the battery pack to the breadboard

The breadboard is the rectangular plastic board with the grid of holes on the top. We use it to build and test electronic circuits quickly without any soldering. Each of the two main panels in the centre of the breadboard consists of 30 short rows of 5 connected holes. To connect any two wires (or components) together, just plug them both into the same short row. For example, wires plugged into holes a3 and e3 will become electrically connected because they’re both in the same row of 5.

The long red and blue lines on each side of the breadboard indicate that each of these long rows of holes is connected continuously along the full length of the board. We call these long rows “rails”. They are normally used to distribute supply voltage to different parts of the circuit. The red rail is used for the positive supply voltage (either 6V or 3.3V in this circuit). The blue rail is used for the negative supply voltage (0V).

Connect the battery pack to the breadboard as shown below. Put three batteries into the battery pack, but leave the last one out until the circuit is ready to be powered up.

01_batteries_and_breadboard

Step 2.2: Install the voltage regulator

The battery pack supplies 6 volts to the circuit, but this supply voltage is too high for some of the components in our circuit, so we need to use a voltage regulator to provide a lower voltage. The LM1117T is a 3.3 volt regulator which we connect as shown below to feed a stable 3.3V supply to the red rail on the right hand side of the breadboard.

  • Very carefully insert the LM1117T voltage regulator (the black rectangular component with three legs and a metal back plate) into holes c28, c29 and c30 of the breadboard. The metal back plate of the voltage regulator should be on the left, as shown in the illustration below. It’s tricky to coax the three legs of the LM1117T into the breadboard without bending them, so be careful!
  • Connect a short red wire between hole a28 and the red rail on the left-hand side of the breadboard (6V).
  • Connect a short black wire between hole a30 and the blue rail on the left-hand side of the breadboard (0V).
  • Connect a medium orange wire between hole e29 and the red rail on the right-hand side of the breadboard (3.3V).
  • Connect a short black wire between hole e30 and the blue rail on the right-hand side of the breadboard (0V).
  • Connect a 220uF capacitor between the two rails on each side of the breadboard, as shown below. The capacitor is the small purple cylindrical component with two parallel legs sticking out the bottom. These capacitors act as reservoirs of electric charge, reducing unwanted fluctuations of the 6V and 3.3V supply voltages. Note that the minus leg of the capacitor, which is marked by a long black stripe running down the body of the capacitor, must be connected to the blue rail (0V).

02_voltage_regulator

Step 2.3: Install the MSP430 microcontroller

WARNING: The MSP430 chip is very fragile! The pins bend and break easily, so be careful when placing it into the breadboard.

The “brain” of the robot is the MSP430 microcontroller. A microcontroller is a complete computer on a single chip. It contains a microprocessor, RAM memory, flash memory (like in a USB memory stick) and other useful features.

Place the MSP430G2553 microcontroller in the position shown. Make sure that the end of the chip with the semi-circular indentation is in row 3.

03_MSP430_IC

Step 2.4: Connect the voltage supply to the MSP430

To supply power to the MSP430 microcontroller,

  • Connect a medium orange wire between hole d3 and the red rail on the right-hand side of the breadboard (3.3V).
  • Connect a short black wire between hole j3 and the blue rail on the right-hand side of the breadboard (0V).

To prevent the microcontroller from resetting while the robot is running, a 10kΩ resistor (colour code: brown, black, orange, gold) must be placed between hole i7 and the red rail on the right-hand side of the breadboard (3.3V).

04_MSP430_power_and_reset_resistor

Step 2.5: Add two indicator LEDs

  • Connect the green LED between hole e1 and hole e2. One side of the LED is slightly flattened. That’s the side that should be connected to hole e1.
  • Connect a 220Ω resistor (colour code: red, red, brown, gold) between hole b1 and the blue rail on the left-hand side of the breadboard (0V). This resistor limits the amount of current that flows through the green LED so that it doesn’t burn out.
  • Connect a short brown wire from hole c2 to hole c4. This wire will supply current from pin 2 (which is also called P1.0) of the MSP430 to the green LED.
  • Connect the red LED between holes f1 and f2. The side of the LED that is slightly flattened should be connected to hole f1.
  • Connect a 220Ω resistor (colour code: red, red, brown, gold) between hole j1 and the blue rail on the right-hand side of the breadboard (0V). This resistor limits the amount of current that flows through the red LED so that it doesn’t burn out.
  • Connect a medium brown wire from hole h2 to hole h8. This wire will supply current from pin 15 (which is also called P1.7) of the MSP430 to the red LED.

05_LEDs

Step 2.6: Connect the LaunchPad to the microcontroller

The LaunchPad is the red circuit board shown below. It is used to transfer the programs you write from the PC to the MSP430 microcontroller. Connect it to the breadboard using the extra long black, yellow and green wires as shown below.

  • Connect an extra long black wire between hole h3 and the GND pin of the Launchpad.
  • Connect an extra long yellow wire between hole h6 and the TEST pin of the Launchpad.
  • Connect an extra long green wire between hole h7 and the RST pin of the Launchpad.

06_Launchpad

Step 2.7: Program the microcontroller to blink the LEDs

It’s time to compile your first program for the microcontroller.

  • Create a folder called "C:\RoboSlam\blink\".
  • Copy and paste the C code below into Notepad++ and save it as the filename "main.c" in the "blink" folder.
  • Copy and paste the file "build_for_g2553.bat" from the "RoboSlam" folder into the "blink" folder.
  • Ask one of the workshop facilitators to check your circuit before inserting the batteries!
  • Insert the batteries into your battery holder so that the microcontroller is receiving power.
  • Double click the file “build_for_g2553.bat” to compile the blinking LED example and copy it onto the microcontroller, where it should start running immediately, causing the LEDs to blink on and off!
Don’t Panic! If the program doesn’t work straight away, don’t worry. It’s probably something quite simple. Just ask one of the workshop facilitators to help you find the problem.
//
// RoboSlam Example: Blinking LEDs
// Code is for MSP430G2553
// Last updated 10-2-2015
//

#include <msp430.h>

// main function
int main( void )
{
    // disable watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    // configure digital inputs and outputs
    P1DIR = 0b10000001;   // Port 1 outputs: P1.0 green LED, P1.7 red LED
    P2DIR = 0b00000000;   // Port 2 outputs: none

    // test LEDs and motors
    while(1)
    {
        P1OUT = 0b10000000; // red LED on for 500ms
        __delay_cycles(500000);
        P1OUT = 0b00000001; // green LED on for 500ms
        __delay_cycles(500000);
    }
}
Challenge: Modify the program so that the LEDs flash in the following sequence over and over again:

  1. Red on, green off
  2. Red on, green on
  3. Red off, green on
  4. Red off, green off

Stage 3: Motor control

Step 3.1: Install the SN754410NE motor driver chip

  • Remove at least one battery from the battery holder to power down the robot.
  • Add the SN754410NE driver chip to the breadboard as shown below. The end of the chip with the semi-circuitar indentation must be in row 19.

07_SN754410NE_IC

Step 3.2: Connect the voltage supply to the motor driver chip

Add the supply voltage connections shown below:

  • A short red wire between the left-hand red rail (6V) and hole a26.
  • A short black wire between the left-hand blue rail (0V) and hole a23.
  • A medium red wire between holes d26 and g19.

08_SN754410NE_power

Step 3.3: Connect the digital outputs of the microcontroller to the inputs of the SN754410NE driver chip

Add the connections shown below. These allow the microcontroller to send signals to the driver chip to control the motors:

  • A long purple wire between hole d10 and hole d25.
  • A medium purple wire between hole d11 and hole d20.
  • A long purple wire between hole d12 and hole g25.
  • A medium purple wire between hole g12 and g20.

09_motor_signals

Step 3.4: Connect the motors to the driver chip

  • Connect the wires of the right motor to holes b21 and b24
  • Connect the wires of the left motor to holes h21 and h24

There’s no need to worry about which way around you connect the wires for each motor. If the motor turns the wrong way, you can simply swap the wires around later on.

10_motors

Step 3.5: Program the microcontroller to control the motors

Firstly, reconnect the Launchpad to the circuit, as shown below:

11_motors_and_launchpad

  • Create another new folder called "C:\RoboSlam\zigzag\".
  • Copy and paste the code below into a new file in Notepad++ and save it as filename "main.c" in the "zigzag" folder.
  • Copy and paste the file "build_for_g2553.bat" from the "RoboSlam" folder into the "zigzag" folder.
  • Ask one of the workshop facilitators to check your circuit before inserting the batteries!
  • Insert the batteries into your battery holder so that the microcontroller is receiving power.
  • Double click the file “build_for_g2553.bat” to compile the zigzag example program and copy it onto the microcontroller, where it should immediately start running, causing the motors to move.
  • Disconnect the robot from the LaunchPad and it should drive along the floor in a zigzag pattern.
//
// RoboSlam Example: Driving ZigZag
// Code is for MSP430G2553
// Last updated 10-2-2015
//

#include <msp430.h>

// function prototypes
void leds(int green, int red);
void motors(int left, int right);

// main function
int main( void )
{
    // stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    // configure digital inputs and outputs
    P1DIR = 0b10000001;   // Port 1 outputs: P1.0 green LED, P1.7 red LED
    P2DIR = 0b00001111;   // Port 2 outputs: P2.0-1 left motor, P2.2-3 right motor

    // Drive in a zigzag pattern indefinitely
    while(1)
    {
        motors(1,1);             // both motors forward
        leds(1,0);               // green LED on, red LED off
        __delay_cycles(2000000); // 2 second delay

        motors(-1,1);             // left motor reverse, right motor forward
        leds(0,1);               // green LED off, red LED on
        __delay_cycles(1000000); // 2 second delay

        motors(1,1);             // both motors forward
        leds(1,0);               // green LED on, red LED off
        __delay_cycles(2000000); // 2 second delay

        motors(1,-1);             // left motor forward, right motor reverse
        leds(0,1);               // green LED off, red LED on
        __delay_cycles(1000000); // 2 second delay
    }

    return 0;
}

//
// This function sets the direction of both motors.
// The first argument controls the left motor.
// The second argument controls the right motor.
// For each motor: positive number for forward,
// negative number for reverse, zero for stop.
//
void motors(int left, int right)
{
    // work out P2OUT value, then write to register
    int p2out_value = 0;
    if (left > 0)  p2out_value += 0b00001000;
    if (left < 0)  p2out_value += 0b00000100;
    if (right > 0) p2out_value += 0b00000010;
    if (right < 0) p2out_value += 0b00000001;
    P2OUT = p2out_value;
}

//
// This function controls the green and red LEDs.
// For each LED: 1 is for on, 0 is for off.
//
void leds(int green, int red)
{
    // work out P1OUT value, then write to register
    int p1out_value = 0;
    if (green == 1) p1out_value += 0b00000001;
    if (red == 1)   p1out_value += 0b10000000;
    P1OUT = p1out_value;
}
Challenge: Modify and recompile the above code to make the robot drive in a square pattern. Place a block in the centre of the RoboSumo arena and see how many times you can make your robot drive around a block without either touching the block or falling off the RoboSumo arena.

Stage 4: Rangefinder

Step 4.1: Add the rangefinder and connect it to the microcontroller

The rangefinder is an ultrasonic distance sensor.

  • Add the rangefinder to the breadboard in the position shown (holes j14, j15, j16 and j17).
  • Connect a medium black wire from the left-hand blue rail (0V) to hole f14.
  • Connect a medium red wire from the left-hand red rail (6V) to hole f17.
  • Connect a 10kΩ resistor (colour code: brown, black, orange, gold) between hole b15 and the blue rail on the left-hand side of the breadboard (0V).
  • Connect a 10kΩ resistor (colour code: brown, black, orange, gold) between hole e15 and hole f15.
  • Connect a medium brown wire between hole h9 and hole h16. This wire is used to transmit a trigger pulse from the MSP430 to the ultrasonic sensor each time the distance needs to be measured.
  • Connect a medium grey wire between hole c9 and hole c15. This wire is used to transmit the “echo” pulse from the ultrasonic sensor to the MSP430 each time the distance has been measured. The duration of the echo pulse is proportional to the distance measured.

12_rangefinder

Step 4.2: Program the microcontroller to navigate using the rangefinder

  • Create a folder called "C:\RoboSlam\sumo\".
  • Copy and paste the C code below into Notepad++ and save it as the filename "main.c" in the "sumo" folder.
  • Copy and paste the file "build_for_g2553.bat" from the "RoboSlam" folder into the "sumo" folder.
  • If in doubt, ask one of the workshop facilitators to check your circuit before inserting the batteries.
  • Insert the batteries into your battery holder so that the microcontroller is receiving power.
  • Double click the file “build_for_g2553.bat” to compile the blinking LED example and copy it onto the microcontroller, where it should start running immediately, causing the robot to spin around looking for an opponent and charge forwards once it detects an object straight ahead!
//
// RoboSlam Example: Rangefinder navigation
// Code is for MSP430G2452 or MSP430G2553
// Last updated 10-2-2015
//

#include <msp430.h>

// function prototypes
void leds(int green, int red);
void motors(int left, int right);
int distance();

// main function
int main( void )
{
    // stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    // configure digital inputs and outputs
    P1DIR = 0b11000001;   // Outputs: P1.0 green LED, P1.6 trig, P1.7 red LED
    P2DIR = 0b00001111;   // Outputs: P2.0 & P2.1 left motor, P2.2 & O2.3 right motor

    // declare variables
    int d;     // used to store distance measurements
    int n = 0; // used to count distance measurements

    // implement robot behaviour
    while(1)
    {
        // Measure distance
        d = distance();

        // is distance less than 500mm?
        if (d < 500)
        {
            // enemy detected straight ahead
            leds(1,0);    // green LED on, red LED off
            motors(1,1);  // both motors forward
            n = 0;        // reset counter
        }
        else if (n < 10)
        {
            // enemy not detected, but was within last 10 readings
            leds(1,1);    // green LED on, red LED on
            n = n + 1;    // count non-detections
        }
        else
        {
            // enemy not detected at least 10 times in a row
            leds(0,1);    // green LED off, red LED on
            motors(1,-1); // spin clockwise (left forward, right reverse)
        }

        __delay_cycles(50000); // 50ms delay
    }

    return 0;
}

//
// This function sets the direction of both motors.
// The first argument controls the left motor.
// The second argument controls the right motor.
// For each motor: positive number for forward,
// negative number for reverse, zero for stop.
//
void motors(int left, int right)
{
    // work out P2OUT value, then write to register
    int p2out_value = 0;
    if (left > 0)  p2out_value += 0b00001000;
    if (left < 0)  p2out_value += 0b00000100;
    if (right > 0) p2out_value += 0b00000010;
    if (right < 0) p2out_value += 0b00000001;
    P2OUT = p2out_value;
}

//
// This function controls the green and red LEDs.
// For each LED: 1 is for on, 0 is for off.
//
void leds(int green, int red)
{
    // work out P1OUT value, then write to register
    int p1out_value = 0;
    if (green == 1) p1out_value += 0b00000001;
    if (red == 1)   p1out_value += 0b10000000;
    P1OUT = p1out_value;
}

//
// This function measures the distance in mm to the nearest object
// using the rangefinder.
//
int distance()
{
    // send trigger pulse
    P1OUT |= BIT6;
    __delay_cycles(20);
    P1OUT &= ~BIT6;

    // measure echo pulse duration
    // configure Timer_A0 for measuring rangefinder echo pulse
    // select SMCLK clock, input divider=1, "continuous" mode
    TA0CTL = TASSEL_2 + ID_0 + MC_2;
    TA0CTL |= TACLR;                            // reset timer
    while ((P1IN & BIT5) == 0 && TA0R < 12000); // wait for start of echo pulse
    TA0CTL |= TACLR;                            // reset timer
    while ((P1IN & BIT5) > 0 && TA0R < 12000);  // wait for end of echo pulse
    return (TA0R / 6);                          // return the distance in mm
}
Challenge: Can your robot find an object and push it out of the RoboSumo arena? If so, you’re ready to rumble!
Advertisements

8 Responses to Instructions as of May 2015

  1. Pingback: Motor Control | donalomuiri086

  2. Pingback: Prep for “RACE TO THE WALL” | donalomuiri086

  3. Rando says:

    Wonderful explanation, very clear. What software do you use to make you cool diagrams?

    Like

    • batchloaf says:

      Thanks Rando, that’s very kind of you. I do all the diagrams in Inkscape (the same program we use to make the laser cutting patterns for our robots). It’s basically a vector drawing program, similar to Adobe Illustrator or Corel Draw or other programs like that. What I love about Inkscape (and I really do love it) is that it’s free, cross-platform and bridges the gap between CAD software like AutoCAD and more graphic design oriented software. You can download Inkscape from here:

      https://inkscape.org/en/

      Also, if you’re interested to see how the illustrations above are done, here’s the editable Inkscape SVG file:

      Editable SVG file of RoboSlam instructions illustrations (March 2015)

      If you open that file, you’ll see that there’s a separate layer for each step of the process which makes it relatively straightforward to maintain as we make changes to the design.

      Ted

      Like

  4. naomi chadderton says:

    Hi. Loved your Roboslam cafe at the maker fair on sat. Could you drop me an email as i need some help with reinserting a wire and the diagram above is different. Thanks Naomi

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s