Khepera Overview

Introduction

khepera-pic.jpg

This page provides a brief description of how to use the Khepera II robots. This will be the main robot platform for use in the class. Kheperas are small desktop-sized differential-drive robots with simple odometry and an array of IR proximity sensors. Each robot is about 7 cm in diameter, and can be programmed in C. They have two user-activateable LEDs on the top and a rechargeable (but not easily replaceable) battery. We have 5 of these robots in the lab for use during the class. This guide is primarily focused on describing the capabilities of the robot, and showing you how to go through the process of writing code, compiling it for the robot's processor, transferring the code to the robot, and running it.

Robot Specifications

processor Motorola 68331, 25 MHz
RAM 512 k
flash 512 k
motors 2 DC brushed servo motors with encoders
speed max: 0.5 m/s, min: 0.02 m/s
sensors 8 IR proximity sensors, max range 10 cm
battery rechargeable NiMH, max life about 30 min
communication serial, up to 115 k
diameter 70 mm
height 30 mm
mass 80 g
payload capacity about 150 g

The Basics

  • The power switch is a small red switch on the front side of the robot near the bottom.
  • The reset button is a black pushbutton on the back side of the robot near the bottom.
  • The serial communications connector is a red 6-pin micromatch connector on the top face of the robot.
  • The power connection is a red 4-pin micromatch connector just above the power switch.
  • The mode selector is a green 16-position rotary switch on the top of the robot. The best way to turn it is with the small green screw drivers in the lab.
  • Documentation, chargers, green screw drivers, cables, and other Khepera—related items are in a set of plastic drawers near the Khepera table in the lab.

Warnings and Requests

  • The power switches are fragile, particularly their connection to the underlying PCB. On some of the robots, the connection is already intermittent. Please be careful with the switches. If a robot appears to power off randomly, or does not turn on, try gently pressing the switch up toward the body of the robot.
  • Please do not recharge a robot unless the battery is actually dead. In other words, do not take a freshly charged robot, use it for a few minutes, then plug it in again so it's full next time. This decreases the lifetime of the batteries, and they are difficult to replace. Instead, please use the boxes in the lab marked “charged” and “dead”. When you need to use a robot, select one from the “charged” box. If you are done with it before the battery is dead, put it back into the “charged” box. When you have exhausted a robot's battery, plug it in to recharge, or if there are no chargers available, place it in the “dead” box.
  • The serial connector and power connector (the red micromatch connectors) are designed so that the cables can only be connected in one orientation. They are weak, though, so please be gentle and don't force them to connect the wrong way.

Programming Example

This section will take you through a simple example. We will write code, compile it, transfer it, and run it. The example code will get data from the IR rangers, make the robot move, and turn LEDs on and off.

Programming Environment

The programming environment for these processors is called KTProject, and is installed on the lab computer. It is freely available from the K-Team website, so feel free to run it on your own machines. You will not be able to test your code without the robots, of course.

The Code

A piece of example code is shown here. This code causes the robot to simply spin in place. Most of it should be self-explanatory. The mot_config_speed sets the parameters of the motor controller. You will probably not need to change them.

#include <sys/kos.h>
void main ()
{
    var_reset();
    tim_reset();
    var_on_led(0);
    var_on_led(1);
 
    tim_suspend_task(1000);
    var_off_led(0);
    var_off_led(1);
    mot_reset();
    mot_config_speed_1m(0, 3500, 800, 100);
    mot_config_speed_1m(1, 3500, 800, 100);
    mot_new_speed_1m(0, -10);
    mot_new_speed_1m(1, 10);
}

Loading Code onto the Robots

The steps are:

  1. Once your code is written, compile it by selecting Tools -> Build -> Start. This produces an .S37 file in the same directory as your code.
  2. Start HyperTerminal. It may ask you to name the new connection; the name is irrelevant and you will never see it again (unless you wish to actually save this connection, which I never do), so just enter something.
  3. Connect using: COM1 (this could be different on other computers)
  4. Serial settings: 9600 bps, 1 start bit, 8 data bits, 2 stop bits, no parity
  5. On Hyperterminal, you will need to select “flow control: hardware”. After this step, you should have an open serial terminal. It's not yet connected to anything.
  6. Set mode 1 on the Khepera.
  7. Connect the robot to the computer.
  8. Turn the robot on. You should see the Khepera welcome message on the terminal.
  9. Type “sfill” (your typing will not be echoed back to the terminal). This will start the loader on the robot. It should respond with “S format Motorola loader mode”.
  10. Select Transfer -> Send Text File. Navigate to the folder containing your .S37 file and choose Open (you may need to select “Files of type: *.*”). When the transfer is complete, which may take a few minutes, the robot will respond with “S: download terminated”.
  11. Erase the non-volatile memory by typing “flash E”. The robot should respond with “FLASH user segments erased”.
  12. Write the code into the flash by typing “flash W”. The robot should respond with “FLASH user segments written”.

Running the Code

Run your code by typing “run user-flash”. If you want the robot to run your code without you having to type this, instead starting your code immediately on startup, set the mode selector to 4. You will need to set it back to reprogram.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License