Tuesday, 29 July 2014

Arduino Libraries for MPU6050 and HMC5883L

In this article I am going to write about the different arduino libraries which i had developed as a part of Summer Internship project at National Institute of Oceanography Goa. My project was based on remote health monitoring system, part of which was to develop an IMU (Inertial Measurement Unit ) for an ambulance.


IMU is used for measuring the orientation of the body, acceleration, angular velocity, heading etc. This is calculated using Accelerometer, Gyroscope and Magnetometer.
For accelerometer and gyroscope we had used MPU6050 module by Robokits and for magnetometer we had used HMC5883L from Robokits.

Actually we can also use ADXL345 accelerometer and  L3G4200 gyroscope which are available in module mentioned in 2nd link along with magnetometer, but it will result in alignment error as both  are 2 different chips. So for highly sensitive applications it is not a sensible thing to use those 2 chips. and hence we had made use of  MPU6050 module which contains both accelerometer and gyroscope on a single chip. 

Libraries can be downloaded from following github link.


There are 2 libraries - 1 for MPU6050 and other 1 for HMC5883L.
Both contain functions for initializing the modules,  converting raw data in proper scale and displaying the data in various forms. 

Libraries are written in C++. So for using the libraries in your program first of all you have to create a class object and then you can access all public variables and functions used in the library.




Thursday, 17 July 2014

Simple color following robot using OpenCV C++

Introduction:
In this article i will be explaining , how to make a simple color following robot, which will follow the object of particular color. This article can be seen as first step in getting started with image processing based robotics.

Things you should know:
-Basics of using any micro-controller which has an interface for serial communication.
-Basics of C++

Hardware requirements:
USB camera, Micro-controller board with serial interface, RF modules (for wireless communication) or USB to RS232 cable (for wired communication between PC and micro-controller).

What exactly is this Image Processing based Robotics ??
Generally while developing any robotics application we use different sensors as input and based on their values robot takes necessary decision. Simarly in image processing based robotics we use image from a camera as an input and uses it to take a decision. Now the problem here is image doesn't give a digital value of true or false as most of the sensors do. So we need to do the processing of the image to remove noise,crop unnecessary part, apply different filters to focus only on object of our interest in the image etc.  
and that's where the opencv libraries comes extremely helpful.

OpenCV (Open Source Computer Vision Library: http://opencv.org) is an open-source BSD-licensed library that includes several hundreds of computer vision algorithms.It has several modules such as core,imageproc,video,calib3d.features2d,objectdetect,highgui and gpu. Of these modules core,imageproc and highgui module module comes quite handful in image processing based robotics.

  • core - a compact module defining basic data structures, including the dense multi-dimensional array Mat and basic functions used by all other modules.
  • imgproc - an image processing module that includes linear and non-linear image filtering, geometrical image transformations (resize, affine and perspective warping, generic table-based remapping), color space conversion, histograms, and so on.
  • highgui - an easy-to-use interface to video capturing, image and video codecs, as well as simple UI capabilities.
How to get started?

1) Setup the overhead camera and connect it to your pc. You may also require to install necessary drivers based on your operating system to get started.

 2) Now once the camera is detected , next task is to take a snapshots.
So our main task here is to continuously take snapshots from overhead camera and process them to drive the bot.

3)Image from the overhead camera may not only include the desired arena, it may also show extra part which is not needed and can cause problems in our processing. So next step is to crop only that part of the image which is required.

So now we have only the only the desired portion of image. Next problem is there will be lot of noise in the image because of imperfect lightening conditions. So  for smooth processing we have to get rid of this noise.This is achieved using Gaussian blur. It is a most common technique which is used for this purpose.

This completes basic setup of the arena environment in OpenCV. If you want to further reduce noise there are lot of filters available in opencv ,more about which you can find from opencv website.


Now here in this problem statement we have 2 objects - one is the bot itself and 2nd is the circular object which bot will follow. To follow the circular object 1st of all we should know position of bot and object. This can be done by painting the top surface of the bot and object with 2 different colors which are different from the arena color. So now we can use filter to detect that color and use techniques like hough circles or polygon detection to detect the object based on shape its shape.

By default image will be in RGB (Red Green Blue). But under non ideal conditions distinguishing  colors on RGB values in not reliable. Distinguishing colors in using hue,saturation and value in grayscale is much reliable option. Hence first we have to convert RGB image in Grayscale format and then decide HSV thresholds using trackbars.

 

So suppose the object to be followed is circular then we can easily detect it first by filtering that color and then applying hough transform to detect circle and its center.

Similarly assuming that bot top part is rectangular we can apply polygon detection on the bot and get its center. But problem here is we also want to know the orientation of the  bot so that accordingly we can give it the directions to move. So we'll need  2 different color objects on top of the bot surface to calculate this angle . Also hough circle transform is much more reliable compared to polygon  detection hence its better to paint 2 circles on bot top then going for 2 rectangles or squares.
                 
Now we have to calculate 2 angles:
1) Angles between 2 objects on bot top
2) Angle made by the object with the bot.
                                     

This can be done using simple geometry as shown in the code.

Once the 2 angles are calculated, we  have to compare 2 angles and determine in which direction bot should move. For example if  difference between bot angle and object angle is 30  degree then bot should move right until the angle difference is zero and then then start moving forward until it reaches the object. Commands can sent to bot from OpenCV using serial communication .

Full code can be downloaded from following github repository Github

This repository  can be used to find  more about image processing techniques and serial communication in OpenCV. 

Wednesday, 4 June 2014

Home Automation System

Introduction
Have you ever dreamed of controlling your home appliances from anywhere in the world using an android app or website?? If that's the case then you are at right place. In this article I'll be explaining  my Home Automation System project. Its basically an embedded system as well as software project.

Things you should know
  • Basics of working with microcontrollers - any platform(AVR,arduino,8051)
  • Basics of database management
  • Basics of website development
  • Basics of android app development

Block diagram
(Note: for all those who don't know about database management and MySQL refer the followings before referring  next part of this article.
Tutorialspoint
MySQL official website )

This is how the project works. User will have to select an appliance and click ON or OFF button either from website or using an android app. Both will perform same task in background i.e updating data in MySQL database.

For example in database there will 1 table named Appliances. This appliances table will have 3 columns :
  1. Sr_no  (Auto increment type)
  2. Name (Varchar type) for storing name of appliance
  3. Current_status  (boolean true/false)
Whichever appliance which will be controlled , first have to registered in this table. On insertion it will get an unique  id(Sr_no column auto_increment). This id will be used for all further database stuff. When user clicks ON button Current_status column of the appliance will be updated to True using its unique id and for OFF button click it will be vice versa.





Now we should host this data some where in cloud. One way is we can buy our own server , 2nd option is to use any old computer for this purpose , or use paid hosting such as Google cloud SQL service. Once this data is available on cloud our next task is to read data using any of the following 3 options:
  1. Any old computer - here you can read the data from MySQL database in cloud using python language which has well developed library for reading MySQL database data in form of MySQL-db library/module. Then you can send this data to micro controller using RS232 (serial) communication between micro controller and pc. This can be done,either using RS232 cable (wired ) or wirelessly using Bluetooth or RF modules. Another advantage of this is you can use this computer as your MYSQL server. You don't need spend more money on hosting the database.
  2. Using arduino ethernet shield: In this case it is not possible to directly read the data  from mysql database. So basically you will have to create a php script which reads the data from MySQL database. Then you will have to call this script from arduiono ,it will read the data and then send the read data to arduino in form of HTTP response. For this you require arduino board with ethernet shield , but the advantage is it removes the need of pc and serial communication between the 2.
  3. Using linux based micro-controller boards such as Raspberry Pi,Intel Galieo etc. These boards are as good as pc plus they have micro-controller features such as IO pins. So we can do all the things which we have done in option 1 with the advantage of non requirement of serial communication.
This completes our task of reading the data from database at the microcontroller. Now we have  to set digital I/O pin of microcontroller ON/OFF based on data received.

Next task is to control the AC appliance based on output of digital I/O pin. We use Relay Switch for this purpose. This is how the relay works:
Relay consists of an electromagnet, so whenever we power it up using digital I/O pin of micro-controller it will act as magnet ,pull down the switch and completes the circuit, and appliance is switched on.

So now you can use any microcontroller as per your convenience, program it as per any 1 option and then use a relay switch to control the appliance. Hope everything works as expected for you all.

You can use the following links for referance on various topics :
Android Application development
Using MySQL with php
Google Cloud Sevices

You can download the project code from following Github repository.
Github repository

Demo:

Future developments:
  • Developing a mechanism to calculate the time for which appliance was on.
  • One of the disadvantage is suppose  main switch of appliance is off then you can't control the appliance. So we can develop some mechanism by which main switch also works through database.




Saturday, 31 May 2014

Introduction

Hi friends!!

I am Lakshadeep Naik, 4th year Electronics and Communication Engineering student from National Institute of Technology Goa. I always had the dream of starting my own blog , but always failed to start. My problems were i didn't know on which topic should i write,who will be my audience etc. etc. 

Today, finally i have decided to start a blog on different embedded and software projects on which i have worked on till now, so that all difficulties which i had faced while implementing those projects will not be faced by other students in future. Since my childhood days i had a dream to become an Engineer and develop a gadgets which  can be extremely useful for other people. As a part to complete this dream i worked on numerous projects based on robotics,computer vision, web development, android etc. during my B.Tech time. So i would like to share those projects with other people through this blog.They can also do further modifications/research on these ideas  and come up with some cool stuff which can really revolutionize the world. I will be also writing up some articles on other technical/non-technical stuff which i find interesting and feels worth sharing.