Khepera III Toolbox/Advantages of the Khepera III Toolbox

From Wikibooks, open books for an open world
< Khepera III Toolbox
Jump to: navigation, search

The Khepera III robot comes with a library called libkorebot to access the sensors and actuators of the Khepera III robot. In addition, a program called khepera3_test can be used to read sensor values on the command line. The Khepera III Toolbox is more or less a clean rewrite of these two pieces of software. Note, however, that the libkorebot library is compatible with several robots produced by K-Team, whereas the Khepera III Toolbox - as its name suggests - is made for the Khepera III robot only.

In this chapter, we motivate why the Khepera III Toolbox should be used instead of the libkorebot library.

A Nicer, Simpler and Safer API[edit]

The Khepera III Toolbox provides an easy-to-use API to access the sensors and actuators of the robot. Values read from sensors are parsed and put inside a data structure for easy access. To read the floor sensor, for example, the following code can be used:

int floor_sum;
khepera3_infrared_proximity();
floor_sum = khepera3.infrared_proximity.sensor[cKhepera3SensorsInfrared_FloorLeft] + khepera3.infrared_proximity.sensor[cKhepera3SensorsInfrared_FloorRight];

Note that re-entrant versions for programs with multiple threads exist as well, and are just slightly more complicated to use.

The libkorebot library only reads messages and provides the programmer with a buffer, which he has to parse by himself. This is very error-prone and makes the resulting code hard to read. The following piece of code is equivalent to the code above:

char buffer[MAXBUFFERSIZE];
int floor_left, floor_right, floor_sum;
kh3_proximity_ir(buffer, dsPic);
floor_left = buffer[15] | buffer[16] << 8;
floor_right = buffer[17] | buffer[18] << 8;
floor_sum = floor_left + floor_right;

Synchronization Issues when Running Multiple Programs at the Same Time[edit]

The libkorebot was written with the idea in mind that only a single program would run on the robot at the same time. The code used to access the sensor values is therefore not safe when two or more programs are running at the same time. E.g., if a program is reading infrared proximity values, and another program ambient infrared values, the programs may occasionally get the wrong type of measurements for their request.

There is not technical reason why running multiple programs at the same time should cause problems, especially when they are working with a different subset of sensors and actuators.

The Khepera III Toolbox communicates with the sensors and actuators in an atomic fashion, and therefore enables running programs side by side.

Additional Modules[edit]

Besides the khepera3 module, the Khepera III Toolbox offers a series of other useful modules to write programs for the robot. Among them are a module to parse command line arguments, a module to send messages over the I2C bus, and a module to track the robot position using wheel odometry.

Programs[edit]

While the khepera3_test program provided by K-Team is one monolithic program intended for testing, the Khepera III Toolbox provides a series of small programs that can be used for testing and serious experiments.

Speed[edit]

Both the libkorebot and the Khepera III Toolbox have comparable speed. The time required to read sensor values or send motor commands mostly depends on the speed of the I2C bus and the length of the messages. The processing overhead is negligibly small.

Scripts[edit]

There is no equivalent to the Khepera III Toolbox scripts in the code provided by K-Team.