Friday, May 3, 2013

Ping Sensor Interfacing

The interfacing of the ping sensor with the Beaglebone was a bit more challenging due to the difference in the   operating voltage levels between the Beaglebone and the Ping sensor. To overcome this an Arduino microcontroller was placed in between, to convert the voltage levels from 3.3V to 5V and vice versa.

The figure below shows the block diagram for interfacing of the ping sensor.


The ping sensor waits for a 5 ms pulse on its signal pin. When it receives a pulse, it sends out ultra sonic pulses for 750 ms and listens for the echo. The output of the ping sensor is a high pulse whose width depends on the distance to the obstacle.

There are three software components that are used to interface the ping sensor.
1. An Arduino which waits for the signal from the Beaglebone and starts the ping operation.
2. A User space program to send a signal to the Arduino, to start the ping operation
3. A kernel driver on the Beaglebone to handle GPIO interrupts and to obtain accurate timing measurements.


The Arduino waits for a high pulse on Pin 8. Upon receiving this, it sends out a pulse to the ping sensor, and the ping sensor starts the ping operation. The Arduino then waits until the signal goes low on its ping pin(Pin 11) and sends out a pulse to the Beaglebone on Pin 9.


The program running on Beaglebone has two parts. One is the user space program and the other is the interrupt handler that is running in the kernel driver. To start the ping operation, the Beaglebone sends out a pulse on GPIO1_6 to the Arduino. It then does a read operation on /dev/gpioInt . This is the node that is associated with the custom driver to handle GPIO interrupts. When the read function is called, the control is transferred to the kernel where a timestamp is taken and the calling process is put to sleep. When the Beaglebone receives the pulse from the Arduino, the interrupt handler in the kernel driver is called. Here, another timestamp is taken, the process that was put to sleep is woken up and the difference in the timestamps is passed to the user space program.


The robot has the ability to slowly come to a halt when it detects an obstacle. The user can set the distance from the obstacle at which the robot has to come to a halt. Initially, the ping sensor is used every 1 second. When an obstacle is detected within 20cm of the set range, the robot starts to ping faster (every 200ms). Depending on the distance to the obstacle, the program generates its own value for the constant forward speed. This is compared to the value obtained from the Android Application (User controls based on slider) and the minimum of these two is used to set the forward speed of the robot.