Project Description:
The overall goal is to create a mobile application that is user friendly that can connect to the trains and control them on the tracks. Each mobile app becomes a CAB (computer address bus) that controls one train at a time. The app should be able to switch between trains that it is controlling and each CAB shows the state of the trains individually. If possible, I am going to look into using the accelerometer to control the trains. Also, I will investigate how to control racing conditions on the CABs and the track so that two apps can't be controlling the same train. Overall, the app should be easy to use and kid-friendly that allows the user to control the train of choice and have information being sent to the trains and received from the trains.
Final Project:
CCR Client
The CCR Client is an application that connects to the server to control the computer controlled trains. It uses a button interface to increase speed, change direction, stop, toggle turnouts, and change train attributes. The information about the train is updated by maintaining the train number, indicating the speed of the train, and displaying the next turnout the train will reach. This client allows the user to enter the IP address and port number of the server and then connects to an open train if available. Client .apk file: CCRClient.apk Client .zip file: Client.zip CCR Server
The server is a C# server that connects to the trains. All control of the track is done through the server. The server doesn't allow users to change turnouts while a train is on top or too close. The server also handles collisions with the end of the track and with other trains the server knows is on the track. The server also implements speed limits at certain points on the track to avoid derailment. CCR Server .zip file: (From Brice Hilgemann's website) Server.zip Documentation
The documentation of this project includes all documentation of this project including the presentation, information about the author, code, problems, protocol, design, and a user-guide Project Documentation Presentations
The walk-through was used before spring break to introduce the project to classmates and receive any help that my fellow students could offer. The final presentation was used on April 23, 2012 to present the project to an audience of students, faculty, alumni, family, and friends. Walk-through Final Presentation |
Project Scope:
Project Justification:
This project correlates with the on going project of using innovative and new ways to control the trains to keep up with the rapidly evolving technology. This project will allow one of the largest used phone operating systems to connect to and control the trains to allow for a more accessible way to allow many people to find the use of computer science in a popular hobby. It allows future students to see how something so popular and widely known as the Android market can be programmed to do things such as control other devices and program it to do what the user needs.
Project Product:
This project will entail a lot of work with the Android operating system and understanding how it can be used to connect to other devices through a wireless connection and how to send and receive information and interpret it into usable information for the user. I will first need to work on how the current client connects and communicates with the server so that I can use that information to understand how to use it when a connection is created using the application. Once a connection is made and the information can be interpreted, then I can begin work on the interface and how to make it look to display the information to the user. I will have to do a lot of research on the Java language since I have not yet used it and it is the language used for Android development. I will also have to first become familiar with the current system in place for the trains. Outside the scope of this project, a basic "Hello World" Android app will need to be created before jumping into working with Android and attempting to connect two devices.
Project Deliverables:
- A basic app will need to make a connection to the trains' server in order to begin work talking to the trains. This will be done by researching the best way to connect a phone to another device by a wireless connection that will connect to the server.
- A communication to the trains will need to be established that allows the app to send information to the trains to allow the user to control the trains. This will be done by using the current communication system that is in place between the client and server and then find a way for the application to send the same or similar commands to the trains. Also, the accelerometer will have to be explored to see if it is usable to control the trains.
- The information that the server sends back will have to be interpreted and used properly to allow an interface to be built that allows a user-friendly interface for the application that displays the information of the trains.
- The application will have to be completed and tested extensively to check for any bugs. Racing will also have to be a problem to deal with so that no more than one application can connect to a train at once to avoid problems with the commands being sent to the trains.
Project Objectives:
- Cost -
The cost of the project will essentially be free since the train is already owned by the college and so are the android devices. Also, my time is included as free.
- Schedule -
February: Analysis and Design
March/April: Coding and implementation of the application
End of April: Deadline. Testing will need to be done in mid-April to make sure the project is completed on time.
-Feasibility -
Each step of the project deliverables is feasible by the help of the Computer Science department and research of the individual tasks in this project. The material needed for the project are all available through the college. Therefore, this project is highly feasible.
This project correlates with the on going project of using innovative and new ways to control the trains to keep up with the rapidly evolving technology. This project will allow one of the largest used phone operating systems to connect to and control the trains to allow for a more accessible way to allow many people to find the use of computer science in a popular hobby. It allows future students to see how something so popular and widely known as the Android market can be programmed to do things such as control other devices and program it to do what the user needs.
Project Product:
This project will entail a lot of work with the Android operating system and understanding how it can be used to connect to other devices through a wireless connection and how to send and receive information and interpret it into usable information for the user. I will first need to work on how the current client connects and communicates with the server so that I can use that information to understand how to use it when a connection is created using the application. Once a connection is made and the information can be interpreted, then I can begin work on the interface and how to make it look to display the information to the user. I will have to do a lot of research on the Java language since I have not yet used it and it is the language used for Android development. I will also have to first become familiar with the current system in place for the trains. Outside the scope of this project, a basic "Hello World" Android app will need to be created before jumping into working with Android and attempting to connect two devices.
Project Deliverables:
- A basic app will need to make a connection to the trains' server in order to begin work talking to the trains. This will be done by researching the best way to connect a phone to another device by a wireless connection that will connect to the server.
- A communication to the trains will need to be established that allows the app to send information to the trains to allow the user to control the trains. This will be done by using the current communication system that is in place between the client and server and then find a way for the application to send the same or similar commands to the trains. Also, the accelerometer will have to be explored to see if it is usable to control the trains.
- The information that the server sends back will have to be interpreted and used properly to allow an interface to be built that allows a user-friendly interface for the application that displays the information of the trains.
- The application will have to be completed and tested extensively to check for any bugs. Racing will also have to be a problem to deal with so that no more than one application can connect to a train at once to avoid problems with the commands being sent to the trains.
Project Objectives:
- Cost -
The cost of the project will essentially be free since the train is already owned by the college and so are the android devices. Also, my time is included as free.
- Schedule -
February: Analysis and Design
March/April: Coding and implementation of the application
End of April: Deadline. Testing will need to be done in mid-April to make sure the project is completed on time.
-Feasibility -
Each step of the project deliverables is feasible by the help of the Computer Science department and research of the individual tasks in this project. The material needed for the project are all available through the college. Therefore, this project is highly feasible.
Test Applications:
HelloWorld
The first application that was created using Android for this project was a HelloWorld application that allowed me to learn a lot about Android, Eclipse, and Java. This application allowed me to open a dialog box, become familiar with buttons, learn how to play a sound (although I had a hard time finding the location of the virtual SD card), and the differences between a relative and linear layout. When the linear layout button is pressed, a new page is opened that allowed me to type in a text box. The update button was meant to add what was typed in the text box to the combo box. However, this didn't work for me and I didn't spend a lot of time troubleshooting as this application was meant to familiarize myself with Eclipse and the Java language.
The tutorial and code for this project came from http://www.higherpass.com/Android/Tutorials/Writing-A-Basic-Android-Application/1/.
Project .apk file:
helloworld.apk
Project zip file:
helloworld.zip
The tutorial and code for this project came from http://www.higherpass.com/Android/Tutorials/Writing-A-Basic-Android-Application/1/.
Project .apk file:
helloworld.apk
Project zip file:
helloworld.zip
Simple Socket Example
The simple socket example created a socket client in Java and allowed me to connect to a C# server. The problem I had with this socket is it did not anchor when reading back from the server and would crash the application. It gave me an introduction to sockets, however, in Java and Android and I also found a server in Java that ran in Eclipse in console mode that allowed my client to communicate (sending and receiving messages) with the Java server. The C# Server that I used with this client was Brice Higlemann's Asynchronous Server Socket example which can be found on his website.
The client for Java came from http://android-er.blogspot.com/2011/01/simple-communication-using.html and the server from Java similarly came from http://android-er.blogspot.com/2011/01/implement-simple-socket-server-in.html.
Project .apk file for client:
socketEx.apk
Project zip file for Java client and Java Server:
socketEx.zip
The client for Java came from http://android-er.blogspot.com/2011/01/simple-communication-using.html and the server from Java similarly came from http://android-er.blogspot.com/2011/01/implement-simple-socket-server-in.html.
Project .apk file for client:
socketEx.apk
Project zip file for Java client and Java Server:
socketEx.zip
Simple Socket Example #2
The simple socket example #2 is a redone version of the first simple socket example. However, this example works with the C# server. In this simple socket example the read commands are put into a thread where the DataInputStream is passed to the thread where a while(true) loop runs to continuously run without android shutting down the main thread. The output for this example is the exact same as the original example as well as the socket connection. The only differences is I have added a disconnect button and the placement of things. The socket connects in the onCreate instead of on the click of the send button. I have also only left the write commands in the send button handler. The disconnect button click handler disconnects the input and output streams as well as the socket. Log statements have been added to the code for testing and so that the input message could be read. Therefore, when using the emulator to test the connection and changes I could see that the messages were getting received correctly. I also changed the readUTF and writeUTF to read and writeBytes since the server was reading and writing bytes to the server. This allowed me to handle the data as bytes and transform it to strings. The C# server used for this application is the same as the other simple socket example and can be found as a zip folder below. I didn't try connecting this server with the Java server since that was not part of the goal.
Project .apk file for client:
socket.apk
Project zip file for Java client and C# server:
socketEx2.zip
Project .apk file for client:
socket.apk
Project zip file for Java client and C# server:
socketEx2.zip
Accelerometer Snippet
The accelerometer snippet uses the sensor in the device to display x, y, and z coordinates of the device. The code for this was found on a blog at http://www.hascode.com/2010/04/sensor-fun-using-the-accelerometer-on-android/. I created my own project name and then used the code to see how the example worked. All documentation notes any changes and also gives the source.
This code gets the sensors for the applications use and gets the values of x, y, and z and displays them in a TextView. For my phone I was able to see it was the y-coordinates that I would be using to make the accelerometer work by tilting the phone down and up. I also used this to find that the coordinates are not the same orientation for the phone and the tablet. The tablet y-coordinates are based off of the tablet in a landscape view and the phone y-coordinates are based off the portrait view. The code was changed to show the value of y between -15 and 15 using mathematical operations.
The screen shot for this application was not accessible since the emulator doesn't have the sensors needed.
Project .apk file for accelerometer:
accelerometer.apk
Project zip file for accelerometer project:
accelerometer.zip
This code gets the sensors for the applications use and gets the values of x, y, and z and displays them in a TextView. For my phone I was able to see it was the y-coordinates that I would be using to make the accelerometer work by tilting the phone down and up. I also used this to find that the coordinates are not the same orientation for the phone and the tablet. The tablet y-coordinates are based off of the tablet in a landscape view and the phone y-coordinates are based off the portrait view. The code was changed to show the value of y between -15 and 15 using mathematical operations.
The screen shot for this application was not accessible since the emulator doesn't have the sensors needed.
Project .apk file for accelerometer:
accelerometer.apk
Project zip file for accelerometer project:
accelerometer.zip
CCR Client with Accelerometer
This CCR client implemented the final CCR Client with the accelerometer sensor used to speed up and slow down. This implementation would allow the train to go forward but the tilting didn't stop the train or put it in reverse. This client implemented ideas from each of the other test applications to implement the working client. It would catch the coordinates of the phone in the x,y,z plane and then would send a speed up command, slow down command, or stop command to the server based on the value of y. There is problems with this implementation since it is not fully working.
Project .apk file for CCR client with Accelerometer:
CCRAccel.apk
Project zip file for CCR client with Accelerometer project:
CCRAccel.zip
Project .apk file for CCR client with Accelerometer:
CCRAccel.apk
Project zip file for CCR client with Accelerometer project:
CCRAccel.zip