S14: Virtual Dog
Contents
Project Title : Virtual Dog - An Object Following Robot
One of our friend has a dog, who likes to play with remote control car. He used to run away from car when car approaches towards him, whereas if car runs away from him, he liked to follow the car! So we thought to make a toy which will do this job automatically. It will try to follow the object, but when object comes closer to it, it will move in opposite direction to maintain the predefined distance between object and itself. So, the name Virtual Dog! This concept can be used in many places, for creating many creative toys that will keep your kids and pets occupied, can be integrated with shopping carts, so that you’ll never need to carry you cart in the mall, the cart will follow you instead or can be integrated with vehicles, which will drive your vehicle automatically in heavy traffic.
Abstract
In this project we built a device which is capable of tracking and following a particular object. This tracking and following is done in two dimensions, i.e. not just forward-backward movement, but left-right also. This is achieved with help of multiple distance sensors mounted on a robot, and a target reference object. Robot continuously monitors the position of target object, if position of target object changes, robot rearranges its position so as to maintain the desired relationship between them.
Objectives & Introduction
The main objective is to build an object following robot, which will follow a particular object in 2-Dimension. To achieve this we divided our design in two parts, viz., sensor module and motor module.
Sensor module reads values from sensor, normalizes them and runs an algorithm that decides the position of target object. Output from this algorithm is given to motor driver module.
Motor driver module decides the speed and direction required to reposition robot, if required. It also generates appropriate PWM output to drive each individual motor so as to achieve resultant motion of a robot in desired direction with appropriate speed.
We also built an android application interfaced with the robot via Bluetooth. This application can start/stop the robot and monitor realtime sensor outputs, as well as display decisions taken by our algorithm.
Team Members & Responsibilities
- Hari
- Implemented Sensor Driver, Algorithm to normalize Sensor values, and Android Application.
- Manish
- Implemented Central Control Logic, and FSM.
- Viral
- Implemented Motor Driver, Motor State Machine, and Bluetooth Driver.
Schedule
Week# | Task | Estimated Completion Date |
Status | Notes |
---|---|---|---|---|
1 | Order Parts | 3/16 | Partially Completed | Not finalized with sensor for distance measurement. Ordered other parts. |
2 | Sensor Study | 3/23 | Completed (3/30) | Research on sensors took more time than expected due to speed constrains of sensors conflicting with our requirement. Finally decided to move with IR proximity sensor. Sensors ordered. |
3 | Sensor Controller Implementation | 3/30 | Completed (4/6) | Three sensors interfaced with on board ADC pins. Controller implemented to determine direction of movement based on those three sensors |
4 | Servo and Stepper Motor Controller Implementation | 4/6 | Completed (4/6) | Initially planned to use stepper motor for steering and servo to move robot. But due to power constraints, decided to use DC motors to make a 4WD robot. Controller implemented to move and turn robot based on differential wheel speeds. |
5 | Central Controller Logic Implementation | 4/13 | Completed (4/13) | Integrated both controllers and developed basic logic to control wheels based on sensor input. |
6 | Assembly and Building Final Chassis | 4/20 | Completed (4/20) | Mounted all hardware parts on chassis to make a standalone robot. Central controller logic is still tuning. |
7 | Unit Testing and Bug Fixing | 4/27 | Completed (5/4) | Tested various combinations of object movement and tuned our algorithm accordingly. Tuning of algorithm took more time than expected because of many corner cases. |
8 | Testing and Finishing Touch | 5/4 | Completed (5/11) | Faced strange problem at final stages. Earlier sensors were giving linear output for distance v/s ADC value. Over the period we realized that our robot is not following the way it used to follow earlier. So we need to calibrate distance v/s ADC value again, and based on that we required to change our algorithm. |
9 | Android Application using Bluetooth | - | Completed (5/22) | Developed an Android Application through which we can start and stop our robot and able to collect real-time data for sensor values as well as decisions taken by robot. |
Parts List & Cost
# | Part Description | Quantity | Manufacturer | Part No | Cost |
---|---|---|---|---|---|
1 | SJOne Board | 1 | Preet | - | $80.00 |
2 | IR Distance Sensor (20cm - 150cm) | 3 | Adafruit | GP2Y0A02YK | $47.85 |
3 | DC Motor (12V) | 4 | HSC Electronics | - | $6.00 |
4 | Wheels | 4 | Pololu | - | $8.00 |
5 | Battery 5V/1A 10000mAh | 1 | Amazon | - | $40 |
6 | Battery 12V/1A 3800mAh | 1 | Amazon | - | $25 |
7 | L2938D (Motor Driver IC) | 2 | HSC Electronic | - | $5.40 |
8 | Chassis | 2 | Walmart | - | $12.00 |
9 | Accessories (Jumper wires, Nut-Bolts, Prototype board, USB socket) | - | - | - | $20.00 |
10 | RN42-XV Bluetooth Module | 1 | Sparkfun | WRL-11601 | $20.95 |
Total (Excluding Shipping and Taxes) | $265.20 |
Design & Implementation
Hardware Design
System Block Diagram:
|
|
Proximity Sensor:
|
|
DC Motor:
|
|
L293D IC:
|
|
Bluetooth Module:
|
Hardware Interface
Software Design
Idea Behind Central Control Logic:
|
State Machine Diagram:
Based on the zones described earlier, we developed a state machine. Entire central logic relies on this state machine. Details of each state are described below:
|
|
Startup Process:
|
|
Sensor Driver:
|
|
Motor Driver:
|
Implementation
Proximity Sensor:
To determine the distance of object from robot with the help of proximity sensor we follow the below steps.
1. The proximity sensor detect the object present in front of it, based on object distance from it, it generate the analog value.
2. The analog value is given as input to ADC which converts this analog value to digital value.
3. Based on the digital value of all the three sensors a normalized algorithm is used which calculate the exact distance of object from sensor.
DC Motor:
To move the robot in a particular direction based on object movement we follow the below steps.
1. Based on the calculated distance from proximity sensor the PWM value is given to different motor.
2. The PWM act as input to the motor via L293D IC, based on this value the motor will accelerate.
Bluetooth Module:
To display the sensor value as well as decision taken by the robot on Android Application we follow the below steps.
1. The sensor value as well as decision taken by robot is send to the Bluetooth UART pin by the UART present on the SJOne board.
2. The UART of the Bluetooth send the data it received wirelessly to the Android device to which it is connected.
3. The Android Application display the data it received wirelessly from the Bluetooth module to which it is connected.
Movement of robot according to the movement of object:
When the object which the robot is following is in ZONE_CLOSE range with respect to middle sensor than the robot will move backward, when the object is in ZONE_IN range with respect to middle sensor than the robot will remain in stationary state, when the object is in ZONE_FAR range with respect to middle sensor than the robot will move forward and start following the object, when the object is in ZONE_TOO_FAR range with respect to middle sensor than the robot will move towards the object at very high speed. When the object is in ZONE_OUT_OF_RANGE than the robot will remain stationary and will notify that the object is out of range.
When the object tries to take left/right turn than it will move ZONE_OUT_OF_RANGE with respect to middle sensor but the left or right sensor will detect the object and move the robot accordingly till it come in ZONE_IN range with respect to middle sensor.
LED conventions:
The four LED’s present on the SJOne Board indicate the movement of the robot in the following way:
When the 1st and 4th LED is blinking simultaneously very fast than the robot is at stationary state and it is waiting for the object to come in its range i.e. object is in ZONE_OUT_OF_RANGE.
When the 1st and 4th LED and 2nd and 3rd LED are blinking alternately than it indicate the object is in ZONE_IN range.
When the 1st and 4th LED is blinking simultaneously than it indicates that the robot is moving in REVERSE direction so the object is in ZONE_CLOSE range.
When the 2nd and 3rd LED is blinking simultaneously than it indicates that the robot is moving in FORWARD direction so the object is in ZONE_TOO_FAR or ZONE_FAR range.
When the 3rd and 4th LED is blinking simultaneously than it indicates that the robot is taking RIGHT turn so that the robot can come in ZONE_IN range with respect to object.
When the 2nd and 1st LED is blinking simultaneously than it indicates that the robot is taking LEFT turn so that the robot can come in ZONE_IN range with respect to object.
When only 4th LED is blinking than it indicates that the robot is taking BACK RIGHT turn so that the robot can come in range with respect to object.
When only 1st LED is blinking than it indicates that the robot is taking BACK LEFT turn so that the robot can come in range with respect to object.
When all the four LED is blinking simultaneously than it indicate that the robot has detect some obstacle in its range.
Virtual DOG Android Application:
The Android application helps in communicating with the Bluetooth Module. The Bluetooth module is RN- 42. This module is directly placed over the location over the zigbee module on the LPC board. Communication between the devices is full duplex. The Initiation and the Termination of the Robot is controlled from the Android application.
On opening application, the Bluetooth has to be turned ON. There are two Buttons for turning the Bluetooth ON and OFF. For the Bluetooth to be turned ON, permissions are required from the Root User. If the authentication is performed, then the devices which are available in the range of the Bluetooth module are listed down using the discovery method of the device. The Module’s name is selected in the mobile. The devices are paired together using a key. The key provides the security feature over the transmission and reception.
There are two buttons. The ‘START’ and ‘STOP’ button which indicate the Robot to turn ON and OFF. This button is created in the XML. This language is used to build the UI functionalities. On clicking the START button, data is written to the Robot in order to indicate the Start status. The Robot starts sensing and sends the back the values along with the direction in which it moves. This is sent in the form as a metadata, so that the time taken for transmitting is less. This improves the performance. The Metadata which comprises of the sensor values and the direction is received until the stop button is pressed. A separate data is written for stopping the data. The Robot shuts down on receiving the data.
In order to connect to the Robot faster, a separate list has been created which maintains the list of the paired devices. This will show the devices which were connected previously.
There is a new fragment (page) created from the MainActivity which is created and the device is opened with that new fragment. On successful completion of the pairing, there are some threads which are made to run in the background. On creation of the instance of the new fragment page, a thread to read the data on the output stream runs as one of the background process. This buffer which is read should happen continuously until there is ‘\n’ or ‘\r’ character is read. If it read, then the data from the UART of the module is read.
Actual Implementation Images:
Robot Top View:
Robot Side View:
Robot Front View:
Testing & Technical Challenges
Motor Selection:
Stepper Motor:
Initially we plan to use the Stepper motor with our DC motor so that we can control the position of our robot very precisely. As the servo motor that we plan to use is very heavy due to which our chassis weight get increased to a extreme level, and there is torque degradation at higher speed in stepper motor which is not desirable for our project so we plan to drop the use of stepper motor.
Servo Motor:
Initially we plan to use the Servo motor instead of DC motor for our project so that we can provide a high torque to our robot wheels, but due to some disadvantage of servo motor like it continue to draw a high current when it is stuck at particular position make it undesirable for our project.
DC Motor:
Finally we select the DC motor instead of using Stepper motor and Servo Motor. There are some advantages of DC motor like they can run at very high RPM value, provide full rotation , continue to rotate until power is removed, can be easily controlled using PWM. This advantage of DC motor matches with the requirement of the motor that we are looking for our project.
Sensor Selection:
Nordic Wi-Fi:
Initially we plan to use Nordic Wi-Fi present on our SJ One board to calculate the distance between robot and the object so that accordingly we can change the position of the robot. When we perform the experiment between two Nordic Wi-Fi and tried calculating the distance between them the outcome result were not favorable, we were getting negligible change in the value when we change the position of one Wi-Fi module with respect to other. The outcome results were not desirable for our project so we drop the idea of using the Wi-Fi module.
Ultrasonic Sensor:
After getting the undesirable result from Wi-Fi we plan to use ultrasonic sensor to calculate the distance between the object and robot. When we perform the experiment the outcome result were not favorable, though the range of ultrasonic sensor was too good but the beam angle it generates to detect the object which come under its range was too high due to which it was able to detect a large number of object, so we were not able to calculate the exact distance between the original object and the robot. So we plan to drop the idea of using Ultrasonic Sensor.
Proximity Sensor:
We than plan to use the proximity sensor to calculate the distance between the object and robot. The proximity sensor we used to perform the experiment has a range of 20 cm to 150 cm, the outcome result from the experiment were favorable. We were able to calculate the exact distance between the robot and the object. So we decide to use the proximity sensor for our project to calculate the distance between robot and object.
Motor Calibration Issue:
As we decided to use DC motor for our project by performing a number of experiments, we plan to use 4 DC motor one for each wheel of the robot. After connecting DC motor to the wheels of the robot we check the alignment of all the four wheels, if they were not alignment we make all of them align by performing a number of hit and trial methods. The next issue is to run each motor at different speed at the same input given voltage so that we can control and move our robot in any direction. All the four motor speed is control individually by calculating the separate PWM value for each motor.
Sensor Calibration Issue:
As we decide to use proximity sensor for our project we have to solve a number of calibration issue related with this sensor. The first thing is we have to decide the number of sensor required for our project. We decided to begin our experiment using three sensors, the next thing we have to decide is the position where we can place these sensor on our robot. After performing a lot of experiment we found that if our target object comes in a range less than 20cm from our robot all the sensor start throwing some garbage value. So we decided to place the sensor at the back of robot with their face facing front so that the sensor will not through garbage values if the target object is very close to the robot. Now we have to decide the angle at which our sensor must be placed so that it can detect the target object anywhere between the angles of 0 to 180 degree. So after performing a number of experiments we place our three sensors at 45, 90 and 135 degree. After placing the sensor at the proper position the next thing we have to determine is the distance between the object and the robot. For this we use the normalization method on the sensor value so that we can predict the correct distance between the object and the robot.
Android Application Issue:
Operations involving the UI have the high Priority in the Android. Because of this, Updating the text Box with the sensor values and the direction will throw an IOexception. Because of this the application crashes.
Solution: Let the thread involving the receive function be executing as the background process and the UI update shall happen only after the execution of the receiving function.
Establishing the initial pairing between the devices caused some faults such as socket was not open or already read.
Solution: This was due to the sudden termination of the previous socket connection. The Socket has to be closed on Application exit, on all the catch exceptions and any sudden termination.
Conclusion
The Virtual Dog was a very challenging and research oriented project. Detailed analysis were made on various sensors while trying to implement the project.
The project was built on a small scale. This would work as a prototype to build the applications such as shopping cart following a person in crowded areas such as the grocery stores etc.
Project Video
Upload a video of your project and post the link here.
Project Source Code
Send me your zipped source code and I will upload this to SourceForge and link it for you.
References
Acknowledgement
The hardware components were made available from Amazon,Sparkfun, Adafruit. Thanks to Preetpal Kang for providing right guidance for our project.
References Used
LPC_USER_MANUAL
RN-42 Data Sheet
Socialledge Embedded Systems Wiki
L293D Data Sheet
IR Sensor Data Sheet