In this lab session we will experiment with navigating a differential-driven Express Bot like car while using the tacho counters to keep track of its position and direction.
Duration of activity: 10 hours
Group members participating: Ole Rasmussen, Kasper Føns
Duration of activity: 10 hours
Group members participating: Ole Rasmussen, Kasper Føns
Goal
To complete the exercises for Lego Lab 9.
Plan
Since our goal is to complete the exercises for this weeks lab the plan will be to complete each exercise in sequence:
The source code for the program used to generally navigate the car can be seen in figure 3.
- Blightbot
Investigate the accuracy of a Lego car inspired by Brian Bagnall's Blightbot [1] navigating in a Cartesian coordinate system. - Avoiding objects while navigating
Experiment with navigating the Lego car with the leJOS classes while avoiding obstacles. - Improved navigation
Experiment with different navigation methods.
1. Blightbot
In this section we will measure how accurately our Lego car drives with the navigator class in leJOS. We will be performing two experiments: accuracy of general navigation and comparing accuracy of driving straight and rotating.
1.1 Setup
The setup for both experiments consists of the following parts: the Lego car, a whiteboard and a whiteboard marker. The car will be driving on the whiteboard with the whiteboard marker.
The car we have used for the experiment is a slightly modified version of the Express Bot (the modifications are just a result of it's usage for the Sumo competition and thus of no relevance to this experiment).
To measure the accuracy of the cars navigation we have attached a marker to the back of the car by using an elastic cord (figure 1 & 2). The car will be performing several navigational runs on a whiteboard.
![]() |
| Figure 2: The marker touching the whiteboard. |
![]() |
| Figure 3: Source code for a test program using the Navigator and DifferentialPilot classes. Notice that we have shortened the path by a factor of 2 to stay within the bounds of the whiteboard. Original code was borrowed from here. |
1.2 Influencing factors
We believe the following to be factors that could influence the experiment:
- Initial placement of the car
For subsequent runs the car must be placed on the exact same position facing the exact same direction. - Position of whiteboard marker
The position of the whiteboard marker may influence where on the whiteboard is drawn compared to the base of the car. It may also influence the thickness of the drawings.
1.3 Experiment 1: comparing accuracy of several navigation runs
Figure 4 and 5 shows the Lego car performing two navigational runs.
Figure 6 shows the result of the two runs.
| Figure 4 - First run with our code from Figure 3. |
| Figure 5 - Second run with our code from Figure 3. |
Figure 6 shows the result of the two runs.
As can bee seen on figure 6 the two runs aren't exactly matching but what's interesting is that they seem to be displacements of each other. It is important to mention that it was relatively easy to place the car on the same starting point each run but it was much harder to ensure the initial directions were the same as well. This was not unexpected though, as we mentioned it to be an influencing factor in section 1.2. From the figure it looks like the displacement could very well be due to initial differences in direction, as the runs differ already from the start on the first straight line. Had we placed the facing the exact same directions we may have had two almost exact matching runs apart from the ending point.
The ending points are interesting because they both seem to be offset from the starting position by a certain amount. The evidence for this is that the ending point closest to the starting point is the ending point for the run that goes a bit more upwards in the beginning; thus turning the direction upwards (or left depending on how you view it) displaces the ending point upwards (and out) as well. In other words it seems like the initial direction of the car determines an ending point on a circle that's surrounding the starting point. We have measured the radius of this circle to be 4.5cm based on the distance to either of the ending points for the two runs. Basically this means that had the initial directions of the car been the exact same the two ending points may have been also the exact same (almost). We are not sure what causes this offsetting anomaly but in the next experiment we will investigate Brian Bagnall observations that rotating (not driving straight) is the hard part that may be the most likely cause.
1.4 Experiment 2: Accuracy of driving straight. vs rotating
Here we will test both straight line and rotation accuracy.
1.4.1 Straight line accuracy
First we will test if we can drive straight and check that the distance driven matches the real world. The setup is a whiteboard with two parallel lines 120cm apart. We want to test if the robot can drive the 120 centimeters to hit the other line. Figure 7 shows the setup. Figure 8 shows the source code.
![]() |
| Figure 7 - Test setup. Two lines parallel lines 120cm apart. We will test if the robot will travel from one side to the other. |
![]() |
| Figure 8 - Forward test source code. Same wheel diamater and trackWidth as in Figure 4. The navigator is told to move 120cm forward. |
We then placed the robot on the left side and started it. We did this multiple times. Figure 9 shows the overall result while Figure 10 shows the stopping positions in closeup.
![]() |
| Figure 9 - The robot started from the left and moved towards the right side. It was told to travel 120cm, but as can be seen, it did not go that far and stopped a bit short of the goal. |
We can see that the robot does not travel the full 120cm, but it is very close (1,5 - 2,0cm off). The runs are very consistent, all traveling the approximately the same distance. We believe the distances are precisely the same, but because of small errors in the start direction and start position they end up with different distances to the black finish line.
From this we can conclude that straight-line moving is not what makes our test run in Figure 6 end up in the wrong position. We suspect the rotation accuracy might be the problem and will test this now.
1.4.2 Rotational test
We will test the rotation by telling the navigator to go forward 120cm, and then go back to the starting point. This will then be done 10 times to see if it is precise enough for that.
The source code for the rotating accuracy test can be seen in Figure 11.
The actual test run can be seen in Figure 12.
From this we can conclude that the rotation is not precise. We are unsure of why this happens. We suspect that it might be when making fast rotation moves, that the robot does not have enough traction with the surface. We will test this in the next section.
![]() |
| Figure 11 - Test code for performing 10 runs going forward and back to start. |
The actual test run can be seen in Figure 12.
![]() |
| Figure 12 - Test run with program from Figure 11. It can be seen that the rotation performed is not precise. |
1.4.3 Decreasing acceleration
We modified the program from Figure 11 slightly. We simply called pilot.setAcceleration(1) before giving it to the navigator. The result can be seen in Figure 12.
![]() |
| Figure 12 - Test run with acceleration set to 1. It took forever to complete, but is much more precise. |
It can be seen that it runs better, staying closer to the start position, but it is still not perfect. This time we will test if going forward or backwards is the problem, and not the rotation.
1.4.4 Straight line again
In this test we will only go forward for 100cm, then reverse for 100cm. This is done 10 times. The code can be seen in Figure 13, the result can be seen in Figure 14.
![]() |
| Figure 13 - Test code for driving forward and backward. Notice that no navigator is used. |
![]() |
| Figure 14 - Result from driving 100cm forward and backward 10 times. Still not precise. |
1.4.5 Accuracy conclusion
As can be seen from all our experiments, it seems that it is not possible to get a very precise run with the robot. Even straight line forward and reverse is not precise. It should therefore be noted, that if one is the build a map, drifiting of coordinates will occour over time.
2. Avoiding objects while navigating
The simplest way to avoid objects is to attach some ultrasonic sensors on top of the robot, and when an object is closer then some threshold, the navigator should be stopped and an avoid behavior should take command. The avoid behavior could use three ultrasonic sensors to make decisions about what way to turn, just like Maja J Mataric [2]. When the avoid behavior does not detect any more objects, the navigator is restarted. We even made a robot design (Figure 15), but then found that we were not to implement a program, just discuss how to avoid objects.
3. Improved navigation
In Enabling Your Robot to Keep Track of its Position [3] it is assumed that all moves are divided into small moves all assumed to be in straight lines. In Foreward Kinematics for the Khepera Robot [4] it is not assumed to move in straight lines. Here we can calculate more precisely where we are if we are moving in an arc.
The question is then if it is possible to upgrade Lejos navigation system to use the more precise mechanisme in [4] to get better locations. After examining Lejos code, it seems they are already using that mechanism. The DifferentialPilot fires move events and these move events describes if the move happened in an arc or in a straight line. An OdemeterPoseProvider is used to update locations and it uses the math described in [4] if an arc move happened and uses the simple math in [3] if the move was a straight move.
Therefore the optimizations of [4]is already implemented in lejos.
The question is then if it is possible to upgrade Lejos navigation system to use the more precise mechanisme in [4] to get better locations. After examining Lejos code, it seems they are already using that mechanism. The DifferentialPilot fires move events and these move events describes if the move happened in an arc or in a straight line. An OdemeterPoseProvider is used to update locations and it uses the math described in [4] if an arc move happened and uses the simple math in [3] if the move was a straight move.
Therefore the optimizations of [4]is already implemented in lejos.
References
- [1] Brian Bagnall, Maximum Lego NXT - Building Robots with Java Brains, Chapter 12, Localization, p.297 - p.298.
- [2] Maja J Mataric, Integration of Representation Into Goal-Driven Behavior-Based Robots.
- [3] Java Robotics Tutorials, Enabling Your Robot to Keep Track of its Position.
- [4] Thomas Hellstrom, Foreward Kinematics for the Khepera Robot









































