Skip to content
Ahmed Khalil edited this page Dec 7, 2017 · 21 revisions

myRobot is broken down into seven classes: TaskActivity, NavigationService, LocationHelper, IOIOClass, IncomingSms, DataParser, and SocialPost. The classes work together in tandem to achieve full functionality for the app. The flow chart shown in Figure 1 provides an overview of how the classes interact with one another and the lifecycle of the app.

When an SMS is received, the code is triggered to start navigating. The SMS should include a location’s name, which could be a building, a street, etc. The robot will use this SMS to file a request to Google Directions API obtaining a navigation route from the robot’s current GPS location to the destination. The route returned by Google is converted to an array of Location points. The robot takes the next point from its location, finds its bearing to that point, and then reacts accordingly. Based on the bearing, the robot would rotate clockwise, anticlockwise, or move forwards. To allow the robot to obtain its location and provide accurate results, this entire cycle occurs every four seconds. In the future, this cycle will be optimized and the NavigationService will be called more frequently to allow the robot to move seamlessly.

In this segment of the wiki, each class will be described as well as the methods within. Code snippets will be shown and explained; however, although these snippets are enough to guide the reader into replicating the app from scratch, it is recommended to also look at the original code itself. Furthermore, before proceeding any further with the report it is highly recommended to look at the code flow chart in Figure 1, because even though each class is individually explained, the overall interaction between the classes is only fully understood through the flowchart.

Figure 1: myRobot flowchart

Code Structure

This section includes the different tasks that had to be done prior to creating any of the classes used in this app. Without these preparations, none of these classes will function. This section discusses the app dependencies and android manifest. For more info go to this page.

TaskActivity is the app's Main Activity. Here the app's view is set up, an instance of IOIOClass is created and controlled, NavigationService is called, the picture is taken, and is uploaded to Twitter. This is the app's main hub. The instance of the IOIOClass represents the robot itself, by controlling this instance, the activity controls the actual robot’s movements. NavigationService is the service class responsible for obtaining all the GPS coordinates and routes needed to move the robot. For more info go to this page.

This service receives the final destination SMS from TaskActivity, it then uses the SMS to start LocationHelper. LocationHelper, finds the robot's current location and returns it to NavigationService. Afterwards, the service starts DataParser by passing the current location and final destination to it. DataParser returns the navigation route points to NavigationService. Finally, NavigationService uses the location points to calculate the robot's bearing to the next location point in the route, as well as the distance from the robot to the final destination. Those two pieces of information are then passed back to TaskActivity, which based on, will move the robot accordingly.

It is necessary to note that NavigationService creates its own thread and it keeps repeating infinitely every four seconds, until the robot reaches its destination. For more info go to this page.

This helper class finds the robot’s current location every 750ms. The location found is returned to the NavigationService for further processing. The way NavigationService receives back the robot's current location is by accessing the public variables of LocationHelper. For more info go to this page.

This class is responsible for setting up the communication between the phone and the IOIO board. It establishes a loop that keeps sending out information to the board. In this class, all the pins required to control the motors are defined. There is a public setter method in this class that allows an external class to change the motors directions. This method is primarily used by TaskActivity to move the robot. For more info go to this page.

This class is on the lookout for any incoming SMS messages when the app is on. Once it receives an SMS, it sends the message to TaskActivity through an EventBus. For more info go to this page.

This helper class is used to parse the data retrieved from the Google API and returns it to NavigationService as an array list. For more info go to this page.

This class is in charge of posting to social media. For more info go to this page.

Clone this wiki locally