Skip to main content

Controlling google earth using 3D Gesture MGC3130 Hillstar Dev Kit

       
           In this blog post I am just going to give overview about one of the application using 3D gesture. In fact the idea I am going to discuss came in mind when discussing about this new technology with my friends. And here is I am able to control Google earth using hand gestures in air. Just see video below to get idea, how does it work exactly




     

     At first I downloaded SDK and Aurea GUI on which I could test functionality of HillStar development Kit. You can find these resources herehttp://www.microchip.com/pagehandler/en-us/technology/gestic/gettingstarted.html.

      I tested Aurea GUI application which worked out of box with Hillstar development kit. Then I also tested SDK example codes which worked without problem.

      For the current application I used one of the sample code from the given SDK which gives data on command line. In this project I had to control Google earth, but there is not way to in C to control google earth, hence I needed to send this data from the MGC3130 Application to Python application that controls Google earth using Google earth API for python. I used socket programming in this and transmitted data over local network using TCP. I could also use shared memory in this. And finally I have a working model that controls google earth. 

       In fact, what I did is written on top of SDK demo code that can be found with SDK called "console". This demo code gives all gesture related data on console. E.g. x,y,z co-ordinates, circle gesture detection, left-right,top-bottom vice versa. Means, In order to use the gesture output to control Google earth, I could use the same console data. But here the main question was how can I control Google earth, obviously using Google API's. I preferred to use Google's Python APIs for same. Now, In this case, I need to send these data whatever I get on console to the program which will control Google earth using Python APIs. Now there can be two options to send this data from C program to Python is to use socket programming or using shared memory. I preferred socket programming and thought to transfer this data on TCP socket over local IP to Python program. So I need to write TCP client which sends the data from TCP client which is implemented in C within SDK provided to TCP Server which is basically python program running.





Code snippets -


Here, I am just going to give details about add on codes which I did to make this application, rather than providing complete code.

Following is the TCP Client implemented in C (You can find lot of examples online about TCP client implementation in C)

  1. /* 
  2.     Create a TCP socket 
  3. */  
  4.   
  5. #include<stdio.h>  
  6. #include<winsock2.h>  
  7. #include "console.h"  
  8.   
  9.   
  10. #pragma comment(lib,"ws2_32.lib") //Winsock Library  
  11.   
  12.  WSADATA wsa;  
  13.  SOCKET s;  
  14.  struct sockaddr_in server;  
  15.  char *message;  
  16.   
  17.   
  18. int tcpInit(void)  
  19. {  
  20.        printf("\nInitialising Winsock...");  
  21.     if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)  
  22.     {  
  23.         printf("Failed. Error Code : %d",WSAGetLastError());  
  24.         return 1;  
  25.     }  
  26.        
  27.     printf("Initialised.\n");  
  28.        
  29.     //Create a socket  
  30.     if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)  
  31.     {  
  32.         printf("Could not create socket : %d" , WSAGetLastError());  
  33.     }  
  34.   
  35.     printf("Socket created.\n");  
  36.     server.sin_addr.s_addr = inet_addr("127.0.0.1");  
  37.     server.sin_family = AF_INET;  
  38.     server.sin_port = htons(5005 );  
  39.   
  40.     //Connect to remote server  
  41.     if (connect(s , (struct sockaddr *)&server , sizeof(server)) < 0)  
  42.     {  
  43.         puts("connect error");  
  44.         return 1;  
  45.     }  
  46.   return 0;  
  47. }  
  48. int tcpSendData(char *uData)  
  49. {  
  50.      //while (1)  
  51.      //{  
  52.   //puts("Connected");  
  53.   
  54.   
  55.   retry:    
  56.   //Send some data  
  57.   //message = "GET / HTTP/1.1\r\n\r\n";  
  58.   if( send(s , uData , strlen(uData) , 0) < 0)  
  59.   {  
  60.   puts("Send failed");  
  61.   return 1;  
  62.   goto retry;  
  63.   }  
  64.   Sleep(1);  
  65.   puts("Data Send\n");  
  66.     //}  
  67.   return 0;  
  68. }  
  69.  //   closesocket(s);  
  70.    // WSACleanup();  
  71.   //  return 0;  
  72. //}  

As you can see the function tcpSendData is used to send data over TCP socket to local Ip over 5005 port. This function is called in gestic.c file, when gesture is detected. Following is the code snippet for same.

  1.        if(data->gestic_gesture != NULL) {  
  2.             /* Remember last gesture and reset it after 1s = 200 updates */  
  3.             if(data->gestic_gesture->gesture > 0 && data->gestic_gesture->gesture <= 6)  
  4.                 data->last_gesture = data->gestic_gesture->gesture;  
  5.             else if(data->gestic_gesture->last_event > 1//Shrenik  
  6.                 data->last_gesture = 0;  
  7.   
  8.   
  9.             printf("Gesture:          %s \n", gestures[data->last_gesture]);  
  10.     
  11. if(strcmp(gestures[data->last_gesture],"DNULL"))  
  12.   {  
  13.   tcpSendData(gestures[data->last_gesture]);  
  14. }  
  15.   
  16.   
  17.   }



Before writing program you need to install Google python API package which is attached with this blog. Install this package as you install normally python package "setup.py install". Following is the python code snippet I am giving which does following job

1. Initiates TCP server over localhost with port numbe 5005.

2. Initiate Google earth APIs default variable value.

3. Reads Gesture data which comes over TCP port 5005 on localhost.

4. Parse that data in order to take specific action to google earth movement according to gesture.

5. Keep doing step 3 and 4 continuously.

  1. import socket     
  2. import win32com.client, time  
  3. googleEarth =  win32com.client.Dispatch("GoogleEarth.ApplicationGE")  
  4. while not googleEarth.IsInitialized():  
  5.     time.sleep(0.5)  
  6.     print "waiting for Google Earth to initialize"  
  7.     
  8. latitude=41.487942                            # Latitude in degrees. Between -90 and 90.  
  9. longitude=0#-81.6865                            # Longitude in degrees. Between -180 and 180. to rotate the earth  
  10. altitude=1000    
  11. # in meters  
  12. tilt=0  # looking to the horizon=90, looking to the center of Earth=0  
  13. azimuth=370  # looking North=0, East=90, South=180, West=270  

  14. speed=0.5    
  15.  # speed transition. must be >= 0, above 5.0 the transition is instantaneous  

  16. range=0              # If not=0 camera will move backward from "range meters along the camera axis  
  17. altMode=1  #Altitude mode that defines altitude reference origin (1=above ground, 2=absolute)  
  18. focusDistance=10000000  #Zoom Value can be changed  

  19. TCP_IP = '127.0.0.1'  
  20. TCP_PORT = 5005  
  21. BUFFER_SIZE = 20  # Normally 1024, but we want fast response  
  22. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
  23. s.bind((TCP_IP, TCP_PORT))  
  24. s.listen(1)  
  25. conn, addr = s.accept()  
  26. print 'Connection address:', addr  
  27. while 1:  
  28. data = conn.recv(BUFFER_SIZE)  
  29.  
  30. if not data: break  

  31. #print "received data:", data  
  32.   
  33. #focusDistance=0  
  34.  
  35. #data=0  
  36.  
  37. if data == "DRIGHT":  
  38.  
  39. print "Right Direction longitude = ", longitude  

  40. if longitude <= 180:  

  41. longitude = longitude-10  

  42. if longitude == -180:  
  43. longitude = 180  

  44. elif data == "DLEFT":  

  45. if longitude >= -180:  
  46.  
  47. longitude = longitude+10  
  48.  
  49. if longitude == 180:  
  50.  
  51. longitude = -180  
  52.   
  53. print "Left Direction longitude = ", longitude  
  54.  
  55. elif data == "DUP":  
  56.  if tilt > 10:  
  57.   
  58. tilt = tilt - 10   
  59.   
  60. if tilt == 0:  
  61.   
  62. tilt = 90  
  63.  
  64. print "Up Direction tilt = ", tilt  
  65.  
  66. elif data == "DDOWN":  
  67.   
  68. if tilt < 90:  

  69. tilt = tilt + 10   
  70.  
  71. if tilt == 90:  
  72. tilt = 0  
  73. print "Down Direction tilt = ", tilt  
  74.  
  75. elif data[0] == 'Z':  

  76. print "Z data Direction"  

  77. data = data[1:6]  
  78. focusDistance = (int(data))  
  79. print 'focus_distance z = ', focusDistance  
  80.     #conn.send(data)  
  81. #conn.close()  
  82. googleEarth.SetCameraParams (latitude, longitude, altitude, altMode, focusDistance, tilt, azimuth, speed)  
  83.  
  84. cam=googleEarth.GetCamera(True)       # returns a ICameraInfoGE  object 


   This project I did as part of RoadTest from Element14. You can find project source here download.

I hope you enjoyed this project. Let me know if any querry/ comments.

Regards,
Shrenik.

Comments

Popular posts from this blog

128 x 64 Graphics LCD Display Interfacing with ATMEGA32 Library from Scratch

            Yes I am diving little into traditional stuff, still its interesting to try something from scratch. While working on some hi-tech stuff where we mostly don't care about writing something from scratch as its time consuming. Now a days platforms like arduino are concentrating on Application, they are not meant to use to understand the hardware peripheral. In fact I never tried it though ;). I know there are lots of example available online regarding this graphics LCD. This LCD I selected is HDG128x64F, which is more or less what is conventionally used, but I found some differences as in column addressing method. I got datasheet about HDG128x64F here , where I can only find some commands which are more or less similar to that of 16x2 LCD except RAM addressing method. To start working on this I preferred using Proteus Simulation software to make it more flexible in terms of Hardware. Note - This software I tried with Proteus not on actual hardware. Put comment belo

How to interface USB modem to ARM board (for android or linux)

How to interface 3G usb modem to any ARM (Android / linux ported) Board.  Hi I am now going to provide quick steps to interface the 3G usb modem to linux/ Android SBC which i have tried during my try which is successful one . More and more USB devices when plugged in for the first time they act like a flash storage and start installing the driver from there. After installation (and on every consecutive plugging) the driver switches the mode internally, the storage device vanishes (in most cases), and a new device (like an USB modem) shows up.       Few modems (Huawie) most of time they do not need to switch from mass storage to usb modem mode. When you connect that modem to USB port then it will be detected as ttyUSB (3 ttyUSB ports are detected). Otherwise you need to switch the mode of usb modem by using usb_modeswitch utility (I am giving examples of idea modem / reliance modem which are from Huawei and a dlink 3G modem which requires usb modeswitch). Follow the steps to

Interfacing M45PE16 SPI Flash to ATMEGA32

       As many people need some sort of storage in their embedded project, they prefer to use SPI flash. Hence I decided to try this interfacing with ATMEGA32 microcontroller. This SPI flash is 16Mb flash, works on SPI interface. You can reuse below code if you want to integrate this flash to your project. I tested this code using proteus simulation, you can also test and comment. Features of M45PE16- 16Mb of page-erasable Flash memory Page size: 256 bytes Sector erase: 512Kb 75 MHz clock frequency (MAX) In current interfacing I only did Page Write/ Read API's. The SPI needs to configure in Mode 0, and Master at Microcontroller side as given in code below. The result or Page read bytes are displayed over terminal using UART. Code- M45PE16.c /*  *  *  *  Created on: Apr 18, 2014  *      Author: Shrenik Shikhare  *      File: M45PE16.c  *      Discription: Interfacing M45PE16 SPI Flash to ATMEGA32  *      Copyrights(C)-April 2014  */ //#define F_CPU 10000