Real time vehicle tracking and driver behaviour monitoring using cellular handset based accelerometer and GPS data 4 th Year Electronic and Computing Project Report 05416361 Supervisor: Mr Liam Kilmartin 4 th January 2008 1
Table of Contents Chapter 1 Introduction 1.1 Project Abstract... 3 1.2 Project Aims... 4 Chapter 2 Background technology 2.1 The Nokia N95... 5 2.2 Phone software... 7 2.2.1 Java... 7 2.2.2 Python... 9 2.2.3 C++ and network sockets... 10 2.3.4 Series 60 standard development kit(sdk)... 10 2.3 Server software 2.3.1 WAMP... 12 2.3.2 Apache... 13 2.3.3 MySQL... 13 2.3.4 PHP... 13 2.3.5 Google maps API... 14 Chapter 3 System design and overview 3.1 System overview... 15 3.2 Generating the accelerometer data... 16 3.3 Main handset Application... 17 3.4 Server Application... 19 3.5 Web based GUI... 20 Chapter 4 Progress to Date and Remaining Work 4.1 Accelerometer processing algorithms... 21 4.2 Completed Work and Remaining Work... 24 2
Chapter 1 Introduction 1.1 Project Abstract The aim of this project is to develop a real time vehicle tracking and driver behaviour monitoring system based on new cellular handset technologies. These technologies include an integrated GPS receiver and built-in accelerometer which are becoming increasingly more common in cellular handsets and will soon be available in all new handsets. These new technologies allow for a very advance and accurate system to be developed. The integrated GPS receiver can acquire the location of the handset and therefore allows for calculation of speed and acceleration. The built-in accelerometer allows for motion detection of the handset and therefore the vehicle. Sudden movements to the vehicle can be recorded processed and highlighted e.g. late breaking manoeuvres. This system is composed of two applications a complex client handset application to acquire the GPS location of the handset, generate accelerometer data and transmit this data over a wireless network and server application which will store the all the information and show the GPS location of the handset using a Google maps GUI. 3
1.2 Project Aims The initial aim of this project is to develop a system where a mobile application sends GPS data to a server over a wireless network. This System is enhanced using a web based graphical user interface (GUI).This GUI will be based on the Google maps API. The triggering of the GPS updates will be done in a number of ways. The simplest will be based on timers, more advanced triggers will included sending GPS updates every 100 meters. To allow for advanced algorithms to be developed accelerometer data will be generated on the handset and be combined with the GPS updates. The final stage of this project will involve development of two advanced algorithms.the first to determine between driving and non driving instances. The second will identify dangerous driver manoeuvres. 4
Chapter 2 Background technology: 2.1 The Nokia N95 The handset that was chosen was the Nokia N95. The Nokia N95 is a series 60(s60) phone. The S60 Platform is a software platform for mobile phones that runs on Symbian OS. This handset contained all of the advanced technologies required for this project. This handset also has a Java Virtual Machine which is needed to run the any java application. Integrated GPS The Nokia N95 contains an integrated GPS receiver which is located below the 0 key on the keypad. This GPS chip acquires the longitude, latitude and altitude of the handset. The Nokia N95 allows for assisted GPS. A typical A-GPS-enabled cell phone will use a data connection (internet, or other) to contact the assistance server. Assisted GPS significantly improves the response times of the GPS receiver. [1] Internet The Nokia N95 can connect to the Internet through a carrier packet data network such as GPRS. This allows for high speed data transfers. The cost of GPRS varies across all networks but for the meteor network its costs 99c for 50mb per day [1][2] 5
Accelerometer The N95 has a built-in tri axis accelerometer. AN accelerometer is an electromechanically device that measures acceleration. A tri axis accelerometer allows for measurement of acceleration in all directions. This allows for detection of shock and vibrations to the handset. The orientation of the handset can also be calculated using the accelerometer. This was originally developed to control the screen orientation and for use as a pedometer in sports applications. [1] Java Virtual Machine A java virtual machine is a virtual machine used by software programs for execution by computer applications. Java applications that are complied to byte code can run on any computer that has a Java virtual machine installed regardless of its architecture. Certain handsets like the iphones don t come with a java virtual machine and there can t run java applications [1] Figure 1: The Nokia N 6
2.2 Phone Software In mobile phone programming there are three different programming languages available the Mobile form of Java, C++ and the mobile version of Python. All three have their advantages and disadvantages.for this project the mobile form of Java and the version of Python. The Python scripts communicate with the Java Applications using internal network sockets. 2.2.1 Mobile form of Java: Java is a platform independent and object orientated programming language. Platform independent programming languages don t rely on any particularly features of a computer architecture which allows it to very portable. Object orientated programming is a fundamental type of programming that uses a variable and their communications to design applications. This type of programming allows for complex computer programs to be design with a high level of transparency. Java standard edition comes with a large variety of programming interfaces (API).An API is a set of routines and protocol provided by libraries in order to support the designing of applications. An advantage Java has over other programming languages is it uses automatic memory management. Java employs automatic garbage collection to manage the variables and objects at the end of their life cycles. The garbage collecting algorithms reclaim memory used by variables that will never be accessed or manipulated by the program again. The mobile form of Java is designed for resource limited devices. The number of application programming interfaces is significantly reduced in these limited devices this is due to their lack of memory,processing power and other resources.they include the Location API which is used when communicating with the built in GPS receiver which is unique to the mobile form of java. The input and output API which is in the mobile form of java and the standard edition of java automatically accesses the wireless internet when used on a handset. The API libraries that a resource limited device has is dependent on it Mobile Information Device Profile (MIDP). The core APIs are defined by 7
the Connected Limited Device Configuration (CLDC).The CLDC is a specification of a framework for Java applications targeted at devices with very limited resources. Figure 2 shows the mobile edition of java API library (J2ME) intersects with the Java standard edition library (J2SE). Depending on the versions MIDP [4] A MIDlet is a Mobile form of Java application. The application takes its framework the Mobile Information Device Profile (MIDP). A MIDlet contains two file a jar file and a jad file. The.jar contains the byte code. The jad file containing the location of the.jar file and describes its contents. [5] Figure 3 intersecting API libraries of both forms of java [6] 8
2.2.2 The mobile version of Python: Python is an interpreted and object-oriented high level programming language. High level programming languages reduce the amount of detail to allow the programmer to focus on fewer concepts this makes the language more users friendly and makes the language syntax minimalistic. Since Python is an interpreted language a Python interpreter must be installed to run python applications. Python was design to takes into consideration future growth using module files. A module is a file containing Python definitions and statements[7] In 2004 nokia released a mobile version of python called Python for S60platfrom (PyS60). In addition to the standard features of the Python language, PyS60 provides access to the phone's unique features, such as camera, contacts, calendar, audio recording and playing, TCP/IP and Bluetooth communications and can communicate with the built in accelerometer. The PyS60 installation package includes the Python interpreter, with Python Standard Libraries and a special module for the smart phones features e.g. GPS and accelerometers.[8] 9
2.2.3 C++ Although you can access more of the phones functionally with C++ compare to java, C++ was not chosen for this project as C++ has many disadvantages compare to java in mobile phone programming. It s not pure object oriented programming language because C++ doesn't support for garbage collection, C++ doesn t have built in thread support and is not as portable as java. 2.2.3 Network sockets: A Network socket is an end-point of a bidirectional process-to-process communication flow across an IP based network [9], a network socket is identified by the type of connection, the system I.P address and the port number used for communicating 10
2.2.4 Series 60 standard development kit(sdk) To develop any mobile phone application the correct development kit must be used. The development kit enables you to create mobile applications using Java Python or C++. The S60 SDK is the recommend SDK for the Nokia N95. The s60 SDK contains A mobile phone emulator this allows for simulation of MIDlets on the computer tools used to compile and package the application An extensive set of example in all programming languages. A external events generator, this allows the developer to simulate signal black outs and a very low battery TCP support this enables the handset emulator to use an Ethernet card to access the internet to simulate GPRS accessing the internet The s60 SDK supports integration in to an Integrated development environment such as eclipse or netbeans. The SDK contains information about all APIs implemented in a particular handset 11
2.3 Server Software 2.3.1 WAMP WAMP was chosen as the application server platform for this project. WAMP is an abbreviation of Windows, Apache, MySQL, and PHP.WAMP provided all the server utilities required for the project.apache is a web server and MySQL is a database management system. A socket server was developed in PHP to handle incoming data. WAMP automatically installs and configures Apache, MySQL, and PHP to work on a windows computer. It allows you to develop dynamic Web sites with Apache server, PHP is a script language, and the database of MySQL. It also possesses PHPMyAdmin and SQLite manager to manage more easily your databases. It also comes with a very useful service manager as an icon in the icon tray. The service manager allows you to quickly restart the server, access your logs an access your setting files. PHPmyadmin and SQLitemanager are programs designed to handle the administration of a MySQL database. Both programs offer a user friendly interface and save the user from writing SQL commands [10] 12
2.3.2 Apache Apache is a web server. A web server is responsible for handling Http requests from clients and their responses. Apache is extendable beyond its core functionality by using apache modules. These include a module that allow for server side programming languages such as PHP or Python and a proxy module.apache features include SSL, a very advanced set of cryptographic protocols for security over the TCP network. 2.3.3 MySQL MySQL is a database management system.the MySQL program runs as a server MySQL is free under the General Public License (GPU).It is very easy to use you can quey a MySQL database using the SQL language. 2.3.4 PHP PHP is a Linux scripting language designed for web based applications.php runs on a web server.php is design to works very well with database management systems. It s free under the under the General Public License (GPU).PHP code can be embedded into html webpage.this allows the html webpage to use PHP to query the databases.this would be impossible without PHP scripts.php queries the data by using simple SQL commands.[12] 13
2.3.5 Google Maps API To enhance the server side application an advanced GUI had to be created to allow the user to track the handset.this advanced GUI had to be embedded in the project webpage and to be dynamic changing as new coordinates came in to the database. The Google maps API could do these requirements. Google developed the Google maps API to allow developers to embed Google maps into their websites with their own key points using longitude and latitude coordinates. Google maps code is written in Java Script and XML. Java Script is a scripting language used for advance front end web development. To use the Google maps API the developer must request a Google maps API key this is a unique key give to a particular web address.google maps features include: to insert markers at specific locations to insert info tags coming out of the markers to insert poly lines between two specific locations, these ploy lines can be instructed to automatically link to roads Figure 4 :This show the My Google maps reading the time and location from the database 14
Chapter 3 System design and overview 3.1 System overview Steps 1&2 Acquire accelerometer and GPS data Send data to the data to the Server Receives data Stores data Converts data to xml Displays data on webpage in GUI Figure 5 System overview Steps 1&2: generates the accelerometer data, acquires the location of the handset and sends this data to a server. Step 3: runs a socket server that inserts data into a MySQL table Step 4: displays a webpage that can read from a MySQL table and display the results on a Google map GUI 15
3.2 Generating the accelerometer data Java could not be used to generate the accelerometer data since there is no Java API to communicate with built in accelerometer.but there is a python module to communicate with the built in accelerometer therefore a python script was designed to constantly generate the data and send it to the java application. This involved creating a simple client and server connection between the python script and the java application Import xyz module (contains function communicate with built in accelerometer chip) Define the socket Bind the socket And listen for the java application to connect Has the Java application connected? No Yes Generate and send accelerometer data to the java application over the socket connection Flow chat of python script 16
3.3 Main handset Application The Java mobile phone Application has several tasks. The main task is to access the integrated GPS receiver and acquire the GPS coordinates of the handset this is done using the Java location API. Once the API acquires the location, the longitude, latitude and attitude of the GPS receiver are returned. The location API allows the developer to configure the accuracy of the GPS receiver, the better the accuracy the longer it will take the GPS receiver to acquire the handset location. To prevent the program from getting hung waiting for the location the API requires the developer to set a timeout. The second task of the Java mobile phone Application is to receive the accelerometer data from the Python script. This requires the java application to run a java client to access the python server and request the accelerometer data. The frequency of the accelerometer is 25Hz which is too much data to be constantly sending back to the server.several algorithm are required to convert all the accelerometer data in to useful concise data.(this is discuss in section 4.1) The final task is to send the location of the handset, processed accelerometer data and time back to the server using GPRS. This is done using the java io API. Once the handset attempts to open a socket connection to an external I.P. address the Nokia prompt pops up and asks the user to choose a wireless communication e.g. GPRS. Using the java io API a java client is created that communicates with the PHP server application.the location, processed accelerometer data and time are combine to a fixed length string. The string is filled with zeros if it doesn t reach the preset string length. 17
Acquire GPS location Has the GPS coordinates been received? No Yes Run a client to access the python server and request the accelerometer data Has the accelerometer data been received? No Yes Process the accelerometer data Step3 Send the processed accelerometer data, GPS locations and time to the server Flow chart of Java Application 18
3.4 Server Application A MySQL table was designed to store the information from the handset. This table had to hold the location, processed accelerometer data and time. This was created using PHPMyadmin. The server application was developed in PHP. The PHP application has two tasks to run a socket server that received data from the mobile java client and insert data into a MySQL database. To run a socket server the PHP script has to first define and bind a socket and then wait for the mobile java client to connect. To insert data into a MySQL database the script must open the database and then insert the data into a specific location on the MySQL table. The data is a string composed of the location, processed accelerometer data and time.the PHP script breaks the string in to its specific parts. To correspond to its values before sending.the first 20 characters are allocated for the longitude coordinates. Characters 20 to 40 are allocated to the latitude coordinates etc. Figure 6 MySQL table 19
3.5 Web based GUI A Google maps GUI was developed that read from the MSL database and update as a new coordinates entered the database from the PHP script. A Google maps maker is inserted at the specific coordinates on the map and a polygon is automatically draw between two consecutive markers The initial step was to request a Google maps API key for my project website. Since JavaScript is unable to read a MySQL database A PHP script was developed to read from the MySQL database and return the constants of the database in xml. The PHP script creates an XML file and then uses the echo command to write to the contents of the database. Once the content of the database is converted to xml the JavaScript can process the xml and then insert makers into the Google maps GUI. 20
Chapter 4 - Progress to Date and Remaining Work 4.1 Algorithms to process the accelerometer data. The accelerometer has a frequency of 25hz.Therefore a new set of values is generated ever.04seconds.this is too much data to send back to the server due to cost of send data and the processor power of the handset therefore this data must be processed in the mobile java application.two algorithms are required the first is to detect whether the phone is in a car or if the phone is on a person who is walking. The second is to identify dangerous driving manoeuvres.to develop these algorithms the sample data was first analyzed. (shown in figure 7).Figure 7 show a person taking 8 steps Detecting between driving and non driving instances The following parameters need to be taken into account when developing this algorithms speed, x axis y axis and z axis. Using the built in GPS unit and the Haversine distance formula the speed the handset can be can calculated. The Haversine distance formula is a formula for calculating the distance between two coordinates. The typical walking speed of a human is 5km/h and the typical running speed of a human is 18km/h. 20km will be defined as the speed threshold, every speed over the 20km is assumed to be in a moving vehicle. An algorithm now needs to determine the difference between a slow moving vehicle and a person running.this will be done using peak detection on the x axis y axis and z axis vales. This will set automatically set a threshold for each value and record the periodicity of this threshold being broken. If the intervals are found to be constant this indicates strides of a person walking or running. Using peak detection will allow the user to move his phone in a slow moving car with the since the intervals will not be constant. The identifying dangerous driving manoeuvres will also be done using accelerometer and GPS data. 21
Figure 7. Sample accelerometer data 22
4.2 Completed Work and Remaining Work Completed Work Development of a system where GPS data is sent from a handset to a server Development of a Google maps GUI that reads from the server and displays results on map Accelerometer Data is being sent from Python to my java application but over whelms my java application Remaining Work Adding Intelligent trigging to the java mobile phone application Development of accelerometer processing algorithms to the java mobile phone application Extra enhancement of the Google maps GUI to all the polygons to automatically to link to roads 23
References: [1]= http://www.forum.nokia.com/devices/n95_8gb [2] http://www.meteor.ie/ [3]http://java.sun.com/javame/index.jsp [4]http://en.wikipedia.org/wiki/Mobile_Information_Device_Profile [5] http://en.wikipedia.org/wiki/midlet [6] http://www.theserverside.com/tt/articles/content/workingwithj2me/j2me.jpg [7] http://www.python.org/ [8] http://wiki.opensource.nokia.com/projects/pys60_history [9] http://en.wikipedia.org/wiki/internet_socket [10] http://www.wampserver.com/en/ [11] http://en.wikipedia.org/wiki/apache_http_server [12] www.php.net/ 24