Arduino Day 5 (Line Following)

Our last task with the sciborgs is to create a sciborg that follows a white line on the ground.  This task with the sciborg took the longest, so Olivia and I worked on some of it outside of class because we are also learning MATLAB and doing final projects in class.

Brightness Sensor

To create a line-following sciborg, we used a LEGO brightness sensor.  The line that the sciborg will follow is a line of white tape on a brown board.  The sensor reads values of brightness, so the white line was around values of 540 or less and the brown board was values of around 570 or more, and the values are printed in the serial monitor.  The following is the basic code for the brightness sensor.


The values are printed in the serial monitor, so before we started on the next task, we played around with the light sensor and a test piece of the track to get some base values for the white strip and the brown background.  We decided to have the brightness sensor calibrate on the white tape.  So we would set the sciborg down with the brightness sensor on the white tape, then plug the batteries in, and it would calibrate to the white tape.

Line Following using Bang-Bang Control

For the bang-bang control we decided to have 3 different levels.  It took us a long time to figure out the different levels and how it would turn both left and right.  If the brightness is less than 540, it goes straight.  If it is greater than 574, it turns right.  And if it is between those two values, 540 and 574, it turns left. This works because as the light sensor moves away from the white line, the values continue to get larger.  We arrived at these numbers through lots of testing, which was probably the longest part of this project.


This is a diagram of what we wanted the sciborg does within the three different ranges. It is supposed to go straight when it senses the white line, but if it goes off the line on the right side, it turns left to get back to the line.  If if goes off on the left side, we have already set a range on each side that makes it turn left, but then that left turn pushes it into the next range, which makes it turn right.


Here is our final code for bang-bang control.  We use the values in our if-else statements.  Inside each statement, we have the code for each movement that corresponds to the range.  In the last else statement, we have the car turning left and then moving forward a tiny bit.  This helps the sciborg on the left side of the line.  When it reaches the first range, it will turn left, and go straight a tiny bit, which helps it reach the "turn right" range, and it will get back to the line.



As I said previously, too get the sciborg to follow the line as best as possible, we had to do a lot of testing.  We changed the values and speeds many times before we finally got a combination that worked very well.  Some of the troubles we had were when the sciborg went to the right of the line, it would start turning left, but wouldn't make it back to the line in time, so it would start turning right (because the second "turn right" range is on both sides).  Here are a few videos of our sciborg following the line.






Line-Following using Proportional Control

After Olivia and I finished our bang-bang control for the line-following, we moved on to proportional control.  Proportional control in this case means that the further away from the line that the sciborg is, the faster the speed of the turn.  For the turning speed, we multiply 60 by the difference in brightness value.  The difference in the brightness value depends on the range values.  For the left turn, we subtract 540 and for the right turn, we subtract 570.  This tells how far away from the line the sciborg is, and so the farther away from the line, the faster the turn speed.






No comments:

Post a Comment