Thanks to the team's winning the 1st Place Robot Design - Programming award at the World Festival I've received a bunch of information requests about some of the things that they do.
In particular, the team gets asked about the line following routine that the judges talked a lot about.At the bottom is the printout of the actual code they used for their robot in the Power Puzzle Challenge. However, I heaartily recommend that you read about and understand the concepts and discovery trail behind it. I've looked for the actual code recenty (3 years later) and cannot be sure that I've located it (I've got it in RobotC now for the FTC team, but haven't looked at it in NXT-G recently). Please remember, it's way more important that your team have and enjoy their own discoveries than that every team can follow a line same way we do...
---- Note that I've added a couple other files to give more information. Also note that the line following algorithms that were used were speciic to the robot. Your robot will have different parameters and concepts that are used. The jpg file, in particular, has all the information that you need to understand what we did. It's not just a pretty picture!
The Lego Guards' Line Following
The Lego Guards figured out the concept behind their line following routines in the summer before the challenge was released and have continually tweaked and adjusted it throughout the year (it was better at the World Festival in April than it was in January when they won the State Championship). Karl, Gavin, and Robin (our programmers) went through a lot of iterations and discoveries to make the concept work.
Generally, this was their discovery path:
- The first part of my job (as the coach) was to make sure they understood what tools they had to work with: We talked about the three types of signals (digital, analog, and text) and I made sure they understood the purpose and possible inputs and outputs of ALL of the blocks in the NXT-G software (sounds boring? - it wasn't - it only took about an hour). If they didn't understand what a block did, they stopped and plugged it into a program on a simple robot to try it until they did. During the course of that time they learned that light sensors put out a value signal of 0 to 100 (depending on how much black or white they see), and that motors used a speed that could be set between 0 and 100 (They learned a lot of other stuff that time - but those related numbers stood out to them).
- The next thing they noticed was mechanical - putting a light sensor at the front of the robot, roughly in line with a rear mounted drive wheel means that the other drive wheel, moving forward or back, moves that light sensor left or right. Detail: Picture a square with the lower left corner pinned down - if the lower right corner is moved up or down, then the upper left corner moves left or right.
- Knowing that, they realized that if they put two motors at the lower corners, moved one at a constant speed, and adjusted the other and it would move forward/back relative to the other and adjust the sensor in the upper left or right simultaneously. Their first version of a line follower started the left-rear motor moving forward at 50%, then went into a loop where the output of the front-left light sensor was directly fed into the input of the right-rear motor speed. The loop was exited when left motor's revolution count was high enough - then they stopped both motors.
- They added things to adjust the amount of variation (smoothing) and adjust the speed. At one point, right before the state competition, they had about 12 different MyBlocks for different types of following (left or right sensor, follow on the left or right, reason to stop) and they realized that they couldn't remember what was what or manage it safely. Finally, they decided to build a MyBlock that took all the settings and light sensor values and calculated a speed for the variable motor, then used that block within three others based on stop type (Follow_until_distance, Follow_until_time, Follow_until_dark) - and those had parameters that let them put the speed, light sensor id, smoothing, etc.
- The team has now done complete re-writes of their follow routine so often that they are on version 8 or 9 (not counting minor revisions or fixes). Their philosophy? If it works pretty well, then it's not good enough. It must work 10 times in a row (10 out of 10) in order to be acceptable to this team.
The NXT-G program listed below was written by me (the coach) it is not one that the team used during the season (the first two files). But, the blocks (however minimal they are) are where the team actually started. The documentation within describes all the pieces that they came up with, but it doesn't go into detail on how they accomplished it.
The final (third) file is a printout of a portion of the team's actual program - It is used to give an idea of the documentation that they did.
|Lego Guards Basic Line Following.jpg||183.9 KB|
|Basic Follow.rbt||317.83 KB|
|Power Puzzle Documented Programs.pdf||3.62 MB|