7. Android

1. Introduction

The objective of the Android team is to develop an android application targeted for Nexus 7 tablet which would act as a wireless remote controller for the robotic system created by the team. It issues commands to the robot to begin various manoeuvres in maze during the leaderboard challenge. It also allows the team to visualize the current status of the maze and robot by providing a graphical 2D display of the maze.

Android application development requires Android sdk and knowledge on java. More details can be found online. Some of our team members have prior knowledge on Android application development, hence our team created the application with relative ease.

The team has two versions of the Android application: one for the checklist(which makes use of Bluetooth connectivity to communicate with RPi) and one for the leaderboard challenge(which makes use of Wifi connectivity as Wifi provides a more robust connection).

2. Main Objectives

  • Develop mobile apps on an Android-powered device (Nexus 7).
  • Design and develop graphical user interface-based apps.
  • Implement wireless connectivity between Bluetooth enabled devices.
  • Design and implement graphical displays in Android app.

3. Development Tools

  • Android Studio
  • MDP Android Module Debugger (AMD) Tool
  • S2 Terminal for Bluetooth To test our application

4. Functionalities:

1)The Android application (AA) is able to transmit and receive text strings over the Bluetooth serial communication link.

If the Bluetooth connection is “STATE_CONNECTED”, then the message can be transmitted using the sendMessage(String Message ) function. This function calls the mChatService.write(send) in order to tell the BluetoothChatService to write the message over the serial Bluetooth  link.

For reading the message received by the application, a string is constructed out of the valid bytes present in the readBuffer and then displayed in the Chat screen.

2)Functional graphical user interface (GUI) that is able to initiatethe scanning, selection and connection with a Bluetooth device.

The array adapters are initialized for paired devices as well as newly discovered devices. A Listview is setup for paired devices and newly discovered devices respectively. The scanning/device discovery is done by calling the startDiscovery( ) function(requesting for discovery through the BluetoothAdapter). When a device is chosen by the user, the MAC address of the device is sent back to the parent Activity in the result Intent. A new ConnectThread is created to initiate connection with the chosen device. The thread is started by calling mConnectedThread.start() in order for the thread to manage the connection and perform transmissions. Finally the name of the connected device is sent back to the UI Activity.

3)Functional GUI that provides interactive control of the robot movement via the Bluetooth link (e.g. move forward, left and right).

To control the robot movement, four control buttons namely, U(Up), R(Right), L(Left) and D(Down) are provided in the main screen of the application. When the user clicks any one of these buttons, a corresponding message is sent:

U: sendMessage(“w”);

R: sendMessage(“d”);

D: sendMessage(“s”);

L: sendMessage(“a”);

Depending on the current coordinates of the robot (i.e. depending on the row and column), the robot is moved accordingly.

4)Functional GUI that indicates the current status of the robot (e.g. stop, moving, etc.).

When any one of the control buttons is pressed, a Toast message is displayed at the bottom of the screen to indicate whether the robot is moving up/down or turning left left/right. This is achieved using the Toast.makeText( )  function whereby the message is displayed for a very short duration.

5)Update of Robot Start Coordinates from Android GUI to PC.

The user can type in the start coordinates( i.e. the x coordinate and the y coordinate) in the text boxes provided and press the Position button. The coordinates are converted from string to integer format using the Interger.parseInt( ) function and passed to the setcoordinates( ) function whereby the coordinates are set for the head (cellFront) and tail (cellRear) of the robot and the invalidate( ) is called to redraw the entire maze with the updated coordinates of the robot.

6)2D display of the maze environment and the robot’s location.

For creating the maze environment, PixelGridView.java file is used where canvas.drawLine( ) function is used to draw the grids. A 15 x 20 maze is thus created.The robot’s location is updated on the maze by painting the head (cellFront) with redPaint and the tail (cellRear) with bluePaint.

7)Functional GUI that provides the selection of Manual or Auto updating of graphical display of the maze environment:

The android GUI allows selection of Manual or Auto state, through which the grid gets updated. On selecting the auto update selection the grid automatically gets updated showing us updates of the robot’s position upon any update made to the robot’s position or the arena. In the case that the auto update state is toggled to manual update state the grid doesn’t get updated instantaneously, instead the robot’s position on the grid gets updated only when the user manually clicks the update button. This feature is implemented by calling the method onTogglebtnUpdatePressed(View view).

8)Functional GUI that provides two buttons that supports

persistent user reconfigurable string commands to the robot.

The GUI has two buttons F1 and F2 which contain a string value.F1 and F2 are reconfigurable and the values can be changed. For implementing the reconfigurable buttons shared preferences is used that enables to store the value of the strings and retrieve the values upon restarting the system. On click of either of these buttons the onBtnF1Pressed or the onBtnF2Pressed method is called respectively. When the respective method is called the String value that is stored in association with the button is extracted and transmitted to the PC or the robot as required via the Bluetooth connection.

9)Robust connectivity with Bluetooth device.

The android remote control provides robust connectivity with devices. The app allows for scanning for devices and connecting to devices found. Once two devices are connected the connection between them is robust. The Bluetooth connection ensures that even if the connection is lost or gets hanged in between transmission, the connection can re-establish itself without any extra effort from our end.

10)Extension beyond the basics

In the application, an addition tilt sensing feature has been implemented using the function onSensorChanged(SensorEvent event). Through this feature the position of the robot can be changed on the grid by tilting the device. If the device is tilted to one direction, say left, then the robot moves left. This is a hands-free way to alter the position of the robot.