Date: 24-05-12
Duration: 5½ hours
Group members attending: Tore, Troels & Kristian
Goal
Today’s goal is to find a way to convert an image to a 2d bit array, and to build the drawing robot. We want the robot to be able to calculate angles and lengths from one point in a coordinate system to another point, thus constantly keeping track of its’ own position.
Plan
1. Google solutions for the image to array problem and implement it.
2. Build the robot.
3. Modify the DifferentialPilot class(used in a previous lab session (*2)) to calculate lengths and angles from a coordinate system.
Execution
1. We started out by googling different solutions to the image conversion. We ended up with a solution where a bitmap picture is converted into an integer array. The integer array consists of bits. If the bit is 1 the robot should draw that pixel and if it is 0 it should leave that pixel blank.
Code can be seen here (*3)
2. We needed to build a differential driven robot with the pen placed exactly between the wheels, so that it would draw a curve when turning. So far, this is the result:
The picture to the right is the front of the robot. Here we will mount the pen along with another motor, so that the robot is able to lift the pen.
3. We wanted to modify the previously used DifferentialPilot class (*2). We need a “go to position (x,y)”-method, so we started by implementing a method that can calculate an angle between the current position and the position to go to. It also calculates the length the robot has to move. We always calculate the angle from the x-axis so this is our 0° direction.
We should therefore always know the angle our robot is currently heading and the position in the coordinate system. If we are at point (1,1) and heading 45 degrees and we want to go to (2,3) in the coordinate system, we would then calculate the angle the robot has to be facing and then calculate the length it should drive.
We talked a lot about how we were supposed to draw the picture. We ended up with a solution called point chains(*1). We analyse the bitmap on the computer and find lines in the 2d array of neighbouring 1’s. We save all of these lines into another array. We will then make the robot draw one line at a time until the whole picture has been drawn.
We create the point chains as follows: We iterate through the bitmap until we hit a 1 which represents a dark spot. Then we analyse the neighbours around this spot. If there is another 1 we put this into our chain, its’ position compared to the previous represented as a number between 1 and 8, as seen below:
1 2 3
4 5
6 7 8
So
a chain could look like: 3,3,3,3,5,8,7,7,7,6,6,6, which would mean go
north east four times, then east, south east, south three times and
south west three times.We don’t want the point chains to make to radical changes in the chain so we limit the next point to be only the nearest neighbours that is:
If we have a 3 in the chain the only possible next numbers in the chain will be 1,2,3,5 and 8. If these directions does not contain a “black dot” then the chain stops and we will start analyzing a new line.
To make sure we do not measure the same lines again, we delete the points in our bit array as we convert the pixels to chains.
Future enhancements to the robot should include some sort of recalibration after each line. The current idea is to use to distance sensors. If we place two walls along the x- and y-axis, then the distance sensor will give us the real current coordinate compared to the walls.
Code can be seen here (*4).
Status
The robot is almost done. We just need to mount the pen to the robot as well as a motor to raise and lower the pen. We have made a construction that will make the pen somewhat sturdy so it will make a straight line, we just need to attach it to the robot.
We have written some code that will transform a bitmap picture into a bitarray as a 0 1 representation. We have have also started working on our point chain algorithm that will analyze the aforementioned bitmap and create lines from it. For now it runs through the bitmap until it hits a 1 and then starts to analyze the neighbours. We have also implemented some mathematical algorithms that will be able to track the car and calculate distance + angle from one point to another.
References
(*1) http://www.convict.lu/Jeunes/ultimate_stuff/Erik_s_xy_plotter/E_xy_plotter.htm
(*2) http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson9.dir/Lesson.html
(*3) http://troelskristiantore.blogspot.dk/2012/06/legolab-code-image-to-array.html
(*4) http://troelskristiantore.blogspot.dk/2012/06/legolab-code-chaincalculator.html
No comments:
Post a Comment