Assignment 1: Compass Design using sensors
Introduction
So far, you have developed apps in Android Studio that focused on writing/sending/displaying text, viewing EMF sensor data, monitoring battery status, and using the camera framework. In this first assignment, we are going to build a compass app using magnetic field sensor as well as accelerometer sensor, that also incorporates features of the camera framework and battery status.
The objectives for Assignment 1 are the following:
1. Develop a Compass app that uses the magnetic field sensor with the following
features:
a. shows the current direction of the compass pointer as an image and text
(e.g N, S, E, W, NW, etc.). This should be sensitive and smooth enough to change as the compass’s pointer changes. (See Notes below for adding compass image/animation)
b. allows the user to take a photo. The resulting image should be saved in the storage file that contains the compass readings tagged onto the image file name.
c. allows the user to check the battery of the phone and go back to the app. Assignment 1 Marking Guidelines:
Grade Guide:
90-100 A1 80-89 A2 70-79 A3
60-69 B 50-59 C 40-49 D 30-39 E 20-29 F 10-19 G
0-9 H
Assessment 1 Embedded and Wireless Systems Oral Assessment Guidelines
These are the guidelines for your oral assessment for Assignment 1. However, you will be given feedback on your online submissions in order to give you useful feedback and prepare you for assessment 2.
Assignment 1 Oral Assessment schedule will be released by Monday of Week 5. Please be in the lab at least 15 minute before your specified time, so that you have time to have your app downloaded and ready to demonstrate for your assessment.
Oral Assessment
The oral assessment marking criteria is as follows:
1. Demonstration and presentation of your developed sensor based applications 35%
• Demonstrating key features of the application addressing its key and distinct features.
• Addressing any distinct features that set the application aside from others developed by researchers or available in the market.
• This should not last more than 5-10 minutes. Imagine presenting your application to a customer or an investor.
2. Technical discussion on how the application was developed. 30%
• Mention any specific sensors used and any APIs used, explain how these were used to build the application.
• Mention any sensors or APIs that distinguish your system and sets it aside.
3. Quality and Originality of the mobile software developed.
20%
• Have you used any original design and /or techniques in your code that
demonstrates innovation?
• How did you address issues such as test?
4. Independence, research, and problem solving ability. 15%
Assignment 1 – Programmer’s/User’s Guide
You need to submit your code and apk through the Learn system. A programmer’s guide in the format of a report is also required for the submission. The aim of the programmer’s guide is to explain the functionality and code implementation of your compass application to other android programmers so that they could understand the working principles of your compass application and capable of programming their own compass. In addition, a user’s guide is also required for submission. The aim of the user guide is to provide instructions to the user on how to use the app and details on the different features in the app.
Programmer’s guide
Following bullet points should be covered and explained in your:
1. Application Interface and functionality introduction (20%)
2. Sensors used in the compass and their implementation (25%)
3. Sensor data processing to achieve functionality of the app (25%)
4. Principal methods/listeners implemented in the code (20%)
5. Elaborate on coding style (e.g. commenting, modularity, naming conventions used,
etc.) (4%)
6. Extra features (if applicable) and its realization should be explained for marking
purpose only (4%)
7. References (if any) (2%)
User’s guide
Following bullet points should be covered and explained in your:
1. Details of the core features that are in the app and what they do (include screenshots) (50%)
2. Instructions on how to use the app and navigate the different features easily (include screenshots) (50%)
General rules for the programmer’s and user’s guide:
1. Each guide should be contained on two pages of A4, flexible layout, within reason.
2. Any number of words, but font size not smaller than Times size 10.
3. Each guide cannot exceed two pages of A4, anything beyond will be discarded
before marking. No title pages, no appendices will be looked at.
4. Graphs / Charts / Tables can be incorporated – but EVERYTHING has to be
contained on two pages of A4.
5. Word processed documents most welcome, equivalent word-processed forms
acceptable.
6. The user’s guide must be written in layman’s terms for users to understand
Hints on Getting Started
This document should you give you a general idea on how to get started. Please note, there may be slight change in Android version; however, basic concepts should be the same.
In this document, you will learn:
• How to design your app Interface using graphical layout.
• How to simplify your code.
• How to implement methods in different ways.
• How to use various sensors in order to complete your first assignment.
Layout design
Create a new project named compass as what we did in the previous lectures. Open the layout xml file and delete the “hello world” text view automatically generated every time a new project is created. Instead of typing, we are going to draw our layout graphically. In the Design view of the content_main.xml (or activity_main.xml) select Plain TextView under Widgets category and drop it to user interface.
Properties of the TextView can be modified by expanding the ‘Component Tree’ tab on the right.
Declarations
Now let’s look at the MainActivity java file. First of all, declare TextView, SensorManager and sensor which will be used later. Also, since we are going to use both magnetic field sensor and accelerometer sensor, two float variables are created to store data from these two sensors.
Method and listener implementation
Under the OnCreate() method, we need to call two user defined methods named ‘initialization()’ and ‘calculateOrientation()’.
You will get errors since these two methods haven’t been created yet. To create these methods automatically, click on the method name, and a red bulb will appear on the left. Click on the bulb to get the list of possible solution to the error flagged. Select the ‘Create method’ option, and the method will created automatically.
We also need to implement onPause() and onResume() methods just like what we did in the last lecture. You can simply right click on the space where you want to implement these two methods and choose Generate->Override methods… Find and select these two methods, and they will added to your application.
Finally, we need to implement the SensorEventListener class to monitor sensor operations.
You will get errors as it has not been imported yet. Import it.
In addition, an error would still exist on the same line since the required methods (onSensorChange(), and onAccuracyChanged()) for the ‘SensorEventListener’ class have not been created. To create this, click on the red bulb again, and choose ‘implement methods’.
Task: What you required to do is to complete all the Methods.
For the first user defined methods named initialization(), we need to do initialization for text view (hint: call findViewById()) and call the sensors (aSensor and mSensor) when the activity starts.
Under the method of calculateOrientation(), just as its name, data from both sensors will be calculated and converted to the degree by which your phone is rotated.
The float variable named “degree” ranges within (-180° – 180°). This means when degree is 0°, you are facing north. Finish the rest of the code to complete calculateOrientation() method.
Finally complete the onPause, onResume and onSensorChanged methods for the two sensors. Remember to call calculateOrientation method at the end of onSensorChanged method since whenever data from sensor is updated we need to recalculate orientation of the compass.
Notes on Adding Compass Image and Animation
Here we propose two possible ways, you may also think about other ways since android programming is quite flexible.
1. Android Canvas
The Canvas class holds the “draw” calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).
A complete compass application can be achieved by defining a new View class, and rewriting its onDraw (Canvas) method for compass interface. Compass rotation can be realized through method canvas. rotate.
2. Android RotateAnimation
RotateAnimation is an animation that controls the rotation of an object. This rotation takes place in the X-Y plane. You can specify the point to use for the center of the rotation, where (0,0) is the top left point. If not specified, (0,0) is the default rotation point.
You can simply consider the compass application as a rotate animation of an imported compass figure.