Tutorial: Tabletop Locomotion

Download this tutorial's presentation PDF

Robotics is a challenging, but fun, engineering subject that includes many sub-fields from mechanical design to electronics to algorithms. These beginner tutorials are to help you build your own basic tabletop robot.

The goal of this tutorial is to build your first robot, then program it to move around using different methods of locomotion. This is an introduction of the hardware and software tools available for club members.

= Prerequisites = Before jumping into the hardware and software, it is recommended that you become more familiar with several tools you will be using. We have already written articles on each of the following topics, and we recommend you browse through them before moving on.


 * Microcontrollers, A piece of hardware that acts as the "brain", or computer, of your robot
 * Arduino, The specific Microcontroller we will be using for your robot
 * C/C++, The programming language used for programming the Arduino. There are small differences this reference points out
 * Servos, A motor-like piece of hardware that can rotate a wheel at a specific rate
 * Robot Locomotion, A general article on different methods of robotic locomotion such as motors and controllers
 * PSRC-I, The club's generic robot chassis

= Getting Started =


 * Form your own team (4 to 8 people), make sure you have a specialist in electronics and software.
 * Find an Executive Team member or senior club member for your group's adviser.
 * Write your names and emails on a paper, and trade it for a kit.

= Hardware =

The kit you have received must contain the following components:
 * Two servos
 * One Arduino
 * One Arduino Proto-Shield
 * USB Cable
 * Small breadboard
 * Generic gray chassis
 * Battery (7.2V Red Brick)
 * Battery to Arduino converter
 * Metal-ball caster
 * Wires

= Software =

Since we are using the Arduino, we need it's software development tools:
 * Download the Arduino IDE (Integrated Development Environment) here.
 * Un-zip the contents to your desktop.
 * Note: If you are installing this on your own computer, you may have to install an associated FTDI USB driver. Read here for more details.

Source(s): Software solutions

= Building & Electronics =


 * 1) Replace the front wooden caster with new metal-ball casters.
 * 2) Connect the black wires from each servo to the ground terminals on the Arduino.
 * 3) Connect the red wires from each servo to the 5v terminal from the Arduino.
 * 4) Connect the white wires from each servo to digital pins 9 and 10 on the Arduino.  This will provide the power to get your servos spinning.

Note that the Arduino's built-in power supply is only able to provide about 1 amp of current on the 5 volt power source. Servos, when under stress, can draw anywhere from .25 amps to 1 whole amp each! We're using the Arduino's power supply for now, but when your robot has more weight and more sensors to power, it would be a good idea to use a separate voltage regulator for the servos. We'll find out how to do that later on.

Proto Shield
Some groups may choose to use an Arduino Proto Shield to help with the electronics. This small board is a very simple prototyping shield that can be placed above the Arduino. This helps with organizing electronics, especially with arrays of sensors or servos.

If your group chooses to use this shield, make sure to correctly wire the servos such that the power and group lines are not mixed.

Arduino Pins
Certain pins on the Arduino have special functionality, but are not strictly reserved. There are 14 digital pins and 6 analog, with the digital pins having certain special properties. Pins 0 and 1 are for serial communication. Pins 3, 5, 6, 9, 10, 11 having the special pulse-width modulation ability. Pins 2 and 3 are special as they are external system interrupts (when pulled HIGH, they call a function).

= Programming =

Learn more with the Arduino Programming; this is covered in lesson 3.

To control robot movement, we must first program the microcontroller to follow our set of instructions. Since our goal is to move the robot in a large rectangle, we will tell the robot to repeat a pattern of movement and turning. To move forward we simply turn on both servos at set speeds. To rotate we turn one off and keep the other running, making the robot rotate on the wheel that is not moving.



This method of control works well for simple movements but does not give you enough control for competitive events. Our method of turning on a set time without a sensor to measure distances traveled or direction is called "dead reckoning". Due to natural variations (Power, friction, timing) it is almost impossible to move precisely. We solve this problem in other tutorials through sensors such as Wheel Encoders, but for now dead reckoning is acceptable.

To start programming the Arduino, you must launch your IDE (Integrated Development Environment) and plug in your USB cable from your computer to the Arduino. An IDE is a special text editor application designed for the language you are writing in. It usually also supplies other features such as a compiler and communication system. "Compiling" is the process of taking your high-level C/C++ instructions to something the processor on the Arduino can understand (machine code). Once this is done we transfer the program over the USB and write to the Arduino's memory. Even after resetting power or removing power, the Arduino will always run your program, until the next time you re-write the memory with a new program. You can download and run the IDE from the official Arduino website.



The Arduino IDE comes with a special tools bar on the top that has several icons. They are described in the image to the right. Also, to start communication with your Arduino, make sure you select the proper serial connection. Simply click on Tools -> Serial Port -> And choose the proper device name. In our case it is most likely the Arduino "Duemilanove".

Pseudocode
Before programming, it's sometimes better to plan out your code via psuedocode. This is an abstract programming language that isn't in any way formal, but is a good way to write out, in a human language, how things should work. The following is a general design of how our robot will be programmed.


 * 1) Initialize Serial Communication (For debugging)
 * 2) Initialize Servo objects / controller (Connect to two servos)
 * 3) Loop Start
 * 4) Set both servo at same speeds (Go straight)
 * 5) Wait three seconds
 * 6) Set the inner / left wheel to stop (Start turning)
 * 7) Wait a second
 * 8) Goto "Loop Start"

Code
The following is the above pseudocode implemented in the Arduino programming language, which is very similar to C/C++. We will be using the standard Servo library. Please read the page's instructions on for more detail.

It is important to observe that for continuous servos the "centers", or input value in which the wheels no longer spin, vary per device. You will have to find this value, and change the "lCenter" and "rCenter" variables to reflect this poisition. Look at the Servos article for more information on finding the center, or stalling, position.

Debugging
Sometimes your code won't do exactly what you want it to do. A solution to try and break-down what is going on internally is to "debug" the code. The Arduino IDE has a serial monitoring tool for this, in which your Arduino program can write messages back to the computer it is attached up to. Before sending messages, you must initialize the serial communication library with "Serial.begin(9600);". To send a string, use the "Serial.println(Some string here...);" command. Make sure that the correct COM device is selected to receive messages. To learn about other messages you can send back (integers, characters, etc) see the Arduino Serial.print(...) Reference.

Below is sample code for demonstrating sending back data to your computer.

= Building Schedule =

If you or your team are building for a specific robotics competition during a semester format, make sure you follow our Tabletop Design Schedule. Contact any club executive to learn more about differences in the schedule for your respective semester.