Difference between revisions of "F15: TopGun"
m (→DBC File Implementation) |
m (→DBC File Implementation) |
||
Line 196: | Line 196: | ||
VERSION "" | VERSION "" | ||
− | NS_ : | + | NS_: |
− | + | NS_DESC_ | |
− | + | CM_ | |
− | + | BA_DEF_ | |
− | + | BA_ | |
VAL_ | VAL_ | ||
CAT_DEF_ | CAT_DEF_ |
Revision as of 20:05, 20 December 2015
Contents
- 1 TopGun Self Driving Car
- 2 Abstract
- 3 Objectives & Introduction
- 4 Schedule
- 5 Parts List & Cost
- 6 DBC File Implementation
- 7 Sensor Controller
- 7.1 Sensor Testing
- 7.1.1 Simple Sensor ping operation
- 7.1.2 HCSR04 Sensor Testing
- 7.1.3 Parallax Ping Sensor Testing
- 7.1.4 Finalizing distance sensors
- 7.1.5 Software timer for repetitive pulse and Hardware timer for calculating pulse width
- 7.1.6 Sequentially Triggering of Sensors
- 7.1.7 Limiting the Scope to Improve Frequency
- 7.1.8 Misfiring of Sensor
- 7.2 Sensor Software Design
- 7.3 Sensor Implementation Using Interrupts
- 7.1 Sensor Testing
- 8 Geographical Controller
- 9 Motor I/O Controller
- 10 Master Controller
- 11 Bluetooth/Bridge Controller
- 12 Overall System Optimizations and fail safe conditions
- 13 Testing & Technical Challenges
- 13.1 Issue #1 (Motor I/O)
- 13.2 Issue #2 (Project Hardware)
- 13.3 Issue #3 (Project Hardware)
- 13.4 Issue #4 (Geo controller software)
- 13.5 Issue #5 (Motor Controller software)
- 13.6 Issue #6 (Sensors using Interrupt on the 4-pin sensor's Echo pin)
- 13.7 Issue #7 (Sensors using Interrupt on the 3-pin sensor's Echo pin)
- 14 Conclusion
- 15 References
TopGun Self Driving Car
This is Top Gun - The super car that drives by itself!
Abstract
The GPS-controlled automated RC car will consists of 5 different LPC 1758 controllers. Each controller will have a specific major tasks required to drive the car. The naming convention goes as:- Motor & I/O controller - this will control the motors of the car and will also connected with a LCD display to show the car's status, Sensor controller - It will be connected to the obstacle detecting sensors on the car, Communication Bridge - It will be connected to an Android mobile phone so as to provide co-ordinates, GEO controller - This will give the exact orientation of the car e.g., heading & bearing, etc. and finally the Master controller - This will collect the data from other controllers and will guide the motor controller. These controllers are connected using CAN bus. After the final implementation, this car will be capable of driving by itself using the destination co-ordinates set by us avoiding every obstacles, overcoming slopes thereby reaching the destination safely!
Objectives & Introduction
Team Members & Responsibilities
Treasurer:
- Anuj Korat
Five Controllers Used
- Master Controller
- Motor I/O Controller
- Sensor Controller
- Geographical Controller
- Bluetooth/Bridge Controller
Schedule
Team Schedule
SI No. | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 09/15/2015 | 09/27/2015 |
|
Completed | 09/27/2015 |
2 | 09/27/2015 | 10/30/2015 | Following up on RC car and other component procurement through team discussions | Completed | 10/30/2015 |
3 | 10/30/2015 | 10/06/2015 | Hardware design of the car including discussions on component placement, soldering and wiring. | Completed | 10/06/2015 |
4 | 10/06/2015 | 10/17/2015 | CAN message ID's, priorities, data size and format proposals for all the possible CAN messages on the bus | Completed | 10/20/2015 |
5 | 10/20/2015 | 11/05/2015 | Discussions and proposals on basic obstacle avoidance algorithm with sensor integration, hands on and testing | Completed | 11/03/2015 |
6 | 11/05/2015 | 11/25/2015 | Integrating other modules and components to the RC car, development of autonomous driving algorithm and finalize on hardware layout of the car | Completed | 12/1/2015 |
7 | 11/25/2015 | 12/7/2015 | Testing the RC car in real world environments | Completed | 12/5/2015 |
Parts List & Cost
Item# | Part Desciption | Vendor | Qty | Cost |
---|---|---|---|---|
1 | RC Car | From Preet | 1 | Free |
2 | RC Car Battery | Amazon | 1 | $24.72 |
3 | Core CPU Supply | Amazon | 1 | $12.70 |
4 | CAN Transceiver MCP2551 | Microchip | 15 | $20.00 |
5 | Printed Circuit Boards | Amazon | 1 | $12.25 |
6 | M-F,F-F,M-M Jumper Wires | Amazon | 120 | $8.75 |
7 | Ultrasonic Parallax Ping Sensor | Fry's Electronics | 1 | $63.99 |
8 | Ultrasonic Sensors | Amazon | 5 | $10.45 |
9 | 9 DOF Razor IMU module | SparkFun | 1 | $74.95 |
10 | FTDI Basic Breakout | SparkFun | 1 | $14.95 |
11 | LCD Display uLCD-32PTU | 4D systems | 1 | $111.00 |
12 | Bluetooth Module | Amazon | 1 | $9.99 |
13 | Wire Cutter | Amazon | 1 | $2.99 |
14 | GPS Sensor | Adafruit | 1 | $39.95 |
Total Cost | $450 |
DBC File Implementation
- This section explains DBC file implementation of the project. The DBC implementation contains the python based DBC file parser, a DBC file and auto generated C code for the five CAN nodes. These five nodes include driver(master), sensor, motor, geo and bluetooth node. The DBC file is a input to the python DBC parser script. The python script will generate a C file for the specific node given by the user at the command line argument. The python script goes through this DBC file and generates code to marshal (covert to raw CAN) and unmarshal (convert from raw CAN) using the provided API that you can enclose in a header file.
- The following is the DBC file of the project.
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 DRIVER MOTORIO BLUETOOTH GEO BO_ 0 DRIVER_KILL_SWITCH: 0 DRIVER SG_ DRIVER_KILL_SWITCH_cmd : 0|0@1+ (1,0) [0|0] "" SENSOR,MOTORIO,BLUETOOTH,GEO BO_ 1 DRIVER_RESET: 0 DRIVER SG_ DRIVER_RESET_cmd : 0|0@1+ (1,0) [0|0] "" SENSOR,MOTORIO,BLUETOOTH,GEO BO_ 2 DRIVER_SYNC_ACK: 0 DRIVER SG_ DRIVER_SYNC_ACK_cmd : 0|0@1+ (1,0) [0|0] "" SENSOR,MOTORIO,BLUETOOTH,GEO BO_ 3 MOTORIO_SYNC: 0 MOTORIO SG_ MOTORIO_SYNC_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 4 SENSOR_SYNC: 0 SENSOR SG_ SENSOR_SYNC_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 5 BLUETOOTH_SYNC: 0 BLUETOOTH SG_ BLUETOOTH_SYNC_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 6 GEO_SYNC: 0 GEO SG_ GEO_SYNC_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 7 MOTORIO_HEARTBEAT: 0 MOTORIO SG_ MOTORIO_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 8 SENSOR_HEARTBEAT: 0 SENSOR SG_ SENSOR_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 9 BLUETOOTH_HEARTBEAT: 0 BLUETOOTH SG_ BLUETOOTH_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 10 GEO_HEARTBEAT: 0 GEO SG_ GEO_HEARTBEAT_cmd : 0|0@1+ (1,0) [0|0] "" DRIVER BO_ 11 MOTORIO_RUNMODE: 1 DRIVER SG_ MOTORIO_RUNMODE_cmd : 0|8@1+ (1,0) [0|3] "" MOTORIO BO_ 12 SENSOR_SONARS: 6 SENSOR SG_ SENSOR_SONARS_front_left : 0|8@1+ (1,0) [0|4] "" DRIVER,MOTORIO SG_ SENSOR_SONARS_front_right : 8|8@1+ (1,0) [0|4] "" DRIVER,MOTORIO SG_ SENSOR_SONARS_front_center : 16|8@1+ (1,0) [0|4] "" DRIVER,MOTORIO SG_ SENSOR_SONARS_left : 24|8@1+ (1,0) [0|4] "" DRIVER,MOTORIO SG_ SENSOR_SONARS_right : 32|8@1+ (1,0) [0|4] "" DRIVER,MOTORIO SG_ SENSOR_SONARS_back : 40|8@1+ (1,0) [0|4] "" DRIVER,MOTORIO BO_ 13 MOTORIO_DIRECTION: 2 DRIVER SG_ MOTORIO_DIRECTION_speed_cmd : 0|8@1+ (1,0) [0|4] "" MOTORIO SG_ MOTORIO_DIRECTION_turn_cmd : 8|8@1+ (1,0) [0|5] "" MOTORIO BO_ 14 DRIVER_CHECKPOINT_REQ: 1 DRIVER SG_ DRIVER_CHECKPOINT_REQ_cmd : 0|8@1+ (1,0) [0|3] "" BLUETOOTH,MOTORIO BO_ 15 BLUETOOTH_CHECKPOINT_SEND: 1 BLUETOOTH SG_ BLUETOOTH_CHECKPOINT_SEND_cmd : 0|8@1+ (1,0) [0|3] "" DRIVER,MOTORIO BO_ 16 BLUETOOTH_CHECKPOINT_DATA: 1 BLUETOOTH SG_ BLUETOOTH_CHECKPOINT_DATA_cmd : 0|8@1+ (1,0) [0|3] "" DRIVER,MOTORIO BO_ 17 DRIVER_LOC_UPDATE: 8 DRIVER SG_ DRIVER_LOC_UPDATE_LAT_cmd : 0|32@1+ (0.0001,0) [0|0] "" GEO,MOTORIO SG_ DRIVER_LOC_UPDATE_LONG_cmd : 32|32@1+ (0.0001,0) [0|0] "" GEO,MOTORIO BO_ 18 GEO_SPEED_ANGLE: 5 GEO SG_ GEO_SPEED_cmd : 0|8@1+ (1,0) [0|0] "" DRIVER,MOTORIO SG_ GEO_ANGLE_heading_cmd : 8|16@1+ (1,0) [0|0] "" DRIVER,MOTORIO SG_ GEO_ANGLE_bearing_cmd : 24|16@1+ (1,0) [0|0] "" DRIVER,MOTORIO BO_ 19 GEO_LOC_DATA: 8 GEO SG_ GEO_LOC_LAT_cmd : 0|32@1+ (0.0001,0) [0|0] "" DRIVER,MOTORIO SG_ GEO_LOC_LONG_cmd : 32|32@1+ (0.0001,0) [0|0] "" DRIVER,MOTORIO BO_ 20 SENSOR_LIGHT_BAT: 2 SENSOR SG_ SENSOR_LIGHT_cmd : 0|8@1+ (1,0) [0|1] "" DRIVER,MOTORIO SG_ SENSOR_BAT_cmd : 8|8@1+ (1,0) [0|1] "" DRIVER,MOTORIO
CM_ BU_ NOONE "No node, used to indicate if it's a debug message going to no one"; CM_ BU_ DRIVER "The driver 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_ BLUETOOTH "The bluetooth controller of the car"; CM_ BU_ GEO "The geo controller of the car"; CM_ BO_ 2 "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_ 7 1; BA_ "GenMsgCycleTime" BO_ 8 1; BA_ "GenMsgCycleTime" BO_ 9 1; BA_ "GenMsgCycleTime" BO_ 10 1; BA_ "GenMsgCycleTime" BO_ 11 1; BA_ "GenMsgCycleTime" BO_ 12 10; BA_ "GenMsgCycleTime" BO_ 13 10; BA_ "GenMsgCycleTime" BO_ 17 10; BA_ "GenMsgCycleTime" BO_ 18 10; BA_ "GenMsgCycleTime" BO_ 19 10;
- Let's understand the above DBC file. The line which contains BU_:... tells the python parser that the user has five nodes in the CAN implementation. In the TopGun project, we have total five nodes -> SENSOR, DRIVER(master), MOTOR, BLUETOOTH, GEO.
- The second important thing in the DBC file is the lines starting from BO_ message_id. These lines define the different message ids for the CAN implementation of the TopGun project. Here, the project includes total 20 message ids. So, The DBC file contains separate BO_ message_id line for each and every message id. Now, let's see what these lines are indicating to the python parser. What the BO_ line contains is given below:
- BO_ 4 SENSOR_SYNC: 0 SENSOR --> BO_ "message_id" "message_id_name" "number_of_bytes_transmitted_on_CANbus" "transmitter_node"
- Now, there are lines which start from SG_. The format of the line contains SG_ is given below. It will contain the variable name that we want to marshal and unmarshal for the CAN bus message data. It also contains the size of that variable and from where it is placed in the 8 bytes of total data. This line will also decide the range of the value held by this variable. User needs to define this max and mim range according to the application. If it is [0|0], then the the parser will consider this as a default and will give the maximum and minimum value of that variable according to its size and the sign information of the variable. Information in the (1,0) will define the multiplier of the value of the variable which in this case is 1. The second value of this bracket is 0 which indicates the offset for the value of the variable.
- Execute the following commands in the command line argument to generate the API for the motor controller node.
- $python dbc_parse.py -i TopGun_12_38am_11_16_2015.dbc -s MOTORIO > generated_code_MOTORIO.c
- The above command will generate the code for the generated_code_MOTORIO.c file
- Sample implementation of CAN dbc for sensor message.
- Sensor message encode code:
can_msg_t sensor_can_msg; SENSOR_TX_SENSOR_SONARS_t sensor_msg; sensor_msg.SENSOR_SONARS_front_center = sen_front_center.szone; sensor_msg.SENSOR_SONARS_front_left = sen_front_left.szone; sensor_msg.SENSOR_SONARS_front_right = sen_front_right.szone; msg_hdr_t sensor_msg_header = SENSOR_TX_SENSOR_SONARS_encode((uint64_t*)&sensor_can_msg.data, &sensor_msg); sensor_can_msg.msg_id = sensor_msg_header.mid; sensor_can_msg.frame_fields.data_len = sensor_msg_header.dlc; transmit_data(sensor_can_msg);
- Sensor message decode code:
SENSOR_TX_SENSOR_SONARS_t sensor_msg; can_msg_t received_msg; msg_hdr_t hdr; hdr = { received_msg.msg_id, (uint8_t)received_msg.frame_fields.data_len }; SENSOR_TX_SENSOR_SONARS_decode(&sensor_msg,(uint64_t*)&received_msg.data,&hdr);
CAN Message ID Table
Message ID | Task associated with ID | Data bit-fields |
---|---|---|
0x00 | Kill Switch | No Data |
0x01 | Reset |
reset_motorio:8; // Acknowledge motorio controller reset_sensor:8; // Acknowledge sensor controller reset_geo:8; // Acknowledge geo controller reset_bluetooth:8; // Acknowledge bluetooth module |
0x02 | Master Sync Ack |
ack_motorio:8; // Acknowledge motorio controller ack_sensor:8; // Acknowledge sensor controller ack_geo:8; // Acknowledge geo controller ack_bluetooth:8; // Acknowledge bluetooth module |
0x03 | MotorIO Controller Sync | No Data |
0x04 | Sensor Controller Sync | No Data |
0x05 | Bluetooth Controller Sync | No Data |
0x06 | Geo Controller Sync | No Data |
0x07 | MotorIO controller Heart-beat | No Data |
0x08 | Sensor controller Heart-beat | No Data |
0x09 | Bluetooth controller Heart-beat | No Data |
0x0A | Geo controller Heart-beat | No Data |
0x0B | Run mode | mode:8; |
0x0C | Distance Sensor Data |
front_left:8; // Front left sensor reading front_right:8; // Front right sensor reading front_center:8; // Front centre sensor reading left:8; // Left sensor reading right:8; // Right sensor reading back:8; // Back sensor reading |
0x0D | MotorIO Direction Data |
speed:8; // Indicate speed for DC motor turn:8; // Indicate turn angle for servo motor |
0x0E | Check-point Request Message | No Data |
0x0F | Check-point Start Message |
num_of_points; // Number of check-points to be loaded |
0x10 | Check-point Data |
float latitude; float longitude; |
0x11 | Geo-Controller New Destination Data |
float latitude; float longitude; |
0x12 | Geo-Controller Speed and Angle message |
speed:8; // Speed as measured by the GPS sensor heading:16; // Heading from the Geo controller bearing:16; // Bearing calculated by the Geo controller |
0x13 | Geo-Controller Location Data |
float latitude; float longitude; |
0x14 | Light and Battery Sensor Data |
light_sensor:8; // Light sensor reading batt_sensor:8; // Battery level sensor reading |
Sensor Controller
Team Members:
Divya Dodda Dhruv Kakadiya
Sensor Controller Schedule
SI No. | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 09/20/2015 | 09/27/2015 | Researching and ordering the sensors to be used in the project | Completed | 9/27/2015 |
2 | 09/27/2015 | 10/03/2015 |
|
Completed | 10/03/2015 |
3 | 10/03/2015 | 10/10/2015 | Interfacing ADC ultrasonic sensor to SJOne board, reading sensor values and filter the readings | Completed | 10/10/2015 |
4 | 10/10/2015 | 10/20/2015 | Understanding inertial measurement unit sensor, interfacing it to SJOne board to get filtered readings | Completed | 10/20/2015 |
5 | 10/20/2015 | 11/05/2015 | Integrating multiple sensors to the SJOne board, testing the sensors and debugging issues | Completed | 11/02/2015 |
6 | 11/05/2015 | 11/15/2015 | Preparing sensor values to be sent over CAN bus and testing out the correctness of sensor can messages | Completed | 11/10/2015 |
7 | 11/25/2015 | 11/30/2015 | Testing of code during final phases, modifying code in cooperation with other teams and optimization of code | Completed | 12/1/2015 |
Sensor Testing
Simple Sensor ping operation
HCSR04 Sensor Testing
- As shown in the figure below, HC-SR04 ultrasonic sensor requires an external 5V DC supply.
- When in the initial testing stage we just connected one sensor for testing the accuracy and the range of the sensor.
- The values we received were very stable and neat.
Parallax Ping Sensor Testing
- As shown in the figure below, Parallax ping ultrasonic sensor requires an external 5V DC supply.
Finalizing distance sensors
- Both sensors being pretty accurate, we were confused while finalizing one. So we were using both sensors, for front we were using Parallax and for left,right and back sensors we were using HCSR04 sensor.
- HCSR04 sensor was better option because as it was much cost efficient than the Parallax Ping Sensor (Where one Parallax Ping costs $30, one HCSR04 costed us only $2)
- Its only drawback is, the cheaper one sensor needed good filter to remove some spikes and Parallax sensor was working pretty good without any filtering.
Software timer for repetitive pulse and Hardware timer for calculating pulse width
- All sensor were triggered using software timers. We declared a soft timer for each sensor which kept track of the time between trigger and echo for that particular sensor.
SoftTimer limit_time; limit_time.reset(25); limit_time.restart(); if(limit_time.expired()){ break; }
- If we apply the before mentioned distance formula to this timer value in milliseconds, we will always get the distance in multiples of 17.
- Let's work out an example for better understanding;
- As the return return type of this function is an integer, we always get the distance in multiples of 17, which compromises the accuracy by a large factor.
- Because of this reason we switched to hardware timers.
- The declaration of hardware timer is as shown below, and this return value of time is in micro-seconds.
lpc_timer_enable(lpc_timer0,1); lpc_timer_set_value(lpc_timer0,0);
- Let's work out the same example for the return value being 1usec.
- Hence, even if the timer value is an integer, as it is in microseconds, we have improved the accuracy.
- As there are only three hardware timers in LPC 1768 we cannot allot individual timer for each sensor. Hence, we use just one hardware timer which runs regardless any individual sensor.
- All sensors get the current timer value during trigger and echo from this single timer, and do the further processing individually.
Sequentially Triggering of Sensors
- We used to trigger all the sensors at the same time, which caused interference between adjacent sensors, which in turn caused mis-firing of echo.
- This resulted in incorrect distance values from all the sensors.
- Thus to solve this issue, we implemented sequential triggering.
- Under this logic, each sensor will be triggered only when the previous sensor receives an echo or exceeds the maximum echo reception wait time which is 60msec.
- This implementation solved the issue at hand but gave rise to a new issue which is mentioned in the next section.
Limiting the Scope to Improve Frequency
- As discussed in the previous section, if we implement sequential triggering for each sensor, if there is no obstacle, then the worst case delay would be 360 msec(60msec*6sensors) to update all sensor values to the master.
- Means the frequency of communicating these values to the master will be, 2.8Hz.
- For proper obstacle avoidance, we need to provide the sensor data to the master atleast 10 times per second, i.e. at 10Hz.
- Which means data from all six sensors must be calculated within 100msec.
- Even if we consider limiting the time allotted to a sensor to time required for maximum distance (400cms), we will require 23.5msec each sensor i.e. 141msec to update the values of all six sensors. This increases the frequency to 7.1Hz.
- This led is to the solution to this problem, if we limit the scope of each sensor then we can update the sensor values more frequently to the master.
- To overcome this issue, we limited the maximum scope of the sensor to 170 cms, limiting the time required to get the echo to 10msec. Which makes the total time required to calculate all six sensors' data about 60msec.
- Hence, as shown in the flowchart, each sensor waits 10msec for an echo. If we get an echo within 10msec, we calculate the distance; if we don't, we assume the obstacle is at 170cms or further.
Misfiring of Sensor
- At times the sensor used to mis-fire. Which means; in a stable condition, if the obstacle is at a constant distance of 150cms, 1 out of 50 continuous values will be 60cms.
- This value being false, misguides the master.
- To overcome this issue, we introduced a threshold value called DELTA (say, 10cms). Which defines the acceptable range from the previous value.
- In this algorithm, an abrupt change in the distance value should be constant for at least two consecutive reads to be considered genuine.
- If the current value from the sensor is in the range of the previous value's +/- 10cms, then this value is considered to be correct, and is provided to the master. Then this current value will be copied in the previous value register.
- If the current value is not is the previous value's +/- DELTA range then it is considered as a misfire and hence is not provided to the master. But this sudden change might be because of a sudden obstacle; hence, the value is copied in the previous value register, and if the same value repeats, it will be considered genuine and provided to the master.
- The code for this algorithm is as shown below;
if(temp-DELTA<current && current<temp+DELTA){ distance = current; } temp = current;
- Hence, this algorithm will overcome the abrupt mis-firing of the sensor and make the data provided to the master more reliable.
Sensor Software Design
Sensor Controller Team Software Design
- Sensor software design is composed of three crucial tasks, which are to read GPIO based sonar, read ADC based sonar, and CAN TX.
Operation Sequences
Tasks
Task Name | Purpose |
---|---|
Period Init | Can bus initialization |
Period Register telemetry | Register sensor_data can message |
Periodic 1Hz Callback | Check can bus off |
Periodic 10Hz Callback | Get and Send Sensor Data |
Sensor Zones
Each sensor can detect obstacles at a maximum range of 400cm. We have divided this range into 3 zones as shown in the figure.
Sensor Pin Connections
Line Item# | Node A Source | Node A Pin | Node B Source | Node B Pin | Description |
---|---|---|---|---|---|
1 | 3.3V Power Supply | 3.3V | SJOne Board | 3V3 | SJOne Power |
2 | 3.3V Power Supply | GND | SJOne Board | GND | SJOne Ground |
3 | CAN Transceiver | Tx | SJOne Board | P0.1 (Tx) | SJOne - CAN Tx |
4 | CAN Transceiver | Rx | SJOne Board | P0.0 (Rx) | SJOne - CAN Rx |
5 | CAN Transceiver | 3.3V | 3.3V Power Supply | 3.3V | SJOne - CAN Power |
6 | CAN Transceiver | Ground | 3.3V Power Supply | GND | SJOne - CAN Ground |
7 | Parallax Ultrasonic Sensor (Front Left) | Vcc | 5V Power Supply | +5V | Front Left Sensor Power |
8 | Parallax Ultrasonic Sensor (Front Left) | GND | 5V Power Supply | GND | Front Left Sensor GND |
9 | Parallax Ultrasonic Sensor (Front Left) | Echo/Trig | SJOne Board | P2.0 | Front Left Sensor Echo |
10 | Parallax Ultrasonic Sensor (Front Right) | Vcc | 5V Power Supply | +5V | Front Right Sensor Power |
11 | Parallax Ultrasonic Sensor (Front Right) | GND | 5V Power Supply | GND | Front Right Sensor GND |
12 | Parallax Ultrasonic Sensor (Front Right) | Echo/Trig | SJOne Board | P2.2 | Front Right Sensor Echo |
13 | Parallax Ultrasonic Range Sensor (Front Middle) | Vcc | 5V Power Supply | +5V | Front Middle Sensor Power |
14 | Parallax Ultrasonic Range Sensor (Front Middle) | GND | 5V Power Supply | GND | Front Middle Sensor GND |
15 | Parallax Ultrasonic Range Sensor (Front Middle) | Echo | SJOne Board | P2.4 | Front Middle Sensor Echo |
16 | Parallax Ultrasonic Range Sensor (Front Middle) | Trig | SJOne Board | P2.5 | Front Middle Sensor Trig |
17 | CAN Transceiver | CANL | CAN BUS | CANL | CANL to CAN BUS |
18 | CAN Transceiver | CANR | CAN BUS | CANR | CANR to CAN BUS |
Sensor Implementation Using Interrupts
- We implemented interrupt based code for 3-pin and 4-pin ping sensors.
Implementation of 4-pin Sensors With Interrupt
- Initially a class for the 4-pin sensor was developed. Three instances of this class were declared for front, right and left sensors with GPIO pin numbers for trigger, echo with trigger being the input to the sensor and echo being the output of the sensor to the board.In addition to the pin numbers an unique index for each sensor.
- First task was to assign the pin numbers to set as input and output pins which were interrupt based GPIO pins.
- From the file "eint.h", we inferred the ports 0 and 2 were interrupt based pins.
Interrupt On The Echo Pin
- To set an interrupt on echo pin, we used the API "eint3_enable_port2(pin, edge_type, callback_function)". The respective echo pin number was provided as the first parameter for front, right and left sensors. The edge type was rising and falling edge on the echo pin of each sensor. Two callback functions were implemented for rising and falling edge. When the echo pin went high,we captured the time using the API "sys_get_uptime_us()" in the rising edge callback function. When the echo pin went low, we captured the time using the same API in the falling edge callback function. The difference between uptime and downtime obtained from these callbacks functions, was used to calculate the distance using the formula "distance(in cms) = (downtime-uptime) * (1.0 / 58.0)."
Design Flow
- The function for pinging the sensors followed the order front,right and left with indexes 0,1, and 2 respectively. The function was called from 1000Hz periodic callback function. The design flow for the function was as follows:
- 1. Check the index of the pinged sensor.
- 2. Send the pulse to the trigger pin for the indexed sensor.
- 3. Calculate uptime, downtime, distance for the current instance sensor.
- 4. Add the latest calculated distance value to a dedicated filter for the respective sensor.
- 5. The filter would update and return the latest average distance.
- 6. Calculate the zone for the distance obtained.
- 7. The data to be sent onto the can bus involves the zone information for all the three sensors for every 1000Hz. This meant the zone information of the pinged and the un-pinged sensor values are needed out to be sent over the bus.
- 8. We concluded that at a given point of time, the can bus would receive the previously calculated values for all the sensors. What this meant is if we calculated the values for current instance of the front sensor, we would push the values of the previous instance of front,right and left sensors on the bus. This would keep the master updated with all the sensor data.
Sensor Implementation with Interrupts Pin Connections
Line Item# | Node A Source | Node A Pin | Node B Source | Node B Pin | Description |
---|---|---|---|---|---|
1 | 3.3V Power Supply | 3.3V | SJOne Board | 3V3 | SJOne Power |
2 | 3.3V Power Supply | GND | SJOne Board | GND | SJOne Ground |
3 | CAN Transceiver | Tx | SJOne Board | P0.1 (Tx) | SJOne - CAN Tx |
4 | CAN Transceiver | Rx | SJOne Board | P0.0 (Rx) | SJOne - CAN Rx |
5 | CAN Transceiver | 3.3V | 3.3V Power Supply | 3.3V | SJOne - CAN Power |
6 | CAN Transceiver | Ground | 3.3V Power Supply | GND | SJOne - CAN Ground |
7 | 4-pin Ultrasonic Sensor (Front) | Vcc | 5V Power Supply | +5V | Front Sensor Power |
8 | 4-pin Ultrasonic Sensor (Front) | GND | 5V Power Supply | GND | Front Sensor GND |
9 | 4-pin Ultrasonic Sensor (Front) | Trig | SJOne Board | P2.0 | Front Sensor Trigger pin |
10 | 4-pin Ultrasonic Sensor (Front) | Echo | SJOne Board | P2.1 | Front Sensor Echo pin |
11 | 4-pin Ultrasonic Sensor (Right) | Vcc | 5V Power Supply | +5V | Right Sensor Power |
12 | 4-pin Ultrasonic Sensor (Right) | GND | 5V Power Supply | GND | Right Sensor GND |
13 | 4-pin Ultrasonic Sensor (Right) | Trig | SJOne Board | P2.2 | Right Sensor Trigger pin |
14 | 4-pin Ultrasonic Sensor (Right) | Echo | SJOne Board | P2.3 | Right Sensor Echo pin |
15 | 4-pin Ultrasonic Sensor (Left) | Vcc | 5V Power Supply | +5V | Left Sensor Power |
16 | 4-pin Ultrasonic Sensor (Left) | GND | 5V Power Supply | GND | Left Sensor GND |
17 | 4-pin Ultrasonic Sensor (Left) | Trig | SJOne Board | P2.4 | Left Sensor Trigger pin |
18 | 4-pin Ultrasonic Sensor (Left) | Echo | SJOne Board | P2.5 | Left Sensor Echo pin |
19 | CAN Transceiver | CANL | CAN BUS | CANL | CANL to CAN BUS |
20 | CAN Transceiver | CANR | CAN BUS | CANR | CANR to CAN BUS |
Implementation 3-pin Sensors With Interrupt
Design flow
- The design flow for the 3-pin ping sensors with interrupts was same as the 4-pin ping sensors with interrupts.
- 3-pin sensor has a single pin for Echo and Trigger.
- 1. In the sensor function, first the Trigger pin is set as output. A high to low pulse is provided.
- 2. Once the low pulse is provided on the trigger pin, the same pin is configured as input pin to the board.
- 3. The echo pin is monitored for rising and falling edge. Once the falling edge is detected, the distance calculation, can data transfer takes place following the same logic as 4-pin sensor.
- The pin connections for this implementation are same as Sensors pin connections mentioned in 7.2.3.
Geographical Controller
Team Members:
Chitrang Talaviya Navjot Singh
Geographical Controller Schedule
SI No. | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 09/20/2015 | 09/27/2015 | Researching and ordering the parts | Completed | 9/27/2015 |
2 | 09/27/2015 | 10/05/2015 | Studying module data sheets and writing code sketches to be used when modules are procured(GPS and IMU) | Completed | 10/05/2015 |
3 | 10/05/2015 | 10/15/2015 | Interfacing GPS module and compass to SJOne board and get consistent filtered readings | Completed | 10/17/2015 |
4 | 10/15/2015 | 10/30/2015 | Proposals for heading and distance calculation, unit testing and integrating modules | Completed | 10/30/2015 |
5 | 10/30/2015 | 11/10/2015 | Calibration of compass and GPS readings, CAN bus communication from geo controller to other boards. | Completed | 11/10/2015 |
6 | 11/10/2015 | 11/25/2015 | Android application connection with data reception and transmit | Completed | 11/25/2015 |
7 | 11/25/2015 | 12/15/2015 | Final phase testing and optimization, collaborating with android team to get better reliable outcomes | Completed | 12/12/2015 |
Geographical Controller H/W Design
- Below figure represents the block diagram of Geo Controller. Geo-controller uses GPS and IMU module for its working. Uart3 and Uart2 are used for interfacing IMU and GPS with SJ One board at baud rate 9600bps.
Geographical Controller Hardware Design Components
Adafruit MTK3339 GPS: This GPS unit is interfaced via UART with build in antenna. The GPS provides latitude and longitude accurately up to 5-10 meters with a strong satellite fix with update rate of 10Hz. By default, the baud rate is 9600bps. Power usage for this module is 20mA during navigation. The GPS module comes with following capabilities:
We chose this part because it provided the base functionality we needed along with many other functions that would be fun to play with and try to include in the project. The antennae options and voltage regulator were also very enticing. We get raw GPS "NMEA sentence" output from module. The most important NMEA sentences include the GGA which provides the current Fix data, the RMC which provides the minimum gps sentences information, and the GSA which provides the Satellite status data. We are filtering the data for RMC, Recommended Minimum, which will look similar to: $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A where:-RMC Recommended Minimum sentence C 123519 Fix taken at 12:35:19 UTC A Status A=active or V=Void. 4807.038,N Latitude 48 deg 07.038' N 01131.000,E Longitude 11 deg 31.000' E 022.4 Speed over the ground in knots 084.4 Track angle in degrees True 230394 Date - 23rd of March 1994 003.1,W Magnetic Variation *6A The checksum data, always begins with *
|
||
9 Degrees of Freedom- Razor IMU: In our project, we used IMU module to get the heading of the device. The 9DOF Razor IMU provides nine degree of inertial measurement incorporates three sensors - an ITG-3200 (MEMS triple-axis gyro), ADXL345 (triple-axis accelerometer), and HMC5883L (triple-axis magnetometer). The outputs of all sensors are processed by an on-board ATmega328 and output over a serial interface. UART interface is used for interfacing with SJ One board and it is connected via UART3 with LPC board and is operated at 3.3V. Features:
|
Geographical Controller H/W Interface
- Below table shows the Pins connection of GPS and IMU module with SJ One Board. Both the h/w's are interfaced with Controller using UART interface. The operating volatge of GPS and IMU is 3.3V.
Description | Interface | Device Port | SJOne Board Port |
---|---|---|---|
Supply Voltage | N/A | Vcc | 3.3 V |
Ground | N/A | GND | GND |
GPS Module | UART2 |
Channel 1 -> Rx Channel 2 -> Tx Channel 3 -> EN |
Channel 1 -> Tx P2.8 Channel 2 -> Rx P2.9 Channel 3 -> Vcc |
IMU Module | UART3 |
Channel 1 -> Rx Channel 2 -> Tx Channel 3 -> DTR |
Channel 1 -> Tx P4.28 Channel 2 -> Rx P4.29 Channel 3 -> GPIO P2.2 |
Geographical Controller S/W Design
Geographical controller uses two modules to get GPS data and headings. These are:
- GPS module
- IMU module
Tasks
Task Name | Purpose |
---|---|
IMU Task | To get IMU reading over UART3. |
GPS Task | Read the GPS data string via UART2 Interrupt Handler. |
Periodic 1Hz Callback | Receive Checkpoint from Master. |
Periodic 10Hz Callback | Send GPS data over CAN BUS
Send IMU heading,bearing,speed and distance data over CAN Bus |
In the below sections, one will see the methods used to get the values from the modules. Both of the modules are interfaced using UART.
GPS
- Initialization: GPS data is retrieved using Interrupts for UART2. Before using Interrupts for receiving GPS string that contains data,UART2 is initialized with Receiving Interrupts Enabled. The code for UART init is as below. The UART init is done once, so is called in main().
void uart2init() { // In our inter-board communication we have used UART 2 for transmission and reception. So, We will unable UART 2. LPC_SC->PCONP |= (1<<24); // We have to Power on the UART 2 peripheral. To do so we have to enable bit 24 of PCONP register. LPC_SC->PCLKSEL1 &= ~((1<<16)|(1<<17)); // Peripheral Clock = CPUClock/4. (48 Mhz/4= 12 Mhz) LPC_PINCON->PINSEL4 &= ~((1<<19)|(1<<18)|(1<<17)|(1<<16)); LPC_PINCON->PINSEL4 |= ((1<<19) | (1<<17)); // We have to set this bits to meet the requirements of selection lines. LPC_UART2-> LCR |= 0xFFFFFF83; // To access DLL and DLM we have to set 7th bit of the LCR. We are enabling Dlatch by setting this bit. // 0 and 1 bits of LCR is 11. 8 bit data format. 1 stop bit. No parity. LPC_UART2 -> DLL = 71; // To set the baud rate 9600 bps we have to set divisor latch least significant bits to 96. LPC_UART2 -> DLM = 0;// and most significant bits to 0. LPC_UART2-> FDR = 0xA1; LPC_UART2-> LCR &=~(1<<7) ; // We have to reset the Dlatch bit before starting the communication. LPC_UART2->FCR = (1 << 0) | (1 << 6); LPC_UART2->FCR |= (1 << 1) | (1 << 2); LPC_UART2->IER = (1 << 0); }
- Getting GPS data from Interrupt Handler: The reason we used Interrupt handler was to get the data from GPS without any delay. Interrupt handler on getting all the string, will send over 'Queue'. To get data from the GPS module, we need to send raw data over UART bus :
char dataTobeSenttoGPS[] = "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"; char dataTobeSenttoGPS_1[] = "$PMTK220,100*2F\r\n"; After sending this, we will be getting GPS string after every 100ms, which is read by interrupt handler as:
extern "C" { void UART2_IRQHandle() { static char GPS_buffer1[100]; static int i_new=0; while(!(LPC_UART2-> LSR & 0x01)); GPS_buffer1[i_new]= LPC_UART2 -> RBR; if(GPS_buffer1[i_new]=='\n') { GPS_buffer1[i_new]='\0'; flag_received = true; if(xQueueSendFromISR(gps_queue1, &GPS_buffer1 , 0)) { } else{ } i_new=0; } else{ i_new++; } } }
- Sending data over CAN bus: In GeoController, we are using can1 for transmit and receive can messages. Latitude and longitude values are getting updated by GPS task using global structure. 'CAN send' function which is getting called every 100hz is using memcpy function to copy the structure data to CAN message and send over can bus.
gps_msg.msg_id = GEO_LOC_DATA_ID; gps_msg.frame_fields.is_29bit = 0; gps_msg.frame_fields.data_len = sizeof(gps_data_dec); memcpy(&gps_msg.data.qword, &gps_data_dec, sizeof(gps_data_dec)); CAN_tx(GEO_CNTL_CANBUS, &gps_msg, GEO_CNTL_CAN_TIMEOUT);
IMU
- Initialization: IMU is initialized using Singleton Class pattern. UART3 is being used for IMU interface with board.
readYawCommand{'#', 'f'} // string is used to get Yaw reading from IMU module. if(IMUInterface.sendYawReadCommand(IMUInterface.readYawCommand)) { // Waits for a response from IMU if(IMUInterface.getYawReadingString()) { CUSTOM_DEBUG("IMUTask : Read success"); } else { CUSTOM_DEBUG("IMUTask : Read fail"); }
The Yaw data we received from getYawReadingString() is used later to calculate heading value.
- Sending data over CAN bus: CAN1 is used for sending can messages. Following code shows, how the structure for IMU is filled by calling respective functions such as : calculateBearing(), getHeading(), calculateDistance() and then send over CAN bus.
void geo_send_heading() { can_msg_t geo_msg; geo_spd_angle geo_data; if(a == GEO_DATA_TO_SEND) { static imu& imu_handle = IMUInterface; // Handle to singleton IMU object geo_data.bearing = calculateBearing(current_checkpoint_data); // put bearing here geo_data.heading = imu_handle.getHeading(); if(geo_data.heading < HEADING_OFFSET2 && geo_data.heading >= 0) { geo_data.heading = 360 - HEADING_OFFSET2 + (geo_data.heading); } else { geo_data.heading = geo_data.heading - HEADING_OFFSET2; } geo_data.speed = speed_gps; geo_data.distance = (uint16_t)calculateDistance(current_checkpoint_data); } if(a == GEO_DO_NOT_SEND) { geo_data.bearing = 0; // put bearing here geo_data.heading = 0; geo_data.speed = 0; geo_data.distance = 0; } geo_msg.msg_id = GEO_SPEED_ANGLE_ID; geo_msg.frame_fields.is_29bit = 0; geo_msg.frame_fields.data_len = sizeof(geo_data); memcpy(&geo_msg.data.qword,&geo_data, sizeof(geo_data)); CAN_tx(GEO_CNTL_CANBUS, &geo_msg, GEO_CNTL_CAN_TIMEOUT); }
- Updating Firmware on IMU:
- For updating the firmware on IMU, we used FTDI basic breakout which uses USB mini cable to connect to PC. The board comes programmed with the 8MHz Arduino bootloader (stk500v1) and some example firmware that demos the outputs of all the sensors. UART connection are made to interface IMU with breakout board at 57600bps. We have modified the firmware in a way that we receive only the required information via UART.
- Connections between IMU and FTDI breakout :-
FTDI BREAKOUT RAZOR GND <--> GND CTS <--> CTS 3.3V <--> 3.3V TXO <--> RXI RXI <--> TXO DTR <--> DTR
The details are given at: https://github.com/ptrbrtz/razor-9dof-ahrs/wiki/Tutorial. Firmware provides the readings Yaw, Pitch and Roll readings. As in the project we only need the Yaw data, so firmware is been updated to provide only the Yaw readings.
- Sensor Calibration:
- Sensor calibration include calibrating the accelerometer, gyroscope and magnetometer. Sensor calibration in our project is done twice, once in the beginning and then at the end when all the boards are mounted on the car. As the magnetic field of motor can effect the gyroscope readings so we did the calibration again. The details can be found on the link given above.
Software Flow Diagram
Motor I/O Controller
Team Members:
Anuj Korat Dhruv Kakadiya
Motor & I/O Controller Schedule
SI No. | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 09/20/2015 | 09/27/2015 | Researching and ordering the LCD module to be used in the project | Completed | 9/27/2015 |
2 | 09/27/2015 | 10/05/2015 |
|
Completed | 10/05/2015 |
3 | 10/05/2015 | 10/12/2015 |
|
Completed | 10/12/2015 |
4 | 10/12/2015 | 10/30/2015 |
|
Completed | 11/5/2015 |
5 | 10/30/2015 | 11/12/2015 | Proposals related to speed controls and sensors for the same and integration of LCD module(with data display) | Completed | 11/12/2015 |
6 | 11/12/2015 | 11/25/2015 | CAN bus communication from motor and I/O controller to other boards | Completed | 11/15/2015 |
7 | 11/25/2015 | 12/15/2015 | Debugging issues during trial runs and testing out fault cases | Completed | 12/8/2015 |
Motor/IO Controller Software Design
Tasks
Task Name | Purpose |
---|---|
Period Init | Can bus initialization, Motor and LCD initialization |
Period Register telemetry | Register Motor_data can message and dc_speed counts for different speeds |
Periodic 1Hz Callback | Check can bus off and Print data on LCD |
Periodic 10Hz Callback | Drive car according to received data from Master controller |
Periodic 100Hz Callback | Receive CAN bus data |
Periodic 1000Hz Callback | Receive touch data from LCD and check RPM sensor |
DC Motor
Our car came with the motor that needed 7.4V of power supply to work. This motor has the power to run the car at a maximum speed of the 35mph.
Table3: DC Motor Duty Cycle v/s Speed |
DC motor is controlled with the help of three wires coming out of the ESC. These wires are VCC, GND and Speed control. The VCC line is not used as required voltage is directly given to the motor through a battery, via ESC. The GND line and Speed control lines are connected to the ground and PWM pin of SJOne board.
DC Motor Pin Connections To drive the DC motor, we are using pwm2 i.e. pin P2.1 of the SJOne board. We are using the in-build PWM generation function which requires two parameters, one is pin being used and the other being the frequency. To set the required duty cycle, the in-build set function is used. |
Servo Motor
Our car came with a waterproof digital servo motor. This motor works without ESC. We can directly control this motor by giving PWM signal from our SJOne board. The below table contains information about PWM (duty cycle) given to the motor and the corresponding turns taken by the car.
Servo Motor Duty Cycle v/s Turn |
Servo motor is controlled with the help of three wires coming out of the servo motor. The wires are VCC, GND and Direction control. The VCC is connected to the 3.3v. GND and direction control are connected to the ground and pwm pins of SJOne board.
Servo Motor Pin Connections We control the Servo motor using pwm1 i.e. pin P2.0 of the SJOne board. We configure the PWM pin using an in-build function which requires two parameters, one is the pin that we are using and the other is the frequency of the pwm. To set the duty cycle, in-build set function is used in which we are passing the duty cycle at which we want servo motor to work. |
Motor PWM Singleton implementation
I/O Software Design
The I/O Software is based off of two tasks: The Event Handler Task and the RX Task.
Event Handler Task (High Priority):
This Task receives any immediate messages sent from the uLCD, processes the message, and sends the message to the CAN BUS.
This task enables the system to: Turn On/Off the Vehicle and Change Vehicle Modes.
RX Task (Low Priority):
This task receives all messages from the CAN BUS, and outputs message data onto the uLCD
High Level IO Software Logic -- Event Handler Task Logic -- RX Task Logic
Different screens on LCD
The contents displayed on LCD were well thought of according to its application in our project. We wanted to test the sensor and the magnetometer readings while we were testing out car along with testing the algorithm of navigation. This would enable us to not connect the LPC controller with a Laptop to check and verify readings. The LCD we bought is from 4D systems and is very convenient and efficient to use. It has its own software which enables us to work in 4 different modes. We chose the mode which gave us different tools to build the compass, buttons and the angularometer. A bluetooth to serial converter is used to program the LCD with the software. We used the tools (that came with the LCD Module), to picturize our LCD screens. We loaded the program into LCD's memory card. The program that we burned on LCD will use the data bytes we send from our microcontroller and will print those bytes appropriately on different elements that we had created. For example, there are 360 degrees values to show on angularometer. The microcontroller will give a value from 0-360 based on the CAN frame which consists of car speed, heading and bearing values broadcasted by the Geo controller. In this way, almost every parameter being exchanged on the CAN bus of the car is displayed.
The LCD Software
The following is the link to the main page of the LCD. It contains everything you need to know to run this LCD and run it to the highest feature. It has the datasheet as well as the info regarding the software too. Go through the software datasheets as well as we will need that software to run the LCD initially. The LCD accepts any data from our microcontroller only if it is programmed that way by the software.
Next link is to the to the collection of go through materials for each every object the LCD uses.
So you know all the features of the LCD now and also have downloaded the Software, now what? The best and the easiest mode of working is the ViSi-Genie. Its fast, efficient and powerful. With Visi-Genie, you can just drag and drop tools you wanna use on your LCD. Lets take an example.
Now, if you have gone through the software datasheets, you will be already have accustomed with the software and its fun too. Select your tool accordingly your requirement. Be creative. We needed to show magnetometer values, from 0 to 360 in order to debug whether the compass is pointing towards north exactly or not. So we used an angularometer under the Gauges tab. It will have all the properties associated with the object. You can test each of them. Now, the data sent from the microcontroller will be directly printed on the LCD to its position on the angularometer. In this way, we can easily know the direction of True North with the help of LCD. Alon with this there are some strings used on LCD which shows longitude, lattitude, etc. This string is also sent from the microcontroller. When you are done with the tools, put a memory card with a maximum of 2 GB of memory into your LCD and connect it serially to your PC. USB to serial converter is to be used here. Burn the software image onto your LCD. At this point, your LCD is programmed to show all the images and the tools and is ready to accept all the data from the controller and print them on itself. So now we have got to do, is only connect the controller with LCD and send data bytes with help of UART.
The connection is done in following way:-
LPC -> LCD TXD2 -> RX RXD -> TX VCC -> VCC GND -> GND
The format overhead for sending data is of 4 bytes. If you want to set the angularometer, you have to give 6 bytes via UART,
Byte1 - Event byte Byte2 - Object type Byte3 - Object number Byte4 - Data byte 1 Byte5 - Data byte 2 Byte6 - Check sum
The following is a code snippet to print a string on LCD
Similarly, when you touch any of the input tool on LCD, it will send 6 bytes in the same format to your microcontroller(Yes! It is touch screen). So, in this way you will know, what object you have set and to what value. For example,
There are some input tools given h=here to change the factor for PWM operation. This really comes in handy when you are testing your car in the field and just to increase your motor's speed you have to change your code and flash your controller again and again. Instead have your LCD set the factor in as simply as this way. When you touch the the left or right arrow, the LCD will send the object's identity to the controller. The controller will check this and it will then set the globally declared PWM factor which changes it in real-time and then print that value on the string object between. See, told you to be creative!. This truly makes your LCD input and output together.
Master Controller
Team Members:
Hemanth Konanur Nagendra Akshay Vijaykumar
Master Controller Schedule
SI No. | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 10/10/2015 | 10/20/2015 |
|
Completed | 10/20/2015 |
2 | 10/21/2015 | 10/31/2015 |
|
Completed | 10/25/2015 |
3 | 10/26/2015 | 11/01/2015 |
|
Completed | 11/01/2015 |
4 | 11/10/2015 | 11/20/2015 |
|
Completed | 11/20/2015 |
5 | 10/21/2015 | 11/30/2015 |
|
Completed | 11/24/2015 |
6 | 12/01/2015 | 12/07/2015 |
|
Completed | 12/12/2015 |
7 | 12/08/2015 | 12/15/2015 | Extensive testing and smoothing out speed, turning, etc | Completed | 12/16/2015 |
The Master Controller receives obstacle information from the Sensor Controller, navigation data from the Geo Controller and routing information from the Bluetooth Controller, collates all this information and provides driving directions to the Motor Controller.
Design
Hardware Design
The diagram shows the hardware connections for the Master Controller.
Pin Connections
Line Item# | Node A Source | Node A Pin | Node B Source | Node B Pin | Description |
---|---|---|---|---|---|
1 | 3.3V Power Supply | 3.3V | SJOne Board | 3V3 | SJOne Power |
2 | 3.3V Power Supply | GND | SJOne Board | GND | SJOne Ground |
3 | CAN Transceiver | CAN Tx | SJOne Board | P0.1 (Tx) | SJOne - CAN Tx |
4 | CAN Transceiver | CAN Rx | SJOne Board | P0.0 (Rx) | SJOne - CAN Rx |
5 | CAN Transceiver | CAN 3.3V | 3.3V Power Supply | 3.3V | SJOne - CAN Power |
6 | CAN Transceiver | CAN Ground | 3.3V Power Supply | GND | SJOne - CAN Ground |
7 | CAN Transceiver | CANL | CAN BUS | CANL | CANL to CAN BUS |
8 | CAN Transceiver | CANR | CAN BUS | CANR | CANR to CAN BUS |
Control Flow
On boot-up, Master Controller first attempts to sync with all the other controllers through a power-up sync and acknowledgement handshake mechanism. Once sync is established with all the controllers, it periodically monitors the heart-beat signals from all the controllers till the end of power cycle. If any controller goes out of sync, the master requests that controller to reset itself.
The Master Controller now enters the ‘stopped’ state where no driving takes place. It continuously monitors the CAN bus for any routes from the Bluetooth Controller. Once all the navigation check points have been received, the Master Controller starts driving the car by directing the Motor Controller based on the Geo controller data. While driving, the Master Controller continuously listens for the obstacle data from the Sensor Controller and avoids any obstacles, if necessary. Once obstacle avoidance has been completed, Master makes any necessary course corrections and proceeds towards the destination as per the route.
The flowchart depicts the entire sequence of events involved in driving the car from a source to destination point.
Communication between Controllers
Power-up Sync and Acknowledgement
Once master boots up, it continuously monitors the CAN bus for a “Power up Sync” message from each of the other controllers. Once it receives the Sync message from all the controllers it acknowledges all of them at once by sending the “Master Sync Ack” message. This should prompt the other controllers to spawn their periodic tasks and start their respective functionalities.
Heart Beat Implementation
After sending the ACK message the master proceeds to spawn its own periodic scheduler and starts monitoring the heartbeat signals from all the controllers at a rate of 1Hz.
Every 1Hz, all the controllers are expected to send their respective “Heart-beat” message over the CAN bus. If this message fails to arrive, the master controller will wait for a specific period of time for the other controller to sync again. The sensor controller and motorIO controllers are very critical components for driving the car. So, they are not allowed to skip any heart-beats. The other controllers have varying thresholds of wait time, allowing them to sync with the master again. Once the threshold time is crossed, the master controller issues a “Reset” message for the controller that went out of sync. The receiving controller is expected to reset and sync again at this point.
If the sensor controller or motor controller go out of sync, the master stops issuing driving directions to the motorIO controller, hence stopping the car.
Data Communication
The master controller performs the following data transactions over the CAN bus.
Bluetooth controller signals to the master controller that a new route has been requested from the Android application through “Check-Point Send” message. In this message, the Bluetooth controller also specifies the number of check-points that are present along the route. The master acknowledges this signal through “Check-point Request” message. The Bluetooth controller starts sending the check-points periodically, at 10Hz, after it receives the ack. The master stores all these check-points in an array and switches to navigation mode.
In navigation mode, master controller issues the next immediate check-point to the Geo controller through “Geo location update” message and expects the current heading, current bearing, current speed and current GPS location information from the Geo controller with respect to this new checkpoint. Master controller continuously calculates the distance between the current GPS location and the current checkpoint location to determine if the checkpoint has been reached. Once reached, the next checkpoint co-ordinates are issued to the Geo controller. This cycle is repeated till the destination has been reached.
All through the navigation mode, master controller directs the motor controller to drive (speed and direction to turn) based on heading and bearing information from the Geo controller. The obstacle information is also being continuously received from the sensor controller. If an obstacle is detected, the master controller stops navigating to the checkpoint and avoids the obstacle. Once obstacle has been avoided the master goes back to navigation.
Driving Algorithm
Overview
Driving algorithm has two parts to it. One is the obstacle avoidance algorithm and the other is the navigation algorithm. Obstacle avoidance has a higher priority. Navigation algorithm drives the car as long as no obstacles are present.
Obstacle Avoidance Algorithm
The primary obstacle avoidance algorithm is based on the front three sensors. The algorithm is based on the truth table below. The near obstacles have higher priority than obstacles in the mid range, which has a higher priority than the obstacles in the far range. The tables below depict the action taken by the master controller when obstacles are in the near and mid-range. A ‘1’ in the table represents that a particular sensor has an obstacle within the range being evaluated. A ‘0’ represents that a particular sensor has no obstacle within the range being evaluated. The last two columns show the command sent from the master controller to the motorIO controller.
Obstacle avoidance in the Near range
Front Left Sensor | Front Center Sensor | Front Right Sensor | Motor Speed | Motor turn |
---|---|---|---|---|
0 | 0 | 0 | Normal | Straight |
0 | 0 | 1 | Slow | Hard Left |
0 | 1 | 0 | Stop | Straight |
0 | 1 | 1 | Slow | Hard Left |
1 | 0 | 0 | Slow | Hard Right |
1 | 0 | 1 | Stop | Straight |
1 | 1 | 0 | Slow | Hard Right |
1 | 1 | 1 | Stop | Straight |
Obstacle avoidance in the Mid range
Front Left Sensor | Front Center Sensor | Front Right Sensor | Motor Speed | Motor turn |
---|---|---|---|---|
0 | 0 | 0 | Normal | Straight |
0 | 0 | 1 | Slow | Slight Left |
0 | 1 | 0 | Normal | Straight |
0 | 1 | 1 | Slow | Slight Left |
1 | 0 | 0 | Slow | Slight Right |
1 | 0 | 1 | Stop | Straight |
1 | 1 | 0 | Slow | Hard Right |
1 | 1 | 1 | Stop | Straight |
As stated before, the Master Controller receives all the necessary parameters for navigation viz, current GPS co-ordinates, heading and bearing from the Geo-Controller. The heading and bearing are angles that are measured from 0 degrees to 360 degrees from the true North. Heading specifies the direction in which the car is currently oriented in. Bearing specifies the direction in which the car has to be oriented so as to reach the next check point. The current navigation algorithm divides the entire 360 degree orientation space of the car into 30 zones of 12 degrees each. The difference between the bearing and heading values is used to correct the direction of the car. This correction value would lie between 0 degrees to 360 degrees, falling into one of the 30 zones. As seen in the diagram, If the correction lies between 0 degrees to 12 degrees, the car should travel straight at normal speed. If the correction lies between 97 degrees to 180 degrees, the car should take a U-turn from the right direction at a slow speed. Similar behaviors of the car in terms of the direction and speed of movement of the car are specified for each zone and are sent as commands to the Motor Controller.
A few examples to test the correctness of the algorithm are discussed. If the heading is 50 degrees and the bearing is 90 degrees, the correction is 40 degrees. The behavior specified for the zone in which this correction will fall into is for the car to perform a hard right turn at slow speed. Similarly, if the heading is 70 degrees and the bearing is 10 degrees, the correction is -60 degrees. Converting this to a value in between 0 degrees and 360 degrees, we have 300 degrees ( 360 degrees - 60 degrees ). The behavior specified for the zone in which this correction will fall into is for the car to perform a slight left turn at normal speed.
Distance Calculation
The distance is calculated as shown in the figure below.
The master controller continuously monitors the distance of the car from the next checkpoint. We issue the next checkpoint co-ordinate when the distance is less than or equal a threshold value. The current threshold has been set to 3m after performing tests with a range of threshold values.
LED and 7-Segment Display Status
LED 1 - ON or OFF when the START or STOP command is issued from the Bluetooth Controller/Mobile Application.
LED 2 - Toggles when in Obstacle Avoidance Mode. OFF when in Navigation Mode.
LED 3 - ON if controller heartbeats are missed. OFF when all controllers are in sync.
LED 4 - ON when an error in CAN communication occurs. Turns OFF when the Errors are handled.
7-Segment Display - Displays the current checkpoint that the car is navigating to. When the destination is reached, the number '99' is displayed.
Bluetooth/Bridge Controller
Team Members:
Anush Shankar Aditya Devaguptapu
Bluetooth/Bridge Controller Schedule
SI No. | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 09/20/2015 | 09/30/2015 | Getting familiarized with Android SDK, Java, Bluetooth API and Google Maps API | Completed | 09/30/2015 |
2 | 09/31/2015 | 10/10/2015 |
|
Completed | 10/10/2015 |
3 | 10/10/2015 | 10/22/2015 |
|
Completed | 10/22/2015 |
4 | 10/22/2015 | 10/30/2015 | Interfacing bluetooth module to SJOne board through UART and receive data on SJOne board sent by the bluetooth application | Completed | 11/05/2015 |
5 | 10/30/2015 | 11/10/2015 | Relay commands and CAN messages from SJOne to android application and test correctness of data | Completed | 11/15/2015 |
6 | 11/10/2015 | 11/22/2015 | Performing correct routing between source and destination, have a complete working application, basic testing of application and bridge interface | Completed | 11/22/2015 |
7 | 11/22/2015 | 12/15/2015 | Extensive Testing of application during final phases, modifying code in cooperation with other teams and optimization of android application | Completed | 12/13/2015 |
Bluetooth Controller
The Bluetooth Controller is responsible to help the RC car navigation by providing it with route information between source and destination as selected on the Android application. It communicates with the Android application over Bluetooth channel to obtain the route and way-point data between two points on the google map. The route and way-point information once received is parsed to get latitude and longitude for all way-points. This information is then communicated to the Master Controller via CAN bus.
HC-06 Bluetooth Module
The HC-06 is a bluetooth controller with slave only configuration used to communicate to and from a master Bluetooth module. The master Bluetooth module is capable to initiating a connection with other Bluetooth module, while slave is not able to do that. The slave can only communicate with the master module over a connection established by the master. The HC-06 by default is in slave configuration as per factory settings.
Some of the features of HC-06 which make it apt for the RC car are as follows:
- Can work at the low voltage (3.1V~4.2V). The current in pairing is in the range of 30~40mA. The current in communication is 8mA.
- Has a 2.4GHz digital wireless transceiver.
- Small (27mm×13mm×2mm)
- Peripherals circuit is simple.
- Low power consumption
- Has high-performance wireless transceiver system
- Low Cost
Bluetooth Controller Hardware Design
Bluetooth Controller Pin Connections
Line Item# | Node A Source | Node A Pin | Node B Source | Node B Pin | Description |
---|---|---|---|---|---|
1 | Power Supply | 3.3V | SJOne Board | 3V3 | SJOne Power |
2 | Power Supply | GND | SJOne Board | GND | SJOne Ground |
3 | CAN Transceiver | CAN Tx | SJOne Board | P0.1 (Tx) | SJOne - CAN Tx |
4 | CAN Transceiver | CAN Rx | SJOne Board | P0.0 (Rx) | SJOne - CAN Rx |
5 | CAN Transceiver | CAN 5V | Power Supply | 5V | SJOne - CAN Power |
6 | CAN Transceiver | CAN Ground | Power Supply | GND | SJOne - CAN Ground |
7 | CAN Transceiver | CANL | CAN BUS | CANL | CANL to CAN BUS |
8 | CAN Transceiver | CANH | CAN BUS | CANH | CANH to CAN BUS |
9 | Bluetooth Module | TXD | SJOne Board | RXD3 | SJOne RX3- Bluetooth module TXD |
10 | Bluetooth Module | RXD | SJOne Board | TXD3 | SJOne TX3- Bluetooth module RXD |
11 | Bluetooth Module | Bluetooth module VCC(3.3V) | Power Supply | 3.3V | Bluetooth module - Power supply 3.3V |
12 | Bluetooth Module | Bluetooth module GND | Power Supply | GND | Bluetooth module - Power supply GND |
Control Flow
On boot-up, Bluetooth Controller first attempts to sync with the Master controller through a power-up sync and acknowledgement handshake mechanism. Once sync is established with the Master Controller, the Bluetooth controller periodically sends heart-beat signals to master controller till the end of power cycle. If any Bluetooth controller goes out of sync, the master requests the controller to reset itself.
Once all initial handshaking procedures are completed and heart beat signal is established, the Bluetooth Controller waits for data from the On board HC-06 Bluetooth module on the UART port. When Bluetooth connection is established between the Android application and the On board HC-06 Bluetooth controller, routing data is sent from the Android app to the SJOne board. The SJOne board receives the data on UART port via interrupts and parses the data to extract 6 point precision floating point values for each way-points latitude and longitude. The way-point latitude and longitude is stored in a array to be sent out on CAN bus.
Once all way-point data is parsed and ready, the SJOne board first sends out the number of way-points to the master controller and waits for acknowledgement from the master controller. One reception of the acknowledgement from the master and intent to receive the way-point data, the data is sent on the CAN bus periodically till all the data is exhausted.
Communication between Bluetooth and Other Controllers
Power-up Sync and Acknowledgement
Once Bluetooth controller boots up, it continuously sends "Power up Sunc" on the CAN bus to the master using "BLUETOOTH_SYNC_ID" can message id. The controller then polls on the sync function to receive an acknowledgement from the master towards "Power on Sync". Once an acknowledgement is received from master with message id "MASTER_SYNC_ACK_ID", the Bluetooth controller starts the FreeRtos scheduler. Only after this will all tasks run on the controller.
Heart Beat Implementation
Once Bluetooth controller starts the scheduler, it starts sending out heart beat messages on can bus directed towards the master controller using message id "BLUETOOTH_HEARTBEAT_ID" every 1 Hz. If the master does not receive heart beat message it asks Bluetooth controller to reset.
Data Communication
The Bluetooth controller performs data transactions over the CAN bus with the master controller and Geographical controller. The Bluetooth controller receives the geo coordinates every 1 hz using "GEO_LOC_DATA_ID" to get current car location and send it to the android application for dynamic location update. Bluetooth controller signals to the master controller that a new route has been requested from the Android application through “CHECKPOINT_SEND_ID” message id. In this message, the Bluetooth controller also specifies the number of check-points that are present along the route. The Bluetooth Controller waits on master's acknowledgement through “CHECKPOINT_REQ_ID” message id. The Bluetooth controller starts sending the check-points periodically, at 10Hz, after it receives the ack. Once all the way-points are sent to the master, the Bluetooth Controller goes to listening to UART interrupts for any changes in the route.
Flow Chart
The flow chart for the Bluetooth Controller is as follows:
Android Application Design
Problem Definition
At the end of the day, an autonomous vehicle is built so as to usher in a new era of transport where the user need not be concerned with driving the vehicle. With this basic idea in mind, we can thus define our problem- how does one communicate with an autonomous vehicle to perform the tasks he/she desires? On further contemplation, it could even be argued that we are able to accomplish the task of navigating from source to destination in a normal vehicle because the user is able to manually control the vehicle. We will hence require an interface by means of which we can specify a source and a destination. With the ubiquity of smart phones, it makes perfect sense for us to leverage the availability of the Android platform to make an application that would augment the user’s ability of accomplishing objectives with the autonomous vehicle.
Design
The objective of the Android App is to be able to let the user control the car by issuing commands from a smartphone- the most fundamental commands being the ability to issue a source and a destination for the Car to traverse. Providing the car with autonomy ensures that we need to be able to specify location information to the car in a form that it can understand. We will thus use Google’s comprehensive mapping solution to look up places on the map. We shall also use their services to get the best route available between the source and the destination. Google’s Android OS is a very popular OS for smartphones. Its proliferation in the smartphone market, very comprehensive documentation and open-source nature make it a natural choice for the platform on top of which the application will be developed. Android Studio is Google’s IDE for developing applications on the Android platform. Their Maps API will be used to implement a Map fragment and to specify travel points while the Directions API works in the background to provide a route from source to direction. The user will be provided with buttons to connect with the car, to issue Start/Stop Commands, to send a route if a travel needs to be performed and to determine the location of the car.
Implementation
App Template and Using Google Maps within an App
Android Studio comes with some default templates which lets the user have a basic app up and running within no time. The project has a .java file to program the logic of the app while the user interface can be modified using the .xml(extended markup language) file. The user can test the app using the in-built emulator or by running it on an Android phone. To use Maps within your application, you will first have to get a API key on Google’s Developer Console online. This API key lets Google track statistics related to the app usage. If the Map loads when the App starts up, then its a sign that you’ve successfully implemented a Map fragment.
Using Maps and Implementing the Directions API
A Maps Fragment comes with several features that let the user specify input to the App. We use Markers (Pin shaped images) to denote locations on the map. Every Marker on the map has its own latitude and longitude which is a necessary value for calculating a route. We essentially want to calculate a route from a source, which in this case, is the location of our car. The CarLocation Button gets us the location of the Car and places a marker on the map at the location of the Car. The App has a OnClickListener function in the background, waiting for a tap input from the user. This tap places a marker that denotes the destination that the user, or in this case, the car will navigate to. On placing the destination marker, the Directions API calculates a route between the source and the destination based on how the parameters for the API are defined. The Directions API returns intermediate points (with latitudes and longitudes of their own) that form a route between the source and the destination. The Polylines function defined within the map can be used to plot a line that connects these points from the source to the destination.
Using Bluetooth and Bluetooth API
Android provides a robust and well defined Bluetooth API as part of application development support. The API provides functions to query devices, pair with devices, connect to devices and send/receive data. In our application pairing, connection and send/receive API functions are used to talk to HC-06 Bluetooth module on the RC car. The application has a bunch of buttons at the bottom which are used to establish Bluetooth communication and used to control markers on the Google Map. The functionalities of the Buttons are as follows:
SI No. | Button | Functionality |
---|---|---|
1 | ON | User is prompted to Turn on Bluetooth device on the phone. User can "allow" or "deny" the request. Application displays message if no bluetooth support on phone. |
2 | CONNECT | Establishes a communication channel with a slave Bluetooth. Connection is done to a Predefined Bluetooth MAC address. |
3 | DISCONNECT | Disconnects communication channel with an already connected Bluetooth module |
4 | START CAR | Sends string 0 over Bluetooth channel to indicate to the SJOne Board start of car. |
5 | STOP CAR | Sends string 0 over Bluetooth channel to indicate to the SJOne Board to kill the car(Wireless Kill switch). |
6 | CLEAR | Clears markers on the Google Map. |
7 | CAR LOC | Places a marker on Google Map based on cars coordinates received from the HC-06 Bluetooth module on-board the car. |
8 | SEND ROUTE | Send route from source to destination selected on map after filtering way-points. |
Our Modifications
- The number of points returned was filtered to obtain an accurate route with sufficient points, enough to not overwhelm the SJOne Board during processing.
- The first point was ignored because it nearly coincides with the location of the car and it made sense for the car to ignore this first point in order to preserve time and power.
- We also place a limit on the maximum number of points that can appear. For a real world scenario, this limit wouldn’t make sense. However for a tiny RC Car which runs on battery to possess so much information and not be able to navigate through vast paths, it wouldn’t make sense for so much information to be filtered.
Workflow
On starting the app, the user first uses the ON button to switch the phone’s bluetooth On. The next step is to Connect to the Bluetooth module that is present on the RC Car. This is accomplished using the Connect button, which toasts a “Connected” notification once this connection happens. The Start Car Button then polls for the location of the car and places a marker on the map. The User may then tap the map and place the destination marker. Placing the destination marker triggers the Directions API to create a route and plot it from the location of the Car till the Destination Marker. The Send Route button sends the route to the controller on the car which lets the car travel from source to destination.
Overall System Optimizations and fail safe conditions
We have taken all fail safe conditions into consideration, so suppose if any controller will not work as desire or will work in very bad way then how our car should respond to that condition?
- If sensor controller is not working properly and sensor CAN messages are not on bus then master controller will detect that and suddenly after some number of missing counts it will issue stop motor command to motor controller.
- At motor controller side as we have connected RPM sensor to increase/decrease speed according to actual real time feedback from rotations of wheel, is not working properly or we can consider that RPM sensor is being dead then in that case normal motor algorithm will detect that RPM sensor count is zero only if my motor actually rotates or not. So in that condition our optimized algorithm was detecting if RPM sensor count is zero for continuous 3 seconds then there is something wrong happening with RPM sensor so Motor controller will immediately send stop command to motors.
- Suppose due to steep slope my motor speed gets increased too fast and then suddenly flat surface is coming then in that condition if we will not optimize our driving algorithm then motor will run away very fast then normal speed, so remove that type of condition we have taken difference of RPM sensor counts in interval of each second. So if that difference is too high then decrease speed at very high factor and speed is too slow then vice and versa. So it is basically like put RPM sensor count difference into PID(Proportional, Integral, Differentiation) algorithm to make out very smooth navigation.
- If bluetooth controller will be out of range after established connection between bluetooth controller and mobile application then it results into some undesired condition like we will not have any control of car in our hand. So to resolve this problem we were continuously sending some heartbeat commands from bluetooth application to controller in each second of interval after establishing connection. So if bluetooth controller will not get heartbeat command from Android application then it will send motor stop command to master and master will forward that command to Motor controller so we can stop motors immediately.
- At Geo controller side if GPS is not stabilized its values and still someone has issued navigation command from bluetooth application then Geo controller will give longitude and latitude as zero only so master will know that it's wrong values so master controller will not issue start command to motors.
- In Geo controller we were not getting just simple reading of compass for heading calculation but we were taking reading of yaw angle from gyrometer in reference of magnetic axis of earth with subtracting necessary pitch of car with Kalman filter implementation. So we were getting very smooth and exact angle in any condition like if car navigates on any type of slope(up/down).
Testing & Technical Challenges
Issue #1 (Motor I/O)
The Motor I/O controller is the only controller which accepts all the CAN messages sent on the bus. This is because the LCD needs to print values from the different controllers like Sensor controller, Master controller and Geo controller. It was decided mutually to use the CAN transmit receive function on the bus at same speed, which was 100 Hz. As our controller had to receive more than one frame in one cycle of 10 ms, the hardware CAN receive queue kept on enlarging. We were dequeueing at a slower speed than what was required. So, the rate at which the data was read by the software was not fast enough when compared to the hardware buffering the data. This slowed down our operation. So, a tip for the future - always make sure that you receive the CAN data frame at the same speed as the transmitter's and dequeue your CAN receive queue completely so as to make sure you are getting all the latest data. Also, make sure to remove all the debug prints in the periodic scheduler running at 100 HZ frequency or more. We could put Telemetry to good use here.
Issue #2 (Project Hardware)
We decided to establish CAN communication across different controllers at an early stage in the project. In order to do so, we rushed into soldering the CAN bus on the PCB. At a later stage, we realized that we had done this in a compact manner. And now, arranging all the LPCs together with the jumper wires connecting to the CAN bus made it hard to debug issues. We had to re-arrange the whole hardware, strictly according to the soldered CAN bus which made the task a little inconvenient. Lesson learnt here was that, when it comes to hardware, always discuss with your teammates about all the aspects of arranging your car and keep some space for future use.
Issue #3 (Project Hardware)
Perhaps the most common problem for all the groups, the car crashed in almost every run during the initial testing phases. Even if you think your code is perfect and your car will do exactly what you think it should, it will crash for sure at start and may wreck something here or there (Trying to save your car and not disappoint you!). Install a kill switch at the earliest that will instantly stop the car whenever you want. At least implement a kill button in your Mobile App. Also, try to cover the front of your car with multiple layers of cardboard, thermocol or sponge material which will help the car to absorb the shock.
Issue #4 (Geo controller software)
- Geo controller was crashing randomly. After careful observation, we figured that the problem was happening because of too many log messages written to SPI flash. The memory was full with log errors. Clearing flash and removing unnecessary logging from the code helped solve the problem.
- While initially testing IMU in raw data mode, the module was providing improper data values. We had to calibrate the Gyrometer and Magnetometer to get exact angles with precision of +/- 2 degrees. Even after this, the magnetometer's readings were changing when any soft/hard iron object was taken near the sensor. In order to remove electromagnetic interference generated from DC motor, we had to place our IMU far from DC Motor.
- To ensure that the data values provided by the IMU were accurate, we calibrated IMU sensors with the help of calibration Software provided by manufacturer.
- Sometimes the string received from GPS module contains void data. To get rid of this invalid data, we started using UART interrupts and receiving all data at once. This is later sent to the GPS task via a Queue. Here, the GPS tasks validates the data and sets GPS structure to NULL in case data is invalid.
- In the beginning, we were not using the volatile keyword due to which, there was no update in the string we read from Queue in the GPS task. By using volatile keyword on the variable used inside the Interrupt handler, we avoided the compiler optimization.
Issue #5 (Motor Controller software)
- While initializing ESC(Electronic Speed Controller), we didn't know the exact sequence to be sent for initialization of DC motor. We tried to figure out the required sequences by using an Oscilloscope. We used this to hack the ESC for the pulse width and frequency, the DC motor parameters used to drive the car in Forward and Reverse direction. We figured out the initialization sequence by trial and error.
- The main point was to give at least a 20ms(miliseconds) time delay to send each pulse. Otherwise, if we send pulses less than 20ms, the pwm pulse value will not be set properly as DC pwm's frequency itself was 20ms(Frequency - 50Hz).
- We had issues driving the DC motor. The ESC would receive the PWM values that we were setting and drive for a short period of time. Then the motor would stall. We had individual PWM objects for DC and Servo motors. There was no way for us to initialize this object in one place and use it in other places. Declaring global or static object of this class did not help. It was being destroyed at some point. Making the PWM class instance as a singleton solved this issue. The lesson here is, PWM generator is a hardware resource available for us and should be initialized only once before being utilized. Singleton classes provide the necessary means to accomplish the same. Moreover, singleton also forces the existence of only one instance of the class just like how there is just one instance of the hardware resource on board.
Issue #6 (Sensors using Interrupt on the 4-pin sensor's Echo pin)
Sequential Pinging
- Initially, we tested the code for front, right and left 4-pin ping sensors. We got satisfactory readings for all the 3 sensors. However, the distance value measured were unusually large at some angles. We concluded that at some point, the echo pin was not reaching the low edge while we were triggering the next sensor. This was affecting the distance value calculated. We solved this issue by checking for the logic level of the echo pin, and proceed with further triggering only when the echo pin was low.
- Once this was resolved, the obtained output readings matched the expected output readings. All the zones and distance values were a match for the obstacle provided for the sensors.
Inline resistors
- The testing was a success on the breadboard. When we loaded the code onto the sensor controller on the car, the readings were inaccurate. We realized, on the breadboard we tested using inline resistors between the echo pin of the sensor and the GPIO pin(set as input pin to the board) of the SJOne board. Once we introduced the inline resistors while testing on the sensor controller, we obtained accurate readings. Thus, we solved the issue of inaccurate readings and unresponsive input to the board by introducing the 1K inline resistors for each echo pin of the three sensors. If you plan to work with the ping sensors, do us the inline resistors as it was very obvious with the readings we experienced, inline resistors made a huge difference.
Issue #7 (Sensors using Interrupt on the 3-pin sensor's Echo pin)
- Once the interrupt algorithm worked for 4-pin sensors, we implemented the same algorithm for 3-pin sensors with changes in the configuration of input and output pins. We tested for a single 3-pin sensor and obtained readings were accurate. Later we introduced the second sensor for testing the algorithm. This created an issue. The front sensor was being triggered and the same pin was configured as echo pin. Reading was obtained on the echo pin of the front sensor. In the next cycle, the index was incremented to the next sensor. The algorithm was stuck on the second sensor triggered. Each time the function was called from the periodic callback the index did not increment as required by the algorithm. We suspected the echo pin of second sensor was not going low at the required time, which would increment the index according to the algorithm. We could not debug this issue in time for demo. We hope to debug the issue and get the algorithm running for 3-pin sensors too.
Conclusion
Altogether, we really enjoyed this class and working on this project. We faced many difficulties throughout the semester including understanding the requirements for the project, planning and executing it. But each time we faced a problem, we got to learn something new. All of us were stuck at our individual tasks at some point or the other, but we helped each other and finally made our project up and running. Not to mention, Preet was always easily approachable.
The project functioned as intended by our design. -> Sending a source, a destination and checkpoints between them, from Android app to the Bluetooth controller -> Sending these co-ordinates to the Geo controller through CAN bus -> Calculating heading and bearing at Geo and sending those values back to Master Controller -> Sensor controller sending its readings from sensors to Master Controller -> Directing the Motor I/O Controller based on the Obstacle Avoidance and Navigation algorithms -> Motor I/O controller driving the car and displaying car parameters on LCD for debugging.
Some tasks were very tough to debug. But if you really put your mind into it, you will be able to see the solution right in front of you. One final tip - Do not get frustrated. Always have a bigger picture in mind! We have uploaded everything regarding this project on this page. We honestly appreciate your interest in reading it. Thank you and best of luck!
Project Video
Project Source Code
References
Acknowledgement
We would like to thank Preet for teaching the concepts in a very practical sense in the class. It really helped us in the implementation and the testing of the project. We would also like to thank Rutwik who was always ready to help and who also gave us many ideas of what we can do in the project. All the team members worked really hard towards this project and this motivated us in accomplishing the team goals every week. All in all, a great course which required us not to memorize, but to think in a practical way. Thanks again Preet to introduce this course to the major. This will surely be a major benefit in building our career!
References Used
[1] Preetpal Kang's lecture notes of CMPE 243, Computer Engineering, San Jose State University, Aug-Dec 2015. [2] Fall 2014 Wiki Projects [3] LPC1758 User Manual [4] Parallax Ultrasonic Sensor [5] CAN Transceiver [6] Razor IMU [7] Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates - Version 3 [8] GPS data calculation accuracy [9] GPS Longitude Latitude distance calculator [10] Calculate distance between two points [11] GLCD with Touchscreen [12] HCSR04 Ultrasonic Sensor [13] GPS Datasheet [14] Learning Git Tutorials