Difference between revisions of "F17: Optimus"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Bridge Controller Software Implementation)
(Motor Controller)
Line 573: Line 573:
 
Issues
 
Issues
  
=== Motor Controller ===
+
== Motor Controller ==
 +
 
 +
=== Design & Implementation ===
 +
The Motor Controller is responsible for the Movement and Steering action of the Car. It includes two types of motors, DC motor for movement and DC Servo motor for Steering. The Motor has an inbuilt driver called ESC (Electronic Speed Control) Circuit used the manipulate the speed and steering of the Car. It has a PWM input for both Servo Motor and DC Motor. We are using RPM sensor to take the feedback from the motor to monitor the speed.
 +
 
 +
=== Hardware Design ===
 +
[[File:CMPE243_F16_SnF_MotorHardwareInterface.png|frame|left|200px|Motor Hardware Schematics]]
 +
 
 +
{| class="wikitable"
 +
|-
 +
! scope="col"|
 +
! scope="col"| SJOne Pin Diagram
 +
! scope="col"|
 +
|-
 +
! scope="col"| Sr.No
 +
! scope="col"| Pin Number
 +
! scope="col"| Pin Function
 +
 
 +
|-
 +
! scope="row"| 1
 +
| P0.0
 +
| CAN RX
 +
 
 +
|-
 +
! scope="row"| 2
 +
| P0.1
 +
| CAN TX
 +
 
 +
|-
 +
! scope="row"| 3
 +
| P2.0
 +
| Servo motor
 +
 
 +
|-
 +
! scope="row"| 4
 +
| P2.1
 +
| DC motor
 +
|-
 +
! scope="row"| 5
 +
| P2.5
 +
| Speed Encoder
 +
 
 +
|}
 +
 
 +
 
 +
<br clear=all>
 +
 
 +
*'''Hardware Specifications'''
 +
 
 +
[[File:CMPE243_F16_SnF_DCMotor.png|thumb|left|200px|DC Motor]]
 +
=====1. DC Motor =====
 +
Our car came with Titan 12T 550 brushed motor and waterproof ESC. The ESC drives the DC motor based on the Pulse Width modulation (PWM) applied to it. The power supply required for this motor is 8.4 V. Maximum speed of upto 30mph can be achieved. The rotational speed is proportional to the EMF generated in its coil and the torque is proportional to the current.The main connection pins driving the motor are VCC,GND and the Control pin (PWM). The pin P2.1 of SJ-one board is connected to supply the required PWM to the motor.
 +
The basic working principle of DC motor is illustrated in the following figure :
 +
Since the preprogrammed controller has to be replaced by using our design ,the DC motor is then tested with Digital Oscilloscope for getting the frequency of operation and equivalent PWM values for full throttle condition in the forward as well as backward condition.
 +
It was observed from the waveform that the frequency of operation is 100Hz. The range of operational duty cycle is 10% to 20% with 15% being the neutral value or the stop condition.
 +
In order to accelerate the car a PWM value in the range of 15.6%-20.0% is applied. The 15.6 is the minimum pickup PWM that should be supplied in order to get the car moving at full load. <br> <br>
 +
 
 +
[[File:CMPE243_F16_SnF_ServoMotor.png|thumb|left|140px|Servo Motor]]
 +
=====2. Servo Motor =====
 +
The servomotor used in the car is #2056 a waterproof all weather-action and double the steering power as compared to standard servos. The servo motor is responsible for controlling the steering action of right or left by applying a suitable PWM pulse. The servo motor can be driven with 3.3 V power supply. The pin P2.0 of SJ-one board is connected to supply the required PWM to the motor. After testing the servo motor, we found that the frequency of operation is 100Hz and the operational duty cycle range is 10.0%-20.0% with 15% being the neutral value. For a full right deflection, we provide input PWM pulse ranging from 15.0-20.0% and for full deflection to the left we apply 10.0-15.0% of PWM. <br>
 +
 
 +
 
 +
<br>
 +
 
 +
 
 +
 
 +
 
 +
[[File:CMPE243_F16_SnF_DSO.png|thumb|centre|700px|Digital Oscilloscope readings for the motors]]<br>
 +
 
 +
[[File:CMPE243_F16_SnF_HallEffectSensor.png|thumb|left|300px|Hall-Effect Principle.]]
 +
=====3. Speed Sensor =====
 +
The speed feedback is monitored through the speed encoder which works on the Hall-effect principle.
 +
The Hall-effect speed sensor works as a transducer whose output voltage varies in response to the magnetic field.
 +
The sensor is mounted on the Spur gear instead of the wheel. The sensor would detect the rotation of axle. The motor controller would detect whenever the magnet is aligned with the sensor. This would generate a pulse. The pulse is detected in the form of rising-edge interrupt.
 +
This gives the wheel rotation count. The wheel rotates for every 1/4th rotation of the spur gear. The rotation count can then be converted to rpm to calculate the speed of the car. <br><br><br><br><br>
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
=== Hardware Interface ===
 +
The CAN bus is used to send and receive messages to and from the Master Controller. The motor controller receives driving and steering signals from the master. The speed calculation is performed using the speed sensor and is sent on the bus, which will be received by the IO controller for display purposes.
 +
 
 +
=== Software Design ===
 +
The following diagram describes the flow of the software implementation for the motor driver and speed feedback mechanism.
 +
[[File:CMPE243_F16_SnF_Flowchart.png|frame|centre|100px|Flowchart.]]
 +
[[File:CMPE243_F16_SnF_Flowchart2.png|frame|centre|100px|Speed Feedback Implementation.]]
 +
 
 +
=== Implementation ===
 +
The motor controller receives all its signals from Master controller from the CAN bus.
 +
The motor controller receives the steer and drive command from the master. The motor controller receives the System start command which boots and decodes further drive signals  to the motor controller. Upon receiving the drive command the motor controller decodes the steering action. Upon receiving suitable data about the obstacle from sensor controller the master controller relays appropriate steering action. To achieve better performance in steering, the turn is categorized as FULL and HALF. This gives better precision in turning.
 +
*Speed Regulation:
 +
Upon detection of uphill the pulse received from the speed encoder reduces. This is detected and the motor feedback is designed such that the speed is increased by providing higher value of PWM value to drive the DC motor. Similarly, for downhill the pulse count received increases which is detected by the speed encoder and the speed is reduced by applying reduced PWM.
 +
 
 +
=== Testing & Technical Challenges ===
 +
*Wheel Alignment Error
 +
Though the neutral value of PWM is 15% at which the servo is supposed to be aligned straight. In practice, however when we tested the car for straight run slight deflection towards right was observed when the PWM pulse width was set to 15.0 %. Thus, to correct this, we provided correction value of -0.98 giving a resultant PWM pulse width of 14.02%. Thus, we fixed the wheel alignment and obtained the desired straight path traversal.
 +
<br>
 +
*Speed Sensor Assembly
 +
The speed encoder was assembled on the spur gear of the car. The installation at first was such that outer fitting was large and was avoiding the pulse trigger by the magnet.As a result of which we were unable to modulate speed.Issue was resolved by using the correct outer assembly of the gear which generated the speed feedback.
  
 
=== Sensor Controller ===
 
=== Sensor Controller ===

Revision as of 00:26, 18 December 2017

Optimus

Optimus - Self Navigating R/C Car powered by SJOne(LPC1758) micro controller.

Abstract

Objectives & Introduction

Team Members & Responsibilities

  • Motor Controller
    • Unnikrishnan
    • Rajul
  • Android and Communication Bridge
  • Master Controller:
    • Revathy
  • Sensor and I/O Controller:
    • Sushma
    • Supradeep
    • Harshitha

Project Schedule

Legend:

Major Feature milestone , CAN Master Controller , Sensor & IO Controller , Android Controller, Motor Controller , Geo , Testing, Ble controller, Team Goal

Week# Date Planned Task Actual Status
1 9/23/2017
  • Decide roles for each team member
  • Read FY16 project reports and understand requirements
  • Setup Gitlab project readme
  • Ordered CAN Tranceivers and get R/C car
  • Team roles are decided and module owners are assigned
  • Gitlab project is set
  • Ordered CAN tranceivers and got R/C Car
Complete.
2 9/30/2017
  • Design software architecture for each module and design signal interfaces between modules
  • Setup Wiki Project Report template
  • Design Hardware layout of system components
  • Create component checklist and order required components for individual modules.
  • Setup Gitlab project code for each modules
  • Overall project requirements are understood
  • Wiki Project report setup is done
  • Odered components for Geo controller module
  • Initial commit of project base is done
Complete
3 10/14/2017
  • Major Feature: Implement Free run mode
    • Implement heartbeat messages and initial system bootup sync between modules
    • Interface the RPLidar to SJOne board via UART
    • Achieve basic communication such as obtaining the device and health info.
    • Study of Android Toolkit for Bluetooth Adapter connections and APIs
    • Study of HC-05 Bluetooth Module
    • Creating APIs for Start/ STOP button requests to write to output-Stream buffers
    • Creating RFComm SPP Connection socket and the rest of UI for basic operation of Pairing, Connection
    • Checking the AT Command sequence for Bluetooth Operation and Pairing
    • Automating the AT Command sequence for Bluetooth HC-05 operation and Android App
    • Run Motors via commands from SJOne Automatically
    • Order the RPM sensor module for the Drive Controller
    • Design and Order PCB
  • Major Feature: Implemented Free run mode
    • Added hearbeat messages from all controllers to master in can_db and implemented the handling functions in master controller
    • Implemented speed steer command CAN msg transmission and handling in Master controller. Master-Drive integration phase-I
    • Interfaced RPLidar to SJOne board and achieved basic communication via UART. Started obtaining data as well.
    • Android:Android API for Bluetooth Adapter connections studied.
    • Android:Learning of AT Command sequence for Bluetooth Operation and Pairing done.
    • Android:Created Start/Stop API's for button requests to be Sent to HC-05 IC.
    • Android:Basic Pairing Operation Working.
    • Motor: ESC Traxxas XL-5 (Electronic Speed Control) interfaced to SJOne board
    • Tested and identified duty cycles for different speeds required; Callibration and testing of ESC is over exteral switch at P0.1
    • Ordered RPM sensor
Complete
4 10/21/2017
  • Major Feature: Implement Basic Obstacle Avoidance in Free-run mode
    • Add all modules CAN messages to DBC file
    • Test steer and speed CAN commands between Master and Motor
    • Implement Obstacle avoidance algorithm
    • Obtain data from the lidar and process the data i.e. decide on the format in which the data has to be sent to the master
    • Write unit test cases for the lidar.
    • Interface compass module to SJOne board and calibrate the errors
    • find the heading and bearing angle based on mocked checkpoint
    • Test and verify GPS module outdoor to receive valid data and check for errors
    • Calibrate the GPS module error
    • Design and implement the DRIVE_CONTROLLER STEER/SPEED interface with Master (TDD)
    • Install the new RPM sensor module for the Drive Controller
    • Operating motors based on the CAN messages from the Master
  • Major Feature: Implemented Free-run mode w/o obstacle avoidance
    • Added all modules basic CAN messages in can_db
    • Implemented interface files in master controller to handle CAN messages from all nodes to master
    • Implemented Master-Drive controller Integration
    • Implemented Master-Bluetooth controller integration
    • Added all modules basic CAN messages in can_db
    • GPS integrated to SJONE board
    • Added all modules basic CAN messages in can_db
    • Wrote unit test cases for the LIDAR.
    • Wrote logic for dividing the information obtained from the lidar into sectors and tracks.
    • MASTER_SPEED_STEER_CMD was defined to use 8-bits for speed control (neutral, forward, and reverse); 9-bits for steer control (straight, left, and right)
    • Designed glue code: DriveManager and hardware interface code: DriveController using TDD (test code in _MOTOR/_cgreen_test/)
    • Got the Traxxas #6520 RPM sensor; installed the same with the slipper clutch; Observed the RPM sensor trigger over an oscilloscope and found the minimum distance of magnet to RPM sensor is not achievable with the stock slipper clutch. Ordered Traxxas #6878 new slipper clutch and ball-bearings
    • Master - Drive Controller Interface implemented and tested over CAN; Check "drive" terminal command on Master controller
complete
5 10/28/2017
  • Major Feature: Implement maneuvering in Master controller
    • Implement maneuvering algorithm to drive steering angle of the servo
    • Implement maneuvering algorithm to control ESC speed
    • Test and validate the information obtained from the sensor.
    • Send the Lidar data and heartbeat over CAN.
    • LIDAR should be fully working.
    • Identify the basic speed(s) at which the car shall move; the min, max and normal forward speeds, and the min and normal reverse speeds
    • Interface the RPM sensor over ADC and validate the readings
    • Writing PID Algorithm for Motor Control
    • Calibrating PID constants according to the Motors
    • Testing the Bluetooth Range and multiple pairing option to establish security of the Master device
    • Testing the accuracy of GPS while moving
    • Made the code modular and added the wrapper function for all the important modules
    • Worked on android app which will dump the lattitude and longitude information for checkpoints
    • Test the accuracy of GPS while moving
    • Get the code review done and do the testing after that
    • Worked on the Android app that will dump the checkpoints into a file
    • Finish PCB design and place order
  • Major Feature: Implemented maneuvering in Master-Geo controller
  • Major Feature: Implemented Basic Obstacle Avoidance in Free-run mode
    • Implement maneuvering algorithm in android app is moved to next week schedule
    • Implemented maneuvering algorithm in Master to drive steering angle of the servo
    • Implement maneuvering algorithm in Master to control ESC speed
    • Unit Testing obstacle avoidance algorithm
    • Tested and validated the sensor data by plotting graphs in an EXCEL sheet.
    • Sending the obstacle information and heartbeat over CAN.
    • LIDAR fully working and sending obstacle information.
    • Identified basic speeds, slow, normal, and turbo for forward and reverse
    • Interfaced the RPM sensor over GPIO and validated; but the clutch gear with magnet was far apart from the RPM Sensor
    • Wrote the PID code keeping future integration in mind; Have pushed the code
    • Failed to use RPM sensor - new clutch gear also did not work (magnet is too far away - validated with Oscilloscope); Have to consider using IR sensor for feedback
    • Android:Tested successfully individual and multiple Device pairing.
    • Android:Android app updated with Navigation and Drawer Modules with Detecting NAV points.
    • Tested the accuracy of GPS while moving
    • Made the GPS and compass code modular and checked the functionaity after the changes
    • Worked on the Android app that will dump the checkpoints into a file
    • Completed PCB Design
Complete
6 11/07/2017
  • Major Feature: Implement maneuvering with mocked GEO checkpoints
    • Collect mock checkpoints using the Android Data Collector application
    • Collect mock checkpoints using the GEO module and compare for any discrepancies
    • Identify I/O on-board Display information; Currenly identified are documented below:
    • Health status like GPS Lock status, etc.
    • Identify hardware to check battery-status and procure the same; update PCB as well
    • Display bluetooth pairing status
    • Test on-board I/O module for bluetooth pairing status
    • In case RPM installation/usage fail, Identify new mechanism for feedback and order components; Update PCB as well to include new hardware
    • Implement simple feature additions on steer control to handle reverse; basically steering rear-left and rear-right has to be practically implemented on motor/drive controller
    • Receive GEO Controller's Turning-angle message and compute target steer
    • Use GEO Controller's distance to next-checkpoint information to compute target speed
    • Mock checkpoint navigation testing using different possible obstacle heights and forms possible
    • Identify advertisement messages on the DBC file and add documentation in Wiki; Currently identified advertisements: a) current GEO location, b) SENSOR radar map
    • Shall define the BLE Controller to android message structure and message generation-intervals (classify on-demand advertisements and periodic advertisements)
    • Implement marker for current location display - which is an on-demand advertisement
    • Implement feature for the user to enter destination - a Google Map View shall be shown to the user to confirm route from source(current car location) to destination
    • Android app (once on the new device) shall download the entire offline map information of the SJSU campus and store it on a SQLite database
  • Major Feature: Implemented maneuvering with mocked GEO checkpoints
    • Provided Mock checkpoints and used the heading and bearing angle logic to get the turning angle
    • Collected mock checkpoints and check for the error with different places
    • Interfaced the Sparkfun Seven segment display with the SJOne Board.
    • Implemented interface method to receive GEO Controller's Turning-angle message and set target steer
    • Target speed is not changed between checkpoints.So geo feedback for distance to destination is not used in design
    • Destination Reached flag is tracked to stop the car on reaching destination
    • Checkpoint Id CAN signal is processed by Master to start the car once destination is selected
    • Android:Implemented Marker for current position Display.
    • Android:User entry for setting up destination on MAP done.
    • RPM Installation failed, but could get auxiliary hardware (motor pinion) from local shop and get it working
    • Implemented basic motor feedback using hall sensor (RPM sensor); tested working on ramps
    • Steer left and right on reverse now follows natural order; Could not finish literal reverse-left and reverse-right implementation; Moved this task forward; Had to test and implement motor feedback this week
    • Defined the BLE Controller messages to android in JSON message structure and message generation-intervals (classify on-demand advertisements and periodic advertisements)
    • On Demand Advertisement- Current Marker Location
    • Draggable Destination Marker for final destination and intermittent checkpoint transmission to GEO from Android via BLE
    • Marking the checkpoints with HUE_BLUE color to do better tracking of the navigation.
    • Added multi state BT options and Added restrictions on buttons like NAV usage dependency on BT Connection, Powerup button dependency on NAV setup before actually powering the car.
Complete
7 11/14/2017
  • Major Feature: Implementing maneuvering with Android app supplied GEO checkpoints with on-board I/O
    • Use mock data from file to compute: a) Heading b) Bearing -> use Haversine's algorithm to compute turning angle
    • Advertise distance to the next checkpoint (again using Haversine's algorithm)
    • Save the proper checkpoints for one route (Clark's to SU) to SDCARD on GEO Controller
    • Implement system start/stop triggers from different use cases
    • Turning angle offset of -10,10 is added to take right / left turn
    • Implement the battery-status DBC Message advertisement
    • Indicate checkpoint proximity using backlight indicators
    • Create 2 CAN messages for Disgnostic and I/O data to transmit it to BLE module
    • Receive the diagnostic CAN message and decode to transmit it to Android App
    • [Android I/O:] Design Android app views for visualizing Diagnostic and I/O data
    • Test and validate success/fail cases for on-board I/O display information(as defined above)
    • Update PWM pulses to match MASTER's target speed with proper feedback from the identified feedback-mechanism
    • Identify PID constants kp, ki, kd and evaluate performance against the basic feedback implementation
    • Finalize feedback algorithm and fine-tuning
  • Major Feature: Implemented maneuvering with Android app supplied GEO checkpoints with on-board I/O
    • [Geo:] Implemented mock data from file to compute: a) Heading b) Bearing -> used Haversine's algorithm to compute turning angle
    • [Geo:] Advertised distance to the next checkpoint (again using Haversine's algorithm)
    • [Geo:] Saving the checkpoints in SDCARD on GEO Controller
    • Implemented start-stop triggers from android and auto start on start of route navigation
    • Turning angle from geo is handled with offset
    • battery-status is optional feature. Planning for later
    • Indicate checkpoint proximity using backlight indicators
    • [BLE:] Created CAN messages for Telemetry data from all modules to BLe to send to Android
    • [BLE:] Received Telemetry messages are transmitted to Android App
    • [Android I/O:] Android app views created for visualizing Telemetry data
    • Test and validate success/fail cases for on-board I/O display information
    • Update PWM pulses to match MASTER's target speed with proper feedback from the identified feedback-mechanism
    • Finalize feedback algorithm and fine-tuning
Complete.
8 11/21/2017
  • Major Feature: Complete maneuvering implementation with Android app and Android I/O
    • [Android I/O:] Implement display of Sensor Obstacle Information on a RADAR map
    • [Android I/O:] Dynamically update car's Current location on the map's route path
    • [Android I/O:] BT Auto Connection and Pairing implemented
    • [Android I/O:] Health information from BLE Controller, namely battery, GPS lock status, and motor speed shall be updated
    • [Android I/O:] BT Auto connect implementation and re-connection on disconnection.
    • Test achievable target speeds with different possible obstacle heights and forms possible, and ground conditions
  • Major Feature: Completed maneuvering implementation with Android app
    • [Android I/O:] Sensor obstacle LIDAR information has been updated on the app
    • [Android I/O:] Dynamic update of Car's current location and intermittent checkpoints implemented.
    • [Android I/O:] Health information from BLE Controller, namely GPS lock status, and motor speed has been updated on the Dashboard of the app.
    • [Android I/O:] Completed BT Auto connect implementation and re-connection on disconnection.
Complete.
9 11/28/2017
  • Major Feature: Full feature integration test
    • Execute the test plan created above [Planned for 11/14] (check Testing documentation in Wiki)
    • Execute the test plan created above [Planned for 11/14]; Phase 1: Test all identified cases for ground-conditions (grass, inclines, etc)
    • Execute the test plan created above [Planned for 11/14]; Phase 2: Test all identified cases for GPS routes and obstacle forms
  • Major Feature: Full feature integration test
    • Integration testing with all controllers and Android App to select routes and send checkpoints from App to Ble.
Complete.
10 12/5/2017
  • Major Feature: Full feature integration test
    • Execute the test plan created above [Planned for 11/14]; Phase 3: Test all identified cases for speed levels and on-board I/O validation
    • Execute the test plan created above [Planned for 11/14]; Phase 4: Test all identified cases for [Android I/O] validation
  • Major Feature: Full feature integration test
    • Integration testing with Android App with Debug view/Dash board with sensor and GPS data
Complete
11 12/12/2017
  • Major Feature: Full feature integration test
    • Execute the test plan created above [Planned for 11/14]; Phase 5: Test all identified cases for desired Turbo mode(s)
  • Update Wiki Complete Report
  • Major Feature: Full feature integration test
On Track

Parts List & Cost

The Project bill of materials is as listed in the table below.

SNo. Component Units Total Cost
General System Components
1 SJ One Board (LPC 1758) 5 $400
2 Traxaas RC Car 1 From Prof. Kaikai Liu
3 CAN Transceivers 15 $55
4 PCAN dongle 1 From Preet
5 PCB Manufacturing 5 $70
6 3D printing 2 From Marvin
6 General Hardware components( Connectors,standoffs,Soldering Kits) 1 $40
7 Power Bank 1 $41.50
8 LED Digital Display 1 From Preet
9 Acrylic Board 1 $12.53
Sensor/IO Controller Components
10 RP Lidar 1 $449
Geo Controller Components
11 GPS Module 1 $50
Bluetooth Bridge Controller Component
12 Bluetooth Module 1 $34.95
Drive Controller Component
13 RPM Sensor 1 $20

CAN Communication

System Nodes : MASTER , MOTOR , BLE , SENSOR , GEO

SNo. Message ID Message from Source Node Receivers
Master Controller Message
1 2 System Start command to start motor Motor
2 17 Target Speed-Steer Signal to Motor Motor
3 194 Telemetry Message to Display it on Android BLE
Sensor Controller Message
4 3 Lidar Detections of obstacles in 360 degree grouped as sectors Master,BLE
5 36 Heartbeat Master
Geo Controller Message
6 195 Compass, Destination Reached flag, Checkpoint id signals Master,BLE
7 4 Turning Angle Master,BLE
8 4 Heartbeat Master
Bluetooth Bridge Controller Message
9 1 Send start command received from Android app to master Master
10 38 Heartbeat Master
11 213 Checkpoint Count from AndroidApp Geo
12 212 Checkpoints (Lat, Long) from Android App Geo

DBC File

https://gitlab.com/optimus_prime/optimus/blob/master/_can_dbc/243.dbc

Hardware & Software Architecture

Master Controller Design & Implementation

Software Architecture Design

The Master Controller Integrates the functionality of all other controllers and it acts as the Central Control Unit of the R/C car. Two of the major functionalities handled by Mater Controller is Obstacle avoidance and Route Manuevering.

The overview of Master Controller Software Architecture is to shown in the below figure.

SW Architecture

As an analogy to Human driving, it receives the imputs from sensors to determine the surrounding of the R/C car and take decisions based on the environments and commands from the user. The input data it receives includes the following. The output of the Master controller is to direct the Motor with target Speed and Steering direction.

1. Lidar Object Detections - To determine if there is any obstacle in the path of navigation

2. GPS and Compass Reading - To understand the Heading and Bearing angle to decide the direction of movement

3. User command from Android - To stop or Navigate to the Destination

Software Implementation

To Add:

Obstacle Detection design

Obstacle Avoidance Algorithm

Overall Control Flow

Debug Leds map

GPIO interface to led, CAN txrx

Description of control flow(periodic tasks)

Handling of Can messages

Unit testing

Issues

Motor Controller

Design & Implementation

The Motor Controller is responsible for the Movement and Steering action of the Car. It includes two types of motors, DC motor for movement and DC Servo motor for Steering. The Motor has an inbuilt driver called ESC (Electronic Speed Control) Circuit used the manipulate the speed and steering of the Car. It has a PWM input for both Servo Motor and DC Motor. We are using RPM sensor to take the feedback from the motor to monitor the speed.

Hardware Design

Motor Hardware Schematics
SJOne Pin Diagram
Sr.No Pin Number Pin Function
1 P0.0 CAN RX
2 P0.1 CAN TX
3 P2.0 Servo motor
4 P2.1 DC motor
5 P2.5 Speed Encoder



  • Hardware Specifications
DC Motor
1. DC Motor

Our car came with Titan 12T 550 brushed motor and waterproof ESC. The ESC drives the DC motor based on the Pulse Width modulation (PWM) applied to it. The power supply required for this motor is 8.4 V. Maximum speed of upto 30mph can be achieved. The rotational speed is proportional to the EMF generated in its coil and the torque is proportional to the current.The main connection pins driving the motor are VCC,GND and the Control pin (PWM). The pin P2.1 of SJ-one board is connected to supply the required PWM to the motor. The basic working principle of DC motor is illustrated in the following figure : Since the preprogrammed controller has to be replaced by using our design ,the DC motor is then tested with Digital Oscilloscope for getting the frequency of operation and equivalent PWM values for full throttle condition in the forward as well as backward condition. It was observed from the waveform that the frequency of operation is 100Hz. The range of operational duty cycle is 10% to 20% with 15% being the neutral value or the stop condition. In order to accelerate the car a PWM value in the range of 15.6%-20.0% is applied. The 15.6 is the minimum pickup PWM that should be supplied in order to get the car moving at full load.

Servo Motor
2. Servo Motor

The servomotor used in the car is #2056 a waterproof all weather-action and double the steering power as compared to standard servos. The servo motor is responsible for controlling the steering action of right or left by applying a suitable PWM pulse. The servo motor can be driven with 3.3 V power supply. The pin P2.0 of SJ-one board is connected to supply the required PWM to the motor. After testing the servo motor, we found that the frequency of operation is 100Hz and the operational duty cycle range is 10.0%-20.0% with 15% being the neutral value. For a full right deflection, we provide input PWM pulse ranging from 15.0-20.0% and for full deflection to the left we apply 10.0-15.0% of PWM.





Digital Oscilloscope readings for the motors

Hall-Effect Principle.
3. Speed Sensor

The speed feedback is monitored through the speed encoder which works on the Hall-effect principle. The Hall-effect speed sensor works as a transducer whose output voltage varies in response to the magnetic field. The sensor is mounted on the Spur gear instead of the wheel. The sensor would detect the rotation of axle. The motor controller would detect whenever the magnet is aligned with the sensor. This would generate a pulse. The pulse is detected in the form of rising-edge interrupt. This gives the wheel rotation count. The wheel rotates for every 1/4th rotation of the spur gear. The rotation count can then be converted to rpm to calculate the speed of the car.







Hardware Interface

The CAN bus is used to send and receive messages to and from the Master Controller. The motor controller receives driving and steering signals from the master. The speed calculation is performed using the speed sensor and is sent on the bus, which will be received by the IO controller for display purposes.

Software Design

The following diagram describes the flow of the software implementation for the motor driver and speed feedback mechanism.

Flowchart.
Speed Feedback Implementation.

Implementation

The motor controller receives all its signals from Master controller from the CAN bus. The motor controller receives the steer and drive command from the master. The motor controller receives the System start command which boots and decodes further drive signals to the motor controller. Upon receiving the drive command the motor controller decodes the steering action. Upon receiving suitable data about the obstacle from sensor controller the master controller relays appropriate steering action. To achieve better performance in steering, the turn is categorized as FULL and HALF. This gives better precision in turning.

  • Speed Regulation:

Upon detection of uphill the pulse received from the speed encoder reduces. This is detected and the motor feedback is designed such that the speed is increased by providing higher value of PWM value to drive the DC motor. Similarly, for downhill the pulse count received increases which is detected by the speed encoder and the speed is reduced by applying reduced PWM.

Testing & Technical Challenges

  • Wheel Alignment Error

Though the neutral value of PWM is 15% at which the servo is supposed to be aligned straight. In practice, however when we tested the car for straight run slight deflection towards right was observed when the PWM pulse width was set to 15.0 %. Thus, to correct this, we provided correction value of -0.98 giving a resultant PWM pulse width of 14.02%. Thus, we fixed the wheel alignment and obtained the desired straight path traversal.

  • Speed Sensor Assembly

The speed encoder was assembled on the spur gear of the car. The installation at first was such that outer fitting was large and was avoiding the pulse trigger by the magnet.As a result of which we were unable to modulate speed.Issue was resolved by using the correct outer assembly of the gear which generated the speed feedback.

Sensor Controller

The Sensor is for detecting and avoiding obstacles. For this purpose we have used RPLIDAR by SLAMTEC.

Introduction

The RPLIDAR A2 is a 360 degree 2D laser scanner (LIDAR) solution developed by SLAMTEC. It can take up to 4000 samples of laser ranging per second with high rotation speed. And equipped with SLAMTEC patented OPTMAG technology, it breakouts the life limitation of traditional LIDAR system so as to work stably for a long time. The system can perform 2D 360-degree scan within a 6-meter range. The generated 2D point cloud data can be used in mapping, localization and object/environment modeling. The typical scanning frequency of the RPLIDAR A2 is 10hz (600rpm). Under this condition, the resolution will be 0.9°. And the actual scanning frequency can be freely adjusted within the 5-15hz range according to the requirements of users. The RPLIDAR A2 adopts the low cost laser triangulation measurement system developed by SLAMTEC, which makes the RPLIDAR A2 has excellent performance in all kinds of indoor environment and outdoor environment without direct sunlight exposure.

This LIDAR consists of a range scanner core and the mechanical powering part which makes the core rotate at a high speed. When it functions normally, the scanner will rotate and scan clockwise. And users can get the range scan data via the communication interface of the RPLIDAR (UART) and control the start, stop and rotating speed of the rotate motor via PWM.


Hardware Implementation

Software Implementation

Android Application

Bluetooth Controller

Hardware Implementation

Bluetooth Module: We are using HC-05 Bluetooth module to send and receive the data from our android application.

GPS and Compass Module

Pin Configuration:

pin configuration

The Bridge controller is connected to the bluetooth module through the uart serial interface (Uart3) with 9600 baud rate 8-bit data and 1 stop bit.

Software Implementation

Pseudo code of Bridge controller:

1. Turn on bridge controller.

2. Initialise Bluetooth controller with Uart3 settings.

3. Initialise CAN-BUS with 100 kbps speed.

4. Handle Incoming IO messages it received from the Geo and the Sensor over CAN Bus.

5. Send the received CAN message to the Android over Bluetooth each second.

6. Send the heartbeat message every second to the Master controller.

7. Read Bluetooth message it received from the Android app.

8. Forward the Android message to GEO controller if it received checkpoints otherwise forward it to Master.

Periodic Task implementation:


1 Hz task

1. Send Heartbeat message to Master.

2. Send IO messages which are already received from Geo and Sensor controller to the Android app.

3. Read Data from the Bluetooth module.


100 Hz task

1. Read CAN messages.


DBC messages:

Messages sent from Bluetooth controller :


BO_ 1 BLE_START_STOP_CMD: 1 BLE

SG_ BLE_START_STOP_CMD_start : 0|4@1+ (1,0) [0|1] "" MASTER
SG_ BLE_START_STOP_CMD_reset : 4|4@1+ (1,0) [0|1] "" MASTER

BO_ 2 MASTER_SYS_STOP_CMD: 1 MASTER

SG_ MASTER_SYS_STOP_CMD_stop : 0|8@1+ (1,0) [0|1] "" MOTOR

BO_ 38 BLE_HEARTBEAT: 1 BLE

SG_ BLE_HEARTBEAT_signal : 0|8@1+ (1,0) [0|255] "" MASTER

BO_ 212 BLE_GPS_DATA: 8 BLE

SG_ BLE_GPS_long : 0|32@1- (0.000001,0) [0|0] "" GEO
SG_ BLE_GPS_lat : 32|32@1- (0.000001,0) [0|0] "" GEO

BO_ 213 BLE_GPS_DATA_CNT: 1 BLE

SG_ BLE_GPS_COUNT : 0|8@1+ (1,0) [0|0] "" GEO,SENSOR


Messages received By Bluetooth controller:


BO_ 214 GEO_CURRENT_COORD: 8 GEO

SG_ GEO_CURRENT_COORD_LONG : 0|32@1- (0.000001,0) [0|0] "" MASTER,BLE
SG_ GEO_CURRENT_COORD_LAT : 32|32@1- (0.000001,0) [0|0] "" MASTER,BLE

BO_ 194 MASTER_TELEMETRY: 3 MASTER

SG_ MASTER_TELEMETRY_gps_mia : 0|1@1+ (1,0) [0|1] "" BLE
SG_ MASTER_TELEMETRY_sensor_mia : 1|1@1+ (1,0) [0|1] "" BLE
SG_ MASTER_TELEMETRY_sensor_heartbeat : 2|1@1+ (1,0) [0|1] "" BLE
SG_ MASTER_TELEMETRY_ble_heartbeat : 3|1@1+ (1,0) [0|1] "" BLE
SG_ MASTER_TELEMETRY_motor_heartbeat : 4|1@1+ (1,0) [0|1] "" BLE
SG_ MASTER_TELEMETRY_geo_heartbeat : 5|1@1+ (1,0) [0|1] "" BLE
SG_ MASTER_TELEMETRY_sys_status : 6|2@1+ (1,0) [0|3] "" BLE
SG_ MASTER_TELEMETRY_gps_tele_mia : 8|1@1+ (1,0) [0|1] "" BLE

BO_ 195 GEO_TELECOMPASS: 6 GEO

SG_ GEO_TELECOMPASS_compass : 0|12@1+ (0.1,0) [0|360.0] "" MASTER,BLE
SG_ GEO_TELECOMPASS_bearing_angle : 12|12@1+ (0.1,0) [0|360.0] "" MASTER,BLE
SG_ GEO_TELECOMPASS_distance : 24|12@1+ (0.1,0) [0|0] "" MASTER,BLE
SG_ GEO_TELECOMPASS_destination_reached : 36|1@1+ (1,0) [0|1] "" MASTER,BLE
SG_ GEO_TELECOMPASS_checkpoint_id : 37|8@1+ (1,0) [0|0] "" MASTER,BLE,SENSOR

BO_ 196 GEO_TELEMETRY_LOCK: 1 GEO

SG_ GEO_TELEMETRY_lock : 0|8@1+ (1,0) [0|0] "" MASTER,SENSOR,BLE

BO_ 3 SENSOR_LIDAR_OBSTACLE_INFO: 6 SENSOR

SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR0 : 0|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR1 : 4|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR2 : 8|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR3 : 12|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR4 : 16|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR5 : 20|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR6 : 24|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR7 : 28|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR8 : 32|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR9 : 36|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR10 : 40|4@1+ (1,0) [0|12] "" MASTER,BLE
SG_ SENSOR_LIDAR_OBSTACLE_INFO_SECTOR11 : 44|4@1+ (1,0) [0|12] "" MASTER,BLE

BO_ 4 GEO_TURNING_ANGLE: 2 GEO

SG_ GEO_TURNING_ANGLE_degree : 0|9@1- (1,0) [-180|180] "" MASTER,BLE

Geographical Controller

Design & Implementation

GPS and Compass Module: We are using DJI’s NAZA GPS/COMPASS to get the GPS coordinates and Heading angle. The diagram of the module is as follows:

GPS and Compass Module

Message Structure: The 0x10 message contains GPS data. The message structure is as follows: 55 AA 10 3A DT DT DT DT LO LO LO LO LA LA LA LA The payload is XORed with a mask that changes over time. Values in the message are stored in little endian.

HEADER


BYTE 1-2: message header - always 55 AA BYTE 3: message id (0x10 for GPS message) BYTE 4: length of the payload (0x3A or 58 decimal for 0x10 message)


PAYLOAD


BYTE 5-8 (DT): date and time BYTE 9-12 (LO): longitude (x10^7, degree decimal) BYTE 13-16 (LA): latitude (x10^7, degree decimal)


CHECKSUM


BYTE 63-64 (CS): checksum


XOR mask


All bytes of the payload except 53rd (NS), 54th, 61st (SN LSB) and 62nd (SN MSB) are XORed with a mask. Mask is calculated based on the value of byte 53rd (NS) and 61st (SN LSB).


Pin Configuration:


The Pin Configuration is as follows:


Block Diagram

Software Design

Algorithm:


Distance calculation:


We are using the ‘haversine’ formula to calculate the great-circle distance between two points – that is, the shortest distance over the earth’s surface


Haversine formula:


a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) c = 2 ⋅ atan2( √a, √(1−a) ) d = R ⋅ c

where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km)


Bearing Angle calculation:

Formula:


θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )

where φ1,λ1 is the start point, φ2,λ2 the end point (Δλ is the difference in longitude)

Since atan2 returns values in the range –π to +π (that is, -180° to +180°), to normalize the result to a compass bearing (in the range 0° to 360°), negative values are transformed into the range 180° to 360°) by converting to degrees first and then using (θ+360) % 360, where % is (floating point) modulo.


DBC Messages:


Messages sent from GEO module:


BO_ 4 GEO_TURNING_ANGLE: 2 GEO

SG_ GEO_TURNING_ANGLE_degree : 0|9@1- (1,0) [-180|180] "" MASTER,BLE

BO_ 37 GEO_HEARTBEAT: 1 GEO

SG_ GEO_HEARTBEAT_signal : 0|8@1+ (1,0) [0|255] "" MASTER

BO_ 195 GEO_TELECOMPASS: 6 GEO

SG_ GEO_TELECOMPASS_compass : 0|12@1+ (0.1,0) [0|360.0] "" MASTER,BLE
SG_ GEO_TELECOMPASS_bearing_angle : 12|12@1+ (0.1,0) [0|360.0] "" MASTER,BLE
SG_ GEO_TELECOMPASS_distance : 24|12@1+ (0.1,0) [0|0] "" MASTER,BLE
SG_ GEO_TELECOMPASS_destination_reached : 36|1@1+ (1,0) [0|1] "" MASTER,BLE
SG_ GEO_TELECOMPASS_checkpoint_id : 37|8@1+ (1,0) [0|0] "" MASTER,BLE,SENSOR

BO_ 196 GEO_TELEMETRY_LOCK: 1 GEO

SG_ GEO_TELEMETRY_lock : 0|8@1+ (1,0) [0|0] "" MASTER,SENSOR,BLE

BO_ 214 GEO_TELEMETRY: 8 GEO

SG_ GEO_TELEMETRY_LONG : 0|32@1- (0.000001,0) [0|0] "" MASTER
SG_ GEO_TELEMETRY_LAT : 32|32@1- (0.000001,0) [0|0] "" MASTER


Messages received by GEO module:


BO_ 212 BLE_GPS_DATA: 8 BLE

SG_ BLE_GPS_long : 0|32@1- (0.000001,0) [0|0] "" GEO
SG_ BLE_GPS_lat : 32|32@1- (0.000001,0) [0|0] "" GEO

BO_ 213 BLE_GPS_DATA_CNT: 1 BLE

SG_ BLE_GPS_COUNT : 0|8@1+ (1,0) [0|0] "" GEO,SENSOR


Implementation

Periodic callback function description:


1 Hz Function:


a. Check CAN bus


b. Send Heartbeat to Master module


c. Send GPS lock to Master and Sensor modules


100 Hz Function:


a. Get GPS coordinates


b. Get Heading angle


c. Get Checkpoints count


d. Calculate Bearing angle


e. Calculate Turning angle


f. Calculate Distance remaining


g. Send Heading angle


h. Send Bearing angle


i. Send Turning angle


j. Send Distance remaining


k. Check Destination reached

Testing & Technical Challenges

Git Project Management

Common Technical Challenges

Project Videos

Conclusion

Project Source Code

References

Acknowledgement

== References Used ==