Participants: Helene, Lukas, Daniela
Duration: 4 hours
Goals
We will try to go back to using the Differential Pilot class and compare it to our manual use of the tacho counter from the last lab session. Futhermore, we will try to make the car detect crossroads' outgoing roads and map the crossroads to an internal representation.
Plan
- Find out how to drive and rotate specific distances and do PID controlle: Manual using the tacho counter vs. the Differential Pilot.
- Programme discovery of the crossroads' outgoing roads
- Programme how to choose the next road to drive along
- Discuss and implement how to make the robot distinguish or recognize nodes.
Results
Controling the wheels
In the last session we abandoned the Differential Pilot and used the tacho counter in order to drive certain distances on the map. This was due to fact that we had some problems with the Differential Pilot when using both the DifferentialPilot class and the Motor class. We felt, that using the Motor class directly, was not a very good solution, because we had to give up all the methods the Differential Pilot provides. We looked through the API for the DifferentialPilot class, and found the steer() method, which we not had used up to this point. We simply tried to combine the P(ID)-controller and the Differential Pilot by using the error as the angle to steer, and surprisingly, it worked very well on the first try.
The implementation of P(ID)-controller using the DifferentialPilot can be seen here:
The result of driving with this new code is shown in the following video:
We now to tried to find optimal parameters for the Differential Pilot - the whele diameter and the track distance. We started by using the measurements from Project Lab Session 1. This was not very precise, so we made some experiments similar to those done in Lab 9 to observe how precise the rotation and distance driven by the differential pilot are.
To begin with we measured the distance between the wheels to 111 mm, but the robot rotated too much. The best value of the parameter was found to be 108 mm.
Now we needed to change the code in order to use the Differential Pilot to move forward when a crossroad is encountered. We already had measured the distance between the color sensor and the wheel, which was ~7.5 cm. So we simply tell the pilot to drive forward that distance:
Map crossroad's outgoing roads
When the robots has its center above the crossroad, the car rotates and looks for black lines. We made a test method that registers in a boolean array whether it has seen black or not. Instead of testing for all 360 angles, we only tested for every 6'th degree, to save some space and computation time.
To make this data a little more useful, we have another simple method, that searches the array, and only returns the angles, at which black lines were found. The angles for continuous strips of ones in the array are averaged, as to not return multiple angles for the same line.
To test if the method words, we wrote the array as pixels to the NXT's screen, as it can be seen in the picture:
![]() |
| We can see two black bars on the screen, which correspond to, that the robot detected two roads at the intersection it just was. |
In the following video, one can see the robot detecting outgoing roads:
Choosing a random road to follow
After detecting and storing the different outgoing roads, we wanted the robot to keep on its discovery of the world. We wrote some code to make the robot choose a random road to drive along using the P(ID) controller.
| The "results" array contains the angles, at which outgoing roads were found. We simply select a random index from the array, and use that angle to turn the robot. |
We then ran the code, and we observed how the robot didn't performe very good in following the black line after it had rotate in order to find it. We think that this is due to the fact that we used a 6 degree accuracy in our measuraments of the roads' angles and this was not precise enough. We decided then to change the detection code so that it senses the color at every rotation degree (360 times). This in fact improved the car's behavior, as it can be seen in the following video:
Another problem we observed, was that the acceleration of the car was a little to big: the car almost jumps when it starts and stops. We decided to lower it to 150 (default value is 600). This turned out to be a problem, since it also affected the way the car stopped, letting it drive too long before standing still. After a few experiments, we found out that the optimal acceleration value for our set up is 500.
Even though the car was behaving quite good, we noticed how we still had a small problem with the car starting to drive when it is not exactly on the black line. Our P(ID) controller seemed not to be good enough to always find and follow the outgoing roads. We decided not to change the P(ID), but instead try to fix this problem by making sure the two light sensor are on each side of the black line when it starts to move again. We decided to look at this in the next session.
Mapping the crossroads
We started discussing how we can distinguish the different crossroads of our map. The problem is that not having any idea of cars (x,y) position, when the robot sees a node, it cannot say if it is a new node or a node that it has seen before.
To solve this problem we decided to combine a topological and a geographical representation of the world. In order to recognize known crossroads, we can use the (x,y) position of the robot. If the robot sees a crossroad and its x,y coordinates are within some distance from some other known locations, we consider the node just detected to be one we already have seen.
To be able to follow our plan, we needed to implement a way of determining the position in form of (x,y) coordinates of the robot in the world.
Determining the position of the robot
We want to keep track of the robots position and direction while it drives. To do this, we need to keep track of, how far the robots moves, while using the P(ID) controller. We tried to use the getMovementIncrement() method of the DifferentialPilot class, just like we used the getAngleIncrement() when turning and searching for roads. To see what values were returned by this method, we simply used the robots LCD screen to print the values line for line. Using this method, values would start over from zero very often, and seem to describe only small parts of the movement. We reasoned that every call to steer() has the potential to reset this value.
While looking for a solution, we found the MoveListener interface, that could add a listener to the DifferentialPilot. A MoveListener is notified, whenever a movement starts or ends, and gets access to how far the robot has driven with every single move. This means we can simply add all the distances up and store them, and reset when we start driving away from a crossroad.
| The DistanceTravelListener, which is a MoveListener, and is added to the DifferentialPilot once created. The differential pilot calls moveStopped with information about the move it just did. |
Conclusion:
We successed in using the Differential Pilot to do all of the wheel contol of the robot car, which makes us able to use all of the build in behaviour of the Differential Pilot class. Futhermore, we were able to implement the robots behaviour at the crossroads: Detect outgoing roads, choosing a road to follow and follow the outgoing road with the P(ID) controller. We have started on discussing and implementing the robots position in form of (x,y) coordianates on the map. When implemented this will make the robot able to determine whether it has seen a crossroad before or whether it is a new one.
What to do next time:
- Improve how the car finds the choose road to follow, so the P(ID) controller can follow the line without getting lost.
- Use distance and angles to determine where the car is (x,y)
- Make a internal representation of the map (maybe sent it to the computer to show the viewer)


No comments:
Post a Comment