Following the line on the ground is too boring!
We've tried to look at a different angle at line followers and bring them to another plane - to the school whiteboard.
Look what came of it!
For one racing robot:
Mechanics:
Electronics:
Miscellaneous:
For a classroom:
Install the magnets on the miniQ platform. Use M3x10 standoffs, M3x8 or M3x6 flat countersunk screws and M3 nuts. Required installation holes are shown in the picture.
That's important!
The length of the standoffs should be exactly 10 mm. After installing the magnets, test the platform on the whiteboard. All four magnets should be adjacent to the magnetic board and the rubber tires on the wheels of the miniQ platform should be preloaded and provide some friction with the board surface.
Manually move robot across the board. During the ride, the magnets should not come off the board. If any magnet comes off it means that the rubber tires on the wheels load maximally. In this case, increase the 10mm distance of all standoffs by 1 or 2 mm by adding a pair of M3 washers and try again.
Mount the Arduino UNO Board on the platform using M3x25 standoffs, M3 screws and M3 nuts. Do not use short standoffs, leave some space under the Arduino board for wires and battery.
Install the Motor shield on the Arduino UNO Board.
Install the Octoliner module. Press it against the platform using a nylon M3 screw and nut.
That's important!
Do not use metal fasteners to mount the Octoliner. Some mounting holes on the breakout board are soldered and used as IO pins. To prevent short circuits, use plastic fastener, for example, nylon.
Link all electronic components as shown in the diagram. The Octoliner module is connected via 4 wires (GND, 5V, SDA, SCL) to the Arduino UNO. Connect motors to the Motor shield. The LiPo battery is linked to the contact pads of the external power supply on the Motor shield as well as to the VIN pin on the Arduino board. Instead of using the VIN pin, you can use the 5.5 mm x 2.1 mm power plug on the board.
That's important!
When using the Motor shield no wires are needed. Two motor channels are controlled by 4 pins. 2 PWM pins are responsible for the speed of rotation while 2 DIR pins for the direction of rotation. Usually, they are already linked with specific Arduino Board pins and their index numbers may differ depending on the manufacturer of the shield. For example, for my Motor shield, numbers are D4 D5 (DIR and PWM for the first channel) and D7 D6 (DIR and PWM for the second channel). For the original Arduino Motor shield, pins numbers correspond to D12 D3 (DIR and PWM for the first channel) and D13 D11 (DIR and PWM for the second channel).
That's important!
Hobby LiPo batteries do not have a reverse polarity protection Board! Accidental shorting of the positive and negative contacts will result in permanent battery failure or fire.
To make a program for such a racing robot is even easier than to assemble it.
In all my projects I use the XOD visual programming environment which allows me to create Arduino programs graphically without writing code. This environment is ideal for fast device prototyping or learning programming algorithms. Follow the XOD documentation web page to read more.
To program this robot, you need to add just one library amperka/octoliner into your XOD workspace. It is necessary for work with an eight-channel line sensor.
The program is based on the principle of a PID-controller operation. If you want to know what the PID-controller is and how it works you can read another article on this topic.
Take a look at the patch with the robot program. Let's see what nodes are present on it and how it all works.
octoliner-line
It is a quick-start node from the amperka/octoliner XOD library which represents the Octoliner module tracking the line. It outputs the "line tracking value" which lays in the range of -1 to 1. The 0 value shows that the line is at the center position relative to the infrared sensors on the Octoliner board (between CH3 and CH4). The -1 value corresponds to the extreme left position (CH0) while the 1 to the extreme right (CH1). On boot node initializes the optocoupler sensors and sets up their default brightness and sensitivity parameters. The inputs for this node are the I2C address of the device (ADDR for the Octoliner board it is 0x1A) and the line tracking value update rate (UPD), I set it continuous.
The line tracking values are fed directly to the pid-controller node.
pid-controller
This node implementing the work of the PID-controller in XOD. The target (TARG) value for it is 0. It is the state when the line is exactly at the center under the robot. If the line tracking value is 0, the PID-controller resets via RST pin. If the line tracking value is different from 0, the PID-controller converts It using Kp, Ki, Kd coefficients into the motor speed values. The coefficients values were selected experimentally and equal to 1, 0.2 and 0.5, respectively. The update rate (UPD) of the PID-controller is set to continuous.
The processed value of the PID-controller is subtracted from the 1 and added to the 1. It is done to desynchronize motors, to make them rotate in opposite directions when the line is lost. The 1 value in these nodes represents the maximum speed of the motors. You can reduce the speed by entering the lower value.
h-bridge-dc-motor
A couple of these nodes are responsible for controlling left and right robot motors. Here set the PWM and DIR pin values through which your Motor shield operates.
Flash the patch and try your racing bot. If you exactly follow assembly instructions, you do not need to change the patch or adjust the PID-controller. The specified settings are quite optimal.
The finished program can be found in the library gabbapeople/whiteboard-races