Docsity

Dynamic Collision Avoidance System: A Toy Car Project, Study Guides, Projects, Research of Electrical and Electronics Engineering

Partial preview of the text

Download Dynamic Collision Avoidance System: A Toy Car Project and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

Dynamic Collision Avoidance

By: Vasko Popstojanov Ramtin Hosseini Tyler Wickenhauser Jane Tu

ECE 395 - Advanced Digital Projects Laboratory Fall 2008

TA: Zuofu Cheng

December 02, 2008

Abstract

Auto accidents happen every hour causing severe injuries and damages. Most of these are due to recklessness or lack of attentiveness to the surroundings. Our goal is to design an autonomous control system that will assist drivers in collisions prevention. The control system is to only take over when a possible collision is detected, and default back to user control once it is cleared of hazards. We will be reverse-engineering a toy car and designing a control system using a microprocessor. The idea is to detect the distance between the car and its surrounding objects using sensors and to either redirect, stop, or restrict certain movement of the car. The project involves collaboration between software and hardware.

Introduction

I. Goal

The goal of this project is to design an additional control system for a car to avoid collision. We implemented our design upon a toy car taken from a previous project to reduce unnecessary troubles and expenses in modeling of the car. The final design incorporates a PIC microcontroller, oscillator, ultrasonic sensors, MOSFETs, capacitors, and NAND-gates. An understanding of those components would provide us a better basic knowledge for future project designs, and the concept behind it may be enhanced for applications to normal vehicles, robots, and any movable objects.

II. Overview

The body of the car consists of a protoboard, mounting bracket, and two motors; the one in the back accelerates the back wheels, and the one in the front turns the front wheels. Initially we familiarized ourselves with MPLAB, PIC microcontrollers, and several on-chip peripherals with simple LED tests. Then we experimented with the analog outputs of the sensors. We also built an H-Bridge with MOSFETs to control the forward/backward movement of the car. Lastly we wrote the software for microcontrollers in C to evaluate its inputs and calculate its outputs to the circuitry. The remaining components and additional sensors are then attached to the circuitry plus some additional minor adjustments for the completion of this project.

The Design

I. Components

MPLAB ICD

dsPIC30F

II. Hardware

The logic for the control system is primarily focused on the software inside the microcontroller. The final design uses a 40-pin dsPIC with 20MHz oscillator for clocking. The ultrasonic sensors are soldered, connected to the microcontroller inputs, and glued to the protoboard mounting bracket. The sensors output analog signals based upon their distance from the nearest object. The internal software then analyzes the signals and feed digital signals to H-Bridge that in turn controls the movement of the car to either stop, go backward, or turn.

  • H-Bridge The H-Bridge allows us to control the motors in both directions. The circuitry consists of four switches, which in this project is implemented with two of both p-channel and n-channel MOSFETs. Each MOSFET has three connections: source, drain, and gate. The sources of the p-channel MOSFETs are connected to voltage supply while the sources of the n-channel MOSFETs are connected to ground. The drains are connected together as well as to either side of the motor. The gates act as switches that connect to outputs of the microcontroller to take on either “on” or “off” state. Various combinations of signals enable various potential differences across the motor thus allowing current to flow in both directions across the motor. The h-bridge can also cause an open circuit across the motor (free run) or a closed circuit across the motor (stopped). This concept is used to steer the back wheels to go forward, backward, or stop as well as the front wheels to turn left, right, or straight.

Digital Signal p-channel MOSFET n-channel MOSFET 0 On Off 1 Off On

(Modes of the motor: forward/left, backward/right, stop/straight)

III. Software

We programmed the microchip in C using the MPLAB software. Originally, we used PIC18F4520 but had no success using its A/D Converter interface. Alternatively, we switched to dsPIC30F4013 and referenced the sample code presented in class. Initially we tested the sensor and microcontroller by lighting an LED. Then we switched to using on-chip UART and set up MAX232 Driver/Receiver and DE-9 Serial Port to display more information on the computer screen through Putty. This benefits us in process of debugging and estimating the sensor ranges by trial-and-error. Lastly we used the PWM to control the outputs to the h-bridge and thus control the car’s speed.

The objective for the software is to analyze the analog outputs from the ultrasonic sensors to detect nearby objects. Then depending on the location and distances of the objects, the dsPIC outputs corresponding digital signals to steer the car and avoid collision. To start off, we defined the I/O of individual pins. Then we created multiple sub-functions include initializing and utilizing the on-chip peripherals (UART, A/D Converter, PWM), and setting the outputs for each possible movement of the car. Below is a list of basic functionality for each function; refer to the code for more details.

Label Distance (approx) ADC output DIST9 ~5 ft 335 DIST8 ~4 ft 275 DIST7 ~30-36 inches 215 DIST6 ~26-30 inches 175 DIST5 ~22-26 inches 150 DIST4 ~16-22 inches 130 DIST3 ~14-16 inches 110 DIST2 ~10-12 inches 95 DIST1 ~6-12 inches 60 DIST0 <6 inches <

Conclusion

I. Obstacles

  • We were unable to figure out the A/D Converter modules to work for PIC18F4520; the problem was solved by using dsPIC30F4013 instead.
  • Initially the front motor for turning the wheels was jammed due to constraints of its packaging. The problem was mostly solved by taking the motor apart, cut a hole in its case, and put it back together.
  • We had multiple trials in attempt to control the motors. The first problem we realized was that there is not enough current to run the motor with typical circuit logic, regardless of using various resistors. The solution was solved by building an H-bridge. Initially we implement the H-bridge with only n-channel MOSFET for all four switches because it has less resistance compare to p-channel MOSFET; however, the circuit seems to malfunction unless we replace the ones near voltage source with p-channel MOSFET.
  • Power was our main concern toward the conclusion of the project. The original battery of the car seems to only have enough power to support the circuitry. We solved the problem by added additionally battery holders and manual switches to run each of the front and the back motors. The negative effect is that the addition batteries increase the weight and require more energy, which led to the trade-off of functionality versus energy efficiency.
  • Each I/O pin of the microchip is associated with three ports, namely TRIS, PORT, LAT. TRIS is self-explanatory, which set the pin as input/output depend on ‘1’ or ‘0’ assignment; however, PORT and LAT are both use to read and write to memory. Initially we assign our outputs using PORT syntax, but when the assignments is written in consecutive lines of code, only the last assignment works. This is because when changing the values of each pin, the process requires a short time for the value to change gradually between logic low and high. Especially when the program is operated under high frequency, the consecutive assignment would operate before the previous assignment reaches a steady value. The problem can be solved by either placing lines of ‘No-op” in between assignments or, more ideally, use LAT instead of PORT for pin assignments.