Bluetooth Library
Robotics Simulation


A RaspiBrick simulation package is available for Python and for Java. It not only let you simulate the robot's movement, but supports most of the sensors like the 4 light sensors, the 5 infrared sensors, the ultrasonic sensor. The environment is modelled with RobotContext static methods that use distributed or user defined sprite images. RobotContext is implemented with empty methods in the real robot libraries, so there is no need to remove or out-comment them to run the real robot. By simply change the import statement you switch from simulation to real mode. The examples on the previous pages are fully functional simulation programs.

The Python simulation package is integrated in the TigerJython distribution. Because it uses the Java JGameGrid game library, the Python simulation only works with Jython/TigerJython.

The Java simulation package is part of the JGameGrid framework. Download JGameGrid and you find more information how to install the simulation for Lego EV3 and RaspiBrick.

The simulation is widely used in classrooms as demonstration and test tool before running an algorithm on the real robot. It is also of great help when not every student has its own robot. But most important, robot simulation shows how the real world is modelled into software and why simulation is crucial for almost all scientific and technological progress.

As an example you try to find an algorithm so that a robot with 4 light sensors pointing upwards (two on the front and two on the rear side) follows a point light source (tourch) moving above the robot ground. The problem is not trivial due to the fact that the light source can be moved quickly from front to back. A simple approach uses the differences of light intensities between the sensors. It is up to you to find a more elegant or more efficient algorithm.

from raspisim import *

RobotContext.useTorch(1, 150, 250, 100)
robot = Robot()
gear = Gear()
ls = [0] * 4
for i in range(4):
   ls[i] = LightSensor(i)
s = 0.02
v = [0] * 4
while not isEscapeHit():
    for i in range(4):
        v[i] = ls[i].getValue()
    d = (v[0] - v[1]) / (v[0] + v[1])
    if v[2] + v[3] > v[0] + v[1]: 
        if v[2] > v[3]:
        if d > -s and d < s:
            if d >= s:
Python Code Simulation

Execute the simulation program locally using WebStart

More than one light source is supported. The physical model for the light source detection is simple: The resulting light intensity at a certain light sensor is the sum of the 1/r^2 decreased intensities of all torches.