I have been using a Make-It Robotics kit, that I picked up from a RadioShack that was closing, to learn more about Arduino, C, etc. After building the line-following robot and downloading the correct libraries, I can get the robot to function as intended. It uses 2 optical sensors in front of 2 driving wheels that are controlled by independent DC motors. The optical sensors determine if the left or right side of the front of the robot is over a white or black area on the test track. The necessary motor then turns on to keep the black line roughly between the 2 sensors as the robot moves along. The default test track that came with the kit was a large black circle on a white background.
I want to make some modifications to the code (and maybe the underlying library files) to try to make the robot able to handle other types of paths with more acute angles and sharper turns, etc. But, I don't understand some aspects of the highest level .ino source code file.
I am a little unsure of pasting such a long code block below and also don't think an image of it will help. The version data for the file I'm using is below. The files can be found online @ LINK
// ****************************************************************************** **
// * File Name : linefollow
// * Author : RadioShack Corporation
// * Version : V1.0
// * Date : 2014/01/16
// * Description : Optical sensors send feedback to PCB
// * to make the robot follow a black line on a white background.
// ********************************************************************************
In this .ino file, I don't understand the code from line 68 onwards: from the Read Left/Right Optical Status onward...
I don't understand some of the bitwise operations there and don't really see how the sensor readings (whether it is over a white or black area on the surface) correlates to which motor activates to keep the robot on the course...
From my limited understanding of Arduino, this robot kit, and the code, it seems like the software and hardware have to interact in this way:
- Robot moves forward using both motors turning the wheels in the same direction. It approaches the black test circle at a shallow angle (i.e. almost tangent to it) to allow one sensor to go over the black line before the other one does.
- Optical readings of each sensor are taken periodically.
- If both sensors detect white space, robot continues to move forward.
- If the right sensor detects that it has gone from white to black and then to white, it means that the robot needs to turn to the left to stay on the path.
- To turn left, the left motor is un-powered and the right motor is powered until the right sensor detects black again.
- Now that the robot is on course, it will keep turning in the direction of the sensor that detects a white to black to white transition.
I am not seeing how my intuitive understanding of the robot's operation matches with that of the code...
The files can be found online.
- Where online...?