SiLi LiLa BOT (Simple Little Line-following Launchpad Robot)
SiLi LiLa BOT (Simple Little Line-following Launchpad Robot)
My aim was to build a cheap and simple line-following robot for beginners.During the design and construction, I tried to keep the robot as simple and cheap to build as possible. I used black electrician’s tape on a white carpet to make the line.
Block diagram of the Robot
Now I can summarize the robot design:
- The robot uses two DC motors and a castor wheel in a differential drive configuration (the steering of the robot is done by adjusting the speed of the motors).
- The speed and direction of the motors are controlled with PWM and digital signals by an L293D motor driver IC.
- The robot uses two battery (one for the electronics and one for the DC motors and motor controller circuits)
- The robot uses a Launchpad panel with a MSP430G2553 microcontroller
- The robot uses two sensors to determine the position of the black line beneath the robot.
By adjusting the speed of the two DC motors based on the sensor readings, the microcontroller can keep the line between the two sensors, and the robot could drive around the track.
Construction of the Robot
As the design is finalized, I can start building the robot.
Construction of the robot frame
The robot frame is made of two CD/DVDs to give enough structural strength. The lower deck will hold the 6V motor battery, two line detecting sensor, two DC motors and the castor wheel. The upper deck will hold the motor controller circuit attached to the Launchpad board and the 9V electronics battery.
The wheels are made from the lid of peanut butter jars.
There is enough space between the two decks to hold the motor battery pack.
The castor wheel should rotate freely around.
Construction of the Line Sensor
The sensors (LDR and LED pair) are assembled on a small perforated PCB.
The Line-following Algorithm
Before we could program the robot, we have to find an appropriate line following algorithm. At first we have to make test measurements with the line following sensor to be able to decide when a sensor is over the black line or the white carpet. Without switching on the electronics and motor power supply, I have connected the Launchpad panel to the PC with the USB cable to power the microcontroller and the line sensor. I have compiled and uploaded the attached code with the Energia IDE into the Launchpad panel (See next paragraph about the Energia IDE). The code reads the left and right sensor data and sends them to the PC via serial communication. The values can be displayed with the serial monitor.
If the sensor was over the black line, the measured ADC values were around 665-675. If the sensor was over the carpet, than the values were around 775-785. So we can use 720 as treshold value. If a sensor value is smaller than 720, then the sensor is over the line. If the sensor value is greater then 720, then it is over the carpet.
Now that we can decide when a sensor is over a line or the background, we can find a line following algorithm.
The microcontroller should read the sensor data, and based on that readings it should adjust the speed of the two DC motors to keep the line between the two sensors. So the robot could drive around the track. If the left sensor is over the line (the left sensor value is smaller than the 720 threshold value), than the robot should turn left (C). Similarly if the right sensor is over the line (the right sensor value is smaller than 720), than the robot should turn right (D). If both sensor value is greater than the threshold (the line is between the two sensors - A), or if both sensor value is smaller than the threshold (the robot approached to a line crossing - B), than the robot should go forward. To prevent oscillation, it is good idea to wait a couple ms before the next sensor measurement.
The line following algorithm displayed on a flowchart:
We should code this algorithm to Launchpad with the Arduino like Energia IDE.
The Energia IDE
Energia is an open-source electronics prototyping platform, which brings the Wiring and Arduino framework to the Texas Instruments MSP430 LaunchPad.
About downloading and installing the Energia IDE and about how to set up your board, see the following site:
About how to set up serial communication:
Loading the Code
Now the robot is nearly finished, it is time to load the code to the Launchpad panel. Make sure, that the MSP2553 chip is in the panel, and that the MSP2553 chip is selected from the “Tools/Board” menu (the attached code is for MSP430G2553 only, because this chip supports hardware UART, if you use other MSP430 Chips, which supports software UART only, than you have to use software serial communication softserial() in the Energia code instead of serial() ). Open the Energia IDE and copy the code from the attached text file into a blank sketch. After copied, press the Compile button to make sure there are no errors. Press the Upload button to load the compiled code into the Launchpad panel.
Understanding the Code
The Energia language is an implementation of Arduino to the Launchpad. So most of the Arduino projects and codes with small modofications can be directly transfered to the Launchpad.
In the main program, the loop() infinite cycle continously reading the left and right sensor data with the analogRead() command into two variables named LeftLDR and RightLDR. The if() and else if() commands decide which sensors are over the line or the carpet. Based on these decisions the microcontroller controls the motors according to the line following algorithm to keep the line between the two sensors.
To make the controlling of the robot easier, I have made the MotorLeft() and MotorRight() motor controlling functions. These functions need a parameter between -100 and 100 to control a motor (reverse 100% - forward 100%). In these motorcontroller functions, the motor direction is adjusted with the digitalWrite() command, and the motor speed is adjusted with the analogWrite() command.
THE END (Finally...)