Monday, December 4, 2017

Public Transportation Tracking System using Hardware and Software: Study Case

Abstract— Public transportation is one of the main means of transport utilized by the population, however it is still inefficient. One of the problems seen by the population is the delay of the bus. This can happen for several reasons such as traffic or accidents on the road. Tracking a bus through GPS and GSM/GPRS can help solve some of the problems related to lack of predictability of arrival, through the planning and management of the bus system. This project proposes the development of a public transportation tracking system, which will estimate the arrival of a bus at a desired bus stop by the passenger as well as allowing the passenger to see the bus in real time. Thus, the passengers will have better control over their time. For this to become a reality, the tracking system will be integrated and programed into a hardware module to determine the location of the vehicle and a mobile application to visualize the bus on a map. It is expected to make public transport an efficient means of transport, where the user can better plan, due to more accurate itinerary, and the bus company can make more concise decisions in regards to route timing.

 

1.     Introduction

Over the last few years, the number of vehicles on the streets of Brazilian cities have increased considerably. This increase was a consequence of tax incentives granted to the population (Lerner, 2009, p.42). According to Lerner (2009: 42), annual car sales increased between 1995 and 2000 and doubled sales of motorcycles (to 500 thousand a year). The increase also occurred until 2005, thus reaching 1.6 million motorcycles in 2007 (Lerner, 2009, p.42) and around 3.8 million in 2015 according to DENATRAN (2015). This increase resulted in losses in urban mobility and in the increase of the emission of gases harmful to the environment.
According to Lerner (2009, page 43), the level of pollution per passenger when using a car is 17 times higher than when using buses. A motorcycle pollutes 32.3 times more than the bus.
Although public transportation is one of the main means of locomotion used in Brazil, with about 29% of total motorized journeys in the Brazilian metropolitan regions (ANTP, 2013), it is inefficient and imposes on users due to long waiting and overcrowding. One of the main problems witnessed by the population is the delay of the buses, which can happen for a multitude of reasons.
New technologies have been applied in different sectors of society for the improvement of several segments, and the same must happen for public transport, in which decision-making management systems are being developed and used worldwide.
The use of technological tools such as tracking can ease the problems related to the lack of predictability in the public urban transport. New tools have been used to improve services related to public transport in several countries, such as the United States, Australia and England (MAGALHÃES, 2008, p.23). As examples of tools, we can mention are Radio Frequency Identification (RFID), bus tracking via Global Positioning System (GPS) and Global System for Mobile Communications (GSM).
Assisted by the low cost of smartphones and the availability of 3G and 4G networks, the number of smartphone users is growing at an average rate of 4.7% per year (BYANSHUL SRIVASTAVA, EMARKETER, 2014). Although the growth rate of mobile phone users has reached a ceiling in developing countries, with the growing number of users in Asia, the Middle East and Africa, 4.5 billion users are soon expected. A report by market research firm, eMarketer, expects the growing market in emerging countries to boost the smartphone market (BYANSHUL SRIVASTAVA; EMARKETER, 2014). Aiming at the growing number of smartphone users allied to tracking technology, there is a great prospect for the development of a project that can contribute to the improvement of public transportation.
Through the planning and management of the fleet, it becomes possible to create new means of organization for public transport companies. From the use of a tracking system, it is possible to have greater control over a particular line or fleet, both by the company and by the passenger. It is also possible to determine the time of arrival of a bus to the next stop, the time of the route, in which stops the bus did not stop, average speed, etc.
The objective of this project is to develop a system that allows the users of public transportation to track the bus via smartphone, as well to be able to have an estimate of the time of arrival at each stop.
The tracking system proposed in this project has already been utilized by other research groups for different purposes such as vehicle tracking, anti-theft and intelligent tracking management. Maurya (2012) proposed a vehicle tracking system using GPS and GSM technology for anti-theft system. The anti-theft system is connected to a vehicle to monitor its movement and report the status of the vehicle, while its positional data is sent to a server and a mobile device. Dinkar (2011) developed a Web-based GPS-GPRS vehicle-tracking system. The Web tracking system developed in this reference project utilized different technologies such as PHP, JavaScript, XML and MySQL with Google Map API to retrieve and display the vehicle’s position on the maps. According to (Chadil et al., 2008) his work proposed a real-time tracking system using a client-server model, with the client having an embedded device with a GPS/GPRS module to identify device location. The server is a personal computer with a Web server program that receives the location information to display on the Google Map and Google Earth software.
2.         Proposed method
The methodological sequence used to model the public transport tracking system through an embedded system, web system and a smartphone application is presented in the Unified Modeling Language (UML) activity diagram in Fig. 1.   
       
Fig. 1. Methodological sequence for the modeling of the public transport tracking system.
As shown in Fig. 2., the data stream begins with the GPS satellite that requires at least three satellites to triangulate the exact position of the device. Once the satellites are triangulated  it is possible to obtain the position using a GPS receiver (HEGARTY, 2012). When the GPS receiver picks up its own position, a microcontroller communicates with the receiver. Therefore, the microcontroller reads this position and creates an HTTP request to send the position obtained to the server (WESTERMO, 2005). The sending of the position uses the GSM/GPRS cellular network. To process this request, a page on the server is invoked with the object's position and other parameters such as time and number of satellites, then a collection of scripts will process and store the position of the object. After the object's position is stored in the database, the passenger can request the time of arrival of the vehicle using a smartphone. When the passenger requests the time of arrival of a bus, a Web page is invoked on the server to restore and estimate the  arrival time of the bus in the requested stop.
With the requirements well defined, the project was modeled and the pilot project was tested. Then, with the results of the pilot project, the previously modeled model was adjusted until the final objective was obtained.



Fig. 2. Overview of bus tracking system.
3.         Project implementation
This topic presents the steps for implementation of this system. First, the technologies used and the project’s schema are described, then the development of the system, and finally, the pilot project in detail.
3.1.  Definition of tools and technologies
In the development of the hardware, a device was used which integrates a GPS module that allows the location of a vehicle, person, or other object to be determined at regular intervals. The obtained localization data for bus routes was transmitted to a database server via GSM/GPRS technologies. Subsequently, the position information was then plotted on a map to view the movement of the bus.
In this project the Arduino Uno R3 was used. The Arduino was responsible for setting up the GPS/GSM/GPRS device, reading the GPS location and sending the location to the server using GSM/GPRS technology. The Arduino used  had an integrated ATmega328P microcontroller, enabling communication with the GPS/GSM/GPRS device.
The SIM808 device used was a complete Quad-Band GSM/GPRS system that combines GPS technology for satellite navigation. This hardware device depends on a voltage source to supply at least 2 amps to power the Arduino Uno R3 and SIM808.
The software used to program the Arduino, compile and transfer the code to the microcontroller, was an open source program called the Arduino Software Integrated Development Environment (IDE).
For the development of the Web platform, the following programming languages and technologies were used: Python/Django, JavaScript, HTML, CSS, Bootstrap and Leaflet. These technologies are widely used because they offer fast implementation and easy maintenance. As an example, the Django framework that is used for agile development, which is based off of the Python language, uses standards for object-oriented programming  and other design patterns (RICHARDSON; RUBY, 2008).
3.2.  Patterned architecture

Fig. 3 shows the web architecture for the public transport tracking system. In web architecture, technologies and protocols are used for the development of the web system and the mobile application. The data is requested through the user interface using OpenShift webserver  and HTTP protocol, then the data is returned in JSON format. The web interface was programmed using the following technologies: HTML5, CSS, Javascript, Leaflet and bootstrap. The Android application has been programmed in native language of the Java system.
PostgreSQL was used as the Database Management System (DBMS) and its spatial extension (PostGIS) for PostgreSQL positions storage.

            
Fig. 3. Web architecture of public transit tracking system.        
3.3.  Database development - entity-relationship model
The entity-relationship model (ER model) of the database is represented in Fig. 4, in this model nine tables were created in Entity-Extended Relationship (EER) notation. The tables are related so that they guarantee the integrity of the data.
The tables "geoPosition" and "busStop" contain position columns of geographic data. Geographic data can use its existing functions, such as calculating the distance between two geographic points and also select data in specific regions.


Fig. 3. Model ER.
3.4. System development
A map was developed using LeafLet framework in the city of Bagé-RS in Brazil with a route line. The map is composed of layers in which the bus stops and the direction of the line were plotted. Fig. 4 shows the developed map.


Fig. 4. Map of the line Damé x Malafaia of the company Stadtbus of the city of Bagé-RS.
The passenger is able to click on the bus stop to obtain the information on the bus arrival. Fig. 5 shows the information on a bus stop. This information is: vehicle id, stop name, existence of metal shelter, existence of concrete shelter, existence of curb, painting of the shelter, existence of signs, photos and the bus arrival.


Fig. 5. Information on bus stops to be shown to passengers.
To speed up the process of creating the application, the Bootstrap framework was used. The Bootstrap framework is responsible for resizing the application screen according to each device (SPURLOCK, 2014).
Fig. 6 shows the online mode of the application, this mode is responsible for loading the online map page.  Fig. 6 shows the options: a) map with the bus stop clusters; B) map with bus stops and bus location; C) information of the bus stop.

Fig. 6. Android app online mode.

3.5.  Development and installation of hardware
Fig. 7 shows a picture of the hardware used. The SIM 808 module was attached to Arduino UNO via a shield. An acrylic box was involved to protect the circuit from dirt and water, avoiding damaging the board. The total price of the hardware was approximately U$ 100.00.


Fig.7. Hardware used in this project.
The flowchart of Fig. 8 illustrates the operation of the developed embedded system. The implementation of the embedded system was divided into five stages. The stages were: connect SIM808 module, start GPS, start GPRS, get GPS position, send position through GPRS. One stage could only proceed to the next if the current one was executed without error. In the programming of the embedded system, several problems occurred due to incorrect configurations of GPS and GPRS. To identify the errors in the settings, the serial output of the SIM808 module was used, so it was possible to identify the error returned by the SIM808.


Fig.8. Flowchart of the operation of the embedded system.
To start the hardware it is necessary to initialize the module elements. Three elements are initialized: the SIM808 board, GPS module and GSM module. To start the SIM808 it is necessary to press the I/O button on the SIM808 board for 3 seconds, then a simple AT command from the microcontroller to the SIM808 is sent, if the return is "OK", then the board is connected correctly. After the GPS module is connected, the satellites are triangulated. In the configuration of the GSM module is necessary to set the Access Point Name (APN) of the internet provider, user and password. After the correct initialization and configuration of these modules it is possible to obtain the GPS position and send it to the server through the GSM network.


3.5.  Pilot project
In order to verify if the system would work satisfactorily, a test of the developed system was carried out with a bus in the urban line of the city of Bagé-RS, Brazil. A mobile network carrier that provides GPRS service in the city was used, the choice of this carrier was based on the quality of the GPRS signal. The tracker was then connected to the electrical system in  the vehicle that Supplied 12 volts.
For four days, the tracker sent the bus position to the server. During this period more than fifty thousand records were stored in the database.  Every 3.95 seconds the position of the bus to the server was sent, this sampling was adequate for the visualization of the moving vehicle on the map. In the experiments, 1MB/hour of data was spent, so if the bus operates for 16 hours/day, in 1 month 480MB of data would be used.
Fig. 9 indicates the location where the tracker was installed. It was attached next to the driver's cab and the electronic control unit of the vehicle.

Fig.9. Hardware installed close to the driver's cab.
The data generated by the tracker was collected and stored in the database. The data stored were: latitude; longitude; altitude; date/time, number of satellites located and  speed.
For the calculation of the vehicle arrival time at the requested bus stop, the average speed of 18 km/h was utilized, as proposed in Meirelles (2000). The calculation of the vehicle arrival time is carried out by dividing the distance between the bus’ current position and the bus stop by the speed proposed by Meirelles (2000). The experimental average speed of the line studied was 14.90 km/h, so the predictability of the bus arrival will be advanced. This anticipation favors the passenger arriving at the stop in advance.
From the positions and velocities collected, the map in Fig. 10 was plotted utilizing RapidMiner Studio program.


Fig.10. Map of the route made by the bus with the speeds.
It can be seen in Fig. 10 that on straight roads, the bus had higher speeds (in yellow). This kind of information can be useful for managers to control the speed in order to avoid accidents and tickets for speeding. In addition, the information can be incorporated into an algorithm and used to improve the predictability of the bus arriving at the bus stop.
In Fig. 11, the maximum velocities were plotted during the daytime hours. In the graph of this figure, it is possible to check two peaks. The first peak shown is the speed between 11am and 2pm. The other peak velocity was verified between 4pm and 8pm. These peaks can occur due to the congestion of lunch as well as the closing of stores and the beginning of classes at the universities. In this way, the drivers compensate the hours spent in the congestion, increasing the speeds on the roads. Through this type of chart, managers can determine the times to make more buses available.

Fig.11. Maximum speeds distributed during hours.
4.         Discussion and conclusion
The main objective of this work was the development of a tracking system to assist in alleviating the problem of unpredictability of bus arrival time. For this, a Web system and an App, capable of obtaining current bus positions, were developed. After the development of the Web system and App, the embedded system was attached to a bus to obtain the vehicle position and to send that information to a server.
 Different technologies were used for the development of the Web system and the application. Some of these technologies were Django, Bootstrap and Leaflet. They streamlined the development of the system and ensured good structuring of the project. With the good organization of the codes, it was possible to reuse a large part of the functions. For example, database queries were developed on the web server, so both the webpage and the application accessed the same queries.
The hardware behaved as expected, which made it possible to track the bus by the application and estimate the bus arrival using an average speed of 18 km/h based on the Meirelles (2000) work.
In addition to providing the location of the bus in real time for passengers through the data collected, it was possible to generate knowledge for the company manager. Thus, the company manager can make concise decisions to improve efficiency of the fleet. Besides the graphs plotted in this work, other information can be correlated with the position of the vehicle such as drivers and buses, thus making it possible to extract more information.
Through the planning and management of the fleet, it becomes possible to create new means of organization for public transport companies. From the use of a tracking system, it is possible to have greater control over a particular line or fleet, both by the company and by the passenger. It is also possible to determine the time of arrival of a bus to the next stop, the time of the route, in which stops the bus did not stop, average speed, etc.
All requirements previously formulated were met and the entire system worked in an acceptable manner. However, due to the high cost of implementing of the GPS/GSM modules, for future work, the acquisition of commercially available trackers should be considered. In the market, trackers that meet the requirements system were found with values ​​ranging from U$15.00 to U$ 30.00.
Besides the technical knowledge acquired during the research and development of the system, it was possible to verify the need for improvements in this sector, and one of the ways to improve public transportation would be through technological tools. Therefore, it is expected that passengers can benefit from these technologies in improving the quality of public transport services. The code is available on https://github.com/rodrigowindows.





Acknowledgment
The authors thank the Coordenação de Aperfeiçoamento de Pessoal de Nível Superior (CAPES), for financial support.
References
[1]           LERNER, J. Avaliação comparativa das modalidades de transporte público urbano. Nacional das Empresas de transporte Urbano, 2009.
[2]           DENATRAN, D. N. DE T.-. Frota municipal de veículos. Brasília, 2015.
[3]           ANTP, A. N. DE T. P.-. Sistema de Informações da Mobilidade Urbana Relatório Geral 2013. São Paulo, ANTP, 2013.
[4]             MAGALHÃES, C. T. DE A. AVALIAÇÃO DE TECNOLOGIAS DE RASTREAMENTO POR GPS PARA MONITORAMENTO DO TRANSPORTE PÚBLICO POR ÔNIBUS. Rio de Janeiro, 2008.
[5]             BYANSHUL SRIVASTAVA; EMARKETER. 2 Billion Smartphone Users By 2015 : 83% of Internet Usage From Mobiles [Study]. Availabe in: . Acesso em: 23 abr. 2016.
[6]             Maurya, K., Singh, M., & Jain, N. (2012). Real Time Vehicle Tracking System using GSM and GPS Technology-An Anti-theft Tracking System. International Journal of Electronics and Computer Science Engineering, 1, 1103–1107. Retrieved from http://www.estdl.org/wp-content/uploads/2012/08/Volume-1Number-3PP-1103- 1107.pdf.
[7]             Dinkar, A. S., Shaikh, S. a, & Significance, P. (2011). Design and Implementation Of Vehicle Tracking System Using, 1(3), 1–7.
[8]             Chadil, N., Russameesawang, A., & Keeratiwintakorn, P. (2008). Real-Time Tracking Management System Using GPS , GPRS and Google Earth. Proceedings of ECTI-CON 2008, 393–396. http://doi.org/10.1109/ECTICON.2008.4600454.
[9]             HEGARTY, C. J. GNSS signals - An overview. 2012 IEEE International Frequency Control Symposium, IFCS 2012, Proceedings, 2012.
[10]           WESTERMO. Industrial Data Communication Westermo Handbook Theoretical and General Applications. Eskilstuna, Sweden: Westermo, 2005.
[11]           RICHARDSON, L.; RUBY, S. RESTful Web Services. Nova York: O’Reilly Media, 2008.
[12]           SPURLOCK, J. Bootstrap. Simon St. ed. Sebastopol, CA: O’Reilly Media, Inc, 2014.

--> [13]           Meirelles, A Review of Bus Priority Systems in Brazil: from Bus Lanes to Busway Transit:SMART URBAN TRANSPORT 

Saturday, April 22, 2017

General Transit Feed Specification (GTFS) Static

The GTFS protocol can be implemented in two ways, using static data or real-time. Static GTFS presents the planned schedule for a given period (such as the timeline for the next six months), while real-time GTFS is used to make last hour based on real-world conditions (such as traffic, meteorological conditions).

The static GTFS protocol is structured into a series of CSV (Comma Separated Values) files that contain information such as routes and journeys. These files are compressed into a ZIP file to be made available in urban mobility applications.

The next figure shows how is the relationships between GTFS files based on the Framework GeoFrame.



Four open source projects were found  for insertion and modification of static GTFS data, the next table shows the projects:

Name Language      Usability       Table Header Link
SimpleGTFSCreator    
Python
Bad
A Python library that contains scripts that helps create GTFS schedules through Geographic Information System (GIS) file with public transportation information.
https://github.com/PatSunter/ SimpleGTFSCreator
OpenTransitTools / gtfsdb 
Python
Bad
The focus of the GTFSDB project is to make GTFS data available to software developers in a
database.
https://github.com/OpenTran sitTools/gtfsdb
Google / transitfeed 
Python
Partially Meets
A Python library for reading, validating and writing traffic itinerary in GTFS format.
https://github.com/google/tra nsitfeed
Conveyal / gtfseditor
Java
Good
A web framework for editing static GTFS data.
https://github.com/conveyal/ gtfs-editor/


Following are the descriptions about the systems:


  • SimpleGTFSCreator is a project that contains a series of functions in Python that assists the structuring of the static GTFS protocol, however this project has as input only GIS file type;
  • OpenTransitTools / gtfsdb is a project that aims to import ZIP file of the static GTFS protocol into a database;
  • Google / transit feed is the official Google project that assists dynamic file validation of the GTFS protocol, in addition the system generates HTML pages with the itinerary from the ZIP file;
  • Conveyal / gtfs-editor is a web editor that assists in structuring static GTFS protocol through maps and forms. The Conveyal / gtfs-editor database is MapDB which provides a set of features for map development with disk storage functionality.
In the next post I will talk about Conveyal / gtfs-editor.


Sunday, April 16, 2017

Parsing latitude and longitude from SIM808

Parsing latitude and longitude from SIM808


SIM808 returns longitude and latitude in ddmm.mmmmmm format, you have to convert it to hours to plot it on maps (e.g. Google maps and Apple Maps) for that you have to convert using the formula:

.d=(mm.mmmmm/60)
DD=dd+.d

For example, the output of CGPSINF:
 +CGPSINF: 0,3118.588459,5408.784576,247.176812,20160613183218.000,22,13,0.000000000000


The longitude in the example is 3118.588459 and latitude is 5408.784576.

DD_long = 31+(18.588459/60) = 31.30980765 (for some reason the signal was not correct) so I changed the number to -  31.30980765
DD_lat  =  54+(08.784576/60) = 54.1464096 (for some reason the signal was not correct) so I changed the number to - 54.1464096


                      Example of lat and long plotted on the map


I coded this in python, you can change it to PHP, Java or any language that you are programing

#Get lat
latitude_float = latDegree # data in ddmm.mmmmmm format
latitude_hour = (int(latitude_float/100))*-1;# Getting hour, getting the first two numbers and changing the signal
latitude_hour = latitude_hour-((latitude_float+(latitude_hour*100))/60)#converting min to hour, dd+(ddmm.mmmmmm-dd00.00)/60

#Get lon
longitude_float = lonDegree # data in ddmm.mmmmmm format
longitude_hour = (int(longitude_float/100))*-1;# Getting hour, getting the first two numbers and changing the signal
longitude_hour = longitude_hour-((longitude_float+(longitude_hour*100))/60)#converting min to hour, dd+(ddmm.mmmmmm-dd00.00)/60

Sunday, April 9, 2017

AT commands on Arduino

To program your SIM shield, you need to test your shield first. To start, you have to test the commands AT directly to the shield ,

The first step is to compile the following code in Arduino, this code makes the bridge between your computer and the shield.


You can either use hyperterminal(http://www.techrepublic.com/article/step-by-step-how-to-use-the-hyperterminal-tool-to-troubleshoot-modem-problems/) or the command test online(http://m2msupport.net/m2msupport/module-tester/). After you understand the AT commands and found out which command works for you, you can then program on Arduino.

                                                                    Arduino and Shield SIM808



Arduino Uno
Generally the processor on the arduino board will connect to the GPRS modem. In order to use the AT Command Tester, the computer should connect to the GPRS modem through the arduino’s USB interface. The following sketch will set that up on the Arduino Uno boards.Download the sketch through the Arduino IDE. Please verify the baud rate setting in the sketch.
—————————————————————————————————————————
//Serial Relay – Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include
SoftwareSerial mySerial(2,3);
void setup()
{
Serial.begin(19200);
//Serial.println(“Begin”);
mySerial.begin(19200);
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
Arduino Leonardo, Arduino Mega 2560, Auduino Mega ADK
Use the following sketch for other Arduino  boards. Please check the baud rate of the modem shield.
—————————————————————————————————————————
//Serial Relay – Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include
SoftwareSerial mySerial(10,11);
void setup()
{
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//Serial.println(“Begin”);
mySerial.begin(19200);
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}

Thursday, April 6, 2017

Public-Transportation-Tracking-Django-PageJavaScript-Database

For the development of the Web platform, the following programming languages and technologies were used: Python/Django, JavaScript, HTML, CSS, Bootstrap and Leaflet. Javascript page created from https://github.com/bmcbride/bootleaf

The code:
https://github.com/rodrigowindows/Public-Transportation-Tracking-Django-PageJavaScript-Database


Fig. 1. Map of the line of the city of Bagé-RS, Brazil.
Fig. 2. Web architecture of public transit tracking system.


Fig. 3. Overview of bus tracking system.

Fig. 4. Model ER.