Software

LegoEv3RobotWithGyroscope
PLEASE BE AWARE THAT ALL THE CODE IN THIS WEB SITE IS EXPERIMENTAL, USE IT AT YOUR OWN RISK!

This section is dedicated to explaining the Robot Navigation software. This code was created to be robot independent, and has been tested with several robot platforms. The way I achieved this is by using Object Oriented Programing. The current software contains code that can be used immediately with a skid/steer robot built using the Lego Mindstorms EV3 kit. However, I am planning to add support for the Lego NXT in the future. This program has been the basis for testing simple and complex robotic applications.

Where to start?
The easier way to understand the program is by looking at the main program. The first lines in the main code are used to define the working variables.

Ev3 robot(PERIOD, TRACK, ENCODER_SCALE_FACTOR, motor_aux_info);
Odometry odometry(&robot); 
Keyboard user_input;
Control control(&odometry);

First, the program creates a Robot class that will be in charge of handling (and hiding) all the low level details needed for interfacing with the hardware. The second variable defines an Odometry object, which computes position using the displacement and rotation information provided by the robot. The third class, Keyboard, is in charge of handling the user keyboard input commands. And the last class Control provides high level control instructions to the robot. Currently, it implements self-homing control.
Notice also the arguments used when the classes are constructed. For example, the Robot class needs to be aware of the port location of the sensors and motors. While the Odometry class will need to use Robot information, the Control class does not need to deal with sensor data at this level, and can use processed information as the one provided by the Odometry.

while(!quit_program)
{
	//1: READ SENSORS
	robot.readSensors();

	//2: COMPUTE POSITION
	odometry.updatePosition();

	//3: DEFINE CONTROL INSTRUCTIONS
	//User interaction
	switch(user_input.getKey())
	{
		case MOVE_FORWARD:
			speed += INC_SPEED_MM_SECOND;
			break;
		case MOVE_BACKWARDS:
			speed -= INC_SPEED_MM_SECOND;
			break;
		...
		case EXIT:
			quit_program = true;
	}
	//High level control
	control.getTargetSpeedRate(speed, rate);

	//4: EXECUTE INSTRUCTIONS
	robot.setActuators(speed, rate);
}

Notice how the different classes are being used for some specific purpose. There are four well defined parts that are common in robotics applications, and generally are executed in the same order:
1: Read sensors
2: Estimate the robot positioning
3: Define Control instruction
4: Execute instructions
The loop is repeated until the exit condition is met (user kit ‘x’).

A demonstration of the complete system in action using gyro enhanced odometry and the self-homing high level control can be seen at:

What to do next?
This section is far from complete and is been updated constantly. In the mean time, users can read information of how to download and compile the code.