Sunday, 24 November 2013

Ultrasonic Rangefinder Capability

Whilst setting up the "Sumo" ring, we had a few moments to think about where this all might go and what we might need from it in the future. Getting a sumo robot to detect an edge and to then turn away from it is an important step. Making the sumobot have ultrasonic functionality is the next step!
This is an ultrasonic rangefinder manufactureed by seeed electronics. In simple terms it sends out a sound wave and then measures the time it takes for the wave to return to the unit. Assuming that most returned sound waves "Bounce" off an object, with cunning programming you can make a robot sense distance.

This image shows the scale of the rangefinder. Note that the image shows two micro-controllers, in fact we will of course only use one. The fritzing diagram for connection to the Uno R3 and the SEN136B5B sensor is shown below...


Thursday, 14 November 2013

Flowcharting a Sumo Bot

Planning your code before you write it out is an essential part of writing efficient programs. Using a flow chart not only helps you think through what you want to achieve, but also allows you to share your thoughts with other people in a visual format. (It's not only computer programs that benefit from this - working out all sorts of processes can be easier using flow charts.)
We have a very effective method of producing and sharing flow charts available at CSC through Google Apps. It's called Lucidcharts and you can create a new chart easily using the Google drive interface...
 The software is very easy to use and is intuitive. This took me ten minutes to make. Part of the process involved dragging the boxes around on the page until I had them in an order that made sense to read through and follow. Here is a screenshot of how it looked before I exported it as a png...


Here is the finished flow chart. This is saved as an image file. If I wish to modify it in any way, I could always go back to the diagram on Lucidchart and make any changes that I want to. Saving files with sensible names and making allowance for future version changes also makes sense.

Wednesday, 13 November 2013

Border Detect Code

This is the basic code used to get the reflectance array to detect a border...
_____________________________________
#include <ZumoBuzzer.h>
#include <ZumoMotors.h>
#include <Pushbutton.h>
#include <QTRSensors.h>
#include <ZumoReflectanceSensorArray.h>

#define LED 13

// this might need to be tuned for different lighting conditions, surfaces, etc.
#define QTR_THRESHOLD  1500 // microseconds
 
// these might need to be tuned for different motor types
#define REVERSE_SPEED     200 // 0 is stopped, 400 is full speed
#define TURN_SPEED        200
#define FORWARD_SPEED     200
#define REVERSE_DURATION  200 // ms
#define TURN_DURATION     400 // ms

ZumoBuzzer buzzer;
ZumoMotors motors;
Pushbutton button(ZUMO_BUTTON); // pushbutton on pin 12

#define NUM_SENSORS 6
unsigned int sensor_values[NUM_SENSORS];

ZumoReflectanceSensorArray sensors(QTR_NO_EMITTER_PIN);

void waitForButtonAndCountDown()
{
  digitalWrite(LED, HIGH);
  button.waitForButton();
  digitalWrite(LED, LOW);
 
  // play audible countdown
  for (int i = 0; i < 3; i++)
  {
    delay(1000);
    buzzer.playNote(NOTE_G(3), 200, 15);
  }
  delay(1000);
  buzzer.playNote(NOTE_G(4), 500, 15);
  delay(1000);
}

void setup()
{
  // uncomment if necessary to correct motor directions
  //motors.flipLeftMotor(true);
  //motors.flipRightMotor(true);
 
  pinMode(LED, HIGH);
 
  waitForButtonAndCountDown();
}

void loop()
{
  if (button.isPressed())
  {
    // if button is pressed, stop and wait for another press to go again
    motors.setSpeeds(0, 0);
    button.waitForRelease();
    waitForButtonAndCountDown();
  }
 

  sensors.read(sensor_values);
 
  if (sensor_values[0] < QTR_THRESHOLD)
  {
    // if leftmost sensor detects line, reverse and turn to the right
    motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
    delay(200);
    motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
    delay(300);
    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
  }
  else if (sensor_values[5] < QTR_THRESHOLD)
  {
    // if rightmost sensor detects line, reverse and turn to the left
    motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
    delay(200);
    motors.setSpeeds(-TURN_SPEED, TURN_SPEED);
    delay(300);
    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
  }
  else
  {
    // otherwise, go straight
    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
  }
}

Sumo - watch out for the edge......


 The first test of the prototype of the Zumo bot arena






Anyone for a fight?

We've talked about sumo for a while now. It's been one of our goals to get some sumo up and running.
The way we see it, we need to do it in three stages:

  1. Get a Zumo chassis up to an operational stage.
  2. Program a Zumo chassis to detect an edge, reverse from it, turn around and run across the sumo ring.
  3. Be a bit more clever and get a Zumo to detect another robot (maybe using an ultrasonic rangefinder) and push it out of the ring.
We have started to make a sumo ring... This will be finished in a couple of days!

Zumo Reflectance Array

Proud photos of the reflectance array. This took a little bit of sorting our to get it working correctly. But we got there in the end. The first time that we got it to work was just amazing! We all stood round it and watched it follow a line of black masking tape around a table in the graphics room.
Here a are a few photos to explain some of it to you...

 The reflectance array consists of six sensors, each consisting of an IR emitter coupled with a phototransistor that responds based on how much emitter light is reflected back to it. The two outside sensors are positioned at the very edges of the module to maximize their usefulness as edge detectors (e.g. for seeing the white edge of a sumo ring) while the four inner sensors are closer together for better detecting lines.
The Zumo Bot chassis with the Arduino R3 mounted on top of it upside down.

The two outside sensors emitting IR. The array is mounted on the leading edge of the bot chassis, just behind the blade. This photo shows the bot positioned upright, balancing on its back.

A closer photo of the array