Difference between revisions of "S14: Virtual Dog"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Conclusion)
(Project Source Code)
 
(65 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[File:Example.jpg]]=== Grading Criteria ===
+
[[File:CmpE244_S14_vDog_angle.jpg|right|520px]]<br>
<strike>
+
 
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
</strike>
 
 
== Project Title : Virtual Dog - An Object Following Robot ==
 
== Project Title : Virtual Dog - An Object Following Robot ==
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.
 +
</p>
  
 
== Abstract ==
 
== Abstract ==
In this project, we build a device which would be able to track and follow a particular object. So if suppose that object is you, that device will follow you just like your dog. This tracking and following will be done in two dimensions, i.e. not just forward-backward movement, but left-right also. This can be achieved with the help of two devices, one will be used as reference and other device will continuously keep on monitoring the reference device. If position of reference device changes other device rearranges its position so as to maintain the desired relationship between them.
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.
 +
</p>
  
 
== Objectives & Introduction ==
 
== Objectives & Introduction ==
The main objective is to build an object following robot, which will follow a particular object in 2-Dimension. To make the robot follow at the same speed as of object we used four DC motor for the four wheels of robot so that it can accelerate the robot to desired speed. To keep track of object movement we used three proximity sensors (20cm-150cm) so that the robot can easily track the object. To power up the robot we used two batteries, one of 5V and other of 12V. 5V battery is used to power up the SJOne Board and 12V battery is required to run the DC motors. We have also implemented an Android App to start/stop robot and read the realtime statistics of sensors and our algorithm. To display the value of sensor as well as decision taken by robot on Android App we used Bluetooth module.
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 
+
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.  
 +
</p>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.
 +
</p>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.
 +
</p>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.
 +
</p>
 
=== Team Members & Responsibilities ===
 
=== Team Members & Responsibilities ===
 
*  Hari
 
*  Hari
**  Implemented sensor driver and algorithm to normalize sensor values, Android Application.
+
**  Implemented Sensor Driver, Algorithm to normalize Sensor values, and Android Application.
 
*  Manish
 
*  Manish
**  Implemented central control logic and FSM.
+
**  Implemented Central Control Logic, and FSM.
 
*  Viral
 
*  Viral
**  Implemented motor driver and Motor State Machine, bluetooth driver.
+
**  Implemented Motor Driver, Motor State Machine, and Bluetooth Driver.
  
 
== Schedule ==
 
== Schedule ==
Line 47: Line 51:
 
| 3/23
 
| 3/23
 
| Completed (3/30)
 
| Completed (3/30)
| Research on sensors took more time than expected due speed constrains of sensors conflicting with our requirement. Finally decided to move with IR proximity sensor. Sensors ordered.
+
| 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.
 
|-
 
|-
 
! scope="row"| 3
 
! scope="row"| 3
Line 87: Line 91:
 
! scope="row"| 9
 
! scope="row"| 9
 
| Android Application using Bluetooth
 
| Android Application using Bluetooth
| N/A
+
| -
 
| Completed (5/22)
 
| Completed (5/22)
| Developed an Android Application through which we can start and stop our robot and able to collect realtime data for sensor values as well as decisions taken by robot.
+
| 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.
 
|}
 
|}
  
Line 106: Line 110:
 
| 1
 
| 1
 
| Preet
 
| Preet
|  
+
| -
 
| $80.00
 
| $80.00
 
|-
 
|-
Line 120: Line 124:
 
| 4
 
| 4
 
| HSC Electronics
 
| HSC Electronics
|  
+
| -
 
| $6.00
 
| $6.00
 
|-
 
|-
Line 126: Line 130:
 
| Wheels
 
| Wheels
 
| 4
 
| 4
| Polulu
+
| Pololu
|  
+
| -
 
| $8.00
 
| $8.00
 
|-
 
|-
Line 134: Line 138:
 
| 1
 
| 1
 
| Amazon
 
| Amazon
|  
+
| -
 
| $40
 
| $40
 
|-
 
|-
Line 141: Line 145:
 
| 1
 
| 1
 
| Amazon
 
| Amazon
|  
+
| -
 
| $25
 
| $25
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
| LM2938D (Motor Driver IC)
+
| L2938D (Motor Driver IC)
 
| 2
 
| 2
 
| HSC Electronic
 
| HSC Electronic
|  
+
| -
 
| $5.40
 
| $5.40
 
|-
 
|-
Line 155: Line 159:
 
| 2
 
| 2
 
| Walmart
 
| Walmart
|  
+
| -
 
| $12.00
 
| $12.00
 
|-
 
|-
 
! scope="row"| 9
 
! scope="row"| 9
| Accessories (jumper wires, nut-bolts, prototype board, USB socket)
+
| Accessories (Jumper wires, Nut-Bolts, Prototype board, USB socket)
|  
+
| -
|  
+
| -
|  
+
| -
 
| $20.00
 
| $20.00
 
|-
 
|-
Line 181: Line 185:
  
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software design.  Organize this section using sub-sections that go over your design and implementation.
 
  
=== Hardware Design ===
+
=== <u>Hardware Design</u> ===
[[File:CmpE244_S14_vDog_system_block_diagram.bmp]]<br>All the three proximity sensor will measure their respective value analog and send it to the ADC pin of the SJOne board which will convert it to the digital value,the convert digital value will be utilized to determine the distance between the robot and the object. Based on the calculated distance the PWM value is determine for each DC motor, these PWM value is given as input to the DC motor via LM293D IC. The Bluetooth device will read the value of the sensor from the SJOne board through UART and send it to the Android App which will display the value of sensor as well as decision taken by robot.
+
<table>
  
<b>DC Motor</b>
+
<tr>
 +
<td valign="top" align="justify" width=400px>
 +
<b>System Block Diagram:</b>
 +
<br>
 +
The Hardware unit consist of three proximity sensors, SJOne board, four DC motors, bluetooth module, chassis, four wheels, and two batteries. All the three proximity sensors will measure their respective analog value and send it to the ADC pin of the SJOne board which will convert it to the digital value, the converted digital value will be utilized to determine the distance between the robot and the object. Based on the calculated distance the PWM value is determine for each DC motor, these PWM value is given as input to the DC motor via L293D IC. The Bluetooth device will read the value of the sensor from the SJOne board through UART and send it to the Android App which will display the real time value of the sensor as well as decision taken by robot.
 +
</td>
 +
<td>
 +
[[File:CmpE244_S14_vDog_system_block_diagram.bmp|300px]]
 +
</td>
 +
</tr>
  
[[File:CmpE244_S14_vDog_DC_motor.png|200px]]<br>We are using four DC motor for our project, the DC motor we are using has following rating 5-12V, 0.16Amp, 2000RPM. We are using DC motor so that we can provide 360 degree rotation to our robot wheel as well as it can help to drive the robot at a very high speed.
+
<tr>
 +
<td valign="top" align="justify">
 +
<b>Proximity Sensor:</b>
 +
<br>
 +
This SHARP distance sensor bounces IR off objects to determine how far away they are. It returns an analog voltage that can be used to determine how close the nearest object is. These sensors are good for detection between 20cm-150cm. We are using three sensors for our project so that our robot can trace the position of object accurately in two dimensions. This sensor provide less influence on the colors of the reflected objects and reflectivity, due to optical triangle measuring method. There is no need of any external circuitry for this sensor. The recommended operating supply voltage for this sensor is from 4.5V to 5.5V.
 +
</td>
 +
<td>
 +
[[File:CmpE244_S14_vDog_IR_sensor.png|200px]]
 +
</td>
 +
</tr>
  
<b>Proximity Sensor</b>
+
<tr>
 +
<td valign="top" align="justify">
 +
<b>DC Motor:</b>
 +
<br>
 +
We are using four DC motors for our project, with rating 5-12V operating voltage @ 0.16Amp, 2000RPM. We are using DC motor so that we can provide 360 degree rotation to our robot wheel as well as it help to drive the robot at a very high speed. DC Motor converts electric energy into mechanical energy. A DC Motor uses direct current - in other words, the direction of current flows in one direction. The speed of DC motors is controlled using Pulse Width Modulation (PWM), a technique of rapidly pulsing the power on and off. The percentage of time spent cycling the on/off ratio determines the speed of the motor.
 +
</td>
 +
<td>
 +
[[File:CmpE244_S14_vDog_DC_motor.png|300px]]
 +
</td>
 +
</tr>
  
[[File:CmpE244_S14_vDog_IR_sensor.png|200px]]<br>This SHARP distance sensor bounces IR off objects to determine how far away they are. It returns an analog voltage that can be used to determine how close the nearest object is. These sensors are good for detection between 20cm-150cm.
+
<tr>
 +
<td valign="top" align="justify">
 +
<b>L293D IC:</b>
 +
<br>
 +
L293D is a typical Motor driver or Motor Driver IC which allows DC motor to drive on either direction. L293D is a 16-pin IC which can control a set of two DC motors simultaneously in any direction. It means that you can control two DC motors with a single L293D IC. The L293D is designed to provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V.
 +
</td>
 +
<td>
 +
[[File:CmpE244_S14_vDog_L293D.png|200px]]
 +
</td>
 +
</tr>
  
<b>LM293D IC</b>
+
<tr>
 +
<td valign="top" align="justify">
 +
<b>Bluetooth Module:</b>
 +
<br>
 +
The RN-42 is compatible with the Bluetooth versions 2 and below. The advantage of using this module is it's low power and at the same time can provide a good data rate. This provides a high performance on chip antenna where data rates upto 3Mbps are transferred. The disadvantage is that, it has a very less distance which is approximately 20 meters. There is a pull up circuit of 1k to the Vcc. This is provided so that if the input power supply has instability or tends to bounce which causes the that device to be damaged. There is separate pin allocated for the Factory Reset such that this comes into the picture when the module is misconfigured. The toggle of the specific GPIO pins indicate the status of the module. When toggled at 1Hz, the module is discoverable and is waiting for a connection. When at 10Hz, it made to change to the command mode. If it is very low, then module is already connected to another device over the bluetooth.
 +
</td>
 +
<td>
 +
[[File:CmpE244_S14_vDog_bluetooth_device.png|200px]]
 +
</td>
 +
</tr>
  
[[File:CmpE244_S14_vDog_L293D.png|200px]]<br>L293D is a typical Motor driver or Motor Driver IC which allows DC motor to drive on either direction. L293D is a 16-pin IC which can control a set of two DC motors simultaneously in any direction. It means that you can control two DC motors with a single L293D IC.
+
</table>
  
<b>Bluetooth Module</b>
+
=== <u>Hardware Interface</u> ===
 +
<table>
 +
<tr>
 +
<td valign="top" align="center">
 +
Pin connections for IR Sensor through ADC:<br>
 +
[[File:CmpE244_S14_vDog_sensor_connections.bmp|260px]]
 +
</td>
 +
<td valign="top" align="center">
 +
Pin connections for Motor Driver using PWM:<br>
 +
[[File:CmpE244_S14_vDog_motor_connections.bmp|320px]]
 +
</td>
 +
<td valign="top" align="center">
 +
Pin connections for Bluetooth Device:<br>
 +
[[File:CmpE244_S14_vDog_bluetooth_connections.bmp|180px]]
 +
</td>
 +
</tr>
 +
</table>
  
[[File:CmpE244_S14_vDog_bluetooth_device.png|200px]]<br>The RN-42 is compatible with the Bluetooth versions 2 and below. The advantage of using this module is it's low power and at the same time can provide a good data rate. This provides a high performance on chip antenna where data rates upto 3Mbps are transferred. The disadvantage is that, it has a very less distance which is approximately 20 meters. There is a pull up circuit of 1k to the Vcc. This is provided so that if the input power supply has instability or tends to bounce which causes the that device to be damaged. There is separate pin allocated for the Factory Reset such that this comes into the picture when the module is misconfigured. The toggle of the specific GPIO pins indicate the status of the module. When toggled at 1Hz, the module is discoverable and is waiting for a connection. When at 10Hz, it made to change to the command mode. If it is very low, then module is already connected to another device over the bluetooth.
+
=== <u>Software Design</u> ===
 +
<table>
 +
<tr>
 +
<td>
 +
[[File:CmpE244_S14_vDog_range_zones.bmp|300px]]
 +
</td>
 +
<td valign="top" align="justify" width=400px>
 +
<b>Idea Behind Central Control Logic:</b>
 +
As we are using IR sensor for measuring the distance between object and robot, we divided area in front of robot in 5 different zones based on the range of IR sensor. Our algorithm tries to maintain the distance between object and robot in such a way that the object will always be in the Zone2:ZONE_IN_RANGE of the robot. When object moves in Zone3:ZONE_FAR, robot will start moving towards the object with medium speed. When object moves in Zone4:ZONE_TOO_FAR, robot detects that and will advance towards object with increased speed until object is not in range with robot, i.e. object is not in Zone2:ZONE_IN_RANGE. When object moves too fast or suddenly disappears, then robot is not able to determine the position of the object. In such scenarios, object is considered to be in the Zone5:ZONE_NOT_IN_RANGE. In such case, robot will stop and alarm the user with buzzer and LED indicator. When object moves closer to robot, object is considered to be in Zone1:ZONE_CLOSE. In such case, algorithm tells motor driver to move robot in backward direction. In all the above said zones, sensor values from all three sensors are monitored, and based on our algorithm, robot also detects left and right movement of object with four different types, viz., Forward Left, Forward Right, Backward Left and Backward Right.</td>
 +
</tr>
 +
</table>
  
=== Hardware Interface ===
+
<table>
Pin connections for IR sensor through ADC:<br>
+
<tr>
[[File:CmpE244_S14_vDog_sensor_connections.bmp]]
+
<td valign="top" align="justify" width=700px>
<br><br>
+
<b>State Machine Diagram:</b>
Pin connections for Motor Driver using PWM:<br>
+
<br>
[[File:CmpE244_S14_vDog_motor_connections.bmp]]
+
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:
<br><br>
+
*  VD_STOP: This is the default state, when robot starts, it’s state first initialized to VD_STOP. When object is in Zone2, then also FSM is this state. In this state motor driver stops all the motors. If object moves to other zones, then FSM state is changed accordingly.
Pin connections for Bluetooth Device for Andoird App<br>
+
*  VD_FWD: When object moves to Zone3 or Zone4, FSM is in this state. Based on the distance, motor driver drives the motors with appropriate speed when in this state. If object is detected in Zone2, FSM state is changed back to VD_STOP. If object suddenly disappears from middle sensor, FSM state is changed to VD_TURN.
[[File:CmpE244_S14_vDog_bluetooth_connections.bmp]]
+
*  VD_REV: When object moves to Zone1, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will move backwards. If object is detected in Zone2, FSM state is changed back to VD_STOP. If object suddenly disappears from middle sensor, FSM state is changed to VD_TURN.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td>
 +
[[File:CmpE244_S14_vDog_state_machine.bmp|700px]]
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="justify" width=700px>
 +
*  VD_FWD_LEFT: If object is detected in Zone3 or Zone4 of left sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take left turn in forward direction. Robot will remain in this state until object is not detected back in Zone2 or Zone3 or Zone4 of middle sensor.
 +
*  VD_FWD_RIGHT: If object is detected in Zone3 or Zone4 of right sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take right turn in forward direction. Robot will remain in this state until object is not detected back in Zone2 or Zone3 or Zone4 of middle sensor.
 +
*  VD_REV_LEFT: If object is detected in Zone1 or Zone2 of right sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take left turn in backward direction. Robot will remain in this state until object is not detected back in Zone1 or Zone2 or Zone3 or Zone4 of middle sensor.
 +
*  VD_REV_RIGHT: If object is detected in Zone1 or Zone2 of left sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take right turn in backward direction. Robot will remain in this state until object is not detected back in Zone1 or Zone2 or Zone3 or Zone4 of middle sensor.
 +
*  VD_TURN: When object suddenly disappears from middle sensor, FSM is in this state. In this state, motor driver stops all the motors. FSM remains in this state until object is detected by either of the sensor. Based on which sensor detects the object, FSM state is changed to appropriate state.
 +
*  VD_ALARM: If any other object/obstacle appears suddenly in between target object and robot, FSM is in this state. Motor driver stops all motors, and user is alarmed with the help of buzzer and blinking LED indicator.
 +
</td>
 +
</tr>
 +
</table>
  
=== Software Design ===
+
<table>
<b>State Machine Diagram</b><br>
+
<tr>
[[File:CmpE244_S14_vDog_state_machine.bmp]]
+
<td width=300px align="center">
<br>
 
<b>Startup Process Flowchart</b><br>
 
 
[[File:CmpE244_S14_vDog_flowchart_startup.bmp]]
 
[[File:CmpE244_S14_vDog_flowchart_startup.bmp]]
 +
</td>
 +
<td valign="top" align="justify" width=400px>
 +
<b>Initialization:</b>
 
<br>
 
<br>
On Start of the ROBOT, the ADC is initialised for the reading the data. This is used to calculate which zone the object lies. Based on this decision, the robot has to decide whether it should follow, stop or turn in any other direction. This is performed by initialising the PWM. If any other obstacle comes in between the range of the object and the robot, then the buzzer is activated and hence buzz sound is produced. The Bluetooth for the UART is initialised so that this is used for the communication between the Android application and ROBOT. With the help of the Application the Robot is started. This activates the sensor task so that data is read from all the three sensors. Based on the sensor readings and after the normalization of the data read, decision is made on which direction the Robot should move. Using the Motor Driver Task and with the help of the decision made, the motors are made to rotate in the appropriate direction. Finally, the values and the direction which are decided are sent to the Bluetooth task. This task functions in transmitting and receiving the data to the android application. This application also used to start and stop the robot.
+
On start process mainly does the initialization job. It initializes ADC pins (P0.26, P1.31, P1.30) that are used by IR sensors. Then PWM pins P2.1 through P2.4 are initialized for motor driver. We use GPIO to sound the buzzer, so GPIO pin P1.23 is configured as output in the init process. We use Bluetooth to connect to android device. Bluetooth device is connected via UART2 on the board. So init process also contains code part to init UART2 for Bluetooth device. After everything is set, three tasks start running, viz., sensor task, motor task and Bluetooth task. Sensor task continuously reads the sensor values, normalizes them and invokes our algorithm/FSM. Motor task generates appropriate PWM signals based on the current FSM state. Bluetooth task communicates with Android Application.
<br><br>
+
</td>
<b>Sensor Driver Flowchart</b><br>
+
</tr>
 +
 
 +
<tr>
 +
<td width=300px align="center">
 
[[File:CmpE244_S14_vDog_flowchart_sensor.bmp]]
 
[[File:CmpE244_S14_vDog_flowchart_sensor.bmp]]
 +
</td>
 +
<td valign="top" align="justify" width=400px>
 +
<b>Sensor Driver:</b>
 
<br>
 
<br>
In the Sensor Driver Task, the sensor values from all the three proximity sensors are read. They are normalized by using calculating the mean of the previous 30 sensor values. Based on this, the object position is determined. If the object is located in the Zone 1 of the middle sensor, then the finite state machine is changed to reverse. The robot moves until the original position is achieved. If the object is located in the       Zone 3 and Zone 4 of the middle sensor, then finite state machine is moved to the Forward state which causes the robot to move forward. The left sensor detects the object if it is in Zone 1 and Zone 2. Based on the decision, the finite state machine is changed to reverse right. This moves the robot in the reverse right direction causing the direction of the robot to turn left. The right sensor detects the object if it is in Zone 1 and Zone 2, and the finite state machine is moved to the reverse left. This causes to change the direction of the robot to the right. The left sensor detects the object if it is in Zone 3 and Zone 4. Based on the decision, the finite state machine is changed to forward left. This moves the robot in the forward and left direction causing the direction of the robot to turn left. The right sensor detects the object if it is in Zone 3 and Zone 4, and the finite state machine is moved to the forward right. This causes to change the direction of the robot to the right. Thus based on the sensor values, the next stage of the Finite State Machine is decided and moves to that particular state.
+
In the Sensor Driver Task, the sensor values from all the three proximity sensors are read. They are normalized by using calculating the median of the previous 30 sensor values. Based on this, the object position is determined. If the object is located in the Zone 1 of the middle sensor, then the finite state machine is changed to reverse. The robot moves until the original position is achieved. If the object is located in the Zone 3 and Zone 4 of the middle sensor, then finite state machine is moved to the Forward state which causes the robot to move forward. If the left sensor detects the object in Zone 1 and Zone 2, the finite state machine is changed to reverse right. This moves the robot in the reverse right direction causing the direction of the robot indirectly to turn left. If the right sensor detects the object in Zone 1 and Zone 2, and the finite state machine is moved to the reverse left. This causes to change the direction of the robot indirectly to the right. If the left sensor detects the object in Zone 3 and Zone 4, the finite state machine is changed to forward left. This moves the robot in the forward and left direction causing the direction of the robot to turn left. If the right sensor detects the object in Zone 3 and Zone 4, the finite state machine is moved to the forward right. This causes to change the direction of the robot to the right. Thus based on the sensor values, the next stage of the Finite State Machine is decided and robot is move to that particular zone.
<br><br>
+
</td>
<b>Motor Driver Flowchart</b><br>
+
</tr>
 +
 
 +
<tr>
 +
<td width=300px align="center">
 
[[File:CmpE244_S14_vDog_flowchart_motor.bmp]]
 
[[File:CmpE244_S14_vDog_flowchart_motor.bmp]]
 +
</td>
 +
<td valign="top" align="justify" width=400px>
 +
<b>Motor Driver:</b>
 +
<br>
 +
In the Motor Driver task, the finite state machine is read for each entry of the sensor data. Based on the state machine the Robot decides on the direction to move. If the decision made is forward, then the front two wheels which are connected to the driver are made to move. This causes the device to move forward. If it is forward left, then the front left wheel speed is decreased. This causes the device to turn left. If it is forward right, then the front right wheel speed is decreased. This causes the device to turn left. If the decision made is reverse, the wheels are made to rotate in the opposite direction. If it is reverse left, then the back left wheel direction is opposite and the speed is decreased. This causes the device to turn reverse left. If it is reverse right, then the back right wheel rotates in the opposite direction and the speed is decreased. This causes the device to turn reverse right. With the help of all the decisions, the Robot can be made to rotate 360 degree making the Robot to detect the object’s range and moving in appropriate direction. Finally, after Robot has moved such that the object comes into the ZONE_2, all the state machines are reset. This loop occurs until there is an indicator received telling the Robot to stop.
 +
</td>
 +
</tr>
 +
</table>
 +
 +
<table>
 +
<tr>
 +
<td valign="top" align="justify" width=340px>
 +
<b>Virtual DOG Android Application:</b>
 +
<br>
 +
The Android application helps in communicating with the Bluetooth module. The Bluetooth module is RN- 42. This module is directly placed in the location given for 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.
 
<br>
 
<br>
In the Motor Driver task, the finite state machine is read for each entry of the sensor data. Based on the state machine the Robot decides on the direction to move. If the decision made is forward, then the front two wheels which are connected to the driver are made to move. This causes the device to move forward. If it is forward left, then the front left wheel’s speed is decreased. This causes the device to turn left. If it is forward right, then the front right wheel speed is decreased. This causes the device to turn left. If the decision made is reverse, the wheels are made to rotate in the opposite direction. If it is reverse left, then the back left wheel’s direction is opposite and the speed is decreased. This causes the device to turn reverse left. If it is reverse right, then the back right wheel’s direction rotates in the opposite direction and the speed is decreased. This causes the device to turn reverse right. With the help of all the decisions, the Robot can be made to rotate 360 degree making the Robot to detect the object’s range and moving in appropriate direction. Finally, after Robot has moved such that the object comes into the ZONE_2, all the state machines are reset. This loop occurs until there is an indicator received telling the Robot to stop.
+
On opening the 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 is required from the 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.
 +
<br>
 +
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 send back the values along with the direction in which it moves. This is sent in the form of 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 stops on receiving this data.
 +
<br>
 +
In order to connect with 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.
 +
<br>
 +
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.
 +
</td>
 +
<td width=400px align="center">
 +
[[File:CmpE244_S14_vDog_android_flowchart.png]]
 +
</td>
 +
</tr>
 +
</table>
  
=== Implementation ===
+
=== <u>Implementation</u> ===
<b>Proximity Sensor:</b><br>
 
To determine the distance of object from robot with the help of proximity sensor we follow the below steps.<br>
 
1. The proximity sensor detect the object present in front of it, based on object distance from it, it  generate the analog value.<br>
 
2. The analog value is given as input to ADC which converts this analog value to digital value.<br>
 
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.<br><br>
 
<b>DC Motor:</b><br>
 
To move the robot in a particular direction based on object movement we follow the below steps.<br>
 
1. Based on the calculated distance from proximity sensor the PWM value is given to different motor.<br>
 
2. The PWM act as input to the motor via L293D IC, based on this value the motor will accelerate.<br><br>
 
<b>Bluetooth Module:</b><br>
 
To display the sensor value as well as decision taken by the robot on Android Application we follow the below steps.<br>
 
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.<br>
 
2. The UART of the Bluetooth send the data it received wirelessly to the Android device to which it is connected. <br>
 
3. The Android Application display the data it received wirelessly from the Bluetooth module to which it is connected.<br>
 
  
<b>Movement of robot according to the movement of object: </b><br>
+
<br><b>Actual Implementation Images:</b><br>
[[File:CmpE244_S14_vDog_range_zones.bmp]]<br>
+
<table>
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.<br>
+
<tr>
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.<br><br>
+
<td valign="top" align="center">
The four LED’s present on the SJOne Board indicate the movement of the robot in the following way.<br>
+
Front View:<br>
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.<br>
+
[[File:CmpE244_S14_vDog_front_view.jpg|360px]]
When the 1st and 4th LED and 2nd and 3rd LED are blinking alternately than it indicate the object is in ZONE_IN range.<br>
+
</td>
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.<br>
+
<td valign="top" align="center">
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.<br>
+
Side View:<br>
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.<br>
+
[[File:CmpE244_S14_vDog_side_view.png|360px]]
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.<br>
+
</td>
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.<br>
+
<td valign="top" align="center">
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.<br>
+
Top View:<br>
When all the four LED is blinking simultaneously than it indicate that the robot has detect some obstacle in its range.<br>
+
[[File:CmpE244_S14_vDog_top_view.jpg|400px]]
 +
</td>
 +
</tr>
 +
</table>
 +
 
 +
<br><b>Application Screenshots:</b><br>
 +
<table>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_android_app_01.png]]
 +
</td>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_android_app_02.png]]
 +
</td>
 +
</tr>
 +
</table>
 +
 
 +
<br><b>LED Conventions:</b><br>
 +
<table>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_stop.gif|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When 1st and 4th LED are blinking, it indicates that object is in range, i.e. Zone2 and FSM state is VD_STOP.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_fwd.bmp|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When 2nd and 3rd LED glows continuously, it indicates that object has moved forward, i.e. in Zone3/Zone4 and FSM state is VD_FWD.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_rev.bmp|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When 1st and 4th LED glows continuously, it indicates that object is coming closer, i.e. in Zone1 and FSM state is VD_REV.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_turn.gif|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When 1st and 4th LED blinks, it indicates that object is taking turn, and robot is trying to figure out where the object has turned and FSM state is VD_TURN. If robot is not able to find out turned object, it means that object has moved out of range.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_fwdleft.bmp|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When 1st and 2nd LED glows continuously, it indicates that object is turning to left and FSM state is VD_FWD_LEFT.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_fwdright.bmp|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When 3rd and 4th LED glows continuously, it indicates that object is turning to right and FSM state is VD_FWD_RIGHT.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_revleft.bmp|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When only 1st LED glows continuously, it indicates that object is turning to left but in backward direction and FSM state is VD_REV_LEFT.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_revright.bmp|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When only 4th LED glows continuously, it indicates that object is turning to right but in backward direction and FSM state is VD_REV_RIGHT.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top" align="center">
 +
[[File:CmpE244_S14_vDog_vd_alarm.gif|200px]]
 +
</td>
 +
<td valign="top" align="justify" width=500px>
 +
When all LEDs blink fast, it indicates that some obstacle has detected and FSM state is VD_ALARM.
 +
</td>
 +
</tr>
 +
</table>
  
 
== Testing & Technical Challenges ==
 
== Testing & Technical Challenges ==
<b>MOTOR SELECTION</b><br>
+
<b>Normalization Algorithm:</b><br>
Stepper Motor:<br>
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
Values retrieved from sensor are not stable. So we required to develop an algorithm that will give stable values from sensor. It should also remove spikes. We experimented a lot with this regard and finally developed an algorithm that gives fairly stable value of sensor without hampering the performance. Following graphs shows the Experiment results:
 +
<br>
 +
[[File:CmpE244_S14_vDog_actual_sensor.png|700px]]
 +
<br>
 +
Above graph shows experimental results of actual sensor values, when object is moved from right to left. It is clearly visible in the graph that values are not stable and also has many spikes.
 +
<br>
 +
[[File:CmpE244_S14_vDog_mean_sensor.png|700px]]
 +
<br>
 +
Above graph shows experimental results of mean/average of past 30 values of sensor. These values are fairly stable, but it does not help to detect object if object moves very fast.
 +
<br>
 +
[[File:CmpE244_S14_vDog_median_sensor.png|700px]]
 +
<br>
 +
Above graph shows experimental results of median of past 30 values. These are the most stable value that we could find out. So we used median to calculate sensor values, and used these values in our algorithm.
 +
</p>
 +
 
 +
<b>Motor Selection:</b><br>
 +
<i>Stepper Motor:</i><br>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 
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.<br>
 
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.<br>
Servo Motor:<br>
+
</p>
 +
<i>Servo Motor:</i><br>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 
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.<br>
 
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.<br>
DC Motor:<br>
+
</p>
 +
<i>DC Motor:</i><br>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 
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.<br>
 
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.<br>
 +
</p>
  
<b>SENSOR SELECTION</b><br>
+
<b>Sensor Selection:</b><br>
Nordic Wi-Fi:<br>
+
<i>Nordic Wi-Fi:</i><br>
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 to Nordic Wi-Fi and tried calculating the distance between them the outcome result were not favourable, we were 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.<br>
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
Ultrasonic Sensor:<br>
+
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.<br>
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 favourable, 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.<br>
+
</p>
Proximity Sensor:<br>
+
<i>Ultrasonic Sensor:</i><br>
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 20cm to 150cm, the outcome result from the experiment were favourable. 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.<br>
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.<br>
 +
</p>
 +
<i>Proximity Sensor:</i><br>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.<br>
 +
</p>
  
<b>Motor Calibration Issue</b><br>
+
<b>Motor Calibration Issue:</b><br>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 
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.<br>
 
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.<br>
 +
</p>
  
<b>Sensor Calibration Issue</b><br>
+
<b>Sensor Calibration Issue:</b><br>
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 from 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 sensor at 45, 90 and 135 degree. After placing the sensor at the proper position the next thing we have to determine is the direction in which our robot will move based on the sensor values. For this we use the normalization method on the sensor value so that we can predict the correct direction in which we have to move our robot. <br>
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.<br>
 +
</p>
  
<b>Android Application Issue</b><br>
+
<b>Android Application Issue:</b><br>
 +
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 
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.<br>
 
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.<br>
 
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. <br>
 
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. <br>
 
Establishing the initial pairing between the devices caused some faults such as socket was not open or already read. <br>
 
Establishing the initial pairing between the devices caused some faults such as socket was not open or already read. <br>
 
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. <br>
 
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. <br>
 +
</p>
  
 
== Conclusion ==
 
== 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. <br>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.
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
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.
 +
</p>
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
http://youtu.be/njPgVcvl1cQ
 +
</p>
  
 
=== Project Source Code ===
 
=== Project Source Code ===
Send me your zipped source code and I will upload this to SourceForge and link it for you.
+
*  [https://sourceforge.net/projects/sjsu/files/CmpE244_SJSU_S2014/ Sourceforge source code link]
  
 
== References ==
 
== References ==
 
=== Acknowledgement ===
 
=== Acknowledgement ===
The hardware components were made available from Amazon,Sparkfun, Adafruit. Thanks to Preetpal Kang for providing right guidance for our project.
+
<p style="text-indent: 1em; width: 700px; text-align: justify;">
 +
The hardware components were made available from Amazon, Sparkfun, Adafruit. Thanks to Preetpal Kang for providing right guidance for our project.
 +
</p>
  
 
=== References Used ===
 
=== References Used ===
 +
<p style="width: 700px; text-align: justify;">
 
[http://www.nxp.com/documents/data_sheet/LPC1769_68_67_66_65_64_63.pdf LPC_USER_MANUAL] <br>
 
[http://www.nxp.com/documents/data_sheet/LPC1769_68_67_66_65_64_63.pdf LPC_USER_MANUAL] <br>
 
[http://www.mouser.com/catalog/specsheets/rn-42-ds-v2.31r.pdf RN-42 Data Sheet]<br>
 
[http://www.mouser.com/catalog/specsheets/rn-42-ds-v2.31r.pdf RN-42 Data Sheet]<br>
Line 310: Line 558:
 
[http://www.ti.com/lit/ds/symlink/l293d.pdf L293D Data Sheet] <br>
 
[http://www.ti.com/lit/ds/symlink/l293d.pdf L293D Data Sheet] <br>
 
[http://sharp-world.com/products/device/lineup/data/pdf/datasheet/gp2y0a02_e.pdf IR Sensor Data Sheet] <br>
 
[http://sharp-world.com/products/device/lineup/data/pdf/datasheet/gp2y0a02_e.pdf IR Sensor Data Sheet] <br>
 
+
</p>
=== Appendix ===
 
You can list the references you used.
 

Latest revision as of 23:42, 6 August 2014

CmpE244 S14 vDog angle.jpg

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:
The Hardware unit consist of three proximity sensors, SJOne board, four DC motors, bluetooth module, chassis, four wheels, and two batteries. All the three proximity sensors will measure their respective analog value and send it to the ADC pin of the SJOne board which will convert it to the digital value, the converted digital value will be utilized to determine the distance between the robot and the object. Based on the calculated distance the PWM value is determine for each DC motor, these PWM value is given as input to the DC motor via L293D IC. The Bluetooth device will read the value of the sensor from the SJOne board through UART and send it to the Android App which will display the real time value of the sensor as well as decision taken by robot.

CmpE244 S14 vDog system block diagram.bmp

Proximity Sensor:
This SHARP distance sensor bounces IR off objects to determine how far away they are. It returns an analog voltage that can be used to determine how close the nearest object is. These sensors are good for detection between 20cm-150cm. We are using three sensors for our project so that our robot can trace the position of object accurately in two dimensions. This sensor provide less influence on the colors of the reflected objects and reflectivity, due to optical triangle measuring method. There is no need of any external circuitry for this sensor. The recommended operating supply voltage for this sensor is from 4.5V to 5.5V.

CmpE244 S14 vDog IR sensor.png

DC Motor:
We are using four DC motors for our project, with rating 5-12V operating voltage @ 0.16Amp, 2000RPM. We are using DC motor so that we can provide 360 degree rotation to our robot wheel as well as it help to drive the robot at a very high speed. DC Motor converts electric energy into mechanical energy. A DC Motor uses direct current - in other words, the direction of current flows in one direction. The speed of DC motors is controlled using Pulse Width Modulation (PWM), a technique of rapidly pulsing the power on and off. The percentage of time spent cycling the on/off ratio determines the speed of the motor.

CmpE244 S14 vDog DC motor.png

L293D IC:
L293D is a typical Motor driver or Motor Driver IC which allows DC motor to drive on either direction. L293D is a 16-pin IC which can control a set of two DC motors simultaneously in any direction. It means that you can control two DC motors with a single L293D IC. The L293D is designed to provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V.

CmpE244 S14 vDog L293D.png

Bluetooth Module:
The RN-42 is compatible with the Bluetooth versions 2 and below. The advantage of using this module is it's low power and at the same time can provide a good data rate. This provides a high performance on chip antenna where data rates upto 3Mbps are transferred. The disadvantage is that, it has a very less distance which is approximately 20 meters. There is a pull up circuit of 1k to the Vcc. This is provided so that if the input power supply has instability or tends to bounce which causes the that device to be damaged. There is separate pin allocated for the Factory Reset such that this comes into the picture when the module is misconfigured. The toggle of the specific GPIO pins indicate the status of the module. When toggled at 1Hz, the module is discoverable and is waiting for a connection. When at 10Hz, it made to change to the command mode. If it is very low, then module is already connected to another device over the bluetooth.

CmpE244 S14 vDog bluetooth device.png

Hardware Interface

Pin connections for IR Sensor through ADC:
CmpE244 S14 vDog sensor connections.bmp

Pin connections for Motor Driver using PWM:
CmpE244 S14 vDog motor connections.bmp

Pin connections for Bluetooth Device:
CmpE244 S14 vDog bluetooth connections.bmp

Software Design

CmpE244 S14 vDog range zones.bmp

Idea Behind Central Control Logic:

As we are using IR sensor for measuring the distance between object and robot, we divided area in front of robot in 5 different zones based on the range of IR sensor. Our algorithm tries to maintain the distance between object and robot in such a way that the object will always be in the Zone2:ZONE_IN_RANGE of the robot. When object moves in Zone3:ZONE_FAR, robot will start moving towards the object with medium speed. When object moves in Zone4:ZONE_TOO_FAR, robot detects that and will advance towards object with increased speed until object is not in range with robot, i.e. object is not in Zone2:ZONE_IN_RANGE. When object moves too fast or suddenly disappears, then robot is not able to determine the position of the object. In such scenarios, object is considered to be in the Zone5:ZONE_NOT_IN_RANGE. In such case, robot will stop and alarm the user with buzzer and LED indicator. When object moves closer to robot, object is considered to be in Zone1:ZONE_CLOSE. In such case, algorithm tells motor driver to move robot in backward direction. In all the above said zones, sensor values from all three sensors are monitored, and based on our algorithm, robot also detects left and right movement of object with four different types, viz., Forward Left, Forward Right, Backward Left and Backward Right.

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:

  • VD_STOP: This is the default state, when robot starts, it’s state first initialized to VD_STOP. When object is in Zone2, then also FSM is this state. In this state motor driver stops all the motors. If object moves to other zones, then FSM state is changed accordingly.
  • VD_FWD: When object moves to Zone3 or Zone4, FSM is in this state. Based on the distance, motor driver drives the motors with appropriate speed when in this state. If object is detected in Zone2, FSM state is changed back to VD_STOP. If object suddenly disappears from middle sensor, FSM state is changed to VD_TURN.
  • VD_REV: When object moves to Zone1, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will move backwards. If object is detected in Zone2, FSM state is changed back to VD_STOP. If object suddenly disappears from middle sensor, FSM state is changed to VD_TURN.

CmpE244 S14 vDog state machine.bmp

  • VD_FWD_LEFT: If object is detected in Zone3 or Zone4 of left sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take left turn in forward direction. Robot will remain in this state until object is not detected back in Zone2 or Zone3 or Zone4 of middle sensor.
  • VD_FWD_RIGHT: If object is detected in Zone3 or Zone4 of right sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take right turn in forward direction. Robot will remain in this state until object is not detected back in Zone2 or Zone3 or Zone4 of middle sensor.
  • VD_REV_LEFT: If object is detected in Zone1 or Zone2 of right sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take left turn in backward direction. Robot will remain in this state until object is not detected back in Zone1 or Zone2 or Zone3 or Zone4 of middle sensor.
  • VD_REV_RIGHT: If object is detected in Zone1 or Zone2 of left sensor, FSM is in this state. In this state, motor driver generates PWM signal in such a way that robot will take right turn in backward direction. Robot will remain in this state until object is not detected back in Zone1 or Zone2 or Zone3 or Zone4 of middle sensor.
  • VD_TURN: When object suddenly disappears from middle sensor, FSM is in this state. In this state, motor driver stops all the motors. FSM remains in this state until object is detected by either of the sensor. Based on which sensor detects the object, FSM state is changed to appropriate state.
  • VD_ALARM: If any other object/obstacle appears suddenly in between target object and robot, FSM is in this state. Motor driver stops all motors, and user is alarmed with the help of buzzer and blinking LED indicator.

CmpE244 S14 vDog flowchart startup.bmp

Initialization:
On start process mainly does the initialization job. It initializes ADC pins (P0.26, P1.31, P1.30) that are used by IR sensors. Then PWM pins P2.1 through P2.4 are initialized for motor driver. We use GPIO to sound the buzzer, so GPIO pin P1.23 is configured as output in the init process. We use Bluetooth to connect to android device. Bluetooth device is connected via UART2 on the board. So init process also contains code part to init UART2 for Bluetooth device. After everything is set, three tasks start running, viz., sensor task, motor task and Bluetooth task. Sensor task continuously reads the sensor values, normalizes them and invokes our algorithm/FSM. Motor task generates appropriate PWM signals based on the current FSM state. Bluetooth task communicates with Android Application.

CmpE244 S14 vDog flowchart sensor.bmp

Sensor Driver:
In the Sensor Driver Task, the sensor values from all the three proximity sensors are read. They are normalized by using calculating the median of the previous 30 sensor values. Based on this, the object position is determined. If the object is located in the Zone 1 of the middle sensor, then the finite state machine is changed to reverse. The robot moves until the original position is achieved. If the object is located in the Zone 3 and Zone 4 of the middle sensor, then finite state machine is moved to the Forward state which causes the robot to move forward. If the left sensor detects the object in Zone 1 and Zone 2, the finite state machine is changed to reverse right. This moves the robot in the reverse right direction causing the direction of the robot indirectly to turn left. If the right sensor detects the object in Zone 1 and Zone 2, and the finite state machine is moved to the reverse left. This causes to change the direction of the robot indirectly to the right. If the left sensor detects the object in Zone 3 and Zone 4, the finite state machine is changed to forward left. This moves the robot in the forward and left direction causing the direction of the robot to turn left. If the right sensor detects the object in Zone 3 and Zone 4, the finite state machine is moved to the forward right. This causes to change the direction of the robot to the right. Thus based on the sensor values, the next stage of the Finite State Machine is decided and robot is move to that particular zone.

CmpE244 S14 vDog flowchart motor.bmp

Motor Driver:
In the Motor Driver task, the finite state machine is read for each entry of the sensor data. Based on the state machine the Robot decides on the direction to move. If the decision made is forward, then the front two wheels which are connected to the driver are made to move. This causes the device to move forward. If it is forward left, then the front left wheel speed is decreased. This causes the device to turn left. If it is forward right, then the front right wheel speed is decreased. This causes the device to turn left. If the decision made is reverse, the wheels are made to rotate in the opposite direction. If it is reverse left, then the back left wheel direction is opposite and the speed is decreased. This causes the device to turn reverse left. If it is reverse right, then the back right wheel rotates in the opposite direction and the speed is decreased. This causes the device to turn reverse right. With the help of all the decisions, the Robot can be made to rotate 360 degree making the Robot to detect the object’s range and moving in appropriate direction. Finally, after Robot has moved such that the object comes into the ZONE_2, all the state machines are reset. This loop occurs until there is an indicator received telling the Robot to stop.

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 in the location given for 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 the 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 is required from the 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 send back the values along with the direction in which it moves. This is sent in the form of 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 stops on receiving this data.
In order to connect with 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.

CmpE244 S14 vDog android flowchart.png

Implementation


Actual Implementation Images:

Front View:
CmpE244 S14 vDog front view.jpg

Side View:
CmpE244 S14 vDog side view.png

Top View:
CmpE244 S14 vDog top view.jpg


Application Screenshots:

CmpE244 S14 vDog android app 01.png

CmpE244 S14 vDog android app 02.png


LED Conventions:

CmpE244 S14 vDog vd stop.gif

When 1st and 4th LED are blinking, it indicates that object is in range, i.e. Zone2 and FSM state is VD_STOP.

CmpE244 S14 vDog vd fwd.bmp

When 2nd and 3rd LED glows continuously, it indicates that object has moved forward, i.e. in Zone3/Zone4 and FSM state is VD_FWD.

CmpE244 S14 vDog vd rev.bmp

When 1st and 4th LED glows continuously, it indicates that object is coming closer, i.e. in Zone1 and FSM state is VD_REV.

CmpE244 S14 vDog vd turn.gif

When 1st and 4th LED blinks, it indicates that object is taking turn, and robot is trying to figure out where the object has turned and FSM state is VD_TURN. If robot is not able to find out turned object, it means that object has moved out of range.

CmpE244 S14 vDog vd fwdleft.bmp

When 1st and 2nd LED glows continuously, it indicates that object is turning to left and FSM state is VD_FWD_LEFT.

CmpE244 S14 vDog vd fwdright.bmp

When 3rd and 4th LED glows continuously, it indicates that object is turning to right and FSM state is VD_FWD_RIGHT.

CmpE244 S14 vDog vd revleft.bmp

When only 1st LED glows continuously, it indicates that object is turning to left but in backward direction and FSM state is VD_REV_LEFT.

CmpE244 S14 vDog vd revright.bmp

When only 4th LED glows continuously, it indicates that object is turning to right but in backward direction and FSM state is VD_REV_RIGHT.

CmpE244 S14 vDog vd alarm.gif

When all LEDs blink fast, it indicates that some obstacle has detected and FSM state is VD_ALARM.

Testing & Technical Challenges

Normalization Algorithm:

Values retrieved from sensor are not stable. So we required to develop an algorithm that will give stable values from sensor. It should also remove spikes. We experimented a lot with this regard and finally developed an algorithm that gives fairly stable value of sensor without hampering the performance. Following graphs shows the Experiment results:
CmpE244 S14 vDog actual sensor.png
Above graph shows experimental results of actual sensor values, when object is moved from right to left. It is clearly visible in the graph that values are not stable and also has many spikes.
CmpE244 S14 vDog mean sensor.png
Above graph shows experimental results of mean/average of past 30 values of sensor. These values are fairly stable, but it does not help to detect object if object moves very fast.
CmpE244 S14 vDog median sensor.png
Above graph shows experimental results of median of past 30 values. These are the most stable value that we could find out. So we used median to calculate sensor values, and used these values in our algorithm.

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

http://youtu.be/njPgVcvl1cQ

Project Source Code

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