S19: Zeus

From Embedded Systems Learning Academy
Revision as of 23:12, 18 May 2019 by Proj user17 (talk | contribs) (Hardware Interface)

Jump to: navigation, search

Grading Criteria

  • How well is Software & Hardware Design described?
  • How well can this report be used to reproduce this project?
  • Code Quality
  • Overall Report Quality:
    • Software Block Diagrams
    • Hardware Block Diagrams
      Schematic Quality
    • Quality of technical challenges and solutions adopted.

Project Title

Zeus : The Autonomous Car

Abstract

When over a century ago Karl Benz invented the first car, it came as a miracle to people. Now, Almost every household owns a car. The industry has come from a 20 Horse power producing 2.9 liter Ford Model T (1908) to a massive 1500 Horsepower 5 liter Koenigsegg Regera (2018). And as such, further developments into the driving industry are bound to come. One such major field is the realm of Driverless smart cars. This project focuses on developing a driverless smart car(model) that is capable of going from one place to the destination without any manual input, avoiding obstacles along the way.

Objectives & Introduction

Zeus revolves around several SJone boards that have LPC 1758 at the center......(continue here). Following are the objectives of this project.:

  • Zeus should successfully navigate from a fixed starting point to a fixed destination based on GPS.
  • Obstacles on the way should be avoided.
  • Code should be 100% Unit-Tested
  • Communication should be established between Zeus and a mobile phone through an APP.

Team Members & Responsibilities

  • Neel Patel
    • Team Lead
    • Master Module
    • Android App
    • BLE Module
  • Aman Chandan
    • Material/ Components manager
    • GEO module
  • Artik Shetty
    • Motor Module
    • PCB
  • Himanshu Gunjal
    • Master Module
    • BLE Module
  • Karan Daryani
    • Car Layout Designer
    • Motor Module
    • PCB
  • Namdev Prabhugaonkar
    • GEO module
    • PCB
  • Oliver Zhu
    • GIT repository Manager
    • Sensor Module
  • Wendy Chao
    • Sensor Module

Schedule

Week# Date Task Activities Status Completion Date
1 02/12/19
  • Form Teams
  • Form a Group of 8 students
  • Completed
  • 02/12/19
2 02/19/19
  • Setup Slack for the team
  • Setup a Slack workspace for the team. (Neel)
  • EDIT: Preet wants a private channel for Zeus in the CMPE 243 Workspace (Neel)
  • Invite Preet to the private Channel. (Neel)
  • Completed
  • Completed
  • Completed
  • 02/19/19
  • 02/19/19
  • 02/19/19
3 02/26/19
  • Create a Gitlab project for Zeus.
  • Order Can trancievers
  • Setup a Gitlab project (Namdev)
  • Each member should clone this to their local devices and try to create/edit/merge a branch.
  • Invite Preet to GIT (Namdev)
  • Get 3.3V CAN trancievers.(Himanshu)
  • Completed
  • Completed
  • Completed
  • Completed
  • 02/26/19
  • 02/26/19
  • 02/26/19
  • 02/26/19
4 03/05/19
  • Research Past Projects.
  • Setup a way to manage Finances.
  • Demo CAN Communication.
  • Read about past projects on SocialLedge.
  • Find out what components to buy and make a list.
  • Shortlist and Buy an RC car.
  • Order Components
  • Make a splitwise Group and add everyone to manage funds.
  • Demo of CAN communication in Class ( Olliver and Wendy)
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • 03/05/19
  • 03/06/19
  • 03/12/19
  • 03/20/19
  • 03/20/19
  • 03/05/19
5 03/12/19
  • Setup Busmaster and demonstrate Busmaster.
  • Setup PCAN Dongle with DB9 Connector
  • Download Busmaster from Busmaster
  • Download PCAN drivers from PCAN_Driver
  • Demo of Busmaster in Class (Namdev and Aman)
  • Completed
  • Completed
  • Completed
  • 03/10/19
  • 03/10/19
  • 03/12/19
6 03/19/19
  • Initial DBC File
  • Each control module should be able to send and receive the date based on their messages in the DBC
  • Completed
  • 03/15/19
7 03/26/19
  • CAN communication demo with all the modules.
  • Steer Car.
  • Class Demo to Send and receive messages on CAN bus and display on Busmaster.
  • Testing the servo motor with the in built PWM API to steer the car. (Karan and Artik)
  • Collected Xbee module, Display and Rear Sensor from Preet.
  • Completed
  • Completed
  • completed
  • 03/26/19
  • 03/24/19
  • 03/26/19
8 04/02/19
  • Final Wiki Schedule
  • Get Acrylic board and Wire Wrapping board.
  • Basic Movement of Car
  • Finish Assigning task for the remainder semester.
  • Mount all 5 SJones on the Car.
  • MOTOR: Receive directions from master and move the Car.
  • MASTER: DBC file messages for movement of Car.
  • ANDROID: Basic Android app using AndroidStudio. (Neel)
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • 04/02/19
  • 04/07/19
  • 04/07/19
  • 04/07/19
  • 05/03/19
9 04/09/19
  • Communication with mobile
  • Implement MIA messages
  • BLE: Establish Communication between ECU and Mobile (Neel and Himanshu)
  • GPS: Parse GPS data for co-ordinates, update DBC with correct message to send the co-ordinates. Indicate GPS lock using LED.
  • MASTER: Turn Car based on GPS data.
  • SENSOR: Send Sensor data to Master.
  • ANDROID: Incorporate Google Maps to provide source and destination co-ordinates.(Neel)
  • Implement MIA messages from all ECUs.
  • Completed
  • In-progress
  • In-Progress
  • Completed
  • Completed
  • Completed
  • 05/03/19
  • 04/10/19
  • 05/01/19
  • 04/12/19
10 04/16/19
  • Project Progress 1 Due
  • Demo Car Progress.
  • SENSOR: Obstacle avoidance Algorithm. Update DBC message to send obstacle data.
  • MASTER: Decision tree to decide where to go based on GPS and SENSOR data.
  • ANDROID: Display compass on App.
  • GPS: Update DBC message to send compass data to App over bluetooth.
  • MOTOR: Ramp Testing. should be able to take ramps into consideration.
  • Completed
  • Completed
  • In-Progress
  • In-Progress
  • In-Progress
  • Completed
11 04/23/19
  • Project Progress 2 Due
  • Demo Car Progress 2.
  • All the modules should be able to communicate with each other.
  • The Car should follow GPS directions and avoid obstacles in the way without any user input. Android app should display start and end point coordinates and have successful communication with the ECUs.
12 04/30/19
  • Preliminary Test
  • Fix the encountered issue
  • Assign the bugs to the respective team and resolve them.
  • Assemble all the components and give final touch to the CAR body.
13 05/07/19
  • Equilibrium Testing
  • Testing harmony between all the system modules.
  • Checking the response of each module to other modules for different conditions and test scenarios.
14 05/14/19
  • Final Testing
  • Final Testing and Stress Testing
  • Body cosmetics and working on other scopes to upgrade
15 05/22/19
  • Final Demo
  • Demo the car and contest with other teams on the demonstration day.

Parts List & Cost

Item# Part Description Vendor Qty Cost $
1 RC Car Sheldon's Hobby Store 1 180.00
2 SJOne board Preet 5 400.00
3 GPS Module 1
4 Lipo Battery (7200 mAh) Amazon 1 37.99
5 DB9 Connector Amazon 1 6.50
6 LIPO Battery Charger Sheldon's Hobby Store 1 39.99
7 Ultrasonic sensor Robotshop 4 99.80
8 PCB
9 CAN Transceiver Amazon 5 49.95
10 LCD Display Obtained From Preet 1 Free
11 Xbee Obtained From Preet 1 Free
12 Adapter for Lipo Charger Amazon 1 15.84

Design & Implementation

The design section can go over your hardware and software design. Organize this section using sub-sections that go over your design and implementation.


GEO Module

The main purpose of the geographical controller is to guide the car towards its destination. This is done by processing data from the GPS and Compass module in order to get the Heading, Bearing, and Distance. The compass will allow the user to calculate the Heading, which tells us which direction the car is pointing relative to magnetic north or simply, "Which way the car is pointing"? The GPS will allow the user to get the current coordinates of the car, which will be useful when calculating the Bearing and Distance. The Bearing tells us the direction from the current location to a checkpoint coordinate, and is given as the angle between the location and the current location of the car. The Distance tells us how many meters away the current checkpoint is. Essentially, How far away are we from our destination?

The geographical controller is also responsible for:
1. Parse the data from GPS and Compass module.
2. Navigate a path towards the destination using the nearest checkpoint
2. Navigate to nearest checkpoints and to set course towards the nest checkpoint along the path towards the destination .
3. Setting up the heading of the car towards the direction of the next checkpoint .

Hardware Design

CMPE243 S19 ZEUS geo block diagram.jpg

Hardware Interface

CAN Bus
The CAN bus interface allows the geographical controller to send and receive data from other microcontrollers on the bus. For example, the geographical controller will send requests to the master controller to tell it to turn right, left, or keep straight in order to reach the set checkpoints. The geographical controller will plan a path towards the destination using the closest checkpoint towards the destination path and then send the steer commands to be taken in order to to steer towards the destination.

MTK3339 Ultimate GPS

The MTK3339 Ultimate GPS module from Adafruit was chosen because it is a plug and play device and gives consistent GPS string The main purpose of the GPS module is to provide an accurate location of the car while the car navigates towards its destination. This is done by parsing NMEA sentences, which are transmitted by up to 66 satellites to pinpoint the current location of the module. There are various different types of NMEA sentences, such as $GPRMC and $GPGGA. The NMEA sentence that was used was $GPGGA, which provides only the recommended minimum. The module is interfaced via UART with a baud-rate set to 57600bps. The module also comes with a fix LED, which indicates if a GPS fix by blinking every 15 seconds, if not, it blinks every 1Hz. The module is powered by 3.3V from the SJOne board.
CMPE243 S19 ZEUS Gpsimage.png
The $GPGGA sentence is separated by commas, which the user has to parse in order to get useful data out of the module. The most important data that the user want is the GPS coordinate, Latitude and Longitude.The parsing of data was done using the strstr() function which returns the pointer of the comma from the NMEA string to be parsed.
Below is an example of a parsed $GPGGA sentence:

      Example:  $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 
1 2 3 4 5 6 7 8 9 10 11 12
Number Raw form Description
1 123519 Time of fix 12:35:19 UTC
2 A Navigation receiver warning A = OK, V = warning
3 4807.038 Latitude 48 deg. 07.038 min
4 N North
5 01131.000 Longitude 011 deg. 31.00 min
6 E East
7 1 Fix Quality, 1 means GPS is fixed
8 08 Number of satellites being tracked
9 0.9 Horizontal dilution of position
10 545.5,M Altitude, Meters, above mean sea level
11 546.9,M Height of geoid (mean sea level) above WGS84
12 *68 the checksum data, always begins with *


CMPS11 - Tilt Compensated Compass Module
The CMPS11 - Tilt Compensated Compass module was chosen because it provides the heading value, which let the user know which way the car is facing relative to magnetic north. Not only does it provide heading, the module also has a 3-axis gyro and a 3-axis accelerometer to remove or neglect any errors while the module is tilted (going up or down a slope). Another compass module was considered before choosing this module because the old module had to be calibrated extensively in order for it to work properly. This module only needed to be calibrated one time in an environment free of magnetic interference. The heading was double-checked after the module was mounted onto the car.
The compass module is placed away from all other components of the car to minimize any magnetic interference from the motor, servo, sensors, and microcontrollers. Placing it in an environment where there is magnetic interference will cause incorrect reading of the heading and the car will navigate towards the wrong direction. The compass module is interfaced via I2C. It is powered on by 3.6-5V, but 3.3V works also.
CMPE243 F17 FOXP2 cmps11 module.png

Motor Module

Motor module is one of the five controllers used in our self-driving car. Motor controller is responsible for driving the car forward and for steering the vehicle. The motor module has two motors viz.DC motor and Servo motor. DC motor makes the car move forward and reverse. Servo motor steers the car either left or right. Along with the two motors, we have the rpm speed sensor which is interfaced with our controller to control the speed of DC and move the car at the desired speed in meters per second (m/s).

Hardware Design

The Motor Module consists of 2 motors viz. DC motor and Servo motor controlled by an SJOne board by varying the PWM signals, which is nothing but the duty cycle. PWM stands for pulse-width modulation, a type of digital signal and can be used to control the motors. Along with two motors, we have interfaced the RPM sensor with the motor module micro-controller to get the wheel feedback and move our car at a constant speed even if the car is going uphill or downhill.

Block Diagram for Motor module

Hardware Interface

Schematic diagram for Motor module with all connections


Servo Motor
Varying Duty cycle and PWM waveforms according to steering position

RC car came with a digital servo motor, requiring around 3-5V. The motor is directly controlled by giving a varying PWM signal from the SJOne board. Servo motor is used to convert an electrical signal into a linear motion. As per the PWM pulse received by the servo motor from SJOne board, it will rotate its shaft by a certain degree left or right. Below table gives the PWM values given to the motor for turning the car in the desired direction.


No. PWM Direction
1 5 Full Left
2 6 Slight Left
4 7 Straight
6 8 Slight Right
7 9 Full Right


DC Motor
DC motor Traxas#3785_Titan_12T


Like servo motor, the DC motor was also embedded in the RC car. The DC motor is used to convert an electrical signal into mechanical power. DC motor is controlled in the same manner as the servo motor i.e., by varying the PWM signal. The only difference here is that the PWM signal from the SJOne board is given to an Electronic Speed Controller or ESC. The ESC is used to generate three-phase electric power of low voltage in order to vary the speed of the DC motor. In case of no ESC, the DC motor will either not move or will start moving at full throttle. The RC car DC motor required 7.4V of power supply to work. The maximum speed that can be attained by this DC motor is 31mph.







Software Design

Testing & Technical Challenges

Following were the problems faced and their resolutions:

Problem 1: In spite of controlling speed using RPM sensor, the car was not in control while on a downhill.

Solution 1: After trying all possible solutions we could think of, we applied a brake momentarily at the start to reduce the sudden increase in PWM and then controlled the car based on the inclination. Also, made sure that if PWM value went below a certain range, then no brake was applied to the car.


Problem 2: The car did not go reverse all of a sudden even with the working code.

Solution 2: When checked with the transmitter/remote, still didn't work. It was found by reading the manual that ESC has 3 modes which can be set by long pressing the power button. And accidentally, ESC was changed to mode 2 where reverse wouldn't work. The car was set back to Mode 1.

Sensors Controller

Group Member

Oliver Zhu, Wen Yuen Chao

Hardware Design

In this project, the sensor we use is LV-MAXSonar-EZ4, which is ultrasonic sensor. There are three sensors put in the front of our RC car and detect the left, middle and right side independently.

Hardware Interface

There are seven pins in this sensor.

LV-EZ4-Ultrasonic-Sensor.jpg


Pin Name Function Purpose
Pin 1 BW Leave open
Pin 2 PW Pulse width
Pin 3 AN Analog voltage
Pin 4 RX Receive
Pin 5 TX Transmit
Pin 6 +5V Vcc
Pin 7 GND Ground
Sensor interface2.png

Software Design

Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it.

Implementation

This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.

Android Application and Bridge

Group Members

Design

The bridge controller is responsible for establishing communication between the CAR and an Android Phone. This communication is achieved using Bluetooth technology and HC-05 bluetooth transceiver. The android app "ZeusApp" sends Co-ordinates as well as Start/Stop command to the car. Once the bridge ECU receives this data over UART, it transmits it to corresponding controllers using CAN bus. The HC-05 module communicates with SJONE over UART at 9600bps baud rate. The overall architecture of the system is given below:

BLE Block Diagram
Pin Configuration:
Sl. No Pin on SJOne Board Pin on HC-05 Purpose
1 TXD3 RXD Transmit using UART3(TXD3) to HC-05
2 RXD3 TXD Receive using UART3(RXD3) from HC-05
3 3V3 VCC 3.3V voltage supply
4 GND GND Ground

Bluetooth Hardware Design

HC-05 module

We decided to go with HC-05 as our bluetooth module HC-05 because of the vast amount of information on it on the internet. It is basically a plug and play module which makes the work very convenient. Given below are features of HC-05:

  • -80dBm sensitivity
  • Up to +4dBm transmit power
  • Low Power operation
  • UART interface with programmable baud rate.
  • Integrated Antenna and edge connector.
  • Supported Baud Rate: 9600,19200,38400,57600,115200,230400,460800.
  • Auto-connect to the last device on power as default.
  • Auto-pairing PINCODE:”0000” as default
  • Auto-reconnect in 30 min when disconnected as a result of beyond the range of connection.

Bluetooth Software Design

The BLE ECU is responsible for receiving data over UART and then Packaging it in correct message format and sending it over the can bus. To achieve this a few messages were made in the DBC file. The Message IDs and info is given in the table below:

Sl. No Message ID Message name Purpose
1 181 APP_DATA Sends 2 bit start OR stop command
2 182 APP_DATA_LAT_LONG Send Destination Latitude and Longitude to the ECU.

Our BLE is ECU is pretty simple and has one function as its core operation. This Function is given below.

void parse_data()
{
   char coord[100]={0};
   getstring(coord,100,0);
   if(coord[0]==1)
   {
       printf("\nStart");
       BLE_data.START_CAR=1;
       c_LED_display_set_number(1);
       memset(coord,0,sizeof(coord));
   }
   else if(coord[0]==2)
   {
       printf("\nStop");
       BLE_data.START_CAR=2;
       c_LED_display_set_number(0);
       memset(coord,0,sizeof(coord));
   }
   else if(strlen(coord))
   {
       while(coord[i] != ',')
       {
               Latitude[i]=coord[i];
               i++;
       }
      Latitude[i]='\0';
       i++;
       while(coord[i] != '@' )
       {
           Longitude[j]=coord[i];
           i++;
           j++;
       }
       Longitude[j]='\0';
       i=0;
       j=0;
       float LAT1=atof(Latitude);
       float LON1=atof(Longitude);
       printf("\nLatitude: %.15f",LAT1);
       printf("\nLongitude: %.15f",LON1);
     
       gps_destination.DEST_LAT=LAT1;    
       gps_destination.DEST_LONG=LON1;  
   }
   dbc_encode_and_send_APP_DATA(&BLE_data);   
   dbc_encode_and_send_APP_DATA_LAT_LONG(&gps_destination);
}

As seen in the code above, there are two DBC structures that are made, BLE_data to send start/stop command and gps_destination to send the destination co-ordinates. The android app sends a string over bluetooth to HC-05 which passes it on to SJone over UART. By parsing this string we can figure out which command was received from the App. If the 1st character of string is '1' the its a START command, if its '2' the it is STOP command and otherwise it parses the string to find Coordinates. Through the app i am sending coordinates in the format of LATITUDE,LONGITUDE so, in parse_data() function, two global character arrays were accessed. Until the iterator reaches the comma it puts everything in the Latitude array and after the till the end of string it puts everything in the Longitude array. Library function atof() was used to convert the character array to float to be able to send it over CAN.

The function parse_data() is periodically called at 1hz (so every one second). This means that the UART data is parsed and a can message is sent every second.

Android Application Design

Implementation

The main purpose of the android application is to provide the user with a way to interact with the Car using a smartphone. This app was built using Android Studio developed by Google and Jetbrains. You have the option of writing the code in either Java or Kotlin. For ZeusApp we decided to go with Java. One of the most important features that needed to be integrated into the app was Google Maps to show current position and the destination coordinates. A Google Maps API key is required to integrate Maps withing the application. This key can be acquired through the Google Developers Console. This key is mainly used to track activity of the app. Google uses the tracking to figure out charges (if any). Since our app is not a public app it doesnt cost anything for us. There are two main activities that form the app.

1. StartScreen.java is the first page that the user is greeted with its a basic home page that allows the user to go to the Map where he/she can interact with the car.

2. MapDemoActivity.java is the main activity where all the important work happens. This is the page which displays Google map fragment and all the controls associated with the car. The map fragment loads and updates the users location which he/she can see by clicking the recenter button. A pin can be dropped on the map by just touching the desired location on it. This activity also lets user connect to HC-05 bluetooth transceiver by simply clicking the Connect button. Once the app is connected to the car, user can then start the car using START button and similarly stop it using the STOP button. After marking the destination there is a button that lets the user send coordinates in the form of LATITUDE, LONGITUDE to the car.

Bluetooth - Android Side

The MapDemoActivity.java , besides UI for map. has one more integral purpose. It establishes a socket communication between the smartphone and HC-05 transceiver. For this a few things need to be done.

1. We need to specify certain permission in the AndroidManifest.xml. These permissions are given below

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

2. Import the following libraries

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import java.io.InputStream;
import java.io.OutputStream;

This lets us define variables that are needed for establishing communication over bluetooth. Input and Output stream classes lets us make buffers to write data to and read data from.

3. For basic communication we need need three things a Bluetooth Device, Bluetooth Adapter and a Bluetooth Socket. These are declared as follows:

BluetoothSocket mBTsocket = null;
BluetoothDevice BoardSJONE = null;
BluetoothAdapter ZeusAdapter; 

Bluetooth adapter lets you represent local device(smartphone) bluetooth adapter and lets you perform bluetooth tasks such as device query, instantiate a BluetoothDevice using MAC ID or UUID and create a socket. The Bluetooth adapter itself can be initialized as follows:

ZeusAdapter = BluetoothAdapter.getDefaultAdapter();

For this app we have initialized the adapter int the onStart function. This funtion is called when the activity becomes visible to the User, so, before anything can be done BluetoothAdapter is initialized.

4. Once the Adapter has been initialized and the device has been paired we now need to establish RF communication between the phone and HC-05. For that we use BluetoothSocket as below.

mBTsocket = BoardSJONE.createInsecureRfcommSocketToServiceRecord(BTMODULEUUID);
mBTsocket.connect();
pairedDevice = BoardSJONE;

Here, BTMODULEUUID is the Universallu Unique Identifier which is a 128 bit ID of the smartphone. Now the Socket connection has been established.

5. For sending data, Output Stream can be used.

tOUTPUT = mBTsocket.getOutputStream();
tOUTPUT.write(string.getBytes());
tOUTPUT.flush();

The parameters inside write() function is the data you want to send over bluetooth. A coordinate string in our case.

Testing & Technical Challenges

Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again? Make a smooth transition to testing section and described what it took to test your project.

Include sub-sections that list out a problem and solution, such as:

<Bug/issue name>

Discuss the issue and resolution.

Conclusion

Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?

Project Video

Upload a video of your project and post the link here.

Project Source Code

References

Acknowledgement

Any acknowledgement that you may wish to provide can be included here.

References Used

List any references used in project.

Appendix

You can list the references you used.