Difference between revisions of "F15: Minion"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Schedule)
(Project Schedule)
 
(779 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=== Grading Criteria ===
 
<font color="green">
 
*  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.
 
</font>
 
 
 
== Minion ==
 
== Minion ==
 +
<div><ul>
 +
<li style="display: inline-block;"> [[File:CMPE_243_F15_Minion_Car_1.jpg|thumb|none|250px]] </li>
 +
<li style="display: inline-block;"> [[File:CMPE_243_F15_Minion_Car_2jpg.jpeg|thumb|none|243x250px]] </li>
 +
<li style="display: inline-block;"> [[File:CMPE_243_F15_Minion_Car_3.jpg|thumb|none|250px]] </li>
 +
<li style="display: inline-block;"> [[File:CMPE_243_F15_Minion_Car_4.jpg|thumb|none|250px]] </li>
 +
</ul></div>
  
 
== Abstract ==
 
== Abstract ==
This section should be a couple lines to describe what your project does.
+
This report is a description of how we built a prototype of a self navigating car by deploying the learnings from our graduate course CMPE- 243 Embedded System Applications.
 +
The prime motive was to navigate the car, autonomously, from a source point to destination point incorporating the following key features
 +
* Driving and steering with the help of DC and Servo motors
 +
* Feedback based speed control
 +
* Obstacle detection and thereby collision avoidance
 +
* Navigation on a user specified path
 +
* Diagnosis of pertinent values through a display feature
  
== Objectives & Introduction ==
+
The Micro-controllers- ARM Cortex3 LPC1758, FreeRTOS(operating system) and a highly reliable communication bus namely CAN constitute the basic building blocks of the car.
Show list of your objectives. This section includes the high level details of your project. You can write about the various sensors or peripherals you used to get your project completed.
+
User interaction is achieved with the help of a dynamic Android application that communicates with the controller through bluetooth. GPS and compass together aid in navigating the car.
  
=== Team Members & Responsibilities ===
+
[[File:CMPE_243_F15_Minion_Abstract System.jpg|centre|800px|thumb|System Block Diagram]]
 +
 
 +
== Objective ==
 +
The main objective of this project is to design and develop a self driving car capable of navigating itself from its source point to a given destination provided by an Android application. The car should follow the given path with the help of GPS and compass in the Geo controller.The car should avoid obstacles in its path with the help of ultrasonic sensors.The Master controller should make decisions to drive the motor as it receives data from Sensor controller and Geo controller in real time.The Android application should communicate with the car via a wireless medium and display sensor data in real time.The IO module should display geo controller data and sensor data on a LCD.
 +
 
 +
== Team Members & Responsibilities ==
 
'''Sensor Controller:-'''  
 
'''Sensor Controller:-'''  
 
*[http://www.linkedin.com/pub/bhupendra-naphade/29/918/916 Bhupendra Naphade]<br>
 
*[http://www.linkedin.com/pub/bhupendra-naphade/29/918/916 Bhupendra Naphade]<br>
Line 28: Line 33:
  
 
'''Communication Bridge & Android Controller:-'''
 
'''Communication Bridge & Android Controller:-'''
*Akshay Kanchar
+
*[https://www.linkedin.com/profile/view?id=193741444 Akshay Kanchar]<br>
*Asmita Deshpande
+
*[https://www.linkedin.com/in/asmita-deshpande-ba93b1100 Asmita Deshpande]<br>
  
 
'''Geographical Controller:-'''
 
'''Geographical Controller:-'''
 
*[http://www.linkedin.com/in/amitpachore Amit Pachore]<br>
 
*[http://www.linkedin.com/in/amitpachore Amit Pachore]<br>
*Sindhuja Gopalakrishnan Elango
+
*[https://www.linkedin.com/in/sindhuja-gopalakrishnan-elango-b97b16106 Sindhuja Gopalakrishnan Elango]<br>
  
 
'''Master Controller:-'''
 
'''Master Controller:-'''
 
*[http://in.linkedin.com/pub/gaurao-chaudhari/26/ab6/420 Gaurao Chaudhari]<br>
 
*[http://in.linkedin.com/pub/gaurao-chaudhari/26/ab6/420 Gaurao Chaudhari]<br>
*Akshay Dabholkar
+
*[https://in.linkedin.com/in/akshaydabholkar Akshay Dabholkar]<br>
 
 
'''Tester:-'''
 
*[http://www.linkedin.com/pub/bhupendra-naphade/29/918/916 Bhupendra Naphade]<br>
 
  
 
'''Treasurer:-'''  
 
'''Treasurer:-'''  
*Keerthanaa Alagudurai
+
*[http://www.linkedin.com/in/amitpachore Amit Pachore]<br>
  
 
'''Hardware:-'''
 
'''Hardware:-'''
*Sudheer Doddapaneni
+
*[http://www.linkedin.com/in/amitpachore Amit Pachore]<br>
 +
*[http://in.linkedin.com/pub/gaurao-chaudhari/26/ab6/420 Gaurao Chaudhari]<br>
 +
*[http://www.linkedin.com/pub/bhupendra-naphade/29/918/916 Bhupendra Naphade]<br>
  
'''Release:-'''
+
== Project Schedule ==
*Akshay Kanchar
 
 
 
== Schedule ==
 
 
 
'''Common Schedule'''
 
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! scope="col"| Sl. No
+
! scope="col"| Sr. No
 
! scope="col"| Start Date
 
! scope="col"| Start Date
 
! scope="col"| End Date
 
! scope="col"| End Date
Line 69: Line 68:
 
|9/28/2015
 
|9/28/2015
 
|RC Car and important component buying
 
|RC Car and important component buying
|
+
|Completed
|
+
|9/28/2015
 
|-
 
|-
 
|-
 
|-
Line 77: Line 76:
 
|10/6/2015
 
|10/6/2015
 
|1) Algorithm and architecture<br>2) Setup of car and decision on CAN Id's
 
|1) Algorithm and architecture<br>2) Setup of car and decision on CAN Id's
|
+
|Completed
|
+
|10/6/2015
 
|-
 
|-
 
|-
 
|-
Line 85: Line 84:
 
|10/13/2015
 
|10/13/2015
 
|1) Coding and final set-up of car<br>2) Successful communication of CAN bus.<br>3) Car in running position.
 
|1) Coding and final set-up of car<br>2) Successful communication of CAN bus.<br>3) Car in running position.
|
+
|Completed
|
+
|10/13/2015
 
|-
 
|-
 
|-
 
|-
Line 92: Line 91:
 
|10/14/2015
 
|10/14/2015
 
|10/20/2015
 
|10/20/2015
|Sensor Data gathering and movement according to sensors.
+
|Controlling car via Motor Controller
|
+
|Completed
|
+
|10/20/2015
 
|-
 
|-
 
|-
 
|-
Line 100: Line 99:
 
|10/21/2015
 
|10/21/2015
 
|10/27/2015
 
|10/27/2015
|1) LCD Display working and finalizing the data to be displayed on LCD module.<br>2) GEO data gathering and controlling of car using Android module.
+
|1) LCD Display working and finalizing the data to be displayed on LCD module.<br>2) Sensor data gathering
|
+
|Completed
|
+
|10/27/2015
 
|-
 
|-
 
|-
 
|-
 
|6
 
|6
 
|10/28/2015
 
|10/28/2015
|11/3/2015
+
|11/30/2015
|Integration of all the modules into one.
+
|Integration of all the modules into one
|
+
|Completed
|
+
|12/05/2015
 
|-
 
|-
 
|-
 
|-
 
|7
 
|7
|11/4/2015
+
|11/04/2015
|11/10/2015
+
|11/30/2015
|Inclusion of new features in the car.
+
|Testing depending upon integrated module
|
+
|Completed
|
+
|12/05/2015
 
|-
 
|-
 
|-
 
|-
 
|8
 
|8
|11/11/2015
 
|11/17/2015
 
|Testing depending upon the newly added features.
 
|
 
|
 
|-
 
|-
 
|9
 
 
|11/18/2015
 
|11/18/2015
|11/24/2015
+
|11/30/2015
 
|Testing of Car and testing the self driving capability
 
|Testing of Car and testing the self driving capability
|
+
|Completed
|
+
|12/05/2015
 
|-
 
|-
 
|-
 
|-
|10
+
|9
 
|11/25/2015
 
|11/25/2015
 
|12/1/2015
 
|12/1/2015
|Testing of Car
+
|Testing of Car  
|
+
|Completed
|
+
|12/15/2015
 
|}
 
|}
  
''' Sensor Controller Schedule'''
+
== Parts List & Cost ==
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! scope="col"| Sl. No
+
! scope="col"| Sr. No
! scope="col"| Start Date
+
! scope="col"| Part Name
! scope="col"| End Date
+
! scope="col"| Source of Purchase
! scope="col"| Task
+
! scope="col"| Part Number
! scope="col"| Status
+
! scope="col"| Quantity
! scope="col"| Actual Completion Date
+
! scope="col"| Cost($)
 
|-
 
|-
 
|-
 
|-
 
|1
 
|1
|9/20/2015
+
|RC Car
|10/5/2015
+
|Sheldons Hobbies
|Study available sensors and place order
+
|360541 Stampede RTR
|Completed
+
|1
|10/4/2015
+
|239.99
 
|-
 
|-
 
|-
 
|-
 
|2
 
|2
|10/6/2015
+
|Battery
|10/13/2015
+
|Sheldons Hobbies
|Collaborate with the other sub teams to finish the CAN bus communication
+
|VEN1548 - 5000NiMh 7.2 V
|Completed
+
|1
|10/13/2015
+
|44.99
 
|-
 
|-
 
|-
 
|-
 
|3
 
|3
|10/13/2015
+
|Traxx AC Adaptor
|10/20/2015
+
|Sheldons Hobbies
|Develop simple test code for the sensors
+
|TRAXXAS 2976 AC Adaptor to 12V
|Completed
+
|1
|10/18/2015
+
|24.99
 
|-
 
|-
 
|-
 
|-
 
|4
 
|4
|10/21/2015
+
|Compass
|10/30/2015
+
|[http://www.amazon.com/uxcell-HMC5883L-Magnetic-Electronic-Compass/dp/B00GYVDBQY/ref=sr_1_1?s=electronics&ie=UTF8&qid=1450217005&sr=1-1&keywords=hmc5883l Amazon.com]
|Interface all sensors and develop code for reading all sensors and implement filter for the same
+
|HMC5883L Digital Compass Module - Blue
 +
|2
 +
|9.2
 +
|-
 +
|-
 +
|5
 +
|GPS Module
 +
|[https://www.sparkfun.com/products/11058 Sparkfun.com]
 +
|SparkFun Venus GPS with SMA Connector GPS 11058
 +
|1
 +
|44.08
 +
|-
 +
|-
 +
|6
 +
|GPS Antenna
 +
|[https://www.sparkfun.com/products/464 Sparkfun.com]
 +
|Antenna GPS Embedded SMA
 +
|1
 +
|19.49
 +
|-
 +
|-
 +
|7
 +
|LCD module
 +
|[http://www.mouser.com/ProductDetail/Newhaven-Display/NHD-0420D3Z-NSW-BBW-V3/?qs=%2fha2pyFadugsZRC%2fBKGy2sA3Q8ulSs%2fgTlW0bul2DH7tOGyGpFEcakK%252bwYv10abz mouser.com]
 +
|NHD-0420D3Z-NSW-BBW-V3-ND
 +
|1
 +
|29.68
 +
|-
 +
|-
 +
|8
 +
|Bluetooth Module
 +
|[http://www.amazon.com/Sunkee-Wireless-Bluetooth-Transceiver-arduino/dp/B00CDG65F8/ref=sr_1_1?s=electronics&ie=UTF8&qid=1450217200&sr=1-1&keywords=sunkee+hc-05 Amazon.com]
 +
|Sunkee HC-05
 +
|1
 +
|8.88
 +
|-
 +
|-
 +
|9
 +
|Ultrasonic sensors
 +
|[http://www.amazon.com/Ultrasonic-HC-SR04-Distance-Transducer-Arduino/dp/B00PVP72JG/ref=sr_1_37?s=electronics&ie=UTF8&qid=1450217322&sr=1-37&keywords=hcsr04 Amazon.com]
 +
|HC-SR04
 +
|10
 +
|17.38
 +
|-
 +
|-
 +
|10
 +
|Sonar Sensor
 +
|Provided by Preet
 +
|Maxbotix MB1010
 +
|1
 +
|Free
 +
|-
 +
|-
 +
|11
 +
|SJ One Board
 +
|Provided by Preet
 +
|LPC1758 Development Board
 +
|5
 +
|400.00
 +
|-
 +
|-
 +
|12
 +
|CAN Tranceivers
 +
|[http://www.microchip.com/samples/default.aspx Microchip.com]
 +
|MCP2551 - Free Samples
 +
|5
 +
|Free
 +
|-
 +
|-
 +
|13
 +
|PCB
 +
|[http://www.amazon.com/gp/product/B00EDJZ7Z2/ref=s9_simh_gw_p23_d2_i1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=desktop-3&pf_rd_r=1F2FJ2JWCFZKKGDMG436&pf_rd_t=36701&pf_rd_p=2084660942&pf_rd_i=desktop Amazon.com]
 +
|PCB
 +
|2
 +
|10.6
 +
|-
 +
|-
 +
|14
 +
|General Components
 +
|Excess solution,aliexpress.com
 +
|LED,Connectors,Screws,Nuts,Standoffs,Connecting Wires, etc.
 +
|1
 +
|31.99
 +
|-
 +
|-
 +
|15
 +
|Speed Sensor<br>Magnet Holder<br>Wire retainer
 +
|Sheldons Hobbies
 +
|Traxxas 6520<br>Traxxas 6538<br>Traxxas 6537
 +
|1<br>1<br>1
 +
|20
 +
|-
 +
|-
 +
|
 +
|
 
|
 
|
 +
|Total =
 
|
 
|
 +
|501.27
 +
|}
 +
 +
== Car Framework and Components ==
 +
 +
The RC car, Traxxas Stampede, in its raw form consists of a Titan 12T 550 Brushed DC motor, a Servo motor, an XL-5 ESC (Electronic Speed Control) unit, battery and a pre-programmed wireless receiver and controller. The Battery used in the RC car is an 8.4 V, 3000 NiMH from Traxxas. The wireless receiver gets commands from the remote control and drives the motors accordingly, but the DC motor can be controlled only through ESC.
 +
 +
 +
                                        [[File:CmpE243_F15_T2_Car.jpg]]
 +
 +
 +
The ESC (Electronic Speed Control) unit is an electronic module, which receives PWM signals from the controller and varies speed and direction of the DC motor and also acts as dynamic brakes. ESCs are often used in RC models. The ESC has the capability to provide dynamic braking depending on the mode in which it is being operated.
 +
 +
==CAN Design==
 +
===CAN Communication Table===
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| Sr. No
 +
! scope="col"| Message ID
 +
! scope="col"| Message function
 +
! scope="col"| Message Data
 +
! scope="col"| From
 +
! scope="col"| To
 +
|-
 +
|-
 +
! colspan="6"| High
 +
|-
 +
|-
 +
|1
 +
|0x220
 +
|Motor Control<br>(Direction Control- Straight, Left or Right<br>Level of Direction-Level 0, Level1, Level 2<br>Motion Control- Stop, Forward or Reverse<br>Speed Control - Stop, Level1, Level2 or Level3)
 +
|Byte[0] -> Direction Control<br>Byte[1] -> Level of Direction<br>Byte[2] -> Motion Control<br>Byte[3] -> Speed Control
 +
|Master
 +
||Motor
 +
|-
 +
|2
 +
|0x010
 +
|Kill Message<br>(User request to stop the car under emergency)
 +
|Control Frame. No data bytes.
 +
|Android
 +
|Master
 +
|-
 +
|-
 +
|3
 +
|0x020
 +
|Kill Message<br>(Master request to stop all controllers and reboot<br>under emergency)
 +
|Control Frame. No data bytes.
 +
|Master
 +
|All
 +
|-
 +
|-
 +
|4
 +
|0x030
 +
|Stop<br>(User request to stop the car)
 +
|Control Frame. No data bytes.
 +
|Android
 +
|Master
 
|-
 
|-
 
|-
 
|-
 
|5
 
|5
|10/30/2015
+
|0x040
|11/2/2015
+
|Stop<br>(Master stops the motor)
|Positioning of sensors and identifying dead band if any
+
|Control Frame. No data bytes.
|
+
|Master
|
+
|Motor
 
|-
 
|-
 
|-
 
|-
 
|6
 
|6
|11/2/2015
+
|0x210
|11/5/2015
+
|Sensor Data<br>(Distance in cms)
|Work on light and battery sensor (optional)
+
|Byte[0] -> Forward Distance<br>Byte[1] -> Left Distance<br>Byte[2] -> Right Distance<br>Byte[3] -> Back Distance
|
+
|Sensor
|
+
|Master/Motor-IO
 
|-
 
|-
 
|-
 
|-
 
|7
 
|7
|11/06/2015
+
|0x230
|12/17/2015
+
|Total Distance to Travel
|Final testing and debugging
+
|Byte[0-1]
|
+
|Android
|
+
|Geo
 +
|-
 +
|-
 +
|8
 +
|0x240
 +
|Send Checkpoints
 +
|Byte[0-3] -> Latitude<br>Byte[4-7] -> Longitude
 +
|Android
 +
|Geo
 +
|-
 +
|-
 +
|9
 +
|0x250
 +
|Distance<br>(Distance in foot)
 +
|Byte[0-1] -> Final Distance remaining  <br>Byte[2-3] -> Checkpoint distance <br>Byte[4] -> Is_Last_Checkpoint
 +
|Geo
 +
|Master
 +
|-
 +
|-
 +
|10
 +
|0x260
 +
|Turn Angle and Direction
 +
|Byte[0] -> Turn Angle <br>Byte[1] -> Direction <br> (1-Left,2-Right)
 +
|Geo
 +
|Master
 +
|-
 +
|-
 +
|11
 +
|0x270
 +
|Run and Pause Command
 +
|Control Frame. No data bytes
 +
|Android
 +
|Master
 +
|-
 +
|-
 +
|12
 +
|0x280
 +
|Heartbeat Message
 +
|Control Frame. No data bytes
 +
|Motor
 +
|Master
 +
|-
 +
|-
 +
|13
 +
|0x281
 +
|Heartbeat Message
 +
|Control Frame. No data bytes
 +
|Geo
 +
|Master
 +
|-
 +
|-
 +
|14
 +
|0x282
 +
|Heartbeat Message
 +
|Control Frame. No data bytes
 +
|Android
 +
|Master
 +
|-
 +
|-
 +
|15
 +
|0x283
 +
|Heartbeat Message
 +
|Control Frame. No data bytes
 +
|Sensor
 +
|Master
 +
|-
 +
|-
 +
! colspan="6"|Medium
 +
|-
 +
|-
 +
|16
 +
|0x410
 +
|Destination reached.<br>(Stops the car when destination is reached)
 +
|Control Frame. No data bytes
 +
|Master
 +
|All
 +
|-
 +
|-
 +
|17
 +
|0x420
 +
|Battery Status
 +
|Byte[0-1]
 +
|Sensor
 +
|Master/IO
 +
|-
 +
|-
 +
! colspan="6"|Low
 +
|-
 +
|-
 +
|18
 +
|0x610
 +
|Boot Request
 +
|Control Frame. No data bytes
 +
|Master
 +
|All
 +
|-
 +
|-
 +
|19
 +
|0x620
 +
|Boot Reply<br>(Date and time will be sent to Master)
 +
|Byte[0-4]
 +
|Motor-IO
 +
|Master
 +
|-
 +
|-
 +
|20
 +
|0x621
 +
|Boot Reply<br>(Date and time will be sent to Master)
 +
|Byte[0-4]
 +
|Sensor
 +
|Master
 +
|-
 +
|-
 +
|21
 +
|0x622
 +
|Boot Reply<br>(Date and time will be sent to Master)
 +
|Byte[0-4]
 +
|Geo
 +
|Master
 +
|-
 +
|-
 +
|22
 +
|0x623
 +
|Boot Reply<br>(Date and time will be sent to Master)
 +
|Byte[0-4]
 +
|Android
 +
|Master
 +
|-
 +
|-
 +
|23
 +
|0x630
 +
|Boot Status<br> (Enable the map and run button in Android)
 +
|Control Frame. No data bytes
 +
|Master
 +
|Motor-IO/Android
 +
|-
 +
|-
 +
|24
 +
|0x640
 +
|System Start
 +
|Control Frame. No data bytes
 +
|Android
 +
|All
 +
|-
 +
|-
 +
|25
 +
|0x650
 +
|Source Co-ordinates
 +
|Byte[0-3] -> Source Latitude <br> Byte[4-7] -> Source Longitude
 +
|Geo
 +
|Android
 
|}
 
|}
  
'''Motor & I/0 Controller Schedule'''
+
===CAN Message Flow===
 +
 
 +
[[File:CMPE243_F15_Minion_CAN_Message_Flow.gif|thumb|centre|1000px|CAN Message Flow]]<br>
 +
 
 +
=== DBC Implementation ===
 +
 
 +
==== Background ====
 +
Generally, data received from the CAN message is handled using structures. If there are 'n' CAN messages, 'n' structures will be used to handle them. Data has to be encoded at one end for CAN transmission and decoded at the other end, after CAN reception. If there are innumerable CAN messages and their respective structures, lot of effort will be spent in writing code for encoding and decoding. A better approach is to use DBC. It has a specific format and generates automatic code consisting of decoding and encoding logic and structures for CAN messages.
 +
 
 +
==== DBC File ====
 +
The following DBC file gives the proper description of CAN messages used in our car.<br>
 +
 
 +
    VERSION ""<br><br>
 +
    NS_ :
 +
        NS_DESC_
 +
        CM_
 +
        BA_DEF_
 +
        BA_
 +
        VAL_
 +
        CAT_DEF_
 +
        CAT_
 +
        FILTER
 +
        BA_DEF_DEF_
 +
        EV_DATA_
 +
        ENVVAR_DATA_
 +
        SGTYPE_
 +
        SGTYPE_VAL_
 +
        BA_DEF_SGTYPE_
 +
        BA_SGTYPE_
 +
        SIG_TYPE_REF_
 +
        VAL_TABLE_
 +
        SIG_GROUP_
 +
        SIG_VALTYPE_
 +
        SIGTYPE_VALTYPE_
 +
        BO_TX_BU_
 +
        BA_DEF_REL_
 +
        BA_REL_
 +
        BA_DEF_DEF_REL_
 +
        BU_SG_REL_
 +
        BU_EV_REL_
 +
        BU_BO_REL_
 +
        SG_MUL_VAL_<br><br>
 +
BS_:
 +
BU_: NOONE SENSOR MASTER MOTORIO ANDROID GEO<br>
 +
BO_ 220 MOTORIO_CMD: 4 MASTER
 +
  SG_ MOTORIO_CMD_LeftRightdirection : 0|8@1+ (1,0) [0|2] "" MOTORIO
 +
  SG_ MOTORIO_CMD_LevelOfDirection : 8|8@1+ (1,0) [0|5] "" MOTORIO
 +
  SG_ MOTORIO_CMD_FrontBackDirection : 16|8@1+ (1,0) [0|2] "" MOTORIO
 +
  SG_ MOTORIO_CMD_LevelOfSpeed : 24|8@1+ (1,0) [0|5] "" MOTORIO<br>
 +
BO_ 010 KILL_REQUEST: 0 ANDROID
 +
  SG_ KILL_REQUEST : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 020 KILL_MESSAGE: 0 MASTER
 +
  SG_ KILL_REQUEST : 0|0@1+ (1,0) [0|0] "" MOTORIO,SENSOR,GEO,ANDROID<br>
 +
BO_ 030 STOP_REQUEST: 0 ANDROID
 +
  SG_ STOP_REQUEST : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 040 STOP_COMMAND: 0 MASTER
 +
  SG_ ANDROID_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MOTOR<br>
 +
BO_ 210 SONARS: 4 SENSOR
 +
  SG_ SENSOR_SONARS_FrontDistance : 0|8@1+ (1,0) [0|0] "" MASTER,MOTORIO
 +
  SG_ SENSOR_SONARS_LeftDistance : 8|8@1+ (1,0) [0|0] "" MASTER,MOTORIO
 +
  SG_ SENSOR_SONARS_RightDistance : 16|8@1+ (1,0) [0|0] "" MASTER,MOTORIO
 +
  SG_ SENSOR_SONARS_RearDistance : 24|12@1+ (1,0) [0|0] "" MASTER,MOTORIO<br>
 +
BO_ 230 TOTAL_DISTANCE_TO_TRAVEL: 4 ANDROID
 +
  SG_ TOTAL_DISTANCE_TO_TRAVEL: 0|16@1+ (1,0) [0|0] "" GEO<br>
 +
BO_ 240 SEND_CHECKPOINTS: 8 ANDROID
 +
  SG_ SEND_CHECKPOINTS_Latitude: 0|32@1+ (1,0) [0|0] "" GEO
 +
  SG_ SEND_CHECKPOINTS_Longitude: 32|64@1+ (1,0) [0|0] "" GEO<br>
 +
BO_ 250 DISTANCE: 4 GEO
 +
  SG_ DISTANCE_FinalDistance : 0|16@1+ (1,0) [0|0] "" MASTER
 +
  SG_ DISTANCE_CheckpointDistance : 16|16@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 260 TURN_ANGLE_DIRECTION: 2 GEO
 +
  SG_ TURN_ANGLE_DIRECTION_TurnAngle : 0|8@1+ (1,0) [0|0] "" MASTER
 +
  SG_ TURN_ANGLE_DIRECTION_TurnDirection : 8|8@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 270 RUN_PAUSE: 0 ANDROID
 +
  SG_ RUN_PAUSE : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 280 HEARTBEAT_: 0 MOTORIO
 +
  SG_ MOTORIO_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 281 HEARTBEAT: 0 GEO
 +
  SG_ GEO_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 282 HEARTBEAT: 0 ANDROID
 +
  SG_ ANDROID_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 283 HEARTBEAT: 0 SENSOR
 +
  SG_ SENSOR_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 410 DESTINATION_REACHED: 0 MASTER
 +
  SG_ SENSOR_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 420 BATTERY_STATUS: 1 SENSOR
 +
  SG_ BATTERY_STATUS_VALUE : 0|0@1+ (1,0) [0|0] "" MASTER,MOTORIO<br>
 +
BO_ 610 BOOT_REQUEST: 0 MASTER
 +
  SG_ BATTERY_STATUS_VALUE : 0|0@1+ (1,0) [0|0] "" MOTORIO,SENSOR,ANDROID,GEO<br>
 +
BO_ 620 BOOT_REPLY_MOTORIO: 0 MOTORIO
 +
  SG_ BOOT_REPLY_MOTORIO : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 621 BOOT_REPLY_SENSOR: 0 SENSOR
 +
  SG_ BOOT_REPLY_SENSOR : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 622 BOOT_REPLY_GEO: 0 GEO
 +
  SG_ BOOT_REPLY_GEO : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 623 BOOT_REPLY_ANDROID: 0 ANDROID
 +
  SG_ BOOT_REPLY_ANDROID : 0|0@1+ (1,0) [0|0] "" MASTER<br>
 +
BO_ 630 BOOT_STATUS: 0 MASTER
 +
  SG_ BOOT_STATUS : 0|0@1+ (1,0) [0|0] "" MOTORIO,ANDROID<br>
 +
BO_ 650 SOURCE_COORDINATE: 8 GEO
 +
  SG_ SOURCE_COORDINATE_LATITUDE : 0|32@1+ (1,0) [0|0] "" ANDROID
 +
  SG_ SOURCE_COORDINATE_LONGITUDE : 32|32@1+ (1,0) [0|0] "" ANDROID<br>
 +
CM_ BU_ NOONE "No node, used to indicate if it's a debug message going to no one.";
 +
CM_ BU_ MASTER "The Master controller driving the car.";
 +
CM_ BU_ SENSOR "The Sensor controller of the car.";
 +
CM_ BU_ MOTORIO "The Motor-IO controller of the car.";
 +
CM_ BU_ ANDROID "The Android controller of the car.";
 +
CM_ BU_ GEO "The Geo controller of the car.";
 +
CM_ BO_ 100 "Sync message used to synchronize the controllers";<br>
 +
BA_DEF_  "BusType" STRING ;
 +
BA_DEF_ SG_ "FieldType" STRING ;
 +
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 0;<br>
 +
BA_DEF_DEF_ "BusType" "CAN";
 +
BA_DEF_DEF_ "FieldType" "";<br>
 +
BA_ "GenMsgCycleTime" BO_ 220 10;
 +
BA_ "GenMsgCycleTime" BO_ 210 10;
 +
BA_ "GenMsgCycleTime" BO_ 250 10;
 +
BA_ "GenMsgCycleTime" BO_ 260 10;
 +
BA_ "GenMsgCycleTime" BO_ 280 1;
 +
BA_ "GenMsgCycleTime" BO_ 281 1;
 +
BA_ "GenMsgCycleTime" BO_ 282 1;
 +
BA_ "GenMsgCycleTime" BO_ 283 1;
 +
BA_ "GenMsgCycleTime" BO_ 420 1;<br>
 +
VAL_ 100 MASTER_HEARTBEAT_cmd 0 "MASTER_HEARTBEAT_cmd_NOOP" 1 "MASTER_HEARTBEAT_cmd_SYNC" 2 "MASTER_HEARTBEAT_cmd_REBOOT";
 +
 
 +
==== Detailed Description ====
 +
1)The above description shows the detailed implementation of the CAN messages used for communication between various controllers. Several types of notations are used in this DBC file. Following is the explanation of these notations which includes range of the CAN data, minimum, maximum values, and number of data bits used in the 64 bit structure. One useful feature of CAN message frame is bitwise access of data. This approach of accessing data using bits instead of bytes avoids wastage of CAN data which could otherwise be utilized properly.
 +
 
 +
2)Detailed explanation of notations used in CAN dbc file format-
 +
  a. BU_: NOONE SENSOR MASTER MOTORIO ANDROID GEO
 +
  The line which is starting with BU_ gives us the information about all the controllers present in the communication BUS.<br>
 +
  b. BO_ 220 MOTORIO_CMD: 4 MASTER
 +
  i.This is the message command which states the message ID. Here 220 is the message ID used for Motor command from Master to Motor.
 +
  ii.The name of the message is MOTORIO_CMD which forms a string of the structure to be created in the auto generated code.
 +
  iii. 4 represents size of data in byte to be transmitted.
 +
  iv.Here last text is written as MASTER, which says that the message is originating from MASTER.<br>
 +
  c. SG_ MOTORIO_CMD_LeftRightdirection : 0|8@1+ (1,0) [0|2] "" MOTORIO
 +
  i.The line has SG_ in the beginning and is known as the signal. This command tells us about the number of different data<br>  in the CAN message.
 +
  ii.0|8 -> 0 is the start bit of the data in the CAN message and 8 is the length of the data in the CAN message.
 +
  iii.[0|2] -> 0 is the minimum value of the data and 2 is the maximum value of the message.
 +
  iv.The last text MOTORIO defines the number of receivers of the message. There can be more than one receivers.<br>  If there are,then they are separated by a comma.
 +
  v.Here ‘MOTORIO_CMD_LeftRightdirection’ is the name of the data that is being transmitted in the message.<br>
 +
  d. BA_ "GenMsgCycleTime" BO_ 220 10
 +
  i.This command describes the general message cycle.
 +
  ii.Here the message 220 i.e the motor command repeats itself after every 10 Hz i.e 100 ms.
 +
  iii.Similarly, there are some message which repeats after every 1 Hz.<br>
 +
 
 +
3)The dbc file was created with these normal basic command and was sent as an input to the python dbc parser which decrypted it to the auto generated code. Following is the python command for the dbc parser:
 +
    >python.exe dbc_parse.py -i Group2.dbc -s MASTER -a -b >generated.h
 +
 
 +
== Design & Implementation of Controllers==
 +
=== Motor and I/O Controller ===
 +
==== Schedule ====
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 290: Line 736:
 
|9
 
|9
 
|11/13/2015
 
|11/13/2015
|11/20/2015
+
|11/30/2015
 
|Testing substantial self driving capability of the car
 
|Testing substantial self driving capability of the car
|
+
|Completed
|
+
|12/5/2015
 
|-
 
|-
 
|-
 
|-
Line 300: Line 746:
 
|11/30/2015
 
|11/30/2015
 
|Complete integration, Debugging and Fine tuning
 
|Complete integration, Debugging and Fine tuning
|
+
|Completed
|
+
|12/5/2015
 
|-
 
|-
 
|-
 
|-
Line 308: Line 754:
 
|12/5/2015
 
|12/5/2015
 
|Final Validation
 
|Final Validation
|
+
|Completed
|
+
|12/15/2015
 +
|}
 +
 
 +
==== Hardware Design ====
 +
=====Motor Module=====
 +
 
 +
The motor module comprises of a servo motor for the direction control and a DC motor for speed control. The servo motor helps the car in turning left and right where as the DC motor on the other hand helps the car move forward and backward. The DC motor used in the project is a brushed motor. Conventionally, brushless motors are faster and more efficient than brushed motors. But, the reason for selecting a brushed motor over a brushless motor is that we employ a dedicated battery for the motor such that we do not have any issues with power and efficiency. Moreover, we need not operate the car at high speeds.
 +
 
 +
The initial task in the motor module is to find the operating ranges of the motor so that we get to know the output signal range and frequency from the SJONE board which would be replacing the pre-programmed controller. The simplest way to find the operating ranges of the motor is to tap and analyze PWM signal that is being supplied to the motor over an oscilloscope. The results as shown in the below pictures indicate that the operating duty cycle of both the motors lie between 10% to 20% and the frequencies at which the motors operate is 100Hz.
 +
 
 +
                                      [[File:CmpE243_F15_T2_PWM_DutyCycle.jpg]]
 +
 
 +
 
 +
The hardware interface of the Motors and SJONE board includes the following connections.
 +
 
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| Sl. No
 +
! scope="col"| Connection on the car
 +
! scope="col"| Pin on SJSU One Board
 +
! scope="col"| Purpose
 +
|-
 +
|-
 +
|1
 +
|Input to DC Motor
 +
|P2.1
 +
|PWM input to drive DC motor
 +
|-
 +
|-
 +
|2
 +
|Input to Servo Motor
 +
|P2.0
 +
|PWM input to drive DC motor
 +
|-
 +
|-
 +
|3
 +
|Speed sensor
 +
|P2.4
 +
|PWM output from speed sensor
 
|}
 
|}
  
'''Geographical Controller Schedule'''
+
 
 +
The Motor controller receives the commands from the Master controller which guides it to navigate the car based on the information from the Sensors and GPS. While it does so, it also needs to get feedback from the DC motor and control the motor independently in order to ensure that the car is moving with the speed requested by the Master. This requires increasing or decreasing the actual speed level that is being provided to the Motor in case of movement along uphill, downhill, grass and high friction tracks.
 +
 
 +
The feedback is achieved through a shaft encoder which works based on Hall-effect. The installation of the speed sensor was pretty easy as we went with the one from Traxass, the same manufacturer as our RC car. It involves removing the DC motor casing, placing the sensor over the spur gear and the magnet holder. The sensor would sense the rotation of the axle. It produces a pulse when the magnet comes into the line of the sensor, which is then detected by the Motor controller.
 +
 
 +
=====IO Module=====
 +
 
 +
The IO module Consists of a 4 line * 20 characters serial LCD. Data from GPS and sensor module is displayed continuously by refreshing it every second. SJ one board communicates with LCD through UART.                        [[File:CMPE243_F15_Minion_LCD.jpg|300px|thumb|right|LCD ]]
 +
 
 +
GPS data :-
 +
*Distance travelled
 +
*Checkpoint Distance
 +
 
 +
Sensor data:-
 +
 
 +
*Left sensor reading
 +
*Right sensor reading
 +
*Front sensor reading
 +
*Rear sensor reading
 +
 
 +
Additionally, IO module controls lighting up headlights/taillights based on the direction of the car movement.<br>
 +
 
 +
[[File:CMPE243_F15_Minion_MotorIO_HardwareInterface.PNG|400px|thumb|centre|MotorIO Hardware Interface]]
 +
 
 +
LCD unit requires 5V power supply for its working. The VCC and Ground pins are connected to common power supply lines that is used to power up all the boards. The Rx pin of LCD is connected to TXD2 (p2.8) pin on SJ one board. Two of the GPIO pins p2.6 and p2.7 controls the headlights LED’S and taillights LED’S respectively.
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
! scope="col"| Sl. No
 
! scope="col"| Sl. No
! scope="col"| Start Date
+
! scope="col"| Pin on IO Module
! scope="col"| End Date
+
! scope="col"| Pin on SJSU One Board
! scope="col"| Task
+
! scope="col"| Purpose
! scope="col"| Status
 
! scope="col"| Actual Completion Date
 
 
|-
 
|-
 
|-
 
|-
 
|1
 
|1
|09/27/2015
+
|Vcc
|10/07/2015
+
|Common power supply
|Ordering Parts and understanding each module
+
|5V for LCD
|Completed
 
|10/11/2015
 
 
|-
 
|-
 
|-
 
|-
 
|2
 
|2
|10/07/2015
+
|Ground
|10/13/2015
+
|Common Ground
|CAN Communication with other boards and understanding each module
+
|Ground for LCD
|Completed
 
||10/13/2015
 
 
|-
 
|-
 
|-
 
|-
 
|3
 
|3
|10/07/2015
+
|Rx
|10/30/2015
+
|P2.8(TXD2)
|Algorithm for distance and heading calculation and coding
+
|Receive data from SJone board through UART
|Completed
 
|10/30/2015
 
 
|-
 
|-
 
|-
 
|-
 
|4
 
|4
|10/14/2015
+
|Headlight LED’s(2)
|10/20/2015
+
|P2.6
|Interfacing of compass(I2C) and GPS (UART) with SJONE board
+
|Turn on headlights when car is moving in the forward direction
|Completed
 
|10/20/2015
 
 
|-
 
|-
 
|-
 
|-
 
|5
 
|5
|10/20/2015
+
|Taillight LED’s (2)
|10/30/2015
+
|P2.7
|Coding, Compass Calibration,GPS Calibration
+
|Turn on tail-lights when car is moving in the reverse direction
|Completed
+
|}
|
+
 
 +
=====Usage of OnBoard LED's: =====
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| LED No.
 +
! scope="col"| Usage
 +
|-
 +
|-
 +
|1
 +
|Speed feedback control active
 +
|-
 
|-
 
|-
 +
|2
 +
|Master commands to Motor
 
|-
 
|-
|5
 
|10/25/2015
 
|11/15/2015
 
|Individual unit testing
 
|Completed
 
|
 
 
|-
 
|-
 +
|3
 +
|Heart beat
 
|-
 
|-
|6
 
|10/30/2015
 
|11/30/2015
 
|Interfacing with Android, Master and IO controllers
 
|
 
|
 
 
|-
 
|-
 +
|4
 +
|Can reception failure
 
|-
 
|-
|7
 
|10/30/2015
 
|11/30/2015
 
|Integration Testing,On Car Calibration
 
|First level of On Car Calibration Completed
 
|
 
 
|}
 
|}
  
'''Master Controller Schedule'''
+
==== Software Design ====
 +
=====Module Flow=====
 +
 
 +
                                        [[File:CMPE243_F15_Minion_Motor_control_alogorithm.PNG|300px|Software Flow Diagram]] 
 +
 
 +
The controller on boot up initializes the CAN communication, UART and also the PWM for initialization pulse required for the motor to run.The inter-controller communication is done over CAN bus. It is configured to receive and transmit messages at 100K baud-rate. The type of CAN ID is Standard. Later these are accomplished at run time using the periodic scheduler task.
 +
 
 +
 
 +
LCD communicates with SJ one board through UART. Communication will happen between LCD and SJone board only when the baud rates are synchronized. The UART port is configured to operate at 19200 bps. “FO” character is sent to initialize the UART port after a delay of 100 ms, upon powering up the board. The display unit responds after 100 ms. Now the LCD module is configured and can receive further messages to display on it. Data from modules such as GPS and sensor are received continuously through CAN. It is decoded, converted into proper format and displayed on the LCD periodically. The corresponding flow is shown below.
 +
 
 +
                        [[File:CMPE243_F15_Minion_Software_Flow.PNG|1280px|715px|Software Flow Diagram]]
 +
 
 +
The Motor controller, after sending the initialization pulse to the DC motor, waits for a start command from the Master over CAN and then controls the motors in order to reach the destination with required levels of speed and direction. The control algorithm for the Motor operation is as shown on the right.
 +
 
 +
====Software Implementation ====
 +
 
 +
“Can receive” function is called in periodic scheduler 100 Hz task. This function lets the Motor/IO module receive CAN messages from other modules connected to it. CAN set up filter function has been used to accept only essential messages required by this module. Based on the CAN message identifier, corresponding action is performed. These are the CAN messages required by the motor/IO module.
 +
 
 +
CAN MESSAGE ID:-
 +
*0x020 – Kill message
 +
*0x210 – Sensor data
 +
*0x220 -  Motor control message
 +
*0x250 – GPS data
 +
*0x610 – Boot request
 +
 
 +
Data from sensor and GPS modules are stored in global message buffers. Sensor data is 8 bit whereas GPS data ranges between 16-32 bits. These integer values are converted into character type and then sent to LCD through UART.
 +
LCD display function is called in 1Hz periodic scheduler task. Thus Sensor and GPS data get displayed on the LCD every sec.
 +
 
 +
                [[File:CMPE243_F15_Minion_IO_Implementation_FlowChart.PNG|800px|IO Implementation Diagram]]
 +
 
 +
The 3D design used as a support for mounting the LCD is shown below:
 +
 
 +
                [[File:CMPE243_F15_Minion_LCD_mount_3DPrint_Design.JPG|400px|thumb|none|3D design for LCD mounting]]
 +
 
 +
=====Motor Control=====
 +
 
 +
On receiving the CAN message(0x220) from the Master, the data is extracted and and used for specific functions as shown below.
 +
          *Byte0 --> Servo Direction
 +
          *Byte1 --> Servo Level
 +
          *Byte2 --> DC Direction
 +
          *Byte3 --> DC Level
 +
 
 +
Based on this data, the first two bytes decide the direction(left/right) and the level(angle), respectively in which the car should turn using the Servo motor. Similaly, the next two bytes decide the direction(forward/backward) and the level(speed) in which the car has to move.
 +
 
 +
To implement all the motor related functions, we have employed a dedicated task. Initially, the pre-scaled PWM values are fed to the motors based on the direction and level from the Master. We have a bit robust algorithm to obtain these PWM values which has offsets and level multipliers. The advantage of this is we can change the code to function for multiple levels with minimum effort.
 +
 
 +
A piece of code for Motor Control:
 +
 
 +
switch(DC_control)
 +
        {
 +
            case 0:
 +
            if(DC_level==DC_level_last)
 +
            {
 +
                    speed_offset = 0;
 +
                    speed_factor =0;
 +
                    LD.setNumber(10);
 +
            }
 +
            else
 +
            {
 +
            pwm2.set(15);
 +
            vTaskDelay(25);
 +
            pwm2.set(13);
 +
                    vTaskDelay(100);
 +
                    speed_offset = 0;
 +
                    LD.setNumber(13);
 +
                    speed_factor =0;
 +
            }
 +
            p2_pin6.setLow();
 +
            p2_pin7.setLow();
 +
          speed_offset = 0;
 +
            speed_factor =0;
 +
            count_rev = 1;
 +
            break;
 +
            case 1:
 +
            speed_offset = 0.4;
 +
            speed_factor = 0.2;
 +
            count_rev = 1;
 +
            p2_pin6.setHigh();
 +
            p2_pin7.setLow();
 +
            break;
 +
            case 2:
 +
            speed_offset = -0.6;
 +
            speed_factor = -0.2;
 +
            p2_pin6.setLow();
 +
            p2_pin7.setHigh();
 +
            break;
 +
            default:
 +
            speed_offset = 0;
 +
            speed_factor =0;
 +
            count_rev = 1;
 +
            p2_pin6.setLow();
 +
            p2_pin7.setLow();
 +
            break;
 +
        }
 +
        PWM_value_DC = 15 + (speed_factor)*(DC_level) + speed_offset;
 +
 
 +
=====Motor Feedback=====
 +
 
 +
After feeding the motors with the required levels, we have to check if the car is actually moving at that speed. This is ensured through feedback and control based on that. The feedback is obtained through the speed sensor collaborated with the DC motor, which triggers a pulse on every rotation and this is recorded by a rising edge based interrupt. The interrupt callback function increments the number of pulses. A separate logic is used to calculate and then compare the actual and required(from Master) speed levels. The corrective measures are enforced to achieve the desired speed.
 +
 
 +
The transmit messages, except Heart beat message(sent every one second), are transmitted once every 100ms. The Motor/IO controller, on receiving a boot request from Master controller, transmits a boot reply message in order to let the Master know that it has booted successfully. The heart beat message is transmitted continuously to indicate that the controller is active and this will be acknowledged by the Master.
 +
<br>
 +
 
 +
====Testing ====
 +
=====Motor Control=====
 +
The motor operation is initially tested for its accuracy with different direction and levels such as forward, reverse, left, right. After ensuring everything is as expected, we went for refining it. Later, with the speed sensor installed, the functioning of it and the control based on it has to be checked properly. For this, we have tested the car by running it over ramp-up, ramp-down, grassy and rough paths. Then we have refined it. Finally, we made sure that the car gets back to the required speed when it deviates from the same.
 +
 
 +
====Technical Challenges and Resolution====
 +
===== Motor Feedback =====
 +
The major difficulty with motor speed feedback was getting enough number of pulses from the speed sensor in order to calculate the current speed. When we run at very low speeds, we get pulses as low as 2 0r 3 at even 10Hz. If the same value is multiplied by required factor(say 600 in 10Hz) to get the rpm, then we have a couple of issues.
 +
 
 +
i) Firstly, we cannot get intermediate speed values as we get only in multiples of the the factor which will be very high.
 +
 
 +
ii) Secondly, we may have some issues, at very low speeds, like we don't get a pulse every 100ms or 10ms, which means the motor is at rest but which  actually is not.
 +
 
 +
Solution: Never try to implement in terms of "rpm". Instead go for "rps" or "m/s". This will eliminate the first issue. And to solve the second problem, we may think of aggregating the pulse count for a greater time interval. But this will lead to a delayed feedback which in turn leads to an undesired behavior. Hence we have a trade-off between the two.
 +
 
 +
===== Motor Control =====
 +
1) The first hurdle one would face with the Motor control through an ESC is starting the motor. This requires an initialization pulse, which would have been sent by the transmitter earlier. We have to realize the required pattern or PWM value for the achieving this.
 +
 
 +
2) The second difficulty with the motor comes into picture when with backward movement of the car. Due to the presence of the ESC and the residual momentum in forward direction, we cannot alter the direction of the motor suddenly. We have to manually discover the pattern required for this forward to reverse transition which takes a bit of time unless one is aware of it.
 +
 
 +
=== Master Controller ===
 +
As the name suggests, it is main controller on the car which interacts with all other controllers over the CAN Bus to achieve real-time functionality. Basic function of the Master Controller is to receive data from Android, Geo and Sensor Modules and develop the algorithm to drive the car autonomously based on the received data through the Motor Controller.
 +
 
 +
==== Schedule ====
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 404: Line 1,025:
 
|10/6/2015
 
|10/6/2015
 
|a) Design of Algorithm and Architecture for Master Module.<br>b) Setup of CAN communication between two controllers.
 
|a) Design of Algorithm and Architecture for Master Module.<br>b) Setup of CAN communication between two controllers.
| Completed   
+
|Completed   
| 10/6/2015
+
|10/6/2015
 
|-
 
|-
 
|-
 
|-
Line 412: Line 1,033:
 
|10/13/2015
 
|10/13/2015
 
|a) Development of CAN message system for Android, Sensor and GPS, I/O reception.<br>b) Decide about periodic function frequencies that’ll be handling different modules.
 
|a) Development of CAN message system for Android, Sensor and GPS, I/O reception.<br>b) Decide about periodic function frequencies that’ll be handling different modules.
| Completed
+
|Completed
| 10/13/2015
+
|10/13/2015
 
|-
 
|-
 
|-
 
|-
Line 420: Line 1,041:
 
|10/20/2015
 
|10/20/2015
 
|a) Development of driving,stopping and obstruction avoidance algorithm for motor.<br>b) Implementation of LED Display to display number of messages on CAN bus.<br>c) Implementation of turning algorithm as per the data received from the Geo Controller.
 
|a) Development of driving,stopping and obstruction avoidance algorithm for motor.<br>b) Implementation of LED Display to display number of messages on CAN bus.<br>c) Implementation of turning algorithm as per the data received from the Geo Controller.
|   Completed
+
|Completed
|   10/20/2015
+
|10/20/2015
 
|-
 
|-
 
|-
 
|-
Line 428: Line 1,049:
 
|10/27/2015
 
|10/27/2015
 
|a) Designing of Kill switch with the help of Motor, I/O and Android.<br>b) Design the system to restore the last known configuration.<br>c) Implementation to reset modules if the CAN bus reaches BUS off state.
 
|a) Designing of Kill switch with the help of Motor, I/O and Android.<br>b) Design the system to restore the last known configuration.<br>c) Implementation to reset modules if the CAN bus reaches BUS off state.
|   Completed
+
|Completed
|   10/27/2015
+
|10/27/2015
 
|-
 
|-
 
|-
 
|-
Line 436: Line 1,057:
 
|11/3/2015
 
|11/3/2015
 
|a) Design of Head Light functionality with the help of Sensor module.<br>b) Implementation of log files saving to SD card.
 
|a) Design of Head Light functionality with the help of Sensor module.<br>b) Implementation of log files saving to SD card.
|
+
|Completed
|
+
|11/1/2015
 
|-
 
|-
 
|-
 
|-
Line 444: Line 1,065:
 
|11/10/2015
 
|11/10/2015
 
|a) Integration of all the modules with Master module and check it after combining everything.<br>b) Probable implementation of additional features.
 
|a) Integration of all the modules with Master module and check it after combining everything.<br>b) Probable implementation of additional features.
|
+
|Completed
|
+
|12/05/2014
 
|-
 
|-
 
|-
 
|-
Line 452: Line 1,073:
 
|11/17/2015
 
|11/17/2015
 
|a) Refine the work done earlier.Change areas that need a change.<br>b) Test the Master module while all the modules are integrated together and list down modifications      and additions to be done.
 
|a) Refine the work done earlier.Change areas that need a change.<br>b) Test the Master module while all the modules are integrated together and list down modifications      and additions to be done.
|
+
|Completed
|
+
|12/05/2014
 
|-
 
|-
 
|-
 
|-
Line 460: Line 1,081:
 
|11/24/2015
 
|11/24/2015
 
|Testing of system and specially making sure that last week’s shortcomings are taken care of.
 
|Testing of system and specially making sure that last week’s shortcomings are taken care of.
|
+
|Completed
|
+
|12/05/2014
 
|-
 
|-
 
|-
 
|-
Line 468: Line 1,089:
 
|12/1/2015
 
|12/1/2015
 
|a) Final testing of individual modules.<br>b) Testing the self-driving capability of the car.
 
|a) Final testing of individual modules.<br>b) Testing the self-driving capability of the car.
|
+
|Completed
|
+
|12/05/2014
 
|-
 
|-
 
|-
 
|-
Line 476: Line 1,097:
 
|12/8/2015
 
|12/8/2015
 
|Final working on the shortcomings in the previous week.
 
|Final working on the shortcomings in the previous week.
|
+
|Completed
|
+
|12/8/2015
 
|-
 
|-
 
|-
 
|-
Line 484: Line 1,105:
 
|12/15/2015
 
|12/15/2015
 
|Final Testing of Car.
 
|Final Testing of Car.
|
+
|Completed
|
+
|12/15/2015
 
|}
 
|}
  
''' Communication Bridge & Android Controller Schedule'''
+
==== Hardware Design ====
 +
*RC car was the basic infrastructure that was required to implement the project.
 +
*CAN Bus with five SJone controller boards was integrated on General purpose Printed Circuit Board (PCB).
 +
*Sufficient power-supply ports and external pins were provided to each controllers.
 +
*Flat Ribbon Cables were used to reduce circuit complexity arising from external connecting wires.
 +
 
 +
=====Usage of OnBoard LED's: =====
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| LED No.
 +
! scope="col"| Usage
 +
|-
 +
|-
 +
|1
 +
|Forward signal to Motor
 +
|-
 +
|-
 +
|2
 +
|Left turn signal to Motor
 +
|-
 +
|-
 +
|3
 +
|Right turn signal to Motor
 +
|-
 +
|-
 +
|4
 +
|Reverse signal to Motor
 +
|-
 +
|}
 +
 
 +
==== Software Design ====
 +
 
 +
This section describes about the general algorithm used for master programming. There are a lot of cases in Master Controller which are to be handled in order to run the car properly. This includes heartbeats, boot messages, running of motor, reading of the sensor values properly and then taking proper decision. The other activities that are done in master are listed below with some fair explanations.<br>
 +
*Master Controller uses FreeRTOS environment to achieve its functionality.
 +
*It uses Periodic Scheduler Task provided by Preet at its core to communicate with all other controllers.
 +
*The functions of the Periodic Scheduler Task were used in a customized manner to transmit/receive the messages at specific intervals of 1Hz,10Hz,100Hz and 1000Hz.
 +
*File logger function was used to log the real-time data onto SD card which was used for debugging purpose.
 +
*Can Message structure of 11-bit id was implemented to send and receive CAN messages over the CAN Bus.
 +
*CAN acceptance filter was set-up to receive messages specific to Master Controller from the CAN Bus, since it is the broadcast Bus.
 +
 
 +
====Software Implementation====
 +
*Master Controller starts with initialization of CAN Bus and setting up reception filter from the main() function.
 +
*The Periodic Scheduler Task then takes over to implement the actual functionality of the Master Controller.
 +
*CAN_is_busoff() was used at an interval of 10Hz through periodic scheduler task to check if the controller was always connected to CAN bus.
 +
*Following are the algorithms that were implemented in the Master controller to drive the motor.
 +
 
 +
=====Algorithm=====
 +
 
 +
=====Geo Processing Algorithm=====
 +
Following is the algorithm that was implemented to process the data sent by Geo controller, which eventually navigates the car towards its destination. At first, it checks if there is any obstruction in the car’s path,  if there is no obstruction it follows the further steps, And if there is an obstruction, it transfers control to the Obstruction Avoidance Algorithm.
 +
 
 +
'''Step 1:''' Check if there is no obstruction. If there is no obstruction proceed to step2, otherwise proceed to step7.<br>
 +
'''Step 2:''' Check if distance towards next check-point is greater than 30. If distance towards next check-point is greater than 30, proceed to step3, otherwise go to Step 6.<br>
 +
'''Step 3:''' Check if turning angle is greater than 10. If turning angle is greater than 10, proceed to step4, otherwise go straight go to step7.<br>
 +
'''Step 4:''' Check if turning angle is greater than or equal to 90. If turning angle is greater than or equal to 90, turn left or right according to the turning bit with level of direction 3 go to        step7,otherwise proceed to step5.<br>
 +
'''Step 5:''' Check if turning angle is greater than or equal to 45 and less than 90. If turning angle is greater than or equal to 45 and less than 90, turn left or right according to the turning bit with level of direction 2, otherwise turn left or right according to the turning bit with level of direction 1 go to step7.<br>
 +
'''Step 6:''' Check if distance towards next check-point is less than 10.If the distance is less than 10, stop the car, otherwise move slowly with level of speed 1.<br>
 +
'''Step 7:''' End.<br>
 +
 
 +
Following is the flow-chart of the above algorithm:
 +
 
 +
                                      [[File:CMPE243_F15_Minion_Geo_Flow_Chart.png|400px|Flow-Chart]]
 +
 
 +
=====Obstacle Avoidance Algorithm=====
 +
The most important part of the Master controller is to control the motors and handling other decision making factors such as when to move and when to not. The Motor/IO controller is almost entirely dependent on the Master controller to drive the motor. The Master controller is responsible for making decisions on when and where to move the car in case of any obstacle and this is where the Sensor controller comes into the bigger picture.
 +
 
 +
1)For exact precision, we are considering most accurate algorithm for Sensor Processing. We have defined three levels of obstacle zones. The exact explanation of this terminology can be understood from the gif image shown below.
 +
 
 +
                                                      [[File:CMPE243_F15_Minion_Obstruction_avoidanceGIF.gif|thumb|800px|centre|Obstacle Avoidance Flow]]
 +
 
 +
 
 +
 
 +
2) There are three zones in which the major sensor processing for obstacle-avoidance is done. In these zones, distances were designated as the safest distance for the car in which it can move ahead though at low speeds. In addition, we also had taken the danger zone into the consideration.Within danger zone distance, the car won’t be able to move ahead and would only take reverse depending on data from rear sensor. Following is the classification of the various zones:<br><br>
 +
Front:<br>
 +
FDanger : This distance would be the distance within 40 cms of the car. Within this distance, the car wouldn’t be able to move ahead and would only take reverse turn only if there is no blockage from the rear side.<br>
 +
F1 :<br>
 +
F1 is the zone between 40 cms and 80 cms. Within this zone, the car speed would be very slow. Since this distance is very short, we have assured that the speed of car is very slow with the motor feedback and then it will take some necessary decisions.<br>
 +
The turn angles in this case would be in the higher range since there would be a necessity to take sharp turns to avoid obstacles.<br>
 +
F2 :<br>
 +
The range of 80 to 130 cms defines the zone F2. The car would run at more higher speeds in this zone.
 +
The turn angles in this case would be in a lesser range as compared to F2 zone.<br>
 +
F3 :<br>
 +
The range of 130 cms to 190 cms defines the zone F3. The car won’t make any turning decisions in this range but would only reduce its speed. We have made sure that within this range of  obstacle detection, the speed of the car won’t be so much that could cause problem in obstacle avoidance in the inner zones.<br><BR>
 +
Left & Right:<br>
 +
LDanger and RtDanger :<br>
 +
LDanger and RtDanger is the zones for the left and the right  sensor obstacle, the distance values are within 40 cms of the car.<br>
 +
L1 and Rt1 :<br>
 +
For L1 and Rt1, the distance between 40 cms and 70 cms is considered. This distance is somewhat more than the danger distance and the car could  only have speed level 1 in this condition and the turning angles are rather sharp.<br>
 +
L2 and Rt2 :<br>
 +
L2 and Rt2 is considered as the zone between the distance 70 cms and 120 cms. In this zone, level of speed is little higher and the turning angle levels are little lesser than previous zone.<br>
 +
 
 +
L3 and Rt3 :<br>
 +
The range of 120 cms to 150 cms is considered as the zone L3 and Rt3. In this zone, only the speed of the car is reduced.<br><br>
 +
Rear :<br>
 +
Reverse :<br>
 +
We have only a single zone for the reverse-motion using rear sensor.
 +
The reason for this is that there won’t be a significant movement in the reverse direction. So, there is not much use of handling the reverse conditions at a higher priority. Just a single level and every case can be handled properly.
 +
The range of the obstacles finding for the reverse sensor is 60 cms.
 +
 
 +
We have considered all the cases for each of the zones, but during the actual running of the car, there were some cases which were only used 0.5% of the times. Just to improve the response of the algorithm, we have ignored those cases and concentrated on all the other cases. The results were fascinating since the reverse algorithm was responding very sharply.
 +
These were all the theoretical explanation about the levels. The, actual algorithm is shown using a flow diagram below. This would clearly showcase how the car would run and in what conditions.
 +
 
 +
                                    [[File:CMPE243_F15_Minion_Master Flowchart.jpg|800x700px|Obstacle Avoidance Flow-Chart]]
 +
 
 +
====Technical Challenges and Resolution====
 +
=====Sensor algorithm=====
 +
Just a straightforward algorithm is easy and short to implement. But the sensor are tested properly when there are a lot of corner cases of obstacles where the car can stuck. These corner cases were indeed a challenge that was faced. These cases were developed in step and the entire algorithm was not implemented at once.
 +
=====CAN Message Handling=====
 +
Collaborating on the message id’s and the data in those messages. Since master is the powerhouse of the system, there are a multiple number of nodes communicating with Master. Since such a number of nodes are communicating with Master, there are a lot of cases which are to be handled in Master and that was indeed a challenging task.
 +
=====Integrating Sensor and Geo Algorithms=====
 +
There were a lot of problems faced while integrating Geo controller and Sensor controller. The first and foremost problem that we faced was while implementing any new feature and synchronising other controllers with the Master controller. For example, the sensors were integrated earlier but when the Geo controller was integrated, the motor did not receive proper data. On debugging, we came to know that the problem was with the algorithm and after we changed it, everything was working on its proper way.
 +
=====CAN Arbitration=====
 +
Since Master controller was the one with a lot number of messages, we faced some issues regarding CAN arbitration. Initially, there were a couple of messages which were high priority messages and were blocking the way of some important low priority one time messages. But after some changes in the ID’s the problem was dealt properly.
 +
 
 +
=== Sensor Controller ===
 +
 
 +
==== Schedule ====
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 500: Line 1,237:
 
|-
 
|-
 
|1
 
|1
|9/29/2015
+
|9/20/2015
|10/06/2015
+
|10/5/2015
|Ordering bluetooth module and setting up android dev enviornment
+
|Study available sensors and place order
 
|Completed
 
|Completed
|10/06/2015
+
|10/4/2015
 
|-
 
|-
 
|-
 
|-
 
|2
 
|2
|10/06/2015
+
|10/6/2015
 
|10/13/2015
 
|10/13/2015
|Implementing basic UI with Start and Stop buttons and testing bluetooth module
+
|Collaborate with the other sub teams to finish the CAN bus communication
 
|Completed
 
|Completed
|10/12/2015
+
|10/13/2015
 
|-
 
|-
 
|-
 
|-
 
|3
 
|3
 
|10/13/2015
 
|10/13/2015
|10/27/2015
+
|10/20/2015
|Integrating android app with bluetooth module and SJ One board
+
|Develop simple test code for the sensors
 
|Completed
 
|Completed
|11/01/2015
+
|10/18/2015
 
|-
 
|-
 
|-
 
|-
 
|4
 
|4
|10/27/2015
+
|10/21/2015
|11/03/2015
+
|10/30/2015
|Establishing communication with other modules using CAN and testing Prototype
+
|Interface all sensors and develop code for reading all sensors.
 
|Completed
 
|Completed
|11/07/2015
+
|10/30/2015
 
|-
 
|-
 
|-
 
|-
 
|5
 
|5
|11/03/2015
+
|10/30/2015
|11/17/2015
+
|11/2/2015
|Enhancing UI features with Google Maps and display of sensor data from different modules
+
|Positioning of sensors and identifying dead band if any
|Ongoing
+
|Completed
|
+
|11/2/2015
 
|-
 
|-
 
|-
 
|-
 
|6
 
|6
|11/17/2015
+
|11/06/2015
|12/01/2015
+
|12/17/2015
|Setting up Communication with GPS and Master and prototype testing
+
|Final testing and debugging
|
+
|Completed
|
+
|11/29/2015
 +
|}
 +
 
 +
==== Hardware Design ====
 +
 
 +
Sensor controller consists of sonar and ultrasonic sensors that are inter-connected to the SJOne board and CAN bus. The sensors detect if there is any obstacle around the car and report the distance of obstacle. Hardware design consists of four sensors connected to port 2 of LPC1758. The sensor in the front direction is MB1010 sonar sensor while the ones at back,right and left direction are HCSR04 ultrasonic sensors. The sensors are connected to +5V power supply to achieve the highest beam pattern that is available.
 +
===== Sensor Hardware Interface =====
 +
<br>
 +
[[File:CMPE243_F15_Minion_Sensor_hardware_interface.jpg|center|600px|thumb|Sensor Hardware Interface]]
 +
<br><br>
 +
 
 +
===== MB1010 LV MaxSonar EZ1 Sensor =====
 +
The LV MaxSonar EZ detects objects from 0 inches to 254 inches and provides sonar range from 6 to 254 inches with 1 inch resolution. Objects from 0 to 6 inches are reported as 6 inches. Sensor operates at 42KHz. The sensor reports output formats in from of pulse width output, analog voltage output, and RS232 serial output. We have selected pulse width output.The sensor will continually measure range and output if RX data is left unconnected or held high. If held low the sensor will stop ranging. We have commanded a range reading by triggering high for 20uS.
 +
Below are the timing diagrams for the sensor <br>
 +
[[File:CMPE243_F15_Minion_Timing_Diagram_MB1010.jpg|left|600x350px|thumb|Timing Diagram for LV MaxSonar EZ Sensor]]
 +
[[File:CMPE243_F15_Minion_LV-EZ Ultrasonic Range Finder_200px.jpg|centre|200px|thumb|MB1010 Sensor]]
 +
<br><br><br><br>
 +
 
 +
===== HCSR-04 sensor =====
 +
 
 +
HCSR-04 sensor is a ultrasonic ranging module which detects obstacle from 0 to 400 cm. It is a four pin module – Vcc, trig, echo and Gnd. It includes transmitter, receiver and control circuit. The sensor operates at 40 KHz.It Requires 5V 15mA power supply. When a short 10uS pulse is provided to the trigger input, the sensor will transmit out 8 cycle of ultrasonic burst at 40kHz and makes the echo pin high.The Echo pin is lowered to logic low when the ultrasound burst is reflected off a distant object.To obtain the distance, measure the width (Ton) of Echo pin.
 +
Time = Width of Echo pulse, in uS (micro second)
 +
Distance in centimeters = Time / 58
 +
Distance in inches = Time / 148
 +
Or you can utilize the speed of sound, which is 340m/s
 +
 
 +
[[File:CMPE243_F15_Minion_Timing_Diagram_HC-SR04_Ultrasonic-Sensor.jpg|left|5000x700px|thumb|Timing Diagram for HC-SR04 Ultrasonic Sensor]]
 +
[[File:CMPE243_F15_Minion_HC-SR04-Ultrasonic-Sensor.jpg|centre|250px|thumb|HCSR-04 Sensor]]<br><br><br><br><br><br><br><br><br><br><br>
 +
 
 +
{| class="wikitable"
 +
|+ Sensor Pin layout
 +
|-
 +
! scope="col"| Pin Name
 +
! scope="col"| Function
 +
|-
 +
! scope="row"| P2_0
 +
|RX trigger for front Sensor
 +
|-
 +
! scope="row"| P2_1
 +
|PWM for front Sensor
 +
|- 
 +
! scope="row"| P2_2
 +
|Trig for back Sensor
 +
|-
 +
! scope="row"| P2_3
 +
|Echo for back Sensor
 +
|- 
 +
! scope="row"| P2_4
 +
|Trig for left Sensor
 +
|-
 +
! scope="row"| P2_5
 +
|Echo for left Sensor
 
|-
 
|-
 +
! scope="row"| P2_6
 +
|Trig for right Sensor
 +
|-|-
 +
! scope="row"| P2_7
 +
|Echo for right Sensor
 
|-
 
|-
|7
 
|12/01/2015
 
|12/08/2015
 
|Final app testing
 
|
 
|
 
 
|}
 
|}
  
== Parts List & Cost ==
+
===== 3D Printing Design =====
Give a simple list of the cost of your project broken down by components.  Do not write long stories here.
+
The 3D design used as a support for mounting the sensors is shown below:
 
 
== Design & Implementation ==
 
  
===CAN Communication Table[Empty spaces will be filled as the project progresses]===
+
[[File:CMPE243_F15_Minion_Sensor_Stand off_3D_Print_Design.jpg|left|600px|thumb|3D Design for Sensor mounting]]
 +
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  
 +
=====Usage of OnBoard LED's: =====
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! scope="col"| Sr. No
+
! scope="col"| LED No.
! scope="col"| Message ID
+
! scope="col"| Usage
! scope="col"| Message function
+
|-
! scope="col"| Message Data
+
|-
! scope="col"| From
+
|1
! scope="col"| To
+
|Boot Reply Successful
 +
|-
 +
|-
 +
|2
 +
|Heartbeat
 +
|-
 +
|-
 +
|3
 +
|Can reception successful
 +
|-
 +
|-
 +
|4
 +
|Can transmission successful
 
|-
 
|-
 +
|}
 +
 +
==== Software Design ====
 +
[[File:CMPE243_F15_Minion_Sensor_software_Design.png|right|800px|thumb|Sensor software flowchart]]
 +
Software design for Sensor controller includes sensor initialization, sequential triggering of sensors, calculating distance of obstacle from the echo received and transmitting the data on CAN bus. Sensor initialization includes interrupt configuration for echo pins of sensor and configuring the trigger pins as output. A trigger of 20 us is required for MB1010 sensor and 10 us is required for HC SR-04 sensor.
 +
 +
=====Algorithm=====
 +
* Initialize trigger pins as output to provide trigger pulse to sensors
 +
* Initialize interrupt pins to receive echo or PW from sensors
 +
* Trigger Front and back sensor
 +
* Wait for echo or PWM pulse
 +
* Capture start time frame on rising edge of interrupt and end time frame at falling edge of interrupt of the sensor
 +
* Trigger Left and Right sensor
 +
* Wait for echo or PWM pulse
 +
* Capture start time frame on rising edge of interrupt and end time frame at falling edge of interrupt of the sensor
 +
* Calculate distance on basis of the time captures in previous steps.
 +
* Broadcast distance on CAN bus
 +
This is a piece of our Interrupt configurations and function callbacks that calculate the distance of sensor.
 +
[[File:CMPE243_F15_Minion_Sensor_code_snippet.jpg|none|500px|thumb|Sensor Code Snippet ]]
 +
 +
=====Module Flow=====
 +
 +
[[File:CMPE243_F15_Minion_Sensor_Workflow.gif|864px|thumb|center|Sensor Controller workflow]]
 +
<br>
 +
 +
====Testing and Technical Challenges ====
 +
===== Sensor Triggering =====
 +
*Initially while testing sensors the triggering was in continuous mode without waiting for appropriate sensor processing time. This resulted in multiple errors in distance measured and eventually damaged the sensor. The readings were stable if the sesnors were triggered every  50ms for MB 1010 sensor and 30 ms for HC SR 04 sensor. Below are the testing results for triggering sensors at different time intervals<br>
 +
[[File:CMPE243_F15_Minion_HCSR-04_Calibration.jpg|thumb|500px|left|HC SR-04 Calibration]]
 +
[[File:CMPE243_F15_Minion_MB1010_Calibration.jpg|thumb|500px|right|MB1010 Calibration]]<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
 +
Referring to the above results we can conclude that the sensor data is more accurate for MB1010 if the time interval for triggering is 50ms. Similarly for HC SR04 the readings are accurate if time interval between the trigger is 30 ms.
 +
 +
===== Sensor Operating frequency =====
 +
*Now if one waits for sequential triggering for all 4 sensors the wait time will be long, resulting in sensor data at low frequency. Hence to make sensors operate at 10Hz, the sensors are triggered in pairs( Front- Back and Right- Left). This has resulted in operating frequency of 10Hz concurrently avoiding interference between adjacent sensors.
 +
===== Ground Reflections =====
 +
*During testing, we observed that that the reflection from ground surface resulted into incorrect readings. This issue was resolved by tilting the 3D frames backward so that the ground reflections were minimal.
 +
*When the car was tested for obstacle avoidance in the university corridors, at particular angles the sensor readings were maximum even though there was presence of wall in front of the sensor. This was overcome by slightly moving the positions of the sensors but could not be resolved completely.
 +
<br>
 +
[[File:CMPE243_F15_Minion_Sensor_reflections_from_extremely_smooth_surface.gif|650x500px|center|thumb|Sensor reflections from extremely smooth surface]]<br><br>
 +
 +
=== Geographical Controller ===
 +
Geographical Controller consists of GPS and Compass module. GPS module  tracks current position (Latitude and Longitude) of  the car and compass module gives the heading of car with respect to north. With the data provided from these modules, turn angle and distance to destination is calculated. Algorithm for these calculations is explained in software section.
 +
 +
'''Heading:''' Heading is the current direction of car,  measured clockwise with respect to  geographic north and ranges from 0 to 360 degrees. The compass gives the values with respect to magnetic north and the Magnetic declination is added to these values to give the actual heading.
 +
 +
'''Bearing:''' Bearing is direction of destination point with respect to north measured clockwise and ranges from 0 to 360 degrees. This value is calculated from destination and current coordinates using Haversine formula described in software section.
 +
 +
'''Turn Angle :''' It is a measurement in degrees that the car needs to take to head towards destination. It is calculated by using Heading and Bearing values.
 +
 +
'''Direction :''' It is the clockwise or anti clockwise  turn of the car to head towards destination.
 +
 +
==== Schedule ====
 +
 +
{| class="wikitable"
 
|-
 
|-
! colspan="6"| High
+
! scope="col"| Sl. No
 +
! scope="col"| Start Date
 +
! scope="col"| End Date
 +
! scope="col"| Task
 +
! scope="col"| Status
 +
! scope="col"| Actual Completion Date
 
|-
 
|-
 
|-
 
|-
 
|1
 
|1
|0x220
+
|09/27/2015
|Motor Control<br>(Direction Control- Straight, Left or Right<br>Level of Direction-Level 0, Level1, Level 2<br>Motion Control- Stop, Forward or Reverse<br>Speed Control - Stop, Level1, Level2 or Level3)
+
|10/07/2015
|Byte[0] -> Direction Control<br>Byte[1] -> Level of Direction<br>Byte[2] -> Motion Control<br>Byte[3] -> Speed Control
+
|Ordering Parts and understanding each module
|Master
+
|Completed
||Motor
+
|10/11/2015
 +
|-
 
|-
 
|-
 
|2
 
|2
|0x010
+
|10/07/2015
|Kill Message<br>(User request to stop the car under emergency)
+
|10/13/2015
|Control Frame. No data bytes.
+
|CAN Communication with other boards and understanding each module
|Android
+
|Completed
|Master
+
||10/13/2015
 
|-
 
|-
 
|-
 
|-
 
|3
 
|3
|0x020
+
|10/07/2015
|Kill Message<br>(Master request to stop all controllers and reboot<br>under emergency)
+
|10/30/2015
|Control Frame. No data bytes.
+
|Algorithm for distance and heading calculation and coding
|Master
+
|Completed
|All
+
|10/30/2015
 
|-
 
|-
 
|-
 
|-
 
|4
 
|4
|0x030
+
|10/14/2015
|Stop<br>(User request to stop the car)
+
|10/20/2015
|Control Frame. No data bytes.
+
|Interfacing of compass(I2C) and GPS (UART) with SJONE board
|Android
+
|Completed
|Master
+
|10/20/2015
 +
|-
 +
|-
 +
|5
 +
|10/20/2015
 +
|10/30/2015
 +
|Coding, Compass Calibration,GPS Calibration
 +
|Completed
 +
|11/10/2015
 
|-
 
|-
 
|-
 
|-
 
|5
 
|5
|0x040
+
|10/25/2015
|Stop<br>(Master stops the motor)
+
|11/15/2015
|Control Frame. No data bytes.
+
|Individual unit testing
|Master
+
|Completed
|Motor
+
|11/20/2015
 
|-
 
|-
 
|-
 
|-
 
|6
 
|6
|0x210
+
|10/30/2015
|Sensor Data<br>(Distance in cms)
+
|11/30/2015
|Byte[0] -> Forward Distance<br>Byte[1] -> Left Distance<br>Byte[2] -> Right Distance<br>Byte[3] -> Back Distance
+
|Interfacing with Android, Master and IO controllers
|Sensor
+
|Completed
|Master/Motor-IO
+
|12/05/2015
 
|-
 
|-
 
|-
 
|-
 
|7
 
|7
|0x230
+
|10/30/2015
|Total Distance to Travel
+
|11/30/2015
|Byte[0-1]
+
|Integration Testing,On Car Calibration
|Android
+
|Completed
|Geo
+
|12/15/2015
 +
|}
 +
 
 +
==== Hardware Design ====
 +
=====Schematic=====
 +
[[File:CMPE243_F15_Minion_Geo Schematic.jpeg|600px|thumb|centre|Schematic]]<br>
 +
 
 +
=====SparkFun Venus GPS with SMA Connector=====
 +
SparkFun Venus GPS uses Skytraq VENUS634FLPx IC. The Venus638FLPx outputs standard NMEA-0183 or SkyTraq Binary sentences at a default rate of 9600 bps which is adjustable to 115200 bps, with update rates up to 20Hz. We configured this module with update rate of 10Hz and 38400 bps UART rate. Module outputs GGA, GSA, GSV, GLL, RMC, VTG, ZDA NMEA standard messages which can be configures to as per our requirements. We configured it to give only GGA messages.
 +
GGA message format is shown below.<br>For configuring GPS modules to UART rate 38400 bps, 10Hz update rate and only GGA message at output, below binary commands are used.
 +
[[File:CMPE243_F15_Minion_GGA_Message.jpeg|600px|thumb|left|GGA Message Format]]
 +
[[File:CMPE243_F15_Minion_Binary_Commnads.jpeg|400px|thumb|right|Binary Configuration Commands]]<br>
 +
[[File:CMPE243_F15_Minion_GPS_Module_with_Antenna.jpeg|400px|thumb|right|SparkFun Venus GPS with SMA Connector and Antenna]]
 +
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
 +
 
 +
=====HMC5883L=====
 +
HMC5883l is a triple axis digital compass IC used for heading calculation.
 +
It has magneto resistive sensors that forms the basis of the working principle of a compass. Please refer data sheet attached in reference section for specifications of the IC. Note that this IC is not tilt compensated and we need to calibrate for instrument error and for tilt.
 +
[[File:CMPE243_F15_Minion_Compass_HMC5883L.png|400px|thumb|left|HMC5883L]]
 +
 
 +
=====HMC5883L and I2C=====
 +
HMC5883L IC communicates to SJOne Board through I2C bus.<br>SJONE board -Master device<br>HMC5883L - Slave device <br> I2C rate is controlled by the master and can be upto maximum 400 KHz. We have configured the rate as 100 KHz.<br>
 +
 
 +
'''Master Transmitter Mode -Slave Receiver Mode'''<br>
 +
In this mode, the master writes to the slave registers.<br>
 +
Compass IC has a set of 8 bit registers to be initially configured for parameters such as device output rate, number of samples, device gain and operating mode. By identifying the device write address and register address, the values can be written by the SJONE board to compass registers.<br><br>
 +
 
 +
'''Master Receiver Mode -Slave Transmitter Mode'''<br>
 +
In this mode, the master reads from the slave registers.<br>
 +
X,Y,Z registers of the compass can be then read by SJOne board one by one knowing the device read address and register address.Register pointer will be incremented by 1 automatically after current register has been successfully read.<br>
 +
 
 +
=====Usage of OnBoard LED's=====
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| LED No.
 +
! scope="col"| Usage
 +
|-
 +
|-
 +
|1
 +
|I2C Device response successful
 +
|-
 
|-
 
|-
 +
|2
 +
|Compass read successful
 
|-
 
|-
|8
 
|0x240
 
|Send Checkpoints
 
|Byte[0-3] -> Latitude<br>Byte[4-7] -> Longitude
 
|Android
 
|Geo
 
 
|-
 
|-
 +
|3
 +
|Checkpoints reception successful
 
|-
 
|-
|9
 
|0x250
 
|Distance<br>(Distance in foot)
 
|Byte[0-1] -> Final Distance remaining  <br>Byte[2-3] -> Checkpoint distance
 
|Geo
 
|Master
 
 
|-
 
|-
 +
|4
 +
|Can Transmission successful
 
|-
 
|-
|10
+
|}
|0x260
+
 
|Turn Angle and Direction
+
==== Software Design====
|Byte[0] -> Turn Angle <br>Byte[1] -> Direction <br> (1-Left,2-Right)
+
=====Compass Heading Calculation=====
|Geo
+
    '''Compass Heading  = Raw values obtained from the compass module + Magnetic deviation + Magnetic declination'''
|Master
+
 
 +
'''Raw values obtained from the compass module -''' Of the 3 axis in compass, the x-axis and y-axis values read from the compass registers are used to calculate the heading value in radians. Due to magnetic deviations these values are not accurate and need to be calibrated for accuracy. Calibrating the values obtained as radians would be more accurate that calibrating in degrees.
 +
The calibrated values in radians are then converted to degrees. The degrees would be values from -180 to 180 degree range and this has to be scaled for 0 to 360 that forms a complete circle.
 +
 
 +
'''Magnetic Deviation -''' It is the error introduced in the compass module due to local magnetic fields. The compass needs to be compensated for it.
 +
 
 +
'''Magnetic Declination -''' It is the angle between the Earth's geographic north and magnetic north. The values from compass IC are with respective to magnetic north whereas the navigation is generally based on geographic north. Hence this declination has to be compensated. Declination varies from place to place and for San Jose it is 13.31 degree East and positive. This value needs to be added.
 +
 
 +
=====Algorithm=====
 +
*Wait for boot request message from master.
 +
*Send boot reply to master.
 +
*Get current readings from GPS and compass module.
 +
*Parse string received from GPS module to get latitude, longitude and number satellite lock.
 +
*Check if number of satellite lock is valid.
 +
*Send current coordinates to android communication bridge via CAN.
 +
*Get checkpoints,destination from android app and store it in queue in CAN reception.
 +
*Fetch first checkpoint from queue.
 +
*Calculate distance and bearing of checkpoint with the help of haversine formula using current and checkpoint coordinates.
 +
*If distance is more than 200 feet, then find middle checkpoint and use it as checkpoint.
 +
*Calculate turn angle with direction using bearing and heading values.
 +
*Send distance, turn angle and direction to master controller using CAN bus.
 +
*If checkpoint distance is less than 10 feet, then fetch next checkpoint from queue.
 +
*Repeat above five steps till destination reached message is received from master.
 +
 
 +
Haversine formula:
 +
  Distance = R ⋅ c
 +
  c = 2 ⋅ atan2(√a, √(1−a))
 +
  a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)<br>
 +
  Bearing (θ)(radians) = atan2(sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ)<br>
 +
Destination point given distance and bearing from start point:
 +
  φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ )
 +
  λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 )<br>
 +
  where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km)
 +
        δ is the angular distance d/R; d being the distance at which checkpoint is needed<br>
 +
  Note: Angles need to be in radians to pass to trig functions,unit of distance depends on unit of radius used.
 +
 
 +
=====Module Flow=====
 +
                              [[File:CMPE243_F15_Minion_geo.gif|thumb|800px|centre|Geo Module Software Flow]]<br>
 +
 
 +
=====Implementation=====
 +
*Geographical Controller uses Periodic Scheduler Task provided by Preet to calculate distance, bearing values, get readings from compass and CAN communication.
 +
*GPS Task is created to read string from GPS module and parse it to get latitude and longitude data.
 +
*CAN and compass initialization is performed in main() function.
 +
*File logger function is used to log the real-time data onto SD card which is used for debugging purpose.
 +
*Can Message structure of 11-bit id is implemented to send and receive CAN messages over the CAN Bus.
 +
*CAN acceptance filter is set-up to receive messages specific to Geographical Controller from the CAN Bus.
 +
*Queues are implemented to store coordinates and use them in different functions whenever required. Producer and consumers of queues are timely managed so that functions will get latest readings.
 +
*CAN bus is checked if it is in bus off status at every 10Hz interval. CAN bus is reset if it is in bus off mode.
 +
<br>
 +
 
 +
==== Testing ====
 +
 
 +
===== Accuracy of GPS Module =====
 +
[[File:CMPE243_F15_Minion_GPS_Module_Coordinates_on_Google_Maps.jpeg|200px|thumb|right|GPS Module Coordinates on Google Maps]]
 +
Accuracy of GPS module was tested by recording/logging coordinates received by module using LOG_INFO() function and plotting them on Google maps [https://www.google.com/maps/d/u/0/embed?mid=zIDeCYKjmwEU.k1EGAZhJH7ko GPS Module Coordinates on Google Maps]. GPS module was very much accurate and we did not needed it to calibrate. It is observed that accuracy depends on number of satellite locks with module, environment conditions. More number of satellite locks and sunny weather conditions, greater the accuracy of readings. You may hear that bluetooth, GPS frequencies interfere with each other reducing accuracy of GPS, but we never experienced this issue.
 +
 
 +
=====Calibration of Compass =====
 +
As any instrument has instrument error, so has the compass IC. The compass needs to be calibrated for accuracy. We undertook two levels of calibration.<br>
 +
1. Level 1 calibration was done without mounting the compass on car. The compass was rotated in its axis for 360 degrees and the error was identified for every 15 degrees (totally 24 zones) with the setup shown by the image in the left.<br>
 +
2. Level 2 calibration was done after mounting the compass on car.The car setup by itself had some tilt and we compensated it by means of adjusting the hardware mounting. Next, the motor’s EMI caused some  magnetic deviation and the motor's influence was taken into account too. The car was rotated in its axis ( its axis being parallel to the compass axis) for 360 degrees with the deviation measured for every 15 degrees(totally 24 zones) with the setup depicted by the image in the right.
 +
[[File:CMPE243_F15_Minion_Compass_calibration_before_mounting_on_car.png|thumb|300px|left|Set up for Compass Calibration before mounting on Car]]<br>
 +
[[File:CMPE243_F15_Minion_Compass_calibration_on_car.png|thumb|300px|centre|Set up for Compass Calibration on Car]]<br>
 +
 
 +
The deviation was not uniform for every zone. Using linear regression analysis technique, the relationship between the predictor variable - degrees and the response variable - radians was found in an ideal environment and the same was repeated several times for accuracy. The average of several such readings was taken as the final calibration value.
 +
[[File:CMPE243_F15_Minion_Compass_BeforeCalibration_1.png|thumb|500px|left|Before Calibration]]
 +
[[File:CMPE243_F15_Minion_Compass_AfterCalibration_1.png|thumb|500px|right|After Calibration]]<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
 +
 
 +
====Technical Challenges and Resolution====
 +
 
 +
===== Configuring GPS Module =====
 +
We faced difficulty in configuring GPS module to sending only $GGA messages, 10Hz Position update rate and updating baud rate to 38400. Initially we were trying to configure GPS module via writing program for SJ One board and we were unable to do it. Later on we completed configuring by connecting GPS module directly to serial port and using  [http://cdn.sparkfun.com/datasheets/Sensors/GPS/Venus/638/viewer/GPS%20Viewer%20-%20Customer%20Release_110613.zip '''GPS Viewer'''] software. Through it we can directly configure GPS module without worrying about binary messages and checksum calculation.
 +
 
 +
===== Compass module and Compass Calibration =====
 +
1.Initially the compass was mounted and tested on breadboard with its upper face downwards as the connecting strips are on the upper side. This made the compass  produce incorrect values.<br>2. While reading the registers in compass HMC5883L, only x and y register values are needed. Hence we tried to read only those registers from the device. But it so happened that z register is in between the x and y registers and the read pointer did not advance after the x register was read and remained in the z register. This led to compass producing constant values.<br>3. While calibrating, the compass should be rotated on a horizontal plane with its axis of rotation fixed. Shifting the axis may result in incorrect values.<br>4. Having a robust hardware that does not cause any or very less tilt, will reduce the efforts of calibration as HMC5883L IC is not tilt compensated.<br>5. Calibration should be done in an environment which does not have iron , magnetic    particles etc as those may cause magnetic deviation. As the motor module influences the compass with the generated EMI, mount the compass far away from the motor and calibrate with the motor ON to take account of the EMI generated.
 +
 
 +
===== Integrating Geo Module on Car =====
 +
In the initial phase of integrating geo module, our car was always going in right direction but going forward towards destination. We had to put car back on track. While testing we it came  to our notice that if car has closer checkpoints then it was following the track perfectly. To solve this we implemented algorithm to find midpoint between checkpoint sent by from android and current source if distance is greater than 200 feet. Mathematical formula to implement this is mentioned in software design section. Online contents are listed in references section.
 +
 
 +
=== Communication Bridge Controller and Android Application===
 +
====  Schedule ====
 +
{| class="wikitable"
 
|-
 
|-
 +
! scope="col"| Sl. No
 +
! scope="col"| Start Date
 +
! scope="col"| End Date
 +
! scope="col"| Task
 +
! scope="col"| Status
 +
! scope="col"| Actual Completion Date
 
|-
 
|-
|11
 
|0x270
 
|Run and Pause Command
 
|Control Frame. No data bytes
 
|Android
 
|Master
 
 
|-
 
|-
 +
|1
 +
|9/29/2015
 +
|10/06/2015
 +
|Ordering bluetooth module and setting up android dev enviornment
 +
|Completed
 +
|10/06/2015
 
|-
 
|-
|12
 
|0x280
 
|Heartbeat Message
 
|Control Frame. No data bytes
 
|Motor
 
|Master
 
 
|-
 
|-
 +
|2
 +
|10/06/2015
 +
|10/13/2015
 +
|Implementing basic UI with Start and Stop buttons and testing bluetooth module
 +
|Completed
 +
|10/12/2015
 
|-
 
|-
|13
 
|0x281
 
|Heartbeat Message
 
|Control Frame. No data bytes
 
|Geo
 
|Master
 
 
|-
 
|-
 +
|3
 +
|10/13/2015
 +
|10/27/2015
 +
|Integrating android app with bluetooth module and SJ One board
 +
|Completed
 +
|11/01/2015
 
|-
 
|-
|14
 
|0x282
 
|Heartbeat Message
 
|Control Frame. No data bytes
 
|Android
 
|Master
 
 
|-
 
|-
 +
|4
 +
|10/27/2015
 +
|11/03/2015
 +
|Establishing communication with other modules using CAN and testing Prototype
 +
|Completed
 +
|11/07/2015
 
|-
 
|-
|15
 
|0x283
 
|Heartbeat Message
 
|Control Frame. No data bytes
 
|Sensor
 
|Master
 
 
|-
 
|-
 +
|5
 +
|11/03/2015
 +
|11/17/2015
 +
|Enhancing UI features with Google Maps and display of sensor data from different modules
 +
|Completed
 +
|11/20/2015
 
|-
 
|-
! colspan="6"|Medium
 
 
|-
 
|-
 +
|6
 +
|11/17/2015
 +
|12/01/2015
 +
|Setting up Communication with GPS and Master and prototype testing
 +
|Completed
 +
|12/05/2015
 
|-
 
|-
|16
 
|0x410
 
|Destination reached.<br>(Stops the car when destination is reached)
 
|Control Frame. No data bytes
 
|Master
 
|All
 
 
|-
 
|-
 +
|7
 +
|12/01/2015
 +
|12/08/2015
 +
|Final app testing
 +
|Completed
 +
|12/10/2015
 +
|}
 +
 +
==== Hardware Design ====
 +
The Communication bridge consists of establishing connection between car and the android phone which is established with the help of bluetooth module HC-05 connected to UART peripheral of SJOne Board. The UART pins on board are connected to bluetooth module in the manner shown in diagram. Once the connection is established between the car and the android phone and signals like 'Start','Stop' and 'Kill' are sent from android phone then they are received by the bluetooth and sent to SJOne board to be further broadcasted over CAN bus.
 +
 +
[[File:CMPE243_F15_Minion_Bluetooth Connection.png|thumb|left|400px|Communication Bridge]][[File:CMPE243_F15_Minion_Bluetooth_Module.jpg|thumb|centre|200px|HC-05 Bluetooth Module]] <br><br><br><br><br><br>
 +
 +
=====Pin Configuration: =====
 +
{| class="wikitable"
 
|-
 
|-
|17
+
! scope="col"| Sl. No
|0x420
+
! scope="col"| Pin on SJOne Board
|Battery Status
+
! scope="col"| Pin on HC-05 Bluetooth module
|Byte[0-1]
+
! scope="col"| Purpose
|Sensor
 
|Master/IO
 
 
|-
 
|-
 
|-
 
|-
! colspan="6"|Low
+
|1
 +
|TXD3
 +
|RXD
 +
|Transmission through UART3 to HC-05
 
|-
 
|-
 
|-
 
|-
|18
+
|2
|0x610
+
|RXD3
|Boot Request
+
|TXD
|Control Frame. No data bytes
+
|Reception through UART3 from HC-05
|Master
 
|All
 
 
|-
 
|-
 
|-
 
|-
|19
+
|3
|0x620
+
|3V3
|Boot Reply<br>(Date and time will be sent to Master)
+
|3.3
|Byte[0-4]
+
|3.3V voltage supply
|Motor-IO
 
|Master
 
 
|-
 
|-
 
|-
 
|-
|20
+
|4
|0x621
+
|GND
|Boot Reply<br>(Date and time will be sent to Master)
+
|GND
|Byte[0-4]
+
|Ground
|Sensor
+
|}
|Master
+
 
 +
The Bluetooth module HC-05 is a MASTER/SLAVE module.The Role of the module (Master or Slave) can be configured only by AT COMMANDS.By default the mode is set to SLAVE.It has pins named KEY and 5V which we are not using because KEY pin is used to enter the Command mode.Bluetooth module when connected to SJOne board needs to be paired with any one of the external devices like android phone in our case, there is LED that blinks at different pace to indicate whether it is paired or not. Once the bluetooth module is paired indicated by slow blinking of the LED, the android phone is all ready to transmit signals to SJOne board.
 +
 
 +
=====Usage of OnBoard LED's: =====
 +
{| class="wikitable"
 
|-
 
|-
 +
! scope="col"| LED No.
 +
! scope="col"| Usage
 
|-
 
|-
|21
 
|0x622
 
|Boot Reply<br>(Date and time will be sent to Master)
 
|Byte[0-4]
 
|Geo
 
|Master
 
 
|-
 
|-
 +
|1
 +
|START/STOP signal successful
 
|-
 
|-
|22
 
|0x623
 
|Boot Reply<br>(Date and time will be sent to Master)
 
|Byte[0-4]
 
|Android
 
|Master
 
 
|-
 
|-
 +
|2
 +
|Map reset
 
|-
 
|-
|23
 
|0x630
 
|Boot Status<br> (Enable the map and run button in Android)
 
|Control Frame. No data bytes
 
|Master
 
|Motor-IO/Android
 
 
|-
 
|-
 +
|3
 +
|Can reception successful
 
|-
 
|-
|24
 
|0x640
 
|System Start
 
|Control Frame. No data bytes
 
|Android
 
|All
 
 
|-
 
|-
 +
|4
 +
|Can transmission successful
 
|-
 
|-
|25
 
|0x650
 
|Source Co-ordinates
 
|Byte[0-3] -> Source Latitude <br> Byte[4-7] -> Source Longitude
 
|Geo
 
|Android
 
 
|}
 
|}
  
=== Car Framework and Components ===
+
==== Software Design ====
 +
=====Communication Bridge Controller=====
 +
The purpose for Communication Bridge is mainly to facilitate communication between Android application and other controllers via Bluetooth module and CAN. The software design mainly follows the flow of data as shown in figure.
 +
The UART peripheral on SJOne is configured by using getInstance( ) on Free Rtos to either receive or transmit data through it.When the communication bridge controller receives CAN msg ids corresponding to Master,Sensor and Geo controllers over the CAN bus, it tends to send data corresponding to each msg id to Android phone through bluetooth module.Once the signals are processed by the android app, in return if it wants to send data through bluetooth over CAN bus then it can.
  
The RC car, Traxxas Stampede, in its raw form consists of a Titan 12T 550 Brushed DC motor, a Servo motor, an XL-5 ESC (Electronic Speed Control) unit, battery and a pre-programmed wireless receiver and controller. The Battery used in the RC car is an 8.4 V, 3000 NiMH from Traxxas. The wireless receiver gets commands from the remote control and drives the motors accordingly, but the DC motor can be controlled only through ESC.
+
  [[File:CMPE243_F15_Minion_Bluetooth Reception.png|thumb|centre|600px|Reception of Bluetooth messages and transmission over CAN]]<br>
  
                                      [[File:CmpE243_F15_T2_Car.jpg]]
+
  [[File:CMPE243_F15_Minion_CAN Reception.png|thumb|centre|600px|Reception of CAN messages and transmission over Bluetooth]]<br>
  
The ESC (Electronic Speed Control) unit is an electronic module, which receives PWM signals from the controller and varies speed and direction of the DC motor and also acts as dynamic brakes. ESCs are often used in RC models. The ESC has the capability to provide dynamic braking depending on the mode in which it is being operated.
+
=====Android Application =====
  
  
=== Motor and I/O Controller ===
+
[[File:CMPE243_F15_Minion_Android flow of work.gif|thumb|centre|800px|Android Workflow]]
  
==== Hardware Design ====
 
'''Motor Module'''
 
  
The motor module comprises of a servo motor for the direction control and a DC motor for speed control. The servo motor helps the car in turning left and right where as the DC motor on the other hand helps the car move forward and backward. The motor used in the project is a brushed motor. Conventionally, brushless motors are faster and more efficient than brushed motors. But, the reason for selecting a brushed motor over a brushless motor is that we employ a dedicated battery for the motor such that we do not have any issues with power and efficiency. Moreover, we need not operate the car at high speeds.
+
As part of the user interface, the android application provides user a way of setting the car on auto drive mode with just few inputs. The application consist of two main activities:
  
The initial task in the motor module is to find the operating ranges of the motor so that we get to know the output signal range and frequency from the SJONE board which would be replacing the pre-programmed controller. The simplest way to find the operating ranges of the motor is to tap and analyze PWM signal that is being supplied to the motor over an oscilloscope. The results as shown in the below pictures indicate that the operating duty cycle of both the motors lie between 10% to 20% and the frequencies at which the motors operate is 100Hz.
+
*Car Connect
 +
**The main purpose of the section of the app is to help user pair up with the Bluetooth module on the car. In this case we are pairing up with HC-05.
  
                                      [[File:CmpE243_F15_T2_PWM_DutyCycle.jpg]]
+
*Map Navigation
 +
**This section of the app will be in usage for most of the time. Considering the effectiveness of Google Maps API v2, the Application relies on the Google Maps to identify real life location on the map. A google Map API key was obtained in order to integrate Google maps into the application.
 +
**For the Bluetooth connection to be established the user needs to Click on the paired up Bluetooth module which enables the socket between the Android and Bluetooth module HC-05.
 +
**The activity consists of Map fragment and Buttons to issue commands. The application listens to incoming Bluetooth messages and locates the current position of the car. User can then set a destination by simply touching a location on the maps. The application computes the route along with checkpoints to precisely set a navigation path for the car. This enables the Run and Kill buttons for further action by the user.
 +
**The application also allows the user to monitor sensor data over the application in real time.
 +
The entire flow of the application between android application and Communication Bridge can be showcased as follows:  
  
==== Software Design ====
 
  
 +
  [[File:CMPE243_F15_Minion_Android Flow Chart.png|thumb|centre|400px|Application Flow]]<br>
  
=== Master Controller ===
+
<div><ul>
'''Description:''' As the name suggests, it is main controller on the car which interacts with all other controllers over the CAN Bus to achieve real-time functionality. Basic function of the Master Controller is to receive data from Android, Geo and Sensor Modules and develop the algorithm to drive the car autonomously based on the received data through the Motor Controller.
+
<li style="display: inline-block;"> [[File:CMPE243_F15_Minion_Home Screen.png|thumb|centre|500x500px|Home Screen]]</li>
 +
<li style="display: inline-block;"> [[File:CMPE243_F15_Minion_Bluetooth Pairing Screen.png|thumb|centre|500x500px|Bluetooth Pairing Screen]] </li>
 +
<li style="display: inline-block;"> [[File:CMPE243_F15_Minion_Checkpoints Computation.png|thumb|centre|500x500px|Checkpoints Computation]] </li>
 +
</ul></div>
  
==== Hardware Design ====
+
====Testing====
*RC car was the basic infrastructure that was required to implement the project.
 
*CAN Bus with five SJone controller boards was integrated on General purpose Printed Circuit Board (PCB).
 
*Sufficient power-supply ports and external pins were provided to each controllers.
 
*Bus wires were used to reduce circuit complexity arising from external connecting wires.
 
  
==== Software Design ====
+
=====Bluetooth Module=====
*Master Controller uses FreeRTOS environment to achieve its functionality.
+
We tested the bluetooth module HC-05 using a Bluetooth chat application from app store. Using this application we could successfully send characters to bluetooth module over UART connected to SJ One board and observe the results on Hercules terminal.<br>
*It uses Periodic Scheduler Task provided by Preet at its core to communicate with all other controllers.
+
=====Android application=====
*The functions of the Periodic Scheduler Task were used in a customized manner to transmit/receive the messages at specific intervals of 1Hz,10Hz,100Hz and 1000Hz.
+
Android application was tested for both functionality and performance.We tested all the application buttons and Map fragment with the bluetooth module and improved the performance of the app over the span of the project.<br>
*File logger function was used to log the real-time data onto SD card which was used for debugging purpose.
+
=====CAN communication =====
*Can Message structure of 11-bit id was implemented to send and receive CAN messages over the CAN Bus.
+
CAN communication between bridge controller and other module was tested in an isolated fashion by setting up the connection of two SJ One board using breadboards and wires.
*CAN acceptance filter was set-up to receive messages specific to Master Controller from the CAN Bus, since it is the broadcast Bus.
 
 
 
====Software Implementation====
 
*Master Controller starts with initialization of CAN Bus and setting up reception filter from the main() function.
 
*The Periodic Scheduler Task then takes over to implement the actual functionality of the Master Controller.
 
*CAN_is_busoff() was used at an interval of 10Hz through periodic scheduler task to check if CAN bus was working continuously.
 
*The basic flow of control is as follows:
 
 
 
=== Sensor Controller ===
 
==== Hardware Design ====
 
==== Software Design ====
 
 
 
 
 
=== Geographical Controller ===
 
 
 
Geographical Controller consists of GPS and Compass module. GPS module is used to track current position of car, find bearing angle of destination with respect to north and compass module used to know heading of car with respect to north. Difference between heading and bearing gives us turn angle which car have to take to reach destination from current position.
 
 
 
==== Hardware Design ====
 
'''Schematic'''<br>
 
  
'''SparkFun Venus GPS with SMA Connector'''<br>
+
===='''Technical Challenges and Resolution'''====
SparkFun Venus GPS uses Skytraq VENUS634FLPx IC. The Venus638FLPx outputs standard NMEA-0183 or SkyTraq Binary sentences at a default rate of 9600 bps which is adjustable to 115200 bps, with update rates up to 20Hz. We configured this module with update rate of 10Hz and 38400 bps UART rate. Module outputs GGA, GSA, GSV, GLL, RMC, VTG, ZDA NMEA standard messages which can be configures to as per our requirements. We configured it to give only GGA messages.
 
GGA message format is shown below.<br>For configuring GPS modules to UART rate 38400 bps, 10Hz update rate and only GGA message at output, below binary commands are used.
 
[[File:CMPE243_F15_Minion_GGA_Message.jpeg|600px|thumb|left|GGA Message Format]]
 
[[File:CMPE243_F15_Minion_Binary_Commnads.jpeg|400px|thumb|right|Binary Configuration Commands]]<br>
 
[[File:CMPE243_F15_Minion_GPS_Module_with_Antenna.jpeg|400px|thumb|right|SparkFun Venus GPS with SMA Connector and Antenna]]
 
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
 
  
'''HMC5883L'''<br>
+
=====Reading via Bluetooth=====
 +
*One of the major challenges we faced while developing android application was designing UI activity with minimum processing on UI. Mainly because Android application tend to crash if huge chunks of data is being processed on UI. One such case was computation of checkpoints and sending via Bluetooth to Communication bridge controller.
 +
**Resolution: As part of the solution we established a new thread in the background which computed checkpoints and forwarded the results to Bluetooth module thereby reducing the processing on UI activity. 
 +
*Our application design initially included constant updating of current location of the car on Google Map as well as sensor data as part of monitoring the car in real time. However we faced several issues keeping the UI functional with unfiltered data. Moreover the usage of data without filtering led to collection of valid as well as invalid data (garbage characters) being used for display.
 +
**Resolution: This forced us to redesign the app to minimize the app crashes resulting in removal of these features. A better resolution would have been filtering the incoming data and reducing the rate of updating data on UI.
  
==== Software Design ====
+
=====Sending via Bluetooth=====
 +
*While sending checkpoints from Android application we found data to be missing on communication controller if it exceeded a size of more than few bytes.
 +
**Resolution: A delay was inserted after sending each byte so as to ensure 100% reception of data to Communication controller. A better solution would be increasing buffer size for Bluetooth module or adjusting data transfer rate.
  
=== Android Communication Bridge Controller ===
+
=====Android App Navigation=====
==== Hardware Design ====
+
*While designing the app for the project, it was observed that bluetooth connectivity was being lost when switching in between two or more activities designed on the app that help us navigate between different screens on the phone.
==== Software Design ====
+
**Resolution:Leading to above challenge the design of app was proposed to convert into fragments but again when conversion of activities to fragments was started, it was observed that Map activity which is a fragment activity can not be converted into fragments because for both activities and fragment activity the syntax of functions used were different from that of fragments so the idea of converting into fragments was changed and the app was redesigned to be implemented only by using activities.
  
 +
==='''Common Technical Challenges'''===
  
=== Android Application ===
+
==== Logging Info to Memory Card====
==== Software Design ====
 
  
== Testing ==
+
It has been observed that if log info size is large then we cannot copy '''log.csv''' file from flash to memory card via terminal command. Command terminates with Error:2. On board flash has limited space which was causing this error to come. To solve this issue we changed '''file_logger.h''' file to log all info directly into memory card which we can directly remove and get all data directly on PC.
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.
 
  
=== Accuracy of GPS Module ===
+
==== CAN Bus Hardware====
[[File:CMPE243_F15_Minion_GPS_Module_Coordinates_on_Google_Maps.jpeg|200px|thumb|right|GPS Module Coordinates on Google Maps]]<br>
 
Accuracy of GPS module was tested by recording/logging coordinates received by module using LOG_INFO() function and plotting them on Google maps [https://www.google.com/maps/d/u/0/embed?mid=zIDeCYKjmwEU.k1EGAZhJH7ko GPS Module Coordinates on Google Maps]. GPS module was very much accurate we did not needed to calibrate it. It is observed that more number of satellite locks with module, greater the accuracy of coordinate readings.
 
<br><br><br><br><br><br><br><br><br>
 
  
==Technical Challenges==
+
Robust hardware setup of CAN bus is very much important. We faced this issue of CAN messages not being sent to other controllers. We checked voltages at every point of CAN bus and we were getting readings as expected. Later on we found that our 5v supply pins are connected to bus they were loose. After soldering supply pins properly, our CAN bus never failed till end of project.
  
=== Configuring GPS Module ===
+
==== CAN Processing loop====
We faced difficulty in configuring GPS module to sending only $GGA messages, 10Hz Position update rate and updating baud rate to 38400. Initially we were trying to configure GPS module via writing program for SJ One board and we were unable to do it. Later on we completed configuring by connecting GPS module directly to serial port and using [http://cdn.sparkfun.com/datasheets/Sensors/GPS/Venus/638/viewer/GPS%20Viewer%20-%20Customer%20Release_110613.zip GPS Viewer] software. Through it we can directly configure GPS module without worrying about binary messages and checksum calculation.
+
Can reception should be put in a while loop so that in one single run of the while loop all received message will be emptied.Initially, we processed the received CAN messages in an if loop. But, the effect of this on our CAN processing was that whenever we used to receive CAN messages at a particular moment, only the first CAN message was considered in processing and the other CAN messages in the queue were ignored. But, when using a while loop, all the CAN messages in the queue are processed and considered.
  
 
== Conclusion ==
 
== Conclusion ==
Conclude your project hereYou can recap your testing and problemsYou should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?
+
In a short span of 3 months, we had an enriching experience in working for the project. We were able to implement the embedded concepts that we had learnt from our course work. Having hands on both software development and hardware interfacing is a very rare opportunity that we acquired. All essential phases of software development cycle such as design, implementation, unit testing and functional testing were mandatory steps in our project and that absolutely prepared us for the futureBesides that, some of the tools that we worked with like Gitlab for version control and Eclipse IDE as build environment are really useful as they are on par with the Industry preferences in the current scenario. Finally it was one wholesome experience and we hope we were able to share some of our learnings in this report.
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
*[https://youtu.be/dMjvUg-6t_0 Minion-Obstacle Avoidance]
 +
*[https://youtu.be/AUpi6EVDqDM Minion-Self Navigation]
 +
*[https://youtu.be/V0rd_I-71jU Minion-All Controllers description]
  
 
=== Project Source Code ===
 
=== Project Source Code ===
*[https://gitlab.com/gauraochaudhari/RCCarFall2015Group2 Git Repository]<br>
+
* [https://gitlab.com/gauraochaudhari/RCCarFall2015Group2 Gitlab]
  
 
== References ==
 
== References ==
 
=== Acknowledgement ===
 
=== Acknowledgement ===
Any acknowledgement that you may wish to provide can be included here.
+
This project has been an amazing learning experience.
 +
We are grateful to '''Prof. Preetpal Kang''' for provision of expertise and technical support in the implementation. Without his superior knowledge and experience, project would have lagged in quality of outcomes. We would also like to express special gratitude and thanks to '''ISA team''' for the valuable inputs and timely feedback during the project development life cycle. Last but not least its the diligence and dedication of team '''Minion''' which led us to success.
  
 
=== References Used ===
 
=== References Used ===
Line 889: Line 1,856:
 
*[http://cdn.sparkfun.com/datasheets/Sensors/GPS/Venus/638/doc/AN0008_v1.4.11-datalogging.pdf GPS Logging Application Note]<br>
 
*[http://cdn.sparkfun.com/datasheets/Sensors/GPS/Venus/638/doc/AN0008_v1.4.11-datalogging.pdf GPS Logging Application Note]<br>
 
*[http://www.movable-type.co.uk/scripts/latlong.html Haversine Calculations]<br>
 
*[http://www.movable-type.co.uk/scripts/latlong.html Haversine Calculations]<br>
 
+
*[http://ww1.microchip.com/downloads/en/DeviceDoc/21667f.pdf CAN Transceivers-MCP2551]<br>
=== Appendix ===
+
*[http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf HMC5883l datasheet]<br>
You can list the references you used.
+
*[http://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf MaxSonar datasheet]<br>
 +
*[http://www.micropik.com/PDF/HCSR04.pdf HCSR04 Ultrasonic sensor datasheet]<br>
 +
*[http://www.electronica60norte.com/mwfls/pdf/newBluetooth.pdf Bluetooth datasheet]<br>
 +
*[http://developer.android.com/guide/topics/connectivity/bluetooth.html Bluetooth Android application development reference]<br>
 +
*[https://developers.google.com/maps/documentation/android-api/ Google maps API development reference]<br>
 +
*[http://developer.android.com/reference/android/app/Activity.html Activity development reference]<br>

Latest revision as of 22:53, 22 March 2016

Contents

Minion

  • CMPE 243 F15 Minion Car 1.jpg
  • CMPE 243 F15 Minion Car 2jpg.jpeg
  • CMPE 243 F15 Minion Car 3.jpg
  • CMPE 243 F15 Minion Car 4.jpg

Abstract

This report is a description of how we built a prototype of a self navigating car by deploying the learnings from our graduate course CMPE- 243 Embedded System Applications. The prime motive was to navigate the car, autonomously, from a source point to destination point incorporating the following key features

  • Driving and steering with the help of DC and Servo motors
  • Feedback based speed control
  • Obstacle detection and thereby collision avoidance
  • Navigation on a user specified path
  • Diagnosis of pertinent values through a display feature

The Micro-controllers- ARM Cortex3 LPC1758, FreeRTOS(operating system) and a highly reliable communication bus namely CAN constitute the basic building blocks of the car. User interaction is achieved with the help of a dynamic Android application that communicates with the controller through bluetooth. GPS and compass together aid in navigating the car.

System Block Diagram

Objective

The main objective of this project is to design and develop a self driving car capable of navigating itself from its source point to a given destination provided by an Android application. The car should follow the given path with the help of GPS and compass in the Geo controller.The car should avoid obstacles in its path with the help of ultrasonic sensors.The Master controller should make decisions to drive the motor as it receives data from Sensor controller and Geo controller in real time.The Android application should communicate with the car via a wireless medium and display sensor data in real time.The IO module should display geo controller data and sensor data on a LCD.

Team Members & Responsibilities

Sensor Controller:-

Motor & I/0 Controller:-

Communication Bridge & Android Controller:-

Geographical Controller:-

Master Controller:-

Treasurer:-

Hardware:-

Project Schedule

Sr. No Start Date End Date Task Status Actual Completion Date
1 9/22/2015 9/28/2015 RC Car and important component buying Completed 9/28/2015
2 9/29/2015 10/6/2015 1) Algorithm and architecture
2) Setup of car and decision on CAN Id's
Completed 10/6/2015
3 10/7/2015 10/13/2015 1) Coding and final set-up of car
2) Successful communication of CAN bus.
3) Car in running position.
Completed 10/13/2015
4 10/14/2015 10/20/2015 Controlling car via Motor Controller Completed 10/20/2015
5 10/21/2015 10/27/2015 1) LCD Display working and finalizing the data to be displayed on LCD module.
2) Sensor data gathering
Completed 10/27/2015
6 10/28/2015 11/30/2015 Integration of all the modules into one Completed 12/05/2015
7 11/04/2015 11/30/2015 Testing depending upon integrated module Completed 12/05/2015
8 11/18/2015 11/30/2015 Testing of Car and testing the self driving capability Completed 12/05/2015
9 11/25/2015 12/1/2015 Testing of Car Completed 12/15/2015

Parts List & Cost

Sr. No Part Name Source of Purchase Part Number Quantity Cost($)
1 RC Car Sheldons Hobbies 360541 Stampede RTR 1 239.99
2 Battery Sheldons Hobbies VEN1548 - 5000NiMh 7.2 V 1 44.99
3 Traxx AC Adaptor Sheldons Hobbies TRAXXAS 2976 AC Adaptor to 12V 1 24.99
4 Compass Amazon.com HMC5883L Digital Compass Module - Blue 2 9.2
5 GPS Module Sparkfun.com SparkFun Venus GPS with SMA Connector GPS 11058 1 44.08
6 GPS Antenna Sparkfun.com Antenna GPS Embedded SMA 1 19.49
7 LCD module mouser.com NHD-0420D3Z-NSW-BBW-V3-ND 1 29.68
8 Bluetooth Module Amazon.com Sunkee HC-05 1 8.88
9 Ultrasonic sensors Amazon.com HC-SR04 10 17.38
10 Sonar Sensor Provided by Preet Maxbotix MB1010 1 Free
11 SJ One Board Provided by Preet LPC1758 Development Board 5 400.00
12 CAN Tranceivers Microchip.com MCP2551 - Free Samples 5 Free
13 PCB Amazon.com PCB 2 10.6
14 General Components Excess solution,aliexpress.com LED,Connectors,Screws,Nuts,Standoffs,Connecting Wires, etc. 1 31.99
15 Speed Sensor
Magnet Holder
Wire retainer
Sheldons Hobbies Traxxas 6520
Traxxas 6538
Traxxas 6537
1
1
1
20
Total = 501.27

Car Framework and Components

The RC car, Traxxas Stampede, in its raw form consists of a Titan 12T 550 Brushed DC motor, a Servo motor, an XL-5 ESC (Electronic Speed Control) unit, battery and a pre-programmed wireless receiver and controller. The Battery used in the RC car is an 8.4 V, 3000 NiMH from Traxxas. The wireless receiver gets commands from the remote control and drives the motors accordingly, but the DC motor can be controlled only through ESC.


                                       CmpE243 F15 T2 Car.jpg

The ESC (Electronic Speed Control) unit is an electronic module, which receives PWM signals from the controller and varies speed and direction of the DC motor and also acts as dynamic brakes. ESCs are often used in RC models. The ESC has the capability to provide dynamic braking depending on the mode in which it is being operated.

CAN Design

CAN Communication Table

Sr. No Message ID Message function Message Data From To
High
1 0x220 Motor Control
(Direction Control- Straight, Left or Right
Level of Direction-Level 0, Level1, Level 2
Motion Control- Stop, Forward or Reverse
Speed Control - Stop, Level1, Level2 or Level3)
Byte[0] -> Direction Control
Byte[1] -> Level of Direction
Byte[2] -> Motion Control
Byte[3] -> Speed Control
Master Motor
2 0x010 Kill Message
(User request to stop the car under emergency)
Control Frame. No data bytes. Android Master
3 0x020 Kill Message
(Master request to stop all controllers and reboot
under emergency)
Control Frame. No data bytes. Master All
4 0x030 Stop
(User request to stop the car)
Control Frame. No data bytes. Android Master
5 0x040 Stop
(Master stops the motor)
Control Frame. No data bytes. Master Motor
6 0x210 Sensor Data
(Distance in cms)
Byte[0] -> Forward Distance
Byte[1] -> Left Distance
Byte[2] -> Right Distance
Byte[3] -> Back Distance
Sensor Master/Motor-IO
7 0x230 Total Distance to Travel Byte[0-1] Android Geo
8 0x240 Send Checkpoints Byte[0-3] -> Latitude
Byte[4-7] -> Longitude
Android Geo
9 0x250 Distance
(Distance in foot)
Byte[0-1] -> Final Distance remaining
Byte[2-3] -> Checkpoint distance
Byte[4] -> Is_Last_Checkpoint
Geo Master
10 0x260 Turn Angle and Direction Byte[0] -> Turn Angle
Byte[1] -> Direction
(1-Left,2-Right)
Geo Master
11 0x270 Run and Pause Command Control Frame. No data bytes Android Master
12 0x280 Heartbeat Message Control Frame. No data bytes Motor Master
13 0x281 Heartbeat Message Control Frame. No data bytes Geo Master
14 0x282 Heartbeat Message Control Frame. No data bytes Android Master
15 0x283 Heartbeat Message Control Frame. No data bytes Sensor Master
Medium
16 0x410 Destination reached.
(Stops the car when destination is reached)
Control Frame. No data bytes Master All
17 0x420 Battery Status Byte[0-1] Sensor Master/IO
Low
18 0x610 Boot Request Control Frame. No data bytes Master All
19 0x620 Boot Reply
(Date and time will be sent to Master)
Byte[0-4] Motor-IO Master
20 0x621 Boot Reply
(Date and time will be sent to Master)
Byte[0-4] Sensor Master
21 0x622 Boot Reply
(Date and time will be sent to Master)
Byte[0-4] Geo Master
22 0x623 Boot Reply
(Date and time will be sent to Master)
Byte[0-4] Android Master
23 0x630 Boot Status
(Enable the map and run button in Android)
Control Frame. No data bytes Master Motor-IO/Android
24 0x640 System Start Control Frame. No data bytes Android All
25 0x650 Source Co-ordinates Byte[0-3] -> Source Latitude
Byte[4-7] -> Source Longitude
Geo Android

CAN Message Flow

CAN Message Flow

DBC Implementation

Background

Generally, data received from the CAN message is handled using structures. If there are 'n' CAN messages, 'n' structures will be used to handle them. Data has to be encoded at one end for CAN transmission and decoded at the other end, after CAN reception. If there are innumerable CAN messages and their respective structures, lot of effort will be spent in writing code for encoding and decoding. A better approach is to use DBC. It has a specific format and generates automatic code consisting of decoding and encoding logic and structures for CAN messages.

DBC File

The following DBC file gives the proper description of CAN messages used in our car.

   VERSION ""

NS_ : NS_DESC_ CM_ BA_DEF_ BA_ VAL_ CAT_DEF_ CAT_ FILTER BA_DEF_DEF_ EV_DATA_ ENVVAR_DATA_ SGTYPE_ SGTYPE_VAL_ BA_DEF_SGTYPE_ BA_SGTYPE_ SIG_TYPE_REF_ VAL_TABLE_ SIG_GROUP_ SIG_VALTYPE_ SIGTYPE_VALTYPE_ BO_TX_BU_ BA_DEF_REL_ BA_REL_ BA_DEF_DEF_REL_ BU_SG_REL_ BU_EV_REL_ BU_BO_REL_ SG_MUL_VAL_

BS_: BU_: NOONE SENSOR MASTER MOTORIO ANDROID GEO
BO_ 220 MOTORIO_CMD: 4 MASTER SG_ MOTORIO_CMD_LeftRightdirection : 0|8@1+ (1,0) [0|2] "" MOTORIO SG_ MOTORIO_CMD_LevelOfDirection : 8|8@1+ (1,0) [0|5] "" MOTORIO SG_ MOTORIO_CMD_FrontBackDirection : 16|8@1+ (1,0) [0|2] "" MOTORIO SG_ MOTORIO_CMD_LevelOfSpeed : 24|8@1+ (1,0) [0|5] "" MOTORIO
BO_ 010 KILL_REQUEST: 0 ANDROID SG_ KILL_REQUEST : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 020 KILL_MESSAGE: 0 MASTER SG_ KILL_REQUEST : 0|0@1+ (1,0) [0|0] "" MOTORIO,SENSOR,GEO,ANDROID
BO_ 030 STOP_REQUEST: 0 ANDROID SG_ STOP_REQUEST : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 040 STOP_COMMAND: 0 MASTER SG_ ANDROID_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MOTOR
BO_ 210 SONARS: 4 SENSOR SG_ SENSOR_SONARS_FrontDistance : 0|8@1+ (1,0) [0|0] "" MASTER,MOTORIO SG_ SENSOR_SONARS_LeftDistance : 8|8@1+ (1,0) [0|0] "" MASTER,MOTORIO SG_ SENSOR_SONARS_RightDistance : 16|8@1+ (1,0) [0|0] "" MASTER,MOTORIO SG_ SENSOR_SONARS_RearDistance : 24|12@1+ (1,0) [0|0] "" MASTER,MOTORIO
BO_ 230 TOTAL_DISTANCE_TO_TRAVEL: 4 ANDROID SG_ TOTAL_DISTANCE_TO_TRAVEL: 0|16@1+ (1,0) [0|0] "" GEO
BO_ 240 SEND_CHECKPOINTS: 8 ANDROID SG_ SEND_CHECKPOINTS_Latitude: 0|32@1+ (1,0) [0|0] "" GEO SG_ SEND_CHECKPOINTS_Longitude: 32|64@1+ (1,0) [0|0] "" GEO
BO_ 250 DISTANCE: 4 GEO SG_ DISTANCE_FinalDistance : 0|16@1+ (1,0) [0|0] "" MASTER SG_ DISTANCE_CheckpointDistance : 16|16@1+ (1,0) [0|0] "" MASTER
BO_ 260 TURN_ANGLE_DIRECTION: 2 GEO SG_ TURN_ANGLE_DIRECTION_TurnAngle : 0|8@1+ (1,0) [0|0] "" MASTER SG_ TURN_ANGLE_DIRECTION_TurnDirection : 8|8@1+ (1,0) [0|0] "" MASTER
BO_ 270 RUN_PAUSE: 0 ANDROID SG_ RUN_PAUSE : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 280 HEARTBEAT_: 0 MOTORIO SG_ MOTORIO_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 281 HEARTBEAT: 0 GEO SG_ GEO_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 282 HEARTBEAT: 0 ANDROID SG_ ANDROID_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 283 HEARTBEAT: 0 SENSOR SG_ SENSOR_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 410 DESTINATION_REACHED: 0 MASTER SG_ SENSOR_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 420 BATTERY_STATUS: 1 SENSOR SG_ BATTERY_STATUS_VALUE : 0|0@1+ (1,0) [0|0] "" MASTER,MOTORIO
BO_ 610 BOOT_REQUEST: 0 MASTER SG_ BATTERY_STATUS_VALUE : 0|0@1+ (1,0) [0|0] "" MOTORIO,SENSOR,ANDROID,GEO
BO_ 620 BOOT_REPLY_MOTORIO: 0 MOTORIO SG_ BOOT_REPLY_MOTORIO : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 621 BOOT_REPLY_SENSOR: 0 SENSOR SG_ BOOT_REPLY_SENSOR : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 622 BOOT_REPLY_GEO: 0 GEO SG_ BOOT_REPLY_GEO : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 623 BOOT_REPLY_ANDROID: 0 ANDROID SG_ BOOT_REPLY_ANDROID : 0|0@1+ (1,0) [0|0] "" MASTER
BO_ 630 BOOT_STATUS: 0 MASTER SG_ BOOT_STATUS : 0|0@1+ (1,0) [0|0] "" MOTORIO,ANDROID
BO_ 650 SOURCE_COORDINATE: 8 GEO SG_ SOURCE_COORDINATE_LATITUDE : 0|32@1+ (1,0) [0|0] "" ANDROID SG_ SOURCE_COORDINATE_LONGITUDE : 32|32@1+ (1,0) [0|0] "" ANDROID
CM_ BU_ NOONE "No node, used to indicate if it's a debug message going to no one."; CM_ BU_ MASTER "The Master controller driving the car."; CM_ BU_ SENSOR "The Sensor controller of the car."; CM_ BU_ MOTORIO "The Motor-IO controller of the car."; CM_ BU_ ANDROID "The Android controller of the car."; CM_ BU_ GEO "The Geo controller of the car."; CM_ BO_ 100 "Sync message used to synchronize the controllers";
BA_DEF_ "BusType" STRING ; BA_DEF_ SG_ "FieldType" STRING ; BA_DEF_ BO_ "GenMsgCycleTime" INT 0 0;
BA_DEF_DEF_ "BusType" "CAN"; BA_DEF_DEF_ "FieldType" "";
BA_ "GenMsgCycleTime" BO_ 220 10; BA_ "GenMsgCycleTime" BO_ 210 10; BA_ "GenMsgCycleTime" BO_ 250 10; BA_ "GenMsgCycleTime" BO_ 260 10; BA_ "GenMsgCycleTime" BO_ 280 1; BA_ "GenMsgCycleTime" BO_ 281 1; BA_ "GenMsgCycleTime" BO_ 282 1; BA_ "GenMsgCycleTime" BO_ 283 1; BA_ "GenMsgCycleTime" BO_ 420 1;
VAL_ 100 MASTER_HEARTBEAT_cmd 0 "MASTER_HEARTBEAT_cmd_NOOP" 1 "MASTER_HEARTBEAT_cmd_SYNC" 2 "MASTER_HEARTBEAT_cmd_REBOOT";

Detailed Description

1)The above description shows the detailed implementation of the CAN messages used for communication between various controllers. Several types of notations are used in this DBC file. Following is the explanation of these notations which includes range of the CAN data, minimum, maximum values, and number of data bits used in the 64 bit structure. One useful feature of CAN message frame is bitwise access of data. This approach of accessing data using bits instead of bytes avoids wastage of CAN data which could otherwise be utilized properly.

2)Detailed explanation of notations used in CAN dbc file format-

 a. BU_: NOONE SENSOR MASTER MOTORIO ANDROID GEO
  The line which is starting with BU_ gives us the information about all the controllers present in the communication BUS.
b. BO_ 220 MOTORIO_CMD: 4 MASTER i.This is the message command which states the message ID. Here 220 is the message ID used for Motor command from Master to Motor. ii.The name of the message is MOTORIO_CMD which forms a string of the structure to be created in the auto generated code. iii. 4 represents size of data in byte to be transmitted. iv.Here last text is written as MASTER, which says that the message is originating from MASTER.
c. SG_ MOTORIO_CMD_LeftRightdirection : 0|8@1+ (1,0) [0|2] "" MOTORIO i.The line has SG_ in the beginning and is known as the signal. This command tells us about the number of different data
in the CAN message. ii.0|8 -> 0 is the start bit of the data in the CAN message and 8 is the length of the data in the CAN message. iii.[0|2] -> 0 is the minimum value of the data and 2 is the maximum value of the message. iv.The last text MOTORIO defines the number of receivers of the message. There can be more than one receivers.
If there are,then they are separated by a comma. v.Here ‘MOTORIO_CMD_LeftRightdirection’ is the name of the data that is being transmitted in the message.
d. BA_ "GenMsgCycleTime" BO_ 220 10 i.This command describes the general message cycle. ii.Here the message 220 i.e the motor command repeats itself after every 10 Hz i.e 100 ms. iii.Similarly, there are some message which repeats after every 1 Hz.

3)The dbc file was created with these normal basic command and was sent as an input to the python dbc parser which decrypted it to the auto generated code. Following is the python command for the dbc parser:

   >python.exe dbc_parse.py -i Group2.dbc -s MASTER -a -b >generated.h

Design & Implementation of Controllers

Motor and I/O Controller

Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/21/2015 9/25/2015 Order LCD Display Completed 9/25/2015
2 9/28/2015 10/3/2015 Going through the motor concepts and PWM Completed 10/2/2015
3 10/4/2015 10/9/2015 Intreface the DC and SERVO Motors with SJONE board Completed 10/8/2015
4 10/10/2015 10/13/2015 Establishing basic CAN communication with other modules Completed 10/13/2015
5 10/11/2015 10/16/2015 Getting the car to run with the PWM signals from Motor controller Completed 10/15/2015
6 10/17/2015 10/23/2015 Research on Speed cotrol method and sensor for the same interface LCD display with LPC1758 via UART Completed 10/21/2015
7 10/23/2015 11/4/2015 Establishing reliable CAN communication for IO & Motor with others Completed 11/4/2015
8 11/5/2015 11/12/2015 Integrate Speed sensor and get feedback. Start working on start,stop buttons and headlight Completed 11/11/2015
9 11/13/2015 11/30/2015 Testing substantial self driving capability of the car Completed 12/5/2015
10 11/21/2015 11/30/2015 Complete integration, Debugging and Fine tuning Completed 12/5/2015
11 12/1/2015 12/5/2015 Final Validation Completed 12/15/2015

Hardware Design

Motor Module

The motor module comprises of a servo motor for the direction control and a DC motor for speed control. The servo motor helps the car in turning left and right where as the DC motor on the other hand helps the car move forward and backward. The DC motor used in the project is a brushed motor. Conventionally, brushless motors are faster and more efficient than brushed motors. But, the reason for selecting a brushed motor over a brushless motor is that we employ a dedicated battery for the motor such that we do not have any issues with power and efficiency. Moreover, we need not operate the car at high speeds.

The initial task in the motor module is to find the operating ranges of the motor so that we get to know the output signal range and frequency from the SJONE board which would be replacing the pre-programmed controller. The simplest way to find the operating ranges of the motor is to tap and analyze PWM signal that is being supplied to the motor over an oscilloscope. The results as shown in the below pictures indicate that the operating duty cycle of both the motors lie between 10% to 20% and the frequencies at which the motors operate is 100Hz.

                                     CmpE243 F15 T2 PWM DutyCycle.jpg


The hardware interface of the Motors and SJONE board includes the following connections.

Sl. No Connection on the car Pin on SJSU One Board Purpose
1 Input to DC Motor P2.1 PWM input to drive DC motor
2 Input to Servo Motor P2.0 PWM input to drive DC motor
3 Speed sensor P2.4 PWM output from speed sensor


The Motor controller receives the commands from the Master controller which guides it to navigate the car based on the information from the Sensors and GPS. While it does so, it also needs to get feedback from the DC motor and control the motor independently in order to ensure that the car is moving with the speed requested by the Master. This requires increasing or decreasing the actual speed level that is being provided to the Motor in case of movement along uphill, downhill, grass and high friction tracks.

The feedback is achieved through a shaft encoder which works based on Hall-effect. The installation of the speed sensor was pretty easy as we went with the one from Traxass, the same manufacturer as our RC car. It involves removing the DC motor casing, placing the sensor over the spur gear and the magnet holder. The sensor would sense the rotation of the axle. It produces a pulse when the magnet comes into the line of the sensor, which is then detected by the Motor controller.

IO Module
The IO module Consists of a 4 line * 20 characters serial LCD. Data from GPS and sensor module is displayed continuously by refreshing it every second. SJ one board communicates with LCD through UART.
LCD

GPS data :-

  • Distance travelled
  • Checkpoint Distance

Sensor data:-

  • Left sensor reading
  • Right sensor reading
  • Front sensor reading
  • Rear sensor reading

Additionally, IO module controls lighting up headlights/taillights based on the direction of the car movement.

MotorIO Hardware Interface

LCD unit requires 5V power supply for its working. The VCC and Ground pins are connected to common power supply lines that is used to power up all the boards. The Rx pin of LCD is connected to TXD2 (p2.8) pin on SJ one board. Two of the GPIO pins p2.6 and p2.7 controls the headlights LED’S and taillights LED’S respectively.

Sl. No Pin on IO Module Pin on SJSU One Board Purpose
1 Vcc Common power supply 5V for LCD
2 Ground Common Ground Ground for LCD
3 Rx P2.8(TXD2) Receive data from SJone board through UART
4 Headlight LED’s(2) P2.6 Turn on headlights when car is moving in the forward direction
5 Taillight LED’s (2) P2.7 Turn on tail-lights when car is moving in the reverse direction
Usage of OnBoard LED's:
LED No. Usage
1 Speed feedback control active
2 Master commands to Motor
3 Heart beat
4 Can reception failure

Software Design

Module Flow
                                       Software Flow Diagram  

The controller on boot up initializes the CAN communication, UART and also the PWM for initialization pulse required for the motor to run.The inter-controller communication is done over CAN bus. It is configured to receive and transmit messages at 100K baud-rate. The type of CAN ID is Standard. Later these are accomplished at run time using the periodic scheduler task.


LCD communicates with SJ one board through UART. Communication will happen between LCD and SJone board only when the baud rates are synchronized. The UART port is configured to operate at 19200 bps. “FO” character is sent to initialize the UART port after a delay of 100 ms, upon powering up the board. The display unit responds after 100 ms. Now the LCD module is configured and can receive further messages to display on it. Data from modules such as GPS and sensor are received continuously through CAN. It is decoded, converted into proper format and displayed on the LCD periodically. The corresponding flow is shown below.

                        Software Flow Diagram

The Motor controller, after sending the initialization pulse to the DC motor, waits for a start command from the Master over CAN and then controls the motors in order to reach the destination with required levels of speed and direction. The control algorithm for the Motor operation is as shown on the right.

Software Implementation

“Can receive” function is called in periodic scheduler 100 Hz task. This function lets the Motor/IO module receive CAN messages from other modules connected to it. CAN set up filter function has been used to accept only essential messages required by this module. Based on the CAN message identifier, corresponding action is performed. These are the CAN messages required by the motor/IO module.

CAN MESSAGE ID:-

  • 0x020 – Kill message
  • 0x210 – Sensor data
  • 0x220 - Motor control message
  • 0x250 – GPS data
  • 0x610 – Boot request

Data from sensor and GPS modules are stored in global message buffers. Sensor data is 8 bit whereas GPS data ranges between 16-32 bits. These integer values are converted into character type and then sent to LCD through UART. LCD display function is called in 1Hz periodic scheduler task. Thus Sensor and GPS data get displayed on the LCD every sec.

                IO Implementation Diagram

The 3D design used as a support for mounting the LCD is shown below:

3D design for LCD mounting
Motor Control

On receiving the CAN message(0x220) from the Master, the data is extracted and and used for specific functions as shown below.

          *Byte0 --> Servo Direction
          *Byte1 --> Servo Level
          *Byte2 --> DC Direction
          *Byte3 --> DC Level

Based on this data, the first two bytes decide the direction(left/right) and the level(angle), respectively in which the car should turn using the Servo motor. Similaly, the next two bytes decide the direction(forward/backward) and the level(speed) in which the car has to move.

To implement all the motor related functions, we have employed a dedicated task. Initially, the pre-scaled PWM values are fed to the motors based on the direction and level from the Master. We have a bit robust algorithm to obtain these PWM values which has offsets and level multipliers. The advantage of this is we can change the code to function for multiple levels with minimum effort.

A piece of code for Motor Control:

switch(DC_control)
       {
           case 0:
           	if(DC_level==DC_level_last)
           	{
                   	speed_offset = 0;
                   	speed_factor =0;
                   	LD.setNumber(10);
           	}
           	else
           	{
           		pwm2.set(15);
           		vTaskDelay(25);
           		pwm2.set(13);
                   	vTaskDelay(100);
                   	speed_offset = 0;
                   	LD.setNumber(13);
                   	speed_factor =0;
           	}
           	p2_pin6.setLow();
           	p2_pin7.setLow();
          		speed_offset = 0;
           	speed_factor =0;
           	count_rev = 1;
           	break;
           case 1:
           	speed_offset = 0.4;
           	speed_factor = 0.2;
           	count_rev = 1;
           	p2_pin6.setHigh();
           	p2_pin7.setLow();
           	break;
           case 2:
           	speed_offset = -0.6;
           	speed_factor = -0.2;
           	p2_pin6.setLow();
           	p2_pin7.setHigh();
           	break;
           default:
           	speed_offset = 0;
           	speed_factor =0;
           	count_rev = 1;
           	p2_pin6.setLow();
           	p2_pin7.setLow();
           	break;
       }
       PWM_value_DC = 15 + (speed_factor)*(DC_level) + speed_offset;
Motor Feedback

After feeding the motors with the required levels, we have to check if the car is actually moving at that speed. This is ensured through feedback and control based on that. The feedback is obtained through the speed sensor collaborated with the DC motor, which triggers a pulse on every rotation and this is recorded by a rising edge based interrupt. The interrupt callback function increments the number of pulses. A separate logic is used to calculate and then compare the actual and required(from Master) speed levels. The corrective measures are enforced to achieve the desired speed.

The transmit messages, except Heart beat message(sent every one second), are transmitted once every 100ms. The Motor/IO controller, on receiving a boot request from Master controller, transmits a boot reply message in order to let the Master know that it has booted successfully. The heart beat message is transmitted continuously to indicate that the controller is active and this will be acknowledged by the Master.

Testing

Motor Control

The motor operation is initially tested for its accuracy with different direction and levels such as forward, reverse, left, right. After ensuring everything is as expected, we went for refining it. Later, with the speed sensor installed, the functioning of it and the control based on it has to be checked properly. For this, we have tested the car by running it over ramp-up, ramp-down, grassy and rough paths. Then we have refined it. Finally, we made sure that the car gets back to the required speed when it deviates from the same.

Technical Challenges and Resolution

Motor Feedback

The major difficulty with motor speed feedback was getting enough number of pulses from the speed sensor in order to calculate the current speed. When we run at very low speeds, we get pulses as low as 2 0r 3 at even 10Hz. If the same value is multiplied by required factor(say 600 in 10Hz) to get the rpm, then we have a couple of issues.

i) Firstly, we cannot get intermediate speed values as we get only in multiples of the the factor which will be very high.

ii) Secondly, we may have some issues, at very low speeds, like we don't get a pulse every 100ms or 10ms, which means the motor is at rest but which actually is not.

Solution: Never try to implement in terms of "rpm". Instead go for "rps" or "m/s". This will eliminate the first issue. And to solve the second problem, we may think of aggregating the pulse count for a greater time interval. But this will lead to a delayed feedback which in turn leads to an undesired behavior. Hence we have a trade-off between the two.

Motor Control

1) The first hurdle one would face with the Motor control through an ESC is starting the motor. This requires an initialization pulse, which would have been sent by the transmitter earlier. We have to realize the required pattern or PWM value for the achieving this.

2) The second difficulty with the motor comes into picture when with backward movement of the car. Due to the presence of the ESC and the residual momentum in forward direction, we cannot alter the direction of the motor suddenly. We have to manually discover the pattern required for this forward to reverse transition which takes a bit of time unless one is aware of it.

Master Controller

As the name suggests, it is main controller on the car which interacts with all other controllers over the CAN Bus to achieve real-time functionality. Basic function of the Master Controller is to receive data from Android, Geo and Sensor Modules and develop the algorithm to drive the car autonomously based on the received data through the Motor Controller.

Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 09/30/2015 10/6/2015 a) Design of Algorithm and Architecture for Master Module.
b) Setup of CAN communication between two controllers.
Completed 10/6/2015
2 10/7/2015 10/13/2015 a) Development of CAN message system for Android, Sensor and GPS, I/O reception.
b) Decide about periodic function frequencies that’ll be handling different modules.
Completed 10/13/2015
3 10/14/2015 10/20/2015 a) Development of driving,stopping and obstruction avoidance algorithm for motor.
b) Implementation of LED Display to display number of messages on CAN bus.
c) Implementation of turning algorithm as per the data received from the Geo Controller.
Completed 10/20/2015
4 10/21/2015 10/27/2015 a) Designing of Kill switch with the help of Motor, I/O and Android.
b) Design the system to restore the last known configuration.
c) Implementation to reset modules if the CAN bus reaches BUS off state.
Completed 10/27/2015
5 10/28/2015 11/3/2015 a) Design of Head Light functionality with the help of Sensor module.
b) Implementation of log files saving to SD card.
Completed 11/1/2015
6 11/4/2015 11/10/2015 a) Integration of all the modules with Master module and check it after combining everything.
b) Probable implementation of additional features.
Completed 12/05/2014
7 11/11/2015 11/17/2015 a) Refine the work done earlier.Change areas that need a change.
b) Test the Master module while all the modules are integrated together and list down modifications and additions to be done.
Completed 12/05/2014
8 11/18/2015 11/24/2015 Testing of system and specially making sure that last week’s shortcomings are taken care of. Completed 12/05/2014
9 11/25/2015 12/1/2015 a) Final testing of individual modules.
b) Testing the self-driving capability of the car.
Completed 12/05/2014
10 12/2/2015 12/8/2015 Final working on the shortcomings in the previous week. Completed 12/8/2015
11 12/9/2015 12/15/2015 Final Testing of Car. Completed 12/15/2015

Hardware Design

  • RC car was the basic infrastructure that was required to implement the project.
  • CAN Bus with five SJone controller boards was integrated on General purpose Printed Circuit Board (PCB).
  • Sufficient power-supply ports and external pins were provided to each controllers.
  • Flat Ribbon Cables were used to reduce circuit complexity arising from external connecting wires.
Usage of OnBoard LED's:
LED No. Usage
1 Forward signal to Motor
2 Left turn signal to Motor
3 Right turn signal to Motor
4 Reverse signal to Motor

Software Design

This section describes about the general algorithm used for master programming. There are a lot of cases in Master Controller which are to be handled in order to run the car properly. This includes heartbeats, boot messages, running of motor, reading of the sensor values properly and then taking proper decision. The other activities that are done in master are listed below with some fair explanations.

  • Master Controller uses FreeRTOS environment to achieve its functionality.
  • It uses Periodic Scheduler Task provided by Preet at its core to communicate with all other controllers.
  • The functions of the Periodic Scheduler Task were used in a customized manner to transmit/receive the messages at specific intervals of 1Hz,10Hz,100Hz and 1000Hz.
  • File logger function was used to log the real-time data onto SD card which was used for debugging purpose.
  • Can Message structure of 11-bit id was implemented to send and receive CAN messages over the CAN Bus.
  • CAN acceptance filter was set-up to receive messages specific to Master Controller from the CAN Bus, since it is the broadcast Bus.

Software Implementation

  • Master Controller starts with initialization of CAN Bus and setting up reception filter from the main() function.
  • The Periodic Scheduler Task then takes over to implement the actual functionality of the Master Controller.
  • CAN_is_busoff() was used at an interval of 10Hz through periodic scheduler task to check if the controller was always connected to CAN bus.
  • Following are the algorithms that were implemented in the Master controller to drive the motor.
Algorithm
Geo Processing Algorithm

Following is the algorithm that was implemented to process the data sent by Geo controller, which eventually navigates the car towards its destination. At first, it checks if there is any obstruction in the car’s path, if there is no obstruction it follows the further steps, And if there is an obstruction, it transfers control to the Obstruction Avoidance Algorithm.

Step 1: Check if there is no obstruction. If there is no obstruction proceed to step2, otherwise proceed to step7.
Step 2: Check if distance towards next check-point is greater than 30. If distance towards next check-point is greater than 30, proceed to step3, otherwise go to Step 6.
Step 3: Check if turning angle is greater than 10. If turning angle is greater than 10, proceed to step4, otherwise go straight go to step7.
Step 4: Check if turning angle is greater than or equal to 90. If turning angle is greater than or equal to 90, turn left or right according to the turning bit with level of direction 3 go to step7,otherwise proceed to step5.
Step 5: Check if turning angle is greater than or equal to 45 and less than 90. If turning angle is greater than or equal to 45 and less than 90, turn left or right according to the turning bit with level of direction 2, otherwise turn left or right according to the turning bit with level of direction 1 go to step7.
Step 6: Check if distance towards next check-point is less than 10.If the distance is less than 10, stop the car, otherwise move slowly with level of speed 1.
Step 7: End.

Following is the flow-chart of the above algorithm:

                                     Flow-Chart
Obstacle Avoidance Algorithm

The most important part of the Master controller is to control the motors and handling other decision making factors such as when to move and when to not. The Motor/IO controller is almost entirely dependent on the Master controller to drive the motor. The Master controller is responsible for making decisions on when and where to move the car in case of any obstacle and this is where the Sensor controller comes into the bigger picture.

1)For exact precision, we are considering most accurate algorithm for Sensor Processing. We have defined three levels of obstacle zones. The exact explanation of this terminology can be understood from the gif image shown below.

Obstacle Avoidance Flow


2) There are three zones in which the major sensor processing for obstacle-avoidance is done. In these zones, distances were designated as the safest distance for the car in which it can move ahead though at low speeds. In addition, we also had taken the danger zone into the consideration.Within danger zone distance, the car won’t be able to move ahead and would only take reverse depending on data from rear sensor. Following is the classification of the various zones:

Front:
FDanger : This distance would be the distance within 40 cms of the car. Within this distance, the car wouldn’t be able to move ahead and would only take reverse turn only if there is no blockage from the rear side.
F1 :
F1 is the zone between 40 cms and 80 cms. Within this zone, the car speed would be very slow. Since this distance is very short, we have assured that the speed of car is very slow with the motor feedback and then it will take some necessary decisions.
The turn angles in this case would be in the higher range since there would be a necessity to take sharp turns to avoid obstacles.
F2 :
The range of 80 to 130 cms defines the zone F2. The car would run at more higher speeds in this zone. The turn angles in this case would be in a lesser range as compared to F2 zone.
F3 :
The range of 130 cms to 190 cms defines the zone F3. The car won’t make any turning decisions in this range but would only reduce its speed. We have made sure that within this range of obstacle detection, the speed of the car won’t be so much that could cause problem in obstacle avoidance in the inner zones.

Left & Right:
LDanger and RtDanger :
LDanger and RtDanger is the zones for the left and the right sensor obstacle, the distance values are within 40 cms of the car.
L1 and Rt1 :
For L1 and Rt1, the distance between 40 cms and 70 cms is considered. This distance is somewhat more than the danger distance and the car could only have speed level 1 in this condition and the turning angles are rather sharp.
L2 and Rt2 :
L2 and Rt2 is considered as the zone between the distance 70 cms and 120 cms. In this zone, level of speed is little higher and the turning angle levels are little lesser than previous zone.

L3 and Rt3 :
The range of 120 cms to 150 cms is considered as the zone L3 and Rt3. In this zone, only the speed of the car is reduced.

Rear :
Reverse :
We have only a single zone for the reverse-motion using rear sensor. The reason for this is that there won’t be a significant movement in the reverse direction. So, there is not much use of handling the reverse conditions at a higher priority. Just a single level and every case can be handled properly. The range of the obstacles finding for the reverse sensor is 60 cms.

We have considered all the cases for each of the zones, but during the actual running of the car, there were some cases which were only used 0.5% of the times. Just to improve the response of the algorithm, we have ignored those cases and concentrated on all the other cases. The results were fascinating since the reverse algorithm was responding very sharply. These were all the theoretical explanation about the levels. The, actual algorithm is shown using a flow diagram below. This would clearly showcase how the car would run and in what conditions.

                                   Obstacle Avoidance Flow-Chart

Technical Challenges and Resolution

Sensor algorithm

Just a straightforward algorithm is easy and short to implement. But the sensor are tested properly when there are a lot of corner cases of obstacles where the car can stuck. These corner cases were indeed a challenge that was faced. These cases were developed in step and the entire algorithm was not implemented at once.

CAN Message Handling

Collaborating on the message id’s and the data in those messages. Since master is the powerhouse of the system, there are a multiple number of nodes communicating with Master. Since such a number of nodes are communicating with Master, there are a lot of cases which are to be handled in Master and that was indeed a challenging task.

Integrating Sensor and Geo Algorithms

There were a lot of problems faced while integrating Geo controller and Sensor controller. The first and foremost problem that we faced was while implementing any new feature and synchronising other controllers with the Master controller. For example, the sensors were integrated earlier but when the Geo controller was integrated, the motor did not receive proper data. On debugging, we came to know that the problem was with the algorithm and after we changed it, everything was working on its proper way.

CAN Arbitration

Since Master controller was the one with a lot number of messages, we faced some issues regarding CAN arbitration. Initially, there were a couple of messages which were high priority messages and were blocking the way of some important low priority one time messages. But after some changes in the ID’s the problem was dealt properly.

Sensor Controller

Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/20/2015 10/5/2015 Study available sensors and place order Completed 10/4/2015
2 10/6/2015 10/13/2015 Collaborate with the other sub teams to finish the CAN bus communication Completed 10/13/2015
3 10/13/2015 10/20/2015 Develop simple test code for the sensors Completed 10/18/2015
4 10/21/2015 10/30/2015 Interface all sensors and develop code for reading all sensors. Completed 10/30/2015
5 10/30/2015 11/2/2015 Positioning of sensors and identifying dead band if any Completed 11/2/2015
6 11/06/2015 12/17/2015 Final testing and debugging Completed 11/29/2015

Hardware Design

Sensor controller consists of sonar and ultrasonic sensors that are inter-connected to the SJOne board and CAN bus. The sensors detect if there is any obstacle around the car and report the distance of obstacle. Hardware design consists of four sensors connected to port 2 of LPC1758. The sensor in the front direction is MB1010 sonar sensor while the ones at back,right and left direction are HCSR04 ultrasonic sensors. The sensors are connected to +5V power supply to achieve the highest beam pattern that is available.

Sensor Hardware Interface


Sensor Hardware Interface



MB1010 LV MaxSonar EZ1 Sensor

The LV MaxSonar EZ detects objects from 0 inches to 254 inches and provides sonar range from 6 to 254 inches with 1 inch resolution. Objects from 0 to 6 inches are reported as 6 inches. Sensor operates at 42KHz. The sensor reports output formats in from of pulse width output, analog voltage output, and RS232 serial output. We have selected pulse width output.The sensor will continually measure range and output if RX data is left unconnected or held high. If held low the sensor will stop ranging. We have commanded a range reading by triggering high for 20uS. Below are the timing diagrams for the sensor

Timing Diagram for LV MaxSonar EZ Sensor
MB1010 Sensor





HCSR-04 sensor

HCSR-04 sensor is a ultrasonic ranging module which detects obstacle from 0 to 400 cm. It is a four pin module – Vcc, trig, echo and Gnd. It includes transmitter, receiver and control circuit. The sensor operates at 40 KHz.It Requires 5V 15mA power supply. When a short 10uS pulse is provided to the trigger input, the sensor will transmit out 8 cycle of ultrasonic burst at 40kHz and makes the echo pin high.The Echo pin is lowered to logic low when the ultrasound burst is reflected off a distant object.To obtain the distance, measure the width (Ton) of Echo pin. Time = Width of Echo pulse, in uS (micro second) Distance in centimeters = Time / 58 Distance in inches = Time / 148 Or you can utilize the speed of sound, which is 340m/s

Timing Diagram for HC-SR04 Ultrasonic Sensor
HCSR-04 Sensor











Sensor Pin layout
Pin Name Function
P2_0 RX trigger for front Sensor
P2_1 PWM for front Sensor
P2_2 Trig for back Sensor
P2_3 Echo for back Sensor
P2_4 Trig for left Sensor
P2_5 Echo for left Sensor
P2_6 Trig for right Sensor
P2_7 Echo for right Sensor
3D Printing Design

The 3D design used as a support for mounting the sensors is shown below:

3D Design for Sensor mounting


















Usage of OnBoard LED's:
LED No. Usage
1 Boot Reply Successful
2 Heartbeat
3 Can reception successful
4 Can transmission successful

Software Design

Sensor software flowchart

Software design for Sensor controller includes sensor initialization, sequential triggering of sensors, calculating distance of obstacle from the echo received and transmitting the data on CAN bus. Sensor initialization includes interrupt configuration for echo pins of sensor and configuring the trigger pins as output. A trigger of 20 us is required for MB1010 sensor and 10 us is required for HC SR-04 sensor.

Algorithm
  • Initialize trigger pins as output to provide trigger pulse to sensors
  • Initialize interrupt pins to receive echo or PW from sensors
  • Trigger Front and back sensor
  • Wait for echo or PWM pulse
  • Capture start time frame on rising edge of interrupt and end time frame at falling edge of interrupt of the sensor
  • Trigger Left and Right sensor
  • Wait for echo or PWM pulse
  • Capture start time frame on rising edge of interrupt and end time frame at falling edge of interrupt of the sensor
  • Calculate distance on basis of the time captures in previous steps.
  • Broadcast distance on CAN bus

This is a piece of our Interrupt configurations and function callbacks that calculate the distance of sensor.

Sensor Code Snippet
Module Flow
Sensor Controller workflow


Testing and Technical Challenges

Sensor Triggering
  • Initially while testing sensors the triggering was in continuous mode without waiting for appropriate sensor processing time. This resulted in multiple errors in distance measured and eventually damaged the sensor. The readings were stable if the sesnors were triggered every 50ms for MB 1010 sensor and 30 ms for HC SR 04 sensor. Below are the testing results for triggering sensors at different time intervals
HC SR-04 Calibration
MB1010 Calibration



















Referring to the above results we can conclude that the sensor data is more accurate for MB1010 if the time interval for triggering is 50ms. Similarly for HC SR04 the readings are accurate if time interval between the trigger is 30 ms.

Sensor Operating frequency
  • Now if one waits for sequential triggering for all 4 sensors the wait time will be long, resulting in sensor data at low frequency. Hence to make sensors operate at 10Hz, the sensors are triggered in pairs( Front- Back and Right- Left). This has resulted in operating frequency of 10Hz concurrently avoiding interference between adjacent sensors.
Ground Reflections
  • During testing, we observed that that the reflection from ground surface resulted into incorrect readings. This issue was resolved by tilting the 3D frames backward so that the ground reflections were minimal.
  • When the car was tested for obstacle avoidance in the university corridors, at particular angles the sensor readings were maximum even though there was presence of wall in front of the sensor. This was overcome by slightly moving the positions of the sensors but could not be resolved completely.


Sensor reflections from extremely smooth surface


Geographical Controller

Geographical Controller consists of GPS and Compass module. GPS module tracks current position (Latitude and Longitude) of the car and compass module gives the heading of car with respect to north. With the data provided from these modules, turn angle and distance to destination is calculated. Algorithm for these calculations is explained in software section.

Heading: Heading is the current direction of car, measured clockwise with respect to geographic north and ranges from 0 to 360 degrees. The compass gives the values with respect to magnetic north and the Magnetic declination is added to these values to give the actual heading.

Bearing: Bearing is direction of destination point with respect to north measured clockwise and ranges from 0 to 360 degrees. This value is calculated from destination and current coordinates using Haversine formula described in software section.

Turn Angle : It is a measurement in degrees that the car needs to take to head towards destination. It is calculated by using Heading and Bearing values.

Direction : It is the clockwise or anti clockwise turn of the car to head towards destination.

Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 09/27/2015 10/07/2015 Ordering Parts and understanding each module Completed 10/11/2015
2 10/07/2015 10/13/2015 CAN Communication with other boards and understanding each module Completed 10/13/2015
3 10/07/2015 10/30/2015 Algorithm for distance and heading calculation and coding Completed 10/30/2015
4 10/14/2015 10/20/2015 Interfacing of compass(I2C) and GPS (UART) with SJONE board Completed 10/20/2015
5 10/20/2015 10/30/2015 Coding, Compass Calibration,GPS Calibration Completed 11/10/2015
5 10/25/2015 11/15/2015 Individual unit testing Completed 11/20/2015
6 10/30/2015 11/30/2015 Interfacing with Android, Master and IO controllers Completed 12/05/2015
7 10/30/2015 11/30/2015 Integration Testing,On Car Calibration Completed 12/15/2015

Hardware Design

Schematic
Schematic

SparkFun Venus GPS with SMA Connector

SparkFun Venus GPS uses Skytraq VENUS634FLPx IC. The Venus638FLPx outputs standard NMEA-0183 or SkyTraq Binary sentences at a default rate of 9600 bps which is adjustable to 115200 bps, with update rates up to 20Hz. We configured this module with update rate of 10Hz and 38400 bps UART rate. Module outputs GGA, GSA, GSV, GLL, RMC, VTG, ZDA NMEA standard messages which can be configures to as per our requirements. We configured it to give only GGA messages. GGA message format is shown below.
For configuring GPS modules to UART rate 38400 bps, 10Hz update rate and only GGA message at output, below binary commands are used.

GGA Message Format
Binary Configuration Commands

SparkFun Venus GPS with SMA Connector and Antenna

























HMC5883L

HMC5883l is a triple axis digital compass IC used for heading calculation. It has magneto resistive sensors that forms the basis of the working principle of a compass. Please refer data sheet attached in reference section for specifications of the IC. Note that this IC is not tilt compensated and we need to calibrate for instrument error and for tilt.

HMC5883L
HMC5883L and I2C

HMC5883L IC communicates to SJOne Board through I2C bus.
SJONE board -Master device
HMC5883L - Slave device
I2C rate is controlled by the master and can be upto maximum 400 KHz. We have configured the rate as 100 KHz.

Master Transmitter Mode -Slave Receiver Mode
In this mode, the master writes to the slave registers.
Compass IC has a set of 8 bit registers to be initially configured for parameters such as device output rate, number of samples, device gain and operating mode. By identifying the device write address and register address, the values can be written by the SJONE board to compass registers.

Master Receiver Mode -Slave Transmitter Mode
In this mode, the master reads from the slave registers.
X,Y,Z registers of the compass can be then read by SJOne board one by one knowing the device read address and register address.Register pointer will be incremented by 1 automatically after current register has been successfully read.

Usage of OnBoard LED's
LED No. Usage
1 I2C Device response successful
2 Compass read successful
3 Checkpoints reception successful
4 Can Transmission successful

Software Design

Compass Heading Calculation
    Compass Heading  = Raw values obtained from the compass module + Magnetic deviation + Magnetic declination

Raw values obtained from the compass module - Of the 3 axis in compass, the x-axis and y-axis values read from the compass registers are used to calculate the heading value in radians. Due to magnetic deviations these values are not accurate and need to be calibrated for accuracy. Calibrating the values obtained as radians would be more accurate that calibrating in degrees. The calibrated values in radians are then converted to degrees. The degrees would be values from -180 to 180 degree range and this has to be scaled for 0 to 360 that forms a complete circle.

Magnetic Deviation - It is the error introduced in the compass module due to local magnetic fields. The compass needs to be compensated for it.

Magnetic Declination - It is the angle between the Earth's geographic north and magnetic north. The values from compass IC are with respective to magnetic north whereas the navigation is generally based on geographic north. Hence this declination has to be compensated. Declination varies from place to place and for San Jose it is 13.31 degree East and positive. This value needs to be added.

Algorithm
  • Wait for boot request message from master.
  • Send boot reply to master.
  • Get current readings from GPS and compass module.
  • Parse string received from GPS module to get latitude, longitude and number satellite lock.
  • Check if number of satellite lock is valid.
  • Send current coordinates to android communication bridge via CAN.
  • Get checkpoints,destination from android app and store it in queue in CAN reception.
  • Fetch first checkpoint from queue.
  • Calculate distance and bearing of checkpoint with the help of haversine formula using current and checkpoint coordinates.
  • If distance is more than 200 feet, then find middle checkpoint and use it as checkpoint.
  • Calculate turn angle with direction using bearing and heading values.
  • Send distance, turn angle and direction to master controller using CAN bus.
  • If checkpoint distance is less than 10 feet, then fetch next checkpoint from queue.
  • Repeat above five steps till destination reached message is received from master.
Haversine formula:
  Distance = R ⋅ c
  c = 2 ⋅ atan2(√a, √(1−a))
  a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
Bearing (θ)(radians) = atan2(sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ)
Destination point given distance and bearing from start point: φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ ) λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 )
where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km) δ is the angular distance d/R; d being the distance at which checkpoint is needed
Note: Angles need to be in radians to pass to trig functions,unit of distance depends on unit of radius used.
Module Flow
Geo Module Software Flow

Implementation
  • Geographical Controller uses Periodic Scheduler Task provided by Preet to calculate distance, bearing values, get readings from compass and CAN communication.
  • GPS Task is created to read string from GPS module and parse it to get latitude and longitude data.
  • CAN and compass initialization is performed in main() function.
  • File logger function is used to log the real-time data onto SD card which is used for debugging purpose.
  • Can Message structure of 11-bit id is implemented to send and receive CAN messages over the CAN Bus.
  • CAN acceptance filter is set-up to receive messages specific to Geographical Controller from the CAN Bus.
  • Queues are implemented to store coordinates and use them in different functions whenever required. Producer and consumers of queues are timely managed so that functions will get latest readings.
  • CAN bus is checked if it is in bus off status at every 10Hz interval. CAN bus is reset if it is in bus off mode.


Testing

Accuracy of GPS Module
GPS Module Coordinates on Google Maps

Accuracy of GPS module was tested by recording/logging coordinates received by module using LOG_INFO() function and plotting them on Google maps GPS Module Coordinates on Google Maps. GPS module was very much accurate and we did not needed it to calibrate. It is observed that accuracy depends on number of satellite locks with module, environment conditions. More number of satellite locks and sunny weather conditions, greater the accuracy of readings. You may hear that bluetooth, GPS frequencies interfere with each other reducing accuracy of GPS, but we never experienced this issue.

Calibration of Compass

As any instrument has instrument error, so has the compass IC. The compass needs to be calibrated for accuracy. We undertook two levels of calibration.
1. Level 1 calibration was done without mounting the compass on car. The compass was rotated in its axis for 360 degrees and the error was identified for every 15 degrees (totally 24 zones) with the setup shown by the image in the left.
2. Level 2 calibration was done after mounting the compass on car.The car setup by itself had some tilt and we compensated it by means of adjusting the hardware mounting. Next, the motor’s EMI caused some magnetic deviation and the motor's influence was taken into account too. The car was rotated in its axis ( its axis being parallel to the compass axis) for 360 degrees with the deviation measured for every 15 degrees(totally 24 zones) with the setup depicted by the image in the right.

Set up for Compass Calibration before mounting on Car

Set up for Compass Calibration on Car

The deviation was not uniform for every zone. Using linear regression analysis technique, the relationship between the predictor variable - degrees and the response variable - radians was found in an ideal environment and the same was repeated several times for accuracy. The average of several such readings was taken as the final calibration value.

Before Calibration
After Calibration




















Technical Challenges and Resolution

Configuring GPS Module

We faced difficulty in configuring GPS module to sending only $GGA messages, 10Hz Position update rate and updating baud rate to 38400. Initially we were trying to configure GPS module via writing program for SJ One board and we were unable to do it. Later on we completed configuring by connecting GPS module directly to serial port and using GPS Viewer software. Through it we can directly configure GPS module without worrying about binary messages and checksum calculation.

Compass module and Compass Calibration

1.Initially the compass was mounted and tested on breadboard with its upper face downwards as the connecting strips are on the upper side. This made the compass produce incorrect values.
2. While reading the registers in compass HMC5883L, only x and y register values are needed. Hence we tried to read only those registers from the device. But it so happened that z register is in between the x and y registers and the read pointer did not advance after the x register was read and remained in the z register. This led to compass producing constant values.
3. While calibrating, the compass should be rotated on a horizontal plane with its axis of rotation fixed. Shifting the axis may result in incorrect values.
4. Having a robust hardware that does not cause any or very less tilt, will reduce the efforts of calibration as HMC5883L IC is not tilt compensated.
5. Calibration should be done in an environment which does not have iron , magnetic particles etc as those may cause magnetic deviation. As the motor module influences the compass with the generated EMI, mount the compass far away from the motor and calibrate with the motor ON to take account of the EMI generated.

Integrating Geo Module on Car

In the initial phase of integrating geo module, our car was always going in right direction but going forward towards destination. We had to put car back on track. While testing we it came to our notice that if car has closer checkpoints then it was following the track perfectly. To solve this we implemented algorithm to find midpoint between checkpoint sent by from android and current source if distance is greater than 200 feet. Mathematical formula to implement this is mentioned in software design section. Online contents are listed in references section.

Communication Bridge Controller and Android Application

Schedule

Sl. No Start Date End Date Task Status Actual Completion Date
1 9/29/2015 10/06/2015 Ordering bluetooth module and setting up android dev enviornment Completed 10/06/2015
2 10/06/2015 10/13/2015 Implementing basic UI with Start and Stop buttons and testing bluetooth module Completed 10/12/2015
3 10/13/2015 10/27/2015 Integrating android app with bluetooth module and SJ One board Completed 11/01/2015
4 10/27/2015 11/03/2015 Establishing communication with other modules using CAN and testing Prototype Completed 11/07/2015
5 11/03/2015 11/17/2015 Enhancing UI features with Google Maps and display of sensor data from different modules Completed 11/20/2015
6 11/17/2015 12/01/2015 Setting up Communication with GPS and Master and prototype testing Completed 12/05/2015
7 12/01/2015 12/08/2015 Final app testing Completed 12/10/2015

Hardware Design

The Communication bridge consists of establishing connection between car and the android phone which is established with the help of bluetooth module HC-05 connected to UART peripheral of SJOne Board. The UART pins on board are connected to bluetooth module in the manner shown in diagram. Once the connection is established between the car and the android phone and signals like 'Start','Stop' and 'Kill' are sent from android phone then they are received by the bluetooth and sent to SJOne board to be further broadcasted over CAN bus.

Communication Bridge
HC-05 Bluetooth Module






Pin Configuration:
Sl. No Pin on SJOne Board Pin on HC-05 Bluetooth module Purpose
1 TXD3 RXD Transmission through UART3 to HC-05
2 RXD3 TXD Reception through UART3 from HC-05
3 3V3 3.3 3.3V voltage supply
4 GND GND Ground

The Bluetooth module HC-05 is a MASTER/SLAVE module.The Role of the module (Master or Slave) can be configured only by AT COMMANDS.By default the mode is set to SLAVE.It has pins named KEY and 5V which we are not using because KEY pin is used to enter the Command mode.Bluetooth module when connected to SJOne board needs to be paired with any one of the external devices like android phone in our case, there is LED that blinks at different pace to indicate whether it is paired or not. Once the bluetooth module is paired indicated by slow blinking of the LED, the android phone is all ready to transmit signals to SJOne board.

Usage of OnBoard LED's:
LED No. Usage
1 START/STOP signal successful
2 Map reset
3 Can reception successful
4 Can transmission successful

Software Design

Communication Bridge Controller

The purpose for Communication Bridge is mainly to facilitate communication between Android application and other controllers via Bluetooth module and CAN. The software design mainly follows the flow of data as shown in figure. The UART peripheral on SJOne is configured by using getInstance( ) on Free Rtos to either receive or transmit data through it.When the communication bridge controller receives CAN msg ids corresponding to Master,Sensor and Geo controllers over the CAN bus, it tends to send data corresponding to each msg id to Android phone through bluetooth module.Once the signals are processed by the android app, in return if it wants to send data through bluetooth over CAN bus then it can.

Reception of Bluetooth messages and transmission over CAN

Reception of CAN messages and transmission over Bluetooth

Android Application
Android Workflow


As part of the user interface, the android application provides user a way of setting the car on auto drive mode with just few inputs. The application consist of two main activities:

  • Car Connect
    • The main purpose of the section of the app is to help user pair up with the Bluetooth module on the car. In this case we are pairing up with HC-05.
  • Map Navigation
    • This section of the app will be in usage for most of the time. Considering the effectiveness of Google Maps API v2, the Application relies on the Google Maps to identify real life location on the map. A google Map API key was obtained in order to integrate Google maps into the application.
    • For the Bluetooth connection to be established the user needs to Click on the paired up Bluetooth module which enables the socket between the Android and Bluetooth module HC-05.
    • The activity consists of Map fragment and Buttons to issue commands. The application listens to incoming Bluetooth messages and locates the current position of the car. User can then set a destination by simply touching a location on the maps. The application computes the route along with checkpoints to precisely set a navigation path for the car. This enables the Run and Kill buttons for further action by the user.
    • The application also allows the user to monitor sensor data over the application in real time.

The entire flow of the application between android application and Communication Bridge can be showcased as follows:


Application Flow

  • Home Screen
  • Bluetooth Pairing Screen
  • Checkpoints Computation

Testing

Bluetooth Module

We tested the bluetooth module HC-05 using a Bluetooth chat application from app store. Using this application we could successfully send characters to bluetooth module over UART connected to SJ One board and observe the results on Hercules terminal.

Android application

Android application was tested for both functionality and performance.We tested all the application buttons and Map fragment with the bluetooth module and improved the performance of the app over the span of the project.

CAN communication

CAN communication between bridge controller and other module was tested in an isolated fashion by setting up the connection of two SJ One board using breadboards and wires.

Technical Challenges and Resolution

Reading via Bluetooth
  • One of the major challenges we faced while developing android application was designing UI activity with minimum processing on UI. Mainly because Android application tend to crash if huge chunks of data is being processed on UI. One such case was computation of checkpoints and sending via Bluetooth to Communication bridge controller.
    • Resolution: As part of the solution we established a new thread in the background which computed checkpoints and forwarded the results to Bluetooth module thereby reducing the processing on UI activity.
  • Our application design initially included constant updating of current location of the car on Google Map as well as sensor data as part of monitoring the car in real time. However we faced several issues keeping the UI functional with unfiltered data. Moreover the usage of data without filtering led to collection of valid as well as invalid data (garbage characters) being used for display.
    • Resolution: This forced us to redesign the app to minimize the app crashes resulting in removal of these features. A better resolution would have been filtering the incoming data and reducing the rate of updating data on UI.
Sending via Bluetooth
  • While sending checkpoints from Android application we found data to be missing on communication controller if it exceeded a size of more than few bytes.
    • Resolution: A delay was inserted after sending each byte so as to ensure 100% reception of data to Communication controller. A better solution would be increasing buffer size for Bluetooth module or adjusting data transfer rate.
Android App Navigation
  • While designing the app for the project, it was observed that bluetooth connectivity was being lost when switching in between two or more activities designed on the app that help us navigate between different screens on the phone.
    • Resolution:Leading to above challenge the design of app was proposed to convert into fragments but again when conversion of activities to fragments was started, it was observed that Map activity which is a fragment activity can not be converted into fragments because for both activities and fragment activity the syntax of functions used were different from that of fragments so the idea of converting into fragments was changed and the app was redesigned to be implemented only by using activities.

Common Technical Challenges

Logging Info to Memory Card

It has been observed that if log info size is large then we cannot copy log.csv file from flash to memory card via terminal command. Command terminates with Error:2. On board flash has limited space which was causing this error to come. To solve this issue we changed file_logger.h file to log all info directly into memory card which we can directly remove and get all data directly on PC.

CAN Bus Hardware

Robust hardware setup of CAN bus is very much important. We faced this issue of CAN messages not being sent to other controllers. We checked voltages at every point of CAN bus and we were getting readings as expected. Later on we found that our 5v supply pins are connected to bus they were loose. After soldering supply pins properly, our CAN bus never failed till end of project.

CAN Processing loop

Can reception should be put in a while loop so that in one single run of the while loop all received message will be emptied.Initially, we processed the received CAN messages in an if loop. But, the effect of this on our CAN processing was that whenever we used to receive CAN messages at a particular moment, only the first CAN message was considered in processing and the other CAN messages in the queue were ignored. But, when using a while loop, all the CAN messages in the queue are processed and considered.

Conclusion

In a short span of 3 months, we had an enriching experience in working for the project. We were able to implement the embedded concepts that we had learnt from our course work. Having hands on both software development and hardware interfacing is a very rare opportunity that we acquired. All essential phases of software development cycle such as design, implementation, unit testing and functional testing were mandatory steps in our project and that absolutely prepared us for the future. Besides that, some of the tools that we worked with like Gitlab for version control and Eclipse IDE as build environment are really useful as they are on par with the Industry preferences in the current scenario. Finally it was one wholesome experience and we hope we were able to share some of our learnings in this report.

Project Video

Project Source Code

References

Acknowledgement

This project has been an amazing learning experience. We are grateful to Prof. Preetpal Kang for provision of expertise and technical support in the implementation. Without his superior knowledge and experience, project would have lagged in quality of outcomes. We would also like to express special gratitude and thanks to ISA team for the valuable inputs and timely feedback during the project development life cycle. Last but not least its the diligence and dedication of team Minion which led us to success.

References Used