F14: Team2-Self Driving Car - AUG

From Embedded Systems Learning Academy
Revision as of 19:15, 16 December 2014 by Proj user15 (talk | contribs) (Master controller)

Jump to: navigation, search

Self Driving Car

Abstract

Objective and Scope

Team Members & Responsibilities

  • Sensor Controller
    • Amey Patil
    • Sujith Durgad
    • Arvind Allawadi
  • Motor Controller and Power
    • Digvijay Patil
    • Rohan Jani
    • Mahesh Chudasama
  • Display
    • Mradula Nayak
    • Karthik Govindaswamy
  • Communication Bridge + Android
    • Siddhata Patil
    • Mohammed Raashid Kheruwala
  • Geographical Controller
    • Yash Parulekar
    • Ajinkya Khasnis
    • Harsh Lavingia
    • Anand Dumbre
  • Master Controller
    • Pradyumna Upadhya
    • Huzefa Siyamwala

Introduction

Schedule

Common Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/16/2014 10/7/2014 Finish Ordering project hardware parts Completed. TBD
2 10/5/2014 10/21/2014 Fine tune subscriber code Completed 10/28/2014
3 10/7/2014 10/21/2014 Finish Development of CAN Transceiver boards Completed 10/25/2014
4 10/5/2014 11/4/2014 Sub teams finalize and implement dependency code(atleast single API per team) Completed 10/28/2014
5 10/5/2014 10/28/2014 Finish hardware Completed 10/27/2014
6 10/28/2014 12/2/2014 Start integration and testing. Scheduled TBD


Master Team Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/30/2014 10/21/2014 Fine tune subscriber code and finalize CAN apis required from other boards Completed Completed on 10/21/2014
2 10/5/2014 10/21/2014 Fine tune subscriber code Completed Completed on 10/27/2014
3 10/5/2014 10/21/2014 Develop CAN Transceiver Board Completed Completed by 10/19/2014
4 10/5/2014 11/4/2014 Implement API co-ordination logic and test with other boards APIs Ongoing Master - motor/sensor communication apis has been completed. Integration of these three modules going on
5 10/21/2014 10/28/2014 Test hardware with master code and motor code. 10/26/2014 Master and motor has been integrated.
6 10/21/2014 11/4/2014 Integrate master with motor and sensor. Ongoing Integration is not fully complete. It is going on.
6 10/28/2014 11/11/2014 Integrate master ,motor,sensor with andriod. Scheduled TBD
7 10/28/2014 11/11/2014 Integrate master with display. Scheduled TBD
7 10/4/2014 11/11/2014 Integrate master with compass and gps. Scheduled TBD
7 11/4/2014 11/18/2014 Fix integration bugs and fine tune boards initialization and communication. Scheduled TBD
8 11/11/2014 11/28/2014 Implement car movement logic as per GPS/COMPASS/Sensor data. Scheduled TBD
9 11/28/2014 12/09/2014 Test hardware/software to remove bugs and fine tune algorithm. Scheduled TBD


GEO Team Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/16/2014 9/23/2014 Decided and then ordered GPS modem
Received Compass module
Completed 9/23/2014
2 9/23/2014 9/30/2014 Acquired GPS modem
Interface Compass with SJOne Board via I2C
Completed 9/30/2014
3 9/30/2014 10/7/2014 Designing GPS driver
Test code to get compass heading information
OnGoing
Completed
TBD
4 10/7/2014 10/21/2014 Integration of GPS with the main board
CAN RX task and subscription handling
In Progress TBD
5 10/21/2014 11/04/2014 Test communication with the Master
Determine final heading using GPS location and compass reading
Scheduled TBD
6 11/04/2014 11/18/2014 Test and debug, Make necessary changes in the driver
Compass Calibration
Scheduled TBD

Motor Team Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/30/2014 10/7/2014 Understand the SERVO and DC motor controller signals Completed 10/4/2014
2 10/4/2014 10/11/2014 Interface SJSU one board to SERVO and DC motor controller Completed 10/10/2014
3 10/7/2014 10/18/2014 Develop CAN transceiver boards Completed 10/12/2014
4 10/12/2014 10/26/2014 Design and Develop unified power distribution circuit and hardware structure for RC car Ongoing Power unit got burnt, working on new design
5 10/19/2014 11/03/2014 Interface motor SJSU board with master SJSU board for motion tuning Ongoing TBD
6 10/26/2014 11/07/2014 Redesign mechanical structure and fix wiring issue Ongoing TBD
7 10/19/2014 11/07/2014 Work on shaft encoder for motor speed feedback Ongoing TBD
8 11/01/2014 11/11/2014 Work with other teams to establish reliable CAN communication. Scheduled TBD
9 11/07/2014 11/30/2014 Fine tuning of turning curves, jerks, acceleration and deceleration algorithm. Scheduled TBD
10 11/07/2014 11/20/2014 Implement Zigbee communication for long range data logging. Scheduled TBD

I/O Team Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/16/2014 9/23/2014 Decided and then ordered display module Completed 9/23/2014
2 9/24/2014 10/7/2014 Setting up the GIT Completed 10/14/2014
3 10/7/2014 10/14/2014 Basic display on LCD with UART interface Completed 10/23/2014
4 10/14/2014 10/28/2014 CAN communication between Master and I/O Completed 10/28/2014
5 10/28/2014 10/31/2014 CAN communication between I/O and sensor Completed 11/02/2014
6 10/31/2014 11/4/2014 CAN communication between I/O and GPS Completed 11/02/2014
7 11/5/2014 11/9/2014 Logic for No. of CAN messages/sec, LED's for Start, CAN Tx,CAN Rx Completed 11/18/2014
8 11/9/2014 11/15/2014 Mount LCD on board on CAR and Final testing Completed 11/30/2014

Sensor Controller

Sl. No Start Date End Date Task Status Actual Completion Date
1 10/3/2014 10/10/2014 Developing a Test code for sensors Completed 10/14/2014
2 10/10/2014 10/17/2014 Finalizing on the sensors Completed 10/14/2014
3 10/17/2014 10/24/2014 Transfer of sensor data via can bus to master Completed 10/21/2014
4 10/24/2014 10/30/2014 Implementation with multiple sensors Ongoing TBD
5 10/30/2014 11/6/2014 Implementation of Light Sensors and Tilt Sensor Scheduled TBD

Communication Bridge + Android Team Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/16/2014 9/23/2014 Design UI of the Android App Completed 9/23/2014
2 9/23/2014 9/30/2014 Interface and pairing the Android App with Bluetooth module Completed 9/30/2014
3 9/30/2014 10/7/2014 Implementation of first stage of Android App (Frame 1: Sending data via Bluetooth to give directions for the car) Completed 10/4/2014
4 10/7/2014 10/14/2014 Implementation of Bridge between Android and UART Completed 10/16/2014
5 10/14/2014 10/28/2014 Implementation of second stage of Android App (Frame 2: Create on click function to give Start and End coordinates for the car) Completed 10/28/2014
6 10/28/2014 11/11/2014 Implementation of third stage of Android App (Frame 3: Navigation path using markers and CLL coordinate system, START button and STOP button) Completed 11/15/2014
7 11/11/2014 11/25/2014 Testing and improving the UI of to the App Completed 11/25/2014

Parts List & Cost

Qty Description Manufacturer Part Number Total Cost
6 Ultra Sonic Sensor Arduino HC-SR04 12.58
1 Compass Module Honeywell HMC6352 Provided By Preet
1 GPS Receiver MediaTek LS20031 5Hz (66 Channel) $59.95
1 RC car Traxxas 1/10 $272
1 Bluetooth module SunFounder HC-06 $7.99

Backup Parts & cost

Qty Description Manufacturer Part Number Total Cost

Design & Implementation

Controller Communication Table

Controller ID Table
Controller ID Controller
0x050 Master Controller
0x051 Geographical Controller
0x052 Motor Controller
0x053 Sensor Controller
0x054 IO Controller
0x055 App/Bridge Controller
Common MessageID Table
MessageID Description ResponseID Description
0x110 Get Board Status 0x52A Send Board Status (Response of 0x42A )
0x111 Get Board Time 0x211 Present Board Time (Response of 0x111)
0x213 Board's New Data (Response of 0x315)
Master Controller MessageID Table
SubscribeID Description PublishID Description
0x42A Subscribe to new motor data to be set 0x52A Publish motor data (Response of 0x42A )
0x44A Subscribe to new input/output data 0x54A Publish data to be displayed (Response of 0x44A )
0x45C Subscribe to reliable sensor value (sensor data from sensor through master) 0x55C Publish reliable sensor value (Response of 0x45C)
0x45D Subscribe to current location data (GPS data from Master through GPS) 0x55D Publish current location data (Response of 0x55D)
0x44A Subscribe to display data (api to be used by display to get new display data) 0x54A Publish new display data (Response of 0x54A)
Master Specific MessageID Description ResponseID Description
0x311 SetTime (master specific command)
0x312 Start (master specific command)
0x313 Stop (master specific command)
Geographical Controller MessageID Table
SubscribeID Description PublishID Description
0x40C Subscribe to Compass Data 0x50C Publish Compass Data (Response of 0x40C )
0x40B Subscribe to GPS Data 0x50B Publish GPS Data (Response of 0x40B )
0x40A Subscribe to Geographical Data 0x50A Publish Geographical Data (Response of 0x40A )
Motor Controller MessageID Table
SubscribeID Description PublishID Description
0x40A Subscribe to Motor Data 0x50A Publish Motor Data (Response of 0x40A)
0x40B Subscribe to Motor Speed 0x50B Publish Motor Speed (Response of 0x40B)
0x40C Subscribe to Motor Direction 0x50C Publish Motor Direction (Response of 0x40C)
Sensor Controller MessageID Table
SubscribeID Description PublishID Description
0x40A Subscribe to Sensor Data 0x50A Publish Sensor Data (Response of 0x40A)
0x44A Subscribe to Sensor Data(I/O unit subscribes 0x54A Publish Sensor Data (Sends data to I/O unit)
IO Controller
SubscribeID Description PublishID Description
0x40A Subscribe to IO Data 0x50A Publish IO Data (Response of 0x40A)
Android and Bridge
SubscribeID Description PublishID Description
0x45A Subscribe Start/Stop command(IO data to Master) 0x55A Publish "start" message (response of 0x312)
0x45B Subscribe GPS longitude and latitude (Android GPS data to Master) 0x55B Publish current location (response of 0x45D)

Master controller

Main Workflow
SendTask Workflow
RxTask Workflow

Android and Bridge

System Diagram

Complete System Diagram for Android communication

The above System Diagram shows the overall connection of the SJOne board and the HC06 bluetooth module. The module has 4 pins labeled on the back, VCC, GND, TXD and RXD. You might buy a module with two more pins KEY and STATE but it won't matter if you leave them open. The communication for configuration of the module is based on AT commands. There is one command for every thing, to set the device name, set the pin, set the baud rate and much more. All you have to do is to save these AT commands in the form of string and send each byte serially to the module using a simple for loop. Initially the baud rate is set to 9600. Following table shows few of the AT commands which you may require.

Command Response Use
AT OK Used to verify communication
AT+NAMExyz OKsetname Sets the module name to “xyz”
AT+PIN1234 OKsetPIN Sets the module PIN to 1234
AT+BAUD1 OK1200 Sets the baud rate to 1200
AT+BAUD2 OK2400 Sets the baud rate to 2400
AT+BAUD3 OK4800 Sets the baud rate to 4800
AT+BAUD4 OK9600 Sets the baud rate to 9600
AT+BAUD5 OK19200 Sets the baud rate to 19200
AT+BAUD6 OK38400 Sets the baud rate to 38400
AT+BAUD3 OK4800 Sets the baud rate to 4800
AT+BAUD4 OK9600 Sets the baud rate to 9600

This bluetooth module requires 5V. Its Rx is connected to Tx of SJOne board and its Tx is connected to Rx of SJOne board with a common ground. We need bluetooth module in order to establish communication between the SJOne board and the Android Phone. In order to do this, code for bluetooth pairing, connecting and transmitting was thus written on Android SDK. There are three main tasks on the Android side :

  1. To send location coordinates (latitude and longitude) to GPS.
  2. To transmit "START" signal to the master.
  3. To transmit "STOP" signal to the master.

At the receiver, this data will be received by the Bluetooth Module and provided to SJOne(Android board) via UART. Then via CAN communication its passed on to the Master and GPS boards.

Software Developing Environment

Android SDK

The software developing Environment used for Android was Android SDK and for bridge we used Free RTOS. To develop an Android App for our self driving car, the first thing we needed was a proper connection between the Bluetooth module and our Android phone. For this we used the Bluetooth APIs available like Bluetooth Adapter, Bluetooth Device etc. Here the Bluetooth Adapter is used as the first step to setup the Bluetooth connection and to verify if the bluetooth is supported or not. The Bluetooth Adapter is returned when we call static BluetoothAdapter.getDefaultAdapter(). Secondly, it is very important that you enable the Bluetooth and this is done by calling startActivityForResult(). According to your requirement you can either use BluetoothAdapter.ACTION_REQUEST_ENABLE or BluetoothAdapter.ACTION_STATE_CHANGED. Third Task is the Discovery, for this we have to call startbtAdapter.startDiscovery(). Next Task is to scan the devices available for Pairing. This is done by BluetoothAdapter.ACTION_DISCOVERY_STARTED and BluetoothAdapter.ACTION_DISCOVERY_FINISHED. And if nothing is happening check if the Bluetooth is ON if not turnOnBT(). Next task is to pair the Devices. This is done by calling btAdapter.getBondedDevices(). This will return already paired devices with the Android Device you using. Next step is to connect the devices which are not already paired. These devices are paired by entering the password for the device. Next step is to initiate a Bluetooth Connection for sending the data. For this simply copy the code for "private class ConnectThread extends Thread" from the Bluetooth|Android Developer site. Final task is set the UUID to "00001101-0000-1000-8000-00805F9B34FB" and you are good to go. It is very important that you add Permissions in the Android Manifest.xml. The permissions that we used were:

   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
   <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
   <uses-permission android:name="android.permission.BLUETOOTH"/>

Developing an Android App

Android App : Stage 1
Android App : Stage 3
Android App : Stage 2


The very first stage was to create a Map fragment. For this we decided to go with the Google Map API V2. For this we need the "Google Play services" . To install this package go to Android SDK Manager, click on Google play services and click on install package. Once the package is installed, we have to import this library. After this we need to add the googleplay_services_lib to our project. To do this, goto Properties -> Android -> Click on the googleplay_services_lib -> Click on Add. In MainActivity.java import the following:

    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;

Now add all the required permissions to your project

   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
   <permission
       android:name="siddhata.patil.sdc243.permission.MAPS_RECEIVE"
       android:protectionLevel="signature" />

Next step is the SHA1 fingerprint key. Goto Mac / Windows -> Preferences -> Android -> Build -> Copy the given SHA1 fingerprint key. Now go on the Internet and search for API Console - Google code. This is Google Developers Console. On left hand side you will see Services -> turn the tab ON for Google Maps Android API v2. Now again go on the left hand side and you will find API Access. Click on that. Generate new key -> Paste the copied SHA1 key ; "your package name" -> Click on Create. Your API key will be generated. Now copy this API key and paste this in your AndroidManifest.xml.

         <meta-data
           android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />
         <meta-data
           android:name="com.google.android.maps.v2.API_KEY"
           android:value="Paste you API key" />

Now for the UI, under Activity_main.xml, we need to create a map fragment in Relative layout.

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   xmlns:map="http://schemas.android.com/apk/res-auto"
   android:id="@+id/LinearLayout1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical" >
   <fragment  
         android:id="@+id/map"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:name="com.google.android.gms.maps.MapFragment"
         />

Now, for the second stage of our Android App, we had to create an On click function to select the Start and End coordinates for our car.

   public void onMapLongClick(LatLng point) 
   {
    AlertDialog.Builder setPasswordDialog = new AlertDialog.Builder(this);
    setPasswordDialog.setTitle("243SDC_Team 2");
    setPasswordDialog.setMessage("Coordinates for the car:"+ String.valueOf(point.latitude) + " , "
    + String.valueOf(point.longitude));
    setPasswordDialog.show();
      if(isStartDone==0)
      {
      SANJOSE1 = new LatLng(point.latitude, point.longitude);
      Log.d("ADebugTag", "Setting Start Point");
      isStartDone=1;
      }
      else
      {
      Log.d("ADebugTag", "Setting End Point");
      SANJOSE2 = new LatLng(point.latitude, point.longitude); 
      }
    }

Now for the third and the last stage of our Android Application, we had to add three buttons for the UI.

  1. Navigation Button - This button gives us a red color path between the selected Start and End coordinates.
  2. Start Button - Once the Start button is pressed, all the coordinates of the desired path are sent to the GPS board a character "a" is sent to the Master board indicating a start signal.
  3. Stop Button - Stop button sends character "z" to the Master board indicating a stop signal.

Sensor Controller

HC-SR04 Ultrasonic Sensor Features

  • It is a four pin ultrasonic sensor. Four pins being; supply, ground, trigger and echo.
  • The module is composed of; ultrasonic transmitter, ultrasonic receiver, and control circuit.
  • It is a non-contact obstacle detector.
  • Range of obstacle detection is from 2cm to 400cm.
  • Requires, 5V 15mA supply.
  • 15 degrees of measuring angle.

HC-SR04 Working Principle

Timing Diagram
  • When a short 10uS pulse is provided to the trigger input, the module will send out an 8 cycle burst of ultrasound at 40 kHz and make its echo pin a logic high.
  • The Echo pin is lowered to logic low when the ultrasound burst is reflected off a distant object.
  • Now, the width of this pulse on the echo pin is in direct proportion with the distance of the obstacle.
  • Timing diagram for all these signals is shown in the above figure.

HC-SR04 Distance Calculation

Actual Distance
  • We know, speed of sound is 340m/s.
  • In our sensor, ultrasonic sound waves needs to travel twice the distance of the obstacle as shown in the above diagram.
  • From the pulse width, we know the time required to get an echo.
  • For example, let us assume the time required to get an echo is 10msec, the following image shows how the distance is calculated.
Distance calculation

Our Implementation

  • As shown in the image below, we are connecting six such sensors.
  • The front three and rear sensors are for obstacle detection, while the middle two sensors are for edge detection.
  • All trigger and echo pins are directly connected to the hardware pins of SJ-One board.

I/O Unit

The I/O Unit consists of an LCD display to report the status of the car such as sensor values, heading and the current degree for the compass. It also displays the CAN messages received per second. The LCD display that is being used in the car is SJONE Serial LCD display which runs on UART.
It is a 20x4 LCD display with a LCD driver which converts the UART characters to data and command signals for the LCD display.

The LCD has two modes of operation:
1. User Control mode
In this mode, the user controls the placing of LCD characters according to row and column by using GOTO command and $ character.
2. Smart LCD mode
In this mode, the user has to maintain a buffer for each line and print it on the line directly with scrolling enabled.

Pin Configuration
LCD Pin SJONE Pin
Rx P0.10(TXD2)
Vcc 5 V
GND Ground

LCD initialization:

Testing & Technical Challenges

Sl. No Test Case Test Description Result

Android Testing

Command Log.d("ADebugTag", "Debugging!!!!") was used a lot of times. There was lot of debugging carried out since, one change in Android SDK would make us do change in the CAN communication in Free RTOS. The very first test carried out was the transmission of the data via bluetooth from Android phone to SJOne board. This was done by sending dummy coordinates to the SJOne board. Second test was carried out for the START and STOP buttons. This was tested by receiving the respective characters on the console. Third and final test was carried out for navigation. This test was done using actual App with the car thus involving GPS as well as Master.

Challenges and Learning

Challenges in Android

There are two activities in Android. One is the bluetooth activity and other is the navigation activity. Switching from bluetooth activity to navigation activity would disconnect the bluetooth activity. This was one of the early challenges faced by us. We overcame this by changing the layout of our App. Then we combined the two activities in one activity itself by adjusting the dimensions. One more challenge faced by us was to differentiate latitude and longitude and give them separately to the GPS team. This was done by inserting one distinguishing character after each latitude and longitude so that the SJOne board could do the parsing and send it to the GPS board accordingly.

Future Enhancement

Conclusion

Project Video

Project Source Code

References

Acknowledgement

References Used

  1. Preetpal Kang, Lecture notes of CMPE 243, Computer Engineering, Charles W. Davidson College of Engineering, San Jose State University, Aug-Dec 2014.
  2. en.wikipedia.org/