Ultrasonic distance sensors are affordable, accurate, and easy to use. So as part of my involvement in an independent undergraduate research class at UCI, my goal was to integrate these sensors onto the Texas Instruments (TI) Basic Robotic System Learning Kit (RSLK) in place of the infrared sensors that come with the Advanced kit. I was successfully able to augment the TI-RSLK with these sensors and will provide details on how I accomplished this.
I began to integrate the distance sensors with the robot after assembling the TI-RSLK, installing Code Composer Studio (CCS), importing the RSLK files, and programming the motors in Lab 12 or 13 of TI's free online curriculum, You can find more information about the TI-RSLK curriculum at https://training.ti.com/ti-robotics-system-learning-kit or sites.uci.edu/orange. I used some mini breadboards to connect the sensors to Launchpad of the RSLK. Each distance sensor has four pins: Vcc, Echo, Trigger, and Ground. I connected each Vcc to a separate 5V pin on the launchpad, and the grounds are connected to the same ground pin. The other connections made from the robot to launchpad are listed below.
Middle Distance Sensor:TriggerPin: P6.4
EchoPin: P6.5
Left Distance Sensor:TriggerPin: P6.0
EchoPin: P3.2
Right Distance Sensor:TriggerPin: P4.1
EchoPin: P3.3
After making these connections, I began writing the code for the distance sensors. The source code for a single ultrasonic distance sensor, and three ultrasonic distance sensors are attached to this project. The source code includes many comments, so it should be easy to read and understand most of the code. However, I will discuss the main functions of the code here.
First, the void Distance_Init(void) function is used to set the launchpad pins to GPIO, echo pins to inputs, and trigger pins to outputs. This function must be called in the main function.
Next, the void SetDistance(int timeOut) functions are used to set the current distance fora sensor. There is a separate function for each distance sensor. The timeOut variable is used to limit the amount of time the distance sensors wait for the echo signal. Without the timeOut variable, this function could end up in an infinite loop.
The void CheckDistance(void) is a function that is periodically called using a timer interrupt. This function analyzes if the distance sensors have detected an object that is closer than a specific threshold value.
void AvoidObject(void) is a function that is called when an object is detected by the sensors. These functions currently contain code that simply tells the robot to turn in the opposite direction of the object detected.
In the int main(void), the robot is programmed to drive forward until an object is detected. It is important to initialize the motor, and launchpad, and enable interrupts in the main.
Additional information and resources about the RSLK can be found at sites.uci.edu/orange
Here are some videos of the RSLK with the ultrasonic distance sensors.
In the video above, the robot experienced some difficulties due to the walls being too short so the distance sensors were not always able to detect them.
Comments
Please log in or sign up to comment.