Wednesday, April 16, 2014

Botting the way - 3Pi Intro (2)

Hey there!

Here's the followup to the 3pi blog.

Now, this assumes some familiarity with the development kit for 3pi.

Now, our 5 light sensors' values can be read (Using Arduino's C++ development kit) with the following function:

  unsigned int sensor_values[5];
  read_line_sensors(sensor_values,IR_EMITTERS_ON);

meaning sensor_values[0] holds the leftmost sensor's value. This is displayed as a number between -2000 (maximum reflection, or "all white") and 2000 (no reflection, or "all black"). With this, a super simple way of guiding our bot on the track is to place it anwhere on the track, and simply find out where it should turn. If it's a closed track and the line is not overly thick, what we do (in pseudocode) is:

position=0; //centered
for i in sensor_values
  position+=sensor_values[i];

What are we saying here? We're basically looking for position to be a rough reflection of wheter we are to the left (negative values) or to the right (positive values). In this supersimple version, we will just assume there are no conflicts (which there certainly WILL be!) on the track, and sensors provide fairilly accurate information. The idea now is simple (pseudocode):

if position < 0
 robot turns right
else if position = 0
 robot moves forward
else if position > 0
 robot turns left

How's this done on our little 3pi friend? It's simple. All we can set is the motor's speed. We have 2 motors: left and right. The robot doesn't know what "forward" means, but that's easy - both motors set to the same speed mean the robot moves forward*Or do they?!. Turn left simply means we set the RIGHT motor speed to something faster than the left's, and vice-versa.

To set so, the code is as follows (C++):

  int velocity_left=0;
  int velocity_right=30;
  OrangutanMotors::setSpeeds(velocity_left,velocity_right);

In this example we make our robot circle around itself with the left motor as the center.

Note that a 3pi's speed is expressed in a number between -255 and 255. Any higher/lower and they are set as if 255/-255 was given as input. This is not meters per second or any international system measure unit, so we can't correspond it to meters or inches. More on this later on.

* Nothing in real experiments is as sweet as it sounds during our planning, is it? Robots are physically more complex than we're assuming here for a variety of reasons. The basic one is that no two objects can be absolutelly equal in a real environment. Sure, we set both motor's speed to 20 in our code, but what if one of them has suffered harsher degradation for some reason? 20 on both speeds will NOT in fact make our bot go forwards, but form a weird angle. Fortunatelly, we can correct this through a method called callibration. This will be explained later on.

Saturday, April 5, 2014

Botting the way - 3Pi Intro (1)

Hey there! In a perhaps more definitive revival of our blog, I'm presenting my current project - or, more accuratelly, parts of it.

A simple 3pi, with no addons.

Having been working with a little robot "3pi", by pololu, I've decided to use one for a game. The idea is to create a somewhat sentient bot that can respond to a player's input. However, let us not get ahead of ourselves! First, the basics: programming a simple 3pi to perform a series of very simple tasks. First, we're looking at following a track consisting of black lines in a white space.

A 3pi with no extensions has 5 light sensors: They detect the amount of light being reflected. We're not yet able to sense anything like location (WHERE on a track am I? North, south?), accept our player's input (No wifi/bluetooth communication), or read images or sound (we lack cameras or sound input). We can, however, do the most important thing to start with: Moving!

With that in mind, our goal is to make a 3PI follow a black line in a white field. This is easier to avoid sensor errors, since those are poar opposites in terms of reflected light. The idea is simple: to guide our little friend through his journey!

We'll check how next time.