Difference between revisions of "S14: Wireless Control Car"
Proj user14 (talk | contribs) (→Implementation) |
Proj user14 (talk | contribs) (→Parts List & Cost) |
||
Line 99: | Line 99: | ||
|- | |- | ||
! scope="row"| 1 | ! scope="row"| 1 | ||
− | | SJOne Board (LPC1758) | + | | SJOne Board (LPC1758)which include: Accelerometer sensor(MMA8452Q) and Nordic Wireless sensor(nRF24L01) |
| One board from SJSU CmpE and one board by Preet | | One board from SJSU CmpE and one board by Preet | ||
| 2 | | 2 | ||
Line 109: | Line 109: | ||
| 1 | | 1 | ||
| $15.00 | | $15.00 | ||
− | |- | + | |-Nordic Wireless sensor (nRF24L01 |
! scope="row"| 3 | ! scope="row"| 3 | ||
− | | Ultrasonic Sensor | + | | Ultrasonic Sensor (HCSr04) |
| Amazone | | Amazone | ||
| 1 | | 1 | ||
Line 117: | Line 117: | ||
|- | |- | ||
! scope="row"| 4 | ! scope="row"| 4 | ||
− | | 9V Battery | + | | 9V-2000mAh Rechargeable Battery (Nickel-metal Hydride battery) |
| Frys | | Frys | ||
| 1 | | 1 | ||
Line 127: | Line 127: | ||
| 1 | | 1 | ||
| $20:00 | | $20:00 | ||
+ | |- | ||
+ | ! scope="row"| 6 | ||
+ | | Motor Controller (L298 Dual H-Bridge DC Motor Controller) | ||
+ | | robotshop | ||
+ | | 1 | ||
+ | | $18:00 | ||
|- | |- | ||
! scope="row"| | ! scope="row"| | ||
Line 132: | Line 138: | ||
| | | | ||
| | | | ||
− | | $ | + | | $150:00 |
|- | |- | ||
|} | |} |
Revision as of 11:18, 24 May 2014
Contents
Grading Criteria
- How well is Software & Hardware Design described?
- How well can this report be used to reproduce this project?
- Code Quality
- Overall Report Quality:
- Software Block Diagrams
- Hardware Block Diagrams
- Schematic Quality
- Quality of technical challenges and solutions adopted.
Project Title
Wireless Control Car
Abstract
This project is about the development of a robotic car which can be controlled wirelessly. A robotic car has two front and back motors which are controlled independently. Both the motors are attached to a wireless module in built in the microcontroller so that it can be controlled wirelessly. This car also has three ultrasonic sensors which are attached to front, left and right side of the car. These three sensors help in avoiding any collision with the obstacle. This car also has an auto mode which enables the car to run without the user's help.
Objectives & Introduction
The objective of this project is to build a wireless robotic car. This car is designed so that it can be controlled wirelessly. This car has two DC motors to control front and back tires, an H bridge dual motor controller to control the speed and direction of the motor, three ultrasonic sensors for obstacle avoidance, an Accelerometer sensor to detect the direction of board rotation and a wireless module to control the car wirelessly.
The project is divided into following objectives:
- Design the circuit and algorithm for motor controller to control both front and back motor independently.
- Write the driver to control in build accelerometer sensor on the microcontroller.
- Write the wireless driver to send and receive commands between two microcontroller boards.
Team Members & Responsibilities
- Deepak Yadav
- Project Design and Testing
Schedule
Week# | Date | Task | Actual |
---|---|---|---|
1 | 02/24 | Project Planning | Completed on Time |
1 | 03/06 | Order Parts | Completed on Time |
1 | 03/10 | Reviewing part's user manual and datasheet | Completed on Time |
3 | 03/24 | PWM Driver | Understanding PWM took more time than I was expecting. It's Completed on (04/6) |
3 | 03/24 | Wireless Driver | Completed on Time |
3 | 04/1 | Acceloremoter Driver | Completed on Time |
3 | 04/12 | Design Integration | Completed on Time |
2 | 04/14 | Testing and Debug-Phase 1 | Completed on Time |
2 | 04/21 | Testing and Debug-Phase 2 | Partially Completed. Found some software bugs that needs to be fixed. |
1 | 05/22 | Project Demo | Pending |
Parts List & Cost
Item# | Part Desciption | Vendor | Qty | Cost |
---|---|---|---|---|
1 | SJOne Board (LPC1758)which include: Accelerometer sensor(MMA8452Q) and Nordic Wireless sensor(nRF24L01) | One board from SJSU CmpE and one board by Preet | 2 | $80.00 |
2 | Toy car(including two DC Motors) | Grocery Outlet (Any toy store/grocery store such as Walmart) | 1 | $15.00 |
3 | Ultrasonic Sensor (HCSr04) | Amazone | 1 | $5:00 |
4 | 9V-2000mAh Rechargeable Battery (Nickel-metal Hydride battery) | Frys | 1 | $12:00 |
5 | Accessories (Jumper Wires, prototype board and battery charger) | Frys | 1 | $20:00 |
6 | Motor Controller (L298 Dual H-Bridge DC Motor Controller) | robotshop | 1 | $18:00 |
Total Cost | $150:00 |
Design & Implementation
Hardware Design
The hardware is designed by going through each project part's datasheet and LPC1758 microcontroller. After understanding the pin connections and the design, all the parts are connected by jumper wires. The Power to the microcontroller is supplied by USB cable which is spliced so that one end is connected to the 5V power supply. The Power source used for this project is rechargeable 9V battery, which is then connected to a power distribution circuit. A Power distribution circuit takes 9V from rechargeable battery converts to 5V. The Following block diagram shows the overall connection between the project parts:
Hardware Interface
The Transmitting Module used the following interfaces:
- I2C Bus
- Used to read the board orientation from Accelerometer sensor
- SPI Bus
- Used to transmit commands from Nordic wireless from receiving board
- GPIO
- Control Motor direction and speed, read ultrasonic sensor and Switches for start and stop
The Receiving Module board used the following interfaces:
- SPI Bus
- Used for receiving commands from a Nordic wireless from transmitting board
- GPIO
- PWM interface for front and back motor
- Direction control for front and back motor
- Send Trigger to Ultrasonic sensor
- Detect Echo back pulse from Ultrasonic sensor
Software Design
The Software is implemented by following the below flowchart:
Transmitting module
Receiving module
Implementation
Accelerometer sensor (Part: MMA8452Q, inbuilt in SJone board).
The direction of board tilt is calculated by reading the accelerometer sensor. To read the sensor data follow the following steps:
- Step1: Initialize accelerometer sensor
- Set Ctrl1_reg1 register's last bit to 0 to select standby mode.
- Enable Portrait/Landscape status register through PL_Cfg register and set bit 4 in Ctrl_reg4 register.
- set denounce counter to 100ms through PL_count register.
- Set the sensor output data rate (100Mhz) and the ACTIVE mode from Ctrl1_reg1 register.
- Step2: Read Pl_status register from accelerometer sensor to get direction and orientation of the SJone board.
- The following value will determine what direction or orientation the board is:
If bit[1:0] is: 0: Portrait Up 1: Portrait Down 2: Landscape Right 3: Landscape Left
If bit[0] is: 0: Front facing orientation 1: Back facing orientation
Motor Controller (L298 Dual H-Bridge DC Motor Controller.
The dual Motor controller is used to control the speed and the direction of both front and back motor. Motor controller has one enable and two interrupts pins for each motor.
Follow the following steps to control the motors through motor controller:
- Step1: Initialize motor controller
- initialize two PWM signal and then set it to 1KHz frequency in SJone board.
- Configure the speed of the motor through PWM by from LPC1758 data sheet.
- I used the inbuilt function provided by the CmpE244 instructor.
PWM front_Motor.set(int percentage of motor speed) The process of converting the percentage of speed is as follow: If percent = 70, mTcMax = 1000, then value will be 70*1000 / 100 = 700 After the calculation, you write these values to the MR memory locations based on which PWM is selected in SJone board.
- Set four GPIO pins for the four interrupt pins as output.
- Step2: Control the direction of motor (clock or anti clock) as following:
PWM Int1 Int2 Function -------------------------------------------------------------- High High Low Turn Anti-clockwise (Reverse) High Low High Turn clockwise (Forward) High High High Stop High Low Low Stop Low X X Stop
The back motor simply turns the wheels forward and backward. The front motor is attached to a toy car inbuilt mechanical system which turn wheels right when motor runs clockwise and turns left when motor runs anti clock wise.
Nordic Wireless sensor (nRF24L01, inbuilt in SJone board).
Nordic Wireless sensor is used to send and receive the data from one SJboard to other. I used the inbuilt wireless function to send and receive data packets.
Set the address: mesh_set_node_address(commander_addr) Send data: wireless_send(car_addr,mesh_pkt_nack, &command,1,max_hops)
For this project I used following protocol:
car_addr=300 commander_addr=400
Function Command move_forward : 1 move_backward : 2 move_right : 3 move_left : 4 stop : 5 start : 10 full_speed : 6 half_speed : 7 auto_pilot_on : 8 auto_pilot_off : 9
For receiving module, set the address: mesh_set_node_address(car_addr) and then read the data.
Ultrasonic sensor (Pasrt: HCSr04). Ultrasonic sensor is used to detect if any object is in front of the car or not. The ultrasonic sensor has four pins. Two are power and ground pins and other two are Echo and Trigger pins. Trigger pin tells ultrasonic sensor to start sending waves and echo pin assert from low to high if it receive a wave back. By calculating the time between sending and receiving the wave, we can calculate it distance between the reflected object.
The process of initializing ultrasonic sensor is as follows:
- Step1: initialize ultrasonic sensor.
- Set Trigger pin as output
- Set Echo pin as input
- Set interrupt on Echo pin on falling edge (I used in built interrupt enable function for port 2 pins provided by the instructor).
- Step2: Take snapshot of the hardware time. I used timer1 function provided by FreeRTOS.
- Step3: Send High pulse for at least between 15us to 20us on the trigger pin and then send low pulse.
- Step4: Record the hardware time again as soon as a interrupt(falling edge) occur on the echo pin.
- Step5: Calculate the distance as following
- TimeDelta = timerValueAtinterrupt - timerValueAtTrigger
- Convert time from nanosecond to microsecond: TimeDelta = TimeDelta * 0.666. Since at Timer1, Each tick = 1/(48Mhz/32) = 666ns (more info on LPC1758 datasheet)
- TimeDelta = TimeDelta - HoldoffTime (from ultrasonic sensor datasheet)
- Convert escalate time to distance such as into centimetre: distance = TimeDelta /29; (This formula can be found in the ultrasonic sensor datasheet)
**The overall implementation of the whole project is explained in the above flow chart diagram.
Testing & Technical Challenges
Testing of this project is done before and after complete project integration. The whole project is tested by printing the output values from each sensor's to the laptop's terminal screen for validation.
Transmitting module: The software testing of transmitting module is done by printing the value from Accelerometer sensor and the command it sends from Nordic wireless sensor on the terminal screen. The SJone board has inbuilt accelerometer and wireless sensor, so it didn't need any hardware testing.
Receiving module: Receiving module is tested by printing the output value that it received from transmitting module and the value that it sends to the motor controller and the ultrasonic sensor.
Ultrasonic sensor is tested by probing (by oscilloscope) on the trigger and echo pins on the ultrasonic sensor. It validated that the microcontroller is sending the trigger and the sensor is outputting the echo back pulse. The timer1 function provided with the code gives the precise timing result as compared to the in built timing function (such as simple for loop).
Motor controller is tested by printing out the speed and the direction of motor value on the terminal screen. At first the motor didn't run because of low current supply, but after correct power supply it started to run. The interrupt pins needed to be set correctly to rotate the motor clock and anticlockwise.
Complete Project testing: The whole project is tested by connecting everything together and then sending the command through a transmitting board to receiving board and observing its behavior. At first the controlling of car such as direction and speed control was difficult, but after increasing the speed(PWM signal)and fixing the signals send to interrupt pins on motor controller for direction. There was also an delay problem that both receving and transmitting module has to controll the car more precisely. This is issue was resolved by minimizing the delay that I put in the code after every command that both the boards send and receive.
Conclusion
The whole project experience was fun and very educational. I learned about how ultrasonic sensor, accelerometer sensor, wireless sensor and motor controllers works. I faced some technical challenges such as controlling the motor speed, getting the right distance value from the ultrasonic sensor, and some of the power issues such as the right amont of current to the DC motors.
This project can be expanded to include more features such as an ultrasonic sensor connected to the servo motor that rotates left and rgiht to get distance from all the sides.
Project Video
Upload a video of your project and post the link here.
Project Source Code
Send me your zipped source code and I will upload this to SourceForge and link it for you.
References
Acknowledgement
I would like to thank Professor Preet for encouraging us to learn and build some practical projects related to embedded systems.
References Used
http://www.socialledge.com/sjsu/index.php?title=PING)))_Ultrasonic_Sensor
https://docs.google.com/document/d/1Y-yZnNhMYy7rwhAgyL_pfa39RsB-x2qR4vP8saG73rE/edit
http://www.robotshop.com/en/l298-dual-h-bridge-dc-motor-controller.html
http://content.solarbotics.com/products/datasheets/solarbotics_l298_compact_motor_driver_kit.pdf
http://www.instructables.com/id/Accelerometer-Gyro-Tutorial/