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.


OPERATION:

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.


Arduino:

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.

Beaglebone:

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.

USING PING TO VARY SPEED:

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.




Monday, March 25, 2013

Video streaming using Gstreamer

A major part of our project is to stream live video from a camera mounted on the Bot to the Android phone. We are using "Microsoft Lifecam Vx-5000" connected to Beaglebone via USB to capture the video.
Gstreamer is an open souce multi-media framework and is widely used for media streaming. It is well documented and provides an easy to use command line interface. The major hurdle in using Gstreamer was to find the right set of commands to reduce the lag in the streaming to less than a second.

Gstreamer Commands Used:
Beaglebone:
 gst-launch v4l2src device=/dev/video0 ! videorate ! video/x-raw-yuv,width=160,height=120,framerate=6/1 !   
 jpegenc quality=30 ! multipartmux ! tcpserversink port=5000  

Client(PC and Android):
 gst-launch tcpclientsrc host=localhost port=5000!multipartdemux!jpegdec!autovideosink  

We used very low resolution (160 X 120) to achieve the low lag requirement. Using these commands, the lag in the streaming was reduced to less than half a second.


Gstreamer on Android:

We followed the tutorial given here to install Gstreamer on Android. We had to install JNI and Gstreamer SDK to build Gstreamer projects in Eclipse. After configuring Eclipse, we made small modifications (changed the string in the gst_parse_launch to the client command given above) to this tutorial to make the app work according to our requirement.

Saturday, March 23, 2013

PWM on Beaglebone- Interfacing of Servo Motor

The parallax boe bot comes with a continuous servo motor. To drive the motor, we required PWM output from the Beaglebone. The Beaglebone has three PWM modules, each with 2 outputs. Accessing the PWM modules is very easy. The tutorial found here gave us detailed step by step instructions on how to configure the PWM module.

The servo motor requires a PWM wave of 50Hz for proper operation. The speed and direction of rotation is controlled by the duty cycle of the PWM wave.

  1. Duty cycle of 1500us stops the motor
  2. Duty cycle of 1300us makes the motor rotate in one direction
  3. Duty cycle of 1700us makes the motor rotate in the other direction
The speed of rotation varies linearly as the duty cycle, i.e. a duty cycle of 1400us makes the motor rotate at half speed and so on. The speed remains constant if the duty cycle is reduced below 1300us or increased above 1700us.

We used the two outputs of EHRPWM0 (Enhanced High Resolution PWM) module to control the two servo motors of the bot. The PWM outputs are connected to pins 29 and 31 of header P9 on the Beaglebone. To interface the servo motor:
  1. Connect VCC, Ground and PWM output pin to appropriate leads of the motor
  2. Configure MUX settings, so that pin 29 outputs PWM wave
     echo 1 > /sys/kernel/debug/omap_mux/mcasp0_aclkx  
    
  3. Request EHRPWM0:0 from the OS
     echo 1 > /sys/class/pwm/ehrpwm.0:0/request  
    
  4. Set PWM frequency
     echo 50 > /sys/class/pwm/ehrpwm.0:0/period_freq  
    
  5. Set PWM duty cycle
     echo 1300000 > /sys/class/pwm/ehrpwm.0:0/duty_ns  
    
  6. Run
     echo 1 > /sys/class/pwm/ehrpwm.0:0/run  
    
These steps were followed to output PWM wave(period of 20ms and duty cycle of 1300us) from the terminal. The same was then converted into C program using file operations

Thursday, March 21, 2013

GPIO on Beaglebone- Blinking LEDs

The first program that we wrote, was the famous "Hello World" of the embedded universe, .i.e. blinking of a led connected to a GPIO port. Access to GPIO ports is provided through the sysfs interface on Angstrom. To blink an led we must:

  1. Look up GPIO number of the pin in the Beaglebone reference manual. For example, pin 3 on P8 is connected GPIO1_6. To obtain the GPIO number we must multiply the port number by 32 and add the pin number. So GPIO1_6 would be 1x32 + 6 = 38
  2. Next we must export this pin, so that it is accessible from user space.
     echo 38 > /sys/class/gpio/export  
    
  3. Set the direction of the pin as output
     echo out > /sys/class/gpio/gpio38/direction  
    
  4. Write values to the 'value' file
     echo 1 > /sys/class/gpio/gpio38/value  
    
The above steps were followed to blink an led from the terminal. The same was then converted into a C program using C file operations (fopen, fprintf)

Wednesday, March 20, 2013

Getting Wifi - Connectivity on the beagle bone

Getting the Wifi connectivity on the beagle bone was a tricky process . It took us some time to get to know the packages that have to be installed to get Wi-fi Connectivity on the beagle bone.
We are using the Belkin F5D7050 USB Wi-fi adapter to connect to the Wi-fi networks. The adapter is connected to the USB port on the beagle bone.
After doing a lot of Google search we found that we had to install two packages onto the Linux distribution to get Wifi connectivity on the beagle bone .

  1. The first was the firmware required for the Wi-fi adapter . The firmware required for this is rt73-firmware. The firmware was downloaded from the angstrom distribution webpage. (http://www.angstrom-distribution.org/)
  2. The second package that we installed was wireless-tools which was also downloaded from the angstrom distribution webpage.
Once we had installed the two packages we had to specify the network ssid and the passphrase in the /etc/wpa_supplicant.conf file. Once this was done we just restarted the beagle bone and did ifup wlan0 to get the wifi connection up on the beagle bone. 



Sunday, March 17, 2013

Installation of Ångström OS on the beagle bone

The installation of the Angstrom OS on the Beagle bone was a quite a simple process . 
  1. Download the latest Angstrom Distribution image onto your PC . (Available at http://beagleboard.org/latest-images)
  2. Connect the micro SD card to your PC .
  3. Write the image to the micro SD card. 
  4. Connect the micro SD card to the beagle bone and the power the beagle bone. 
  5. ssh into the beagle bone to access the files on the beagle bone.
We followed the tutorial on this page http://beagleboard.org/static/beaglebone/latest/README.htm .








Friday, March 15, 2013

Overview

In this project, we intend to develop a remote control robot with a webcam mounted on it that transmits a live video feed to an Android application on the user's phone. The Android application will be used to control the robot.

Embedded Side:

A beagle bone will be mounted on a small robot. The output pins of the beagle bone will be connected to the actuators of the motor to control the robot. A camera will be mounted on the robot, which will be interfaced with the beagle bone via USB. There will be ping sensors attached on the front of the robot to detect any obstacles within its range. A Wi-fi adapter will be used to connect the beagle bone to the network.

Android Side:

The user will control the robot using an android application. The live video feed from the robot will be rendered on the android application. The user will use the phone's accelerometer to control the Bot.

Components: 

Given below is the list of hardware and software components that will be used in the project.

Hardware:
  1. Beaglebone
  2. Belkin F5D7050 Wi-fi adapter
  3. Parallax Boebot 
  4. Webcam
  5. Parallax ping sensors
  6. Android phone
Software:
  1. Angstrom OS for Beaglebone
  2. Gstreamer for streaming
  3. Eclipse and ADT tools
BLOCK DIAGRAM / ARCHITECTURE: