Line follower code nxt robot programming
However, as the robot only distingushes between black and white, the resulting movement looks as if it would be drunk. The idea behind the new version is, not only to distinguish between black and white, but to consider various degrees of grey.
If the sensor is exactly on the boundary, it will see a colour that is between black and white. The more the sensor gets on the line, the blacker the perceived colour is. On the other hand, the more the sensor gets on the white surface, the whiter the perceived colour is. This is called Fuzzy Logic as we do not consider absolute states Boolean Logic, here "Black and White" but different degrees of those states Whiter, Blacker. Now we are not limited anymore to turn only left and right, but can turn more right blacker colour or more left whiter colour.
The reflected light sensor gives a value between 0 and A typical value for a black surface is around 20 and for a white surface something around These values depend of on the ambient right conditions and the distance of the sensor from the surface. The motor power itself as well is a value between 0 and To produce the motor commands as described in the schema, the following calculations have to be done:.
If you program your NXT with the above program, and the robot does not run as expected, check the following:. Original Line Follower Courtesy of Davidin2. A solution that produces a much better solution is the Fuzzy Logic approach presented earlier. However, only a few students at the primary school level are able to understand and program this algorithm. If the block receives a steering value of zero, the robot goes straight on.
For positive values, it will turn to one side and for negative values to the other side. We want the robot to go straight on when it is exactly on the edge of the black line. Thus, the value the sensor reads when on the edge needs to be subtracted from the current sensor value.
Most of the time, the different sensor readings between the black line and the white surface are relatively small.