Wednesday, June 25, 2014

Project lab session 3

Date: 22/5/2014
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.

We let the robot turn 360 degrees. While the robot turns, we test how far it has turned as of yet, and sample the light sensor. The result is, that for angles relative to the robots current direction now, where there are black lines.




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.


Using the dtl (DistanceTravelListener) inside the control loop for the robot. We always update the currentDistance variable, which holds how far the robot has driven since the last time the counter was reset. At the end, when we drive away from a crossroad, we reset the counter.

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)

Project lab session 4


Date: 29/5/2014
Participants: Helene, Lukas, Daniela
Duration: 6 hours


Goals
Determine the position of the robot relative to the starting point and build an internal representation of the map.


Plan

  • Use distances and angles to determine what the robots coordinates and direction are, in relation to its starting position.
  • Use the coordinates to build a graph or map and send the information to the computer for a graphical representation.


Results
We programmed the robot to keep track of, how far it drove since the last crossroad. We also keep track of the direction the robot driving in, by adding the angle the robot turns at a crossroad to the current angle of the robot. This angle is the same angle we give to the Differential Pilot to turn, when it has choosen which road to follow away from a crossroad.

The angle and the distance are used to determine the new position with the following formula:
   x = x + cos(angle) + distance
   y = y + sin(angle) + distance


Because we use Java's cos and sin functions, we need to make sure that we give the angle in radians, and not degrees.
Java code to update the robots position.

We wrote the coordinates to the screen of the NXT, but when running the program we had trouble reading the values, because the robot never stands still. We decided to program the robot to send coordinates to the computer, so we can read them there instead.

We wrote a small program called MainProject.java, that runs on the computer and connects to the NXT. In the NXT program we use a DataOutputStream to send the integers to the computer. We want a space character between the two integers (x and y) for the computer to see that it is two integers and not a a single number.


This is the code where we set up the bluetooth connection on the NXT.
Here we send the coordinates to the computer, separated by whitespace.
In the MainProject program on the computer, we read the x and y values using the Scanner class and print them to the console. We had some problems with this part, since the the scanner.hasNextInt() does not seem to be able to read any values at all, and just blocks the program.

Instead we use the InputStream in the MainProject directly to read the bytes send by the NXT. Because the writeInt() method sends an integer as four bytes, we have to reassemble the bytes into one integer. We wrote a simple method to shift the bytes to their correct position and OR the bytes together. Using this method, we can output the coordinates the NXT sends.

This still did not work, nothing was ever read and printed in the console.
We then tried to flush the DataOutputStream in the NXT program, to see if this was the problem. But the computer would still never recieve any data. We found out that the in.available() method we used to check if there was data being received always returned zero, so it claims that there is never a byte available to read. We stopped using in.available() and simple used in.read(), which blocks until it receives bytes. This finally works. The code for receiving integers is shown below.

Reassembling bytes to an integer


Reading, converting and printing coordinates.

The result form this run can be seen below in table 1. We see that our calculation/measure of the angle is not very precise. The error increases over time, since the direction we want to turn to, is not the direction the robot drives to, because the PID controller will correct the direction to follow the line. When the robot reaches the the next crossroad, the angle in the program, and the angle in the real world differ. We see that there is a differense of ~28 cm on the x value and ~33 cm on the y value on the start node (node 1) from the first (0,0) to (278,-326) on the last observation.




Coordinates for, where the robot computes that it is currently positioned. The coordinates for a node should be very close to or the same. Instead, coordinates change a lot.

This method turns out too crude to reliably identify at which crossroad the robot is positioned. We had a look at the Lejos api to see if there were methods that could help with this task. We found that we could use the MoveListener interface to get access to all movements the DifferentialPilot uses to steer the robot. This interfaces gives access to the distance that is driven and what angle the robot turns at some radius.

To understand what data we could use from the MoveListener interface, we send some of the information from the interface to the computer, to be shown there. This way, we could see what the robot was doing, while getting an idea of how the MoveListeners methods were called.

Because there were angles and distances expressed in floats, we wanted to send floats from the robot and reassemble them at the computer. The reassembling was achived by using the following code:


Reading floats sent from the robot.


We now wanted to send information about the position of the robot, and send the information from the MoveListener, whenever its methods were called. For this purpose, before sending any information, we would now send a number, to identify what type of data would follow.

The MoveListener interface describes movement along the circumference of a circle. The size of the circle describes the turn radius of the robot. A turn radius of zero would mean that the robot turns around itself, while a turn radius of infinity means the robot drives along a straight line. We are also given the distance, the robot travels along the circle, and the associated angle.

For every Move event, we were only given one angle, which we assume is the angle counter clockwise from the x-axis. The y-axis of the coordinate system would then point in the direction, in which the robot would drive in the very first moment, if it was driving forward. The position, where the Move event ends can then be determined  with a vector operation, if the robot turns left, which is indicated by a positive angle. When the starting position (x0,y0) = (radius,0), the new coordinates are


x = cos(angle) * radius
y = sin(angle) * radius

This situation for the move event can be illustrated like this:




These coordinates are valid for the current Move event, but are not in the same coordinate system as the coordinates for the crossroad or the robots position in the world. We have to transform these coordinates to the word-coordinate system. To do this, we consider the y-axis of the Move coordinate system to be forward i.e. the same direction as the robots current angle. This means we need to use a rotation-matrix to transform a vector from one system into another, where the angle we need to rotate with, is the robots current angle minus 90 degrees, because the y-axis is considered forward, while in the world-coordinate system, the x-axis is considered forward, when the robots current angle is 0.

Additionally, before we can rotate a vector, the robots initial position in the move's coordinates system, should be spot on the robots position in the word's coordinate system, which means we must subtract the radius of the circle from the vectors x-coordinate.

The transformation can be visualized like this:

   
The world coordinate system, before adding the new position from the move event.


Visualizing the move event coordinate system at its position in the world coordinate system.


We were discussing how to calculate the robots position, given the information the MoveListener interface provides, when we found out that there already is a class that implemented what we were trying to calculate. This class is called OdometryListener.

Instead of finishing our own implementation, we simply used the OdometryListener to update the robots position and direction. We again sent positions to the computer, to see, how consistent the coordinates for the intersection would now be. The results can be seen here:




These positions are not as bad as before, bit still quite bad. Driving from intersection 1 to intersection 2 and back to 1, the robot had calculated, it was now 5 cm from where it started. These measurements are probably still too unreliable to use to find out, at which intersection we are. We decided to limit the number of directions the robot could drive in to four, so that we either would change the position on the x-axis, or the y-axis, but not both at the same time.


Conclusion
We did not manage to do what we started out today, because our methods of computing the robots position were too unreliable. Because of this, we could not start with building an internal representation of the graph.

Plan for next time

  • Change the graph to only contain 90 degree angles, so that all lines are parallel, and there are only four directions to drive in.
  • Change the robot to only use four directions.
  • Implement discovering the graph and recognizing visited intersections based on coordinates.


References


Project lab session 5

Date: 13/6-14
Participants: Helene, Lukas, Daniela
Duation: 6 hours

Goals
Implement detecting of new nodes and determine the robots position on the map. Start building the internal graph representation of the map.

Plan:

  • Refine mechanisms for determining road directions and for finding black lines while rotating.


Results:

General problems with changing light conditions
During this session, we encountered a problem with the color sensor. The color detection that we used in the previous sessions, started to not recognize the yellow markers anymore. We argue that the problem was due to the changing levels of light between the sessions due to weather conditions. The first thing we did, was then to move away our track from the window, thus providing a more stable light level. This did improve the situation a bit, but we still had a lot of problems. We then decided to look into the color detection code going from the use of build-in colors IDs to analyzing raw sensor data, but saw how the values still were too unstable and therefore it was difficult to detect the yellow color from these values. In the end, we decided to move our track away from the windows, to a place where the light was mostly artificial and did not change all the time.


Detecting crossroad's outgoing edges and driving along a random direction
Last session, we decided to limit the the number of directions to four. This means, all angles have to be changed to 0, 90, 180, 270, and there can not be any skew edges. All edges on the graph have to be orthogonal to each other. To normalize all angles the robot encounters, we wrote a simple function:

Method to normalize all angles to four cardinal directions.

We changed all angles in the program to be normalized. Now, after detecting edges at a crossroad, the robot tried to turn to an edge, but would not turn enough or too much, and simply drove off the map. This happens, because the angles in the real world are not necessarily normalized direction. To remedy this, we chose to let the robot rotate less than the angle it wanted to turn, and then keep turning, while using the left sensor to detect a black line. When the black line is detected, the robot stops turning, and only turn a small amount, which we estimated, to place the light sensors above the black line. Now we can safely give control to the P(ID) controller again, without the robot just driving off the map.
Code for searching a black line, while rotation to a chosen angle. When rotating, test if the robot sees a dark value, if so, turn 7 degrees.

Finding crossroads and building nodes
We have implemented a Location class that maintains the coordinates (x,y) of a crossroads and which other nodes (crossroads) it is connected to. The implementation can be found here:
Location class

When the robot meets a crossroads, we search through all the Location-objects we have stored, and search for the node, that hast the shortest distance to the robots current position.
 We now have three scenarios:

  1. There are no Location objects yet: We simply create a new Location, and store the position the robot is at right now.
  2. The distance is below some threshold (5-10 cm): We assume that the node we currently visit is the same as the closest node. We then reset the robots current position to the position of the closest node. We do this to keep the error in the robots position to be the same, as the first time the robot visited this node. This helps keeping the error from accumulation over time
  3. The distance is bigger than the threshold: We assume that we are visiting a new crossroad that we have not seen before. We create a new Location object and save the new crossroad position and let the robot rotate around its axis in order to detect the outgoing roads. We connect the current crossroad/Location to the Location we saw last.



We ran the robot a few times and noticed some problems in the node detection mechanism, since the robot wasn't always able to detect new nodes. What happened was, that the robot could not correctly compute, which Location-object was the one that was closest by, and the Location-objects coordinates would change, even though these coordinates are never supposed to change. We assumed that there must be some error in the code and decided to address the problem in the next session.


Conclusion:
We experienced some problems with the light conditions, and found that the best way to handle this, was to move our track away from the windows, and hope that the light conditions would not be to much of a problem.

We found that our resriction to 90 degree angles was very successful, since the car almost never drove of the track. However, we experienced some strage error in the information about the location of the robot and the crossroads. We did not have time to investiagete this further at this lab session, but will start by adressing this concern at the next session.

Plan for next time:

  • Debug our program to find the error with the location.
  • Start building the internal and send it to the computer.
  • Write a graphical interface for the computer to show the map the robot is building.

Project lab session 6

Date: 16/6-14
Participants: Helene, Lukas, Daniela
Duation: 4 hours

Goals:

Debugging errors from previous session. Program a graphical interface on the PC that shows the real time postion of the robot and a representation of nodes and edges of the map. Make sure that the robot eventually gets to know all the map. Implement navigation between two know point in the map. 

Plan:


  • Debugging and refactoring from previous session
  • Write a graphical interface for the computer
  • Make the robot visit all crossroads and all roads



Results:


Debug and refactor:
We started by fixing the error we introduced last time, which consisted of the position of Location objects changing, even though they are supposed to never change. This was possible, because we used the LeJOS Point class, which contains x and y coordinates. The Point classes are mutable, and when not careful, two objects can have the same reference to the same Point object and modify it, which was what happened here. To make sure, other objects do not modify a Locations point, we make defensive copies, so that other classes never get the reference to a Locations point, but only a copy of it. Also, upon creation, the Location class copies the point it is given and only stores the copy.

Furthermore the location and internal map representation of the world was refactored in the World class. 



Programming the graphical interface for the pc.
At this point, the robot already saves in its internal graph datastructure the nodes it has encountered and their connections. Now we wanted to show the nodes and their connections on the pc in order to easily check how well the robot does, when mapping the world. 
We had now the problem that the angles that the robot registers at every cross roads are relative to the robot's own direction in the track, while we needed angles relative to a reference coordinate system. 

We solved this problem in the following way:
The robot knows at any moment its direction (angle) relative to the reference coordinate system. When the robot turns at a crossroad in order to detect roads, it saves the values of the directions relative to the direction the robot entered the crossroad. To calculate the roads' angles relative to the reference coordinate system we simply add the robots direction to the directions of the roads. The angles and the nodes position are then sent to the pc where they are given a graphical representation on the screen.


Making sure that the robot gets to know the whole world

We considered the possibility of using a breadth first search (BFS) or a depth first search (DFS) in order to let the robot discover all the edges and nodes in our world. This possibility was dismissed since it was much easier to traverse the graph in a more random fashion.
The idea is that the robot will have to remember which directions from a node it has already visited. When at a node, the robot will choose randomly one on the directions that has not been visited yet and will drive in that direction to continue building the map. 

If being at a node, the robot discovers that all directions have been visited already, the robot finds the closest (euclidean distance) node that has unvisited directions and drives toward it. Because such a node can be more than one intersection away, we uses Dijkstra's algorithm to find a path to such a node.

When there are no more nodes with unvisited directions, the robot stops searching and assumes that it now knows all intersections in the world.

To even know, if the robot has visited all roads and crossroads in the world, we have to store what directions are possible to drive, for every crossroad. We can reuse the code we wrote to choose a random direction to drive in, to store the found directions in the Location object. This is done with a single integer, where we set some bits according to what directions are possible to drive in. We take all the found directions, and add the robots current angle to them, to obtain directions in the world coordinate system. If there is an edge in direction 0, we set the first bit of the integer to one, if there is an edge in direction 90, we set the second bit and so on. 


Given the relative angles and the robots current angle, we construct a byte that tells us what directions are possible to drive in.
 
The integer is then stored in the Location that was created for this crossroad. Now we know what the possible directions are, for all the crossroads that have been visited, and we already connect nodes when driving along edges. To find out which edges have yet to be visited, we can simply compare the edges of the graph to the possible directions. 

This code lists all the directions, that are known to exist for this Location, but that have not been visited yet. Edges are only visited, when the robot has driven along that edge. The connectionBits() method just test all visited edges and builds a bit in the same manner we did before. The integers are compared bit for bit, to see what angles have yet to be visited.
 

We implemented a shortest path algorithm using Dijkstra's algorithm. The goal is to get a list of nodes to navigate through in order to drive from the current Location to some destination Location. (Code: Dijkstra's algorithm implementation - lines 14-57)

Our implementation of Dijkstra's algorithm returns a stack of Locations that have to be visited. When the robot is at one crossroad, the corresponding Location objects holds the coordinates and we have the Location object for the next node to be visited. To choose the right direction to drive in, we can simply calculate the direction from one Location to another, using the coordinates. This gives direction in the world coordinate system, in which the robot has to drive. Now the robot just has to turn toward that direction and follow the road. The Location object is removed from the stack, and this continues until the goal has been reached, i.e. the stack is empty.


Code for computing the absolute direction between to Location objects. the p.angle() method uses javas Math.atan2(y,x) method. The loops are to make sure, that values are between 0 and 360, because Math.atan2 can return negative values.


Following a path returned by Dijkstra's algorith. This is how Locations from the stack are used to drive to the next crossroad. The limitAngle() methods simply makes sure that angles are between 0 and 360.

When using these changes, the robot now discovers the graph, if the error for its position does not get too big. When the error gets too big, the robot can consider a previously visited node as a new node, because it thinks its too far away to be the same location. In this case, the robot will probably not stop searching, because it keeps creating new locations all the time, and thinks there are more unvisited edges to discover.


If this does not happen, the robot visits all edges in the graph, and stops, once there is nothing more to discover.


Navigate to a specific crossroad:
The last thing we implemented, is the possibility of giving the robot user input through the graphical interface on the pc, when the robot has discovered the whole map.

When the robot is asked to move from the current node to a certain other node, it does it by calculating the shortest path to the node (using the Dijkstra algoritm implemented before). 

We then made a few experiments in order to see if the robot is able to move without problems between different nodes. Again, the error in the robots position could accumulate so much, that it thinks it visited a previously unknown node, and thus starts building new nodes in the graph. We saw this happen especially when the robot was asked to travel longer paths between nodes far from each other. 

The world we had build for the robot to drive on, was very skew, and did not have right angles. So we blame the track we build for the remaining problems, and decided to build a new one.


Conclusion:

We found the error in our code from the last lab session, and fixed it. Running the robot now, gave some very good results for the coordinates and it was close enough to be able to use it for the internal map representation.

We implemented a graphical interface for the computer, which live shows the position of the robot and the crossroads it has detected. This tool gave us good ways of determining how good the robot is at navigating tha map, and determine its coordinates. 

Futhermore we implemented that the robot maps the entire world and does not get stuck in some corner. We did this by remembering which roads we have visit for each crossroad. Then we uses Dijkstra algorithm to get the shortest path to a crossroad with unvisited roads. 

As a last thing we implemented that when the robot is done mapping the world, the computer can send it instructions to drive to a specific crossroad.

All in all our implementation seems to work very well and some of the errors that makes the robot drive of the track or not recognizing known crossroads, might be due to the track it self were the black lines not are completely straight and not have completely 90 degree angles.

Plan for next time:
  • Build a new and more precise track.
  • Test the robot several times. 




Project lab session 7

Date: 16/6-14
Participants: Helene, Lukas, Daniela
Duation: 1,5 hours

Goals:
Build a new track in order to see if this affects the behavior of the robot for the better

Results:
We built a new track making sure that the lines are as straight and ortogonal to each other as possible. 

We then run the robot on the track from different starting points. We noticed how letting the robot start somewhere around the center of the track gave better results compared to placing the robot in a corner of the track. We argue that this is due to the accumulation of errors when the robot gets far away from its starting point. Placing the robot in the center of the track, guarantees in fact that the distances travelled before the robot gets a chance to reset its coordinates to the starting point are smaller than when we place the robot in a corner. 

Picture of the old track:

Picture of the new track:


Video of the performance of the robot navigating the track, when it starts in the middle of the track:
(The video was to big to be uploaded to the blog)

The final codeThe final code of the project can be found here: Final Code link
Conclusion:
We build a new track that gave some improved performance.


Project Lab Session 2

Date: 15 May 2014
Duration of activity: 5 hours
Group members participating:  Daniela, Helene, Lukas


Goals
In this lab session we will start developing the final project, by building the world and the robot car, and  start developing software for the robot.


Plan:

  • Determine the appearance of the world our robot should navigate in, and build a sample world for testing.
  • Determine the internal map representation of the world
  • Build a robot car.
  • Start writing software for the robot to navigate the world.

Results


Building the world:
We discussed several ways of building the map the robot car should navigate in. Our ideas can be split in two main catagories:
  1. Avoid walls: A grid with white and black square indicating where the robot can drive. 
  2. Follow a line: A graph consisting of black lines where nodes represent the crossroads and the edges represent the roads (the black lines). 

The first idea was to have the world consist of a large white surface with black line indicating the walls. Then the robot car should drive around in the white passageways, and not cross the black walls. The representation of the world would then be a pixel grid, where each cell in the grid represents a ½-1 cm square on the physical map. Each cell of the grid should then be black or white in order to represent walls or passages. Our plan then was to let the robot car use the differential pilot to navigate the world map, using a light sensor to avoid the walls. One clear problem with this approach is that the robot car always must be aware of its location in the grid with some x and y cooordinates. We saw this as a clear challenge since it prevents us from letting the car drive around at random untill it sees a black wall. We discussed different variants of this approach with a smaller (½ cm) or larger grid.

After discussing the above approach we wanted to investigate a completely different approach and decided to think of the world as a graph consisting of nodes and edges. In this representation the physical world would consist of a number of black lines crossing each other. We would then use a PID controller to make the robot car follow the black line. The crossroads should be made in a way that makes the robot discover them (e.i. a distinct color). The robot car should then be able to determine all outgoing roads from the crossroad and build up an internal map using angles to determine in which direction they are leading.


We decided to use the second approach for several reasons. For the first we had a clear idea of how to create a solution using the techniques we have learned throughout the course. Furthermore the map representation of this approach will take up less space than the first approach, which might be a concern because of the restricted space capacity of the NXT. Depending on the resolution and size of the pixel map, it could take up several megabytes of memory.


For the physical world we got a white surface on which we used black tape to make the roads. We started off by making a very small sample map we can use to test the PID controller and other things.




This means that the internal map representation of the world will be a node for each crossroad, and the roads between the crossroads will be the edges between the nodes.


Building the robot car:

Having decided upon the physical and internal reprensentation of the world we went to the task of building the robot car.

From the physical representation of the world we determined that we need two light sensors for doing the PID line follower control and a color sensor to detect the distinct color at the crossroads. Since the the discription of the project and the physical world does not force the car to look in a specific way we determined to build the standard car from the lego instructions with a small modification that lets us attach three sensors at the front of the car. See the following picture of  the car:








Software:


PID Controller:

We started by writing the PID controller greatly inspired by the one we made for the "race" competition. Our plan was to follow the Ziegler-Nichols method, where one starts by finding the ultimate proportional gain and the oscillation periode, and uses this information to find the best parameters for the PID controller. Duing our search of finding the ultimate proportional gain we found the car driving quite smooth along the straight line only using the porportional part of the PID controller. In the fist version of our world we have only straight line with no curves. For this reason we decided to only use the proportional part of the PID controller, since it seems to be good enough for our purpose. If we later decide to design a more complex world with curved lines we can extend the controller to a full PID controller.

The following code shows the code for the P(ID) controller:





Detect crossroads:

We decided to mark crossroads with a distinct color, which the robot car can detect with the color sensor. We had to determine the id's of the different colors available in the ColorSensor class. To do this we wrote the following code, which uses the color sensors getColorID method to return the id of the color the sensor is registering. Futhermore the method writes the color and the corresponding color id to the screen, which let us examine how good the color sensor is in dertermining the color.



This code gave the following result for the build in color ids:





After having determined the values of the id's, we used the getColorID method in the ColorSensor class on different colored papers to see if the ColorSensor meassured correct, how accurate it is, and to determine which colored paper would be best. 


Our first try was with a light green paper, but the result of the getColorID method was that it was white. Our next go was a yellow paper, where the color sensor measured it to be green. Which let us conclude that the getColorID method might not be very precise or the color of the papers are too light. For our purpose it is enough that the color sensor can distinguish the color from black and white, which it indeed can. Thus, we decided to use the yellow paper to indicate a crossroad. 


We were a little concerned whether the colored paper would interfere with the line follower. For this reason we wanted a bright color, that would look like white to the light-sensors. After having decided on the yellow paper we taped it on the map and ran the line follower to see if it would be a problem, but the P(ID) controller worked just fine with the yellow paper in place.


Our next step was making the robot car follow the line using the light sensors and stop when it sees the yellow color with the color sensor. We did this by adding a check to the infinite while loop for the line follower. The check simply sees whether the color sensor have seen yellow - if so it stops the motors and breaks out of the loop otherwise it continues following the line. See the following code:







When running the above code, the robot could detect crossroads, even if we only used a small strip of yellow paper.


Map the crossroad:

When the robot car has detected a crossroad, it should begin to map which roads lead away from it. To do this we want the robot car to turn around its own axis and look for black lines. To be able do do this we need the robot car to have the center of the crossroad precisely between its wheels. Since the color sensor is in the front of the robot car we need it to drive a specific distance forward. To do this we want to use the DifferentialPilot class which we used in Lab Session 9. We decided to use it beacuse the result of Lab Session 9 was that the DifferentialPilot class is a good tool to use when you need to drive a specific distance.

Meassurements needed for the differenetial pilot:

  • Wheel diameter: 56 mm (read from the print on the wheel)
  • Track distance: 111 mm (see picture)
  • Distance bewteen the color sensor and the wheels: ~75 mm (see picture) (this is a very rough meassurement, but for our purpose it is not need to be completely precise).





When running the code were we used the Differential Pilot only to drive the specific distance to the crossroads center, we observed som strange behaivor: The robot made some strange noises and sometimes it did not move correctly. We think that this might be due to the fact that we are using two different ways of controling the wheels, and the controls might not be completely released when we switch between the two. 

As a solution to this we want to use the tachocounter instead of the Differential Pilot. We wrote the following code for diving the distance using the tachocounter:




The following video show the result we got using the tachocounter:





Conclusion
In this lab session we have discussed different ways of making the physical world and decided to go with the one using black lines as roads. Futhermore we managed to implement some of the behaviors needed in the robot car: Follow the black line and detect crossroads. We had some problem with using different tools to control the wheels, and our initial solution was to implement some of the Differential Pilots behaviour manual. 

Next time our plan is to:

  • Try again to use the Differential Pilot to control the wheels, since it implements alot of the behaoviour we need.
  • Make the robot car detect the roads leading away from the crossroad.
  • Determine how the car should build the internal representation of the map.

References: