CAN Based Accident Avoidance
CAN Based Accident Avoidance
CAN Based Accident Avoidance
INTRODUCTION
Cars on the same direction in highway usually keep a safe distance one another with a similar speed. However, due to the drivers distraction, long-time driving fatigue, flake out, or even a sudden deceleration of the previous car, a serious collision accident may occur if the driver can not react in time to brake. On the other hand, drivers need the mirrors to know other approaching cars from two-side or from the rear end. Even the driver check around carefully, he cannot take an immediate respond, except push the horn, to a sudden approaching car and an accident is thus unavoidable. Therefore, developing a front-obstacle warning system and a rear end collision avoidance system subject to all directions are important in collision avoidance. For the front-end collision avoidance subsystem, Ultrasonic sensor is adopted to measure the distance with respect to the previous car. For rear-end end collision avoidance subsystem, the currently available ultrasonic sensors for vehicles are adopted for approaching cars with relatively low speed. While the rough reading of distance data cannot be applied directly, an intelligent approach is proposed to process the raw distance readout of sensors to produce appropriate warning signals. When there are more electrical control devices in the modem cars, such as power train management system, antilock braking system (ABS), and acceleration skid control (ASC) system, etc, the functionality and wiring of these electric control units (!XU) are getting more complicated. Therefore, it is of great concern to upgrade the traditional wire harness to a smart &car network. In 198Os, a Germany car component provider Robert Bosch Co. introduced an in-car network; the controller area network (CAN) bus, to replace the complex and expensive traditional in-car wiring [5]. In this study, a highlevel protocol CAN open is adopted to interconnect those CAN nodes with reliable communications among sensors.
The block diagram of system which includes sensor, ADC, LCD, LPC2129, buzzer, fuel sensor and speed sensor is as shown in fig 1.1. The system mainly consists of front-end-sub-system and rear-end-sub-system.
A D C
Fuel Sensor
L P C 2 1 2 9
CAN 1
CAN 2
L P C 2 1 2 9
A D C
Figure 1.1: BLOCK DIAGRAM for the can based accident avoidance system
signal can be generated for the approaching car drivers, can be taken. Therefore, rear-end collision avoidance warning sub-system is constructed with the available ultrasonic sensors which have been widely implemented on commercial vehicles. The distance between the driving car and the approaching cars can be measured only with a rough distance readout every 5 on and a limited range as 20- 150 cm as in Table 1. They show that an intelligent approach to process those readout of the sensor is required to provide reliable warning signal. Output Code corresponding the distance of the ultrasonic sensors(LMS221-30206) Distance Code Physical Distance(cm) 30 35 40 45 .. 130 135 140 145 150 5 15 25 35 . 205 215 225 235 245
Table 1.1 The warning subsystem is developed to be less independent of the approaching speed so that an appropriate precaution time can be provided for the approaching car to prevent the rear-end collision passively.
port ,I2C interface, UART, 10 bit ADC, and standard JTAG interface. These two microcontroller are connected by CAN bus for transmission of data between them.
CHAPTER 2
ARM7TDMI PROCESSOR
The ARM7TDMI core is a member of the ARM family of general-purpose 32-bit Microprocessors. The ARM [4] family offers high performance for very low power Consumption and small size. The ARM architecture as shown in fig 2.2 is based on Reduced Instruction Set Computer (RISC) principles. The RISC instruction set and related decode mechanism are much simple than those of Complex Instruction Set Computer (CISC) designs. This simplicity gives: A high instruction throughput An excellent real-time interrupt response A small, cost-effective, processor macrocell.
During normal operation, while one instruction is being executed, its successor is being decoded, and a third instruction is being fetched from memory. The program counter points to the instruction being fetched rather than to the instruction being executed. This is important because it means that the Program Counter (PC) value used in an executing instruction is always two instructions ahead of the address.
SUPERVISOR ABORT R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13_SVC R14_SVC R15(PC) R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12
CPSR
CPSR
CPSR
CPSR
CPSR
CPSR
SPSR_FIQ SPSR_SVC
The ARM7TDMI core has four basic types of memory cycle: Idle cycle
2.4 Architecture
The ARM7TDMI processor has two instruction sets: The 32-bit ARM instruction set The 16-bit Thumb instruction set. The ARM7TDMI processor is an implementation of the ARMv4T architecture.
On execution, 16-bit Thumb instructions are transparently decompressed to full 32-bit ARM instructions in real time without performance loss.
Thumb has all the advantages of a 32-bit core: 32-bit address space 32-bit registers 32-bit shifter, and Arithmetic Logic Unit (ALU) 32-bit memory transfer. Thumb therefore offers a long branch range, powerful arithmetic operations, and a large address space. Thumb code is typically 65% of the size of ARM code, and provides 160% of the performance of ARM code when running from a 16-bit memory system. Thumb, therefore, makes the ARM7TDMI core ideally suited to embedded applications with restricted memory bandwidth, where code density and footprint is important. The availability of both 16-bit Thumb and 32-bit ARM instruction sets gives designers the flexibility to emphasize performance or code size on a subroutine level, according to the requirements of their applications. For example, critical loops for applications such as fast interrupts and DSP algorithms can be coded using the full ARM instruction set then linked with Thumb code.
CHAPTER 3
Controller Area Network (CAN) is an advanced serial bus system that efficiently supports distributed control system with a very high level of security. Robert Bosch, Germany[1][2][3] initially developed it for the use in motor vehicles in the late 1980s.Its domain of application ranges from high-speed network to low cost multiplex wiring. To improve the behavior of the vehicle, it was necessary for the different control system (and their sensor) to exchange information. This was usually done by discrete interconnection of the different system (i.e. point -to - point wiring). The requirement for the information exchange has then grown to such an extent that a cable network with a length up to several miles and many connectors were required. This leads to growing problems concerning material cost, production time and reliability. The solution to this problem was the connection of the Control system via a serial bus system. With the use of CAN, point - to - point wiring is replaced by one serial bus connecting to all control systems. This is accomplished by adding some CAN specific hardware to each control unit that provides the rules " or the protocol for transmitting and receiving information via the bus. The CAN protocol uses the data link layer and the physical layer in the ISO_OSI model.
In CAN protocol, two versions are available. They are version 2.0A CAN and version 2.0B CAN. Version 2.0A is original CAN specifications specify an 11 bit identifier which allows 2^11(=2048) different message identifiers and is known as
standard CAN. Version 2.0B CAN contain 29 bit identifiers which allows 2^29 (over 536 million) message identifiers. CAN has the following properties: Prioritization of messages. Guarantee of latency times. Configuration flexibility. Multicast reception with time synchronization. System wide data consistency. Error detection and error signaling. called Carrier
Sense Multiple Access with arbitration on message priority ". This arbitration Concept avoids collisions of messages whose transmission was started by more than one node simultaneously and makes sure the most important message is sent first without time loss. If two or more bus nodes start their transmission at the same time after having found the bus to be idle, collision of the messages is avoided by bitwise arbitration. Each node sends the bits of its message identifier and monitors the bus level.
3.2.1 Messages
Information on the bus is sent in fixed format messages of different but limited length. When the bus is free any connected unit may start to transmit a new message.
3.2.5 Multicasting
As a consequence of the concept of message filtering any number of nodes can receive and simultaneously act upon the same message.
Within a CAN network it is guaranteed that a message is simultaneously accepted either by all nodes or by no node. Thus data consistency of a system is achieved by the concepts of multicast and by error handling.
3.2.8 Priorities
The identifier defines a static message priority during bus access.
3.2.10 Multimaster
When the bus is free any may start to transmit a message. The unit with the message of highest priority to be transmitted gains bus access.
3.2.11 Arbitration
Whenever the bus is free, any unit may start to transmit a message. If two or more units start transmitting messages at the same time, the bus access conflict is resolved by bit wise arbitration using the identifier. The mechanism of arbitration grantees that neither information nor time is lost. If a data frame and a remote frame with the same identifier are initiated at the same time, the data frame prevails over the remote frame. During arbitration every transmitter compares the level of the bit
transmitted with the level that is monitored on the bus. If these levels are equal the unit may continue to send. When a recessive level is sent and a dominant level is monitored, the unit has lost arbitration and must withdraw without sending one more bit.
Figure 3.1: Bus characteristics There are two bus states, called "dominant" and "recessive". The bus logic uses a "Wired-AND" mechanism, that is, "dominant bits" (equivalent to the logic level "Zero") overwrite the "recessive" bits (equivalent to the logic level "One).
In the picture above you see the trace of the transmit pins of three bus nodes called A, B and C, and the resulting bus state according to the wired-AND principle. If two or more bus nodes start their transmission at the same time after having found the bus to be idle, collision of the messages is avoided by bitwise arbitration. Each node sends the bits of its message identifier and monitors the bus level. At a certain time nodes A and C send a dominant identifier bit. Node B sends a recessive identifier bit but reads back a dominant one. Node B loses bus arbitration and switches to receive mode. Some bits later node C loses arbitration against node A. This means that the message identifier of node A has a lower binary value and therefore a higher priority than the messages of nodes B and C. In this way, the bus node with the highest priority message wins arbitration without losing time by having to repeat the message. Nodes B and C automatically try to repeat their transmission once the bus returns to the idle state. Node B loses against node C, so the message of node C is transmitted next, followed by node Bs message. It is not permitted for different nodes to send messages with the same identifier as arbitration could fail leading to collisions and errors
The Start of Frame bit is followed by the Arbitration Field consisting of 12 bits. The 11-bit Identifier, which reflects the contents and priority of the message, and the Remote Transmission Request bit. The Remote transmission request bit is used to distinguish a Data Frame (RTR = dominant) from a Remote Frame (RTR = recessive).The next field is the Control Field, consisting of 6 bits. The first bit of this field is called the IDE bit (Identifier Extension) and is at dominant state to specify that the frame is a Standard Frame. The following bit is reserved and defined as a dominant bit. The remaining 4 bits of the Control Field are the Data Length Code (DLC) and specify the number of bytes of data contained in the message (0 - 8 bytes). The data being sent follows in the Data Field which is of the length defined by the DLC above (0, 8, 16, 56 or 64 bits).The Cyclic Redundancy Field (CRC field) follows and is used to detect possible transmission errors. The CRC Field consists of a 15 bit CRC sequence, completed by the recessive CRC Delimiter bit. The next field is the Acknowledge Field. During the ACK Slot bit the transmitting node sends out a recessive bit. Any node that has received an error free frame acknowledges the correct reception of the frame by sending back a dominant bit (regardless of whether the node is configured to accept that specific message or not). From this it can be seen that CAN belongs to the "in-bit-response" group of protocols. The recessive Acknowledge Delimiter completes the Acknowledge Slot and may not be overwritten by a dominant bit. Seven recessive bits (End of Frame) end the Data Frame.
Generally data transmission is performed on an autonomous basis with the data source node (e.g. a sensor) sending out a Data Frame. It is also possible, however, for a destination node to request the data from the source by sending a Remote Frame. There are 2 differences between a Data Frame and a Remote Frame. Firstly the RTR-bit is transmitted as a dominant bit in the Data Frame and secondly in the Remote Frame there is no Data Field. In the very unlikely event of a Data Frame and a Remote Frame with the same identifier being transmitted at the same time. The Data Frame wins arbitration due to the dominant RTR bit following the identifier. In this way, the node that transmitted the Remote Frame receives the desired data immediately.
Counter will count down 128 occurrences of the Bus Free condition (11 consecutive recessive bits). Software can monitor this countdown by reading the Tx Error Counter. When this countdown is complete, the CAN Controller clears BS and ES in CANSR, and sets EI in CANSR if EIE in IER is 1. The Tx and Rx error counters can be written if RM in CANMOD is 1. Writing 255 to the Tx Error Counter forces the CAN Controller to Bus-Off state. If Bus-Off (BS in CANSR) is 1, writing any value 0 through 254 to the Tx Error Counter clears Bus-Off. When software clears RM in CANMOD thereafter, only one Bus Free condition (11 consecutive recessive bits) is needed before operation resumes.
3.5.3 Interrupts
Each CAN Controller produces 3 interrupt requests, Receive, Transmit, and other status. The Transmit interrupt is the OR of the Transmit interrupts from the three Tx Buffers. Each Receive and Transmit interrupt request from each controller is assigned
its own channel in the Vectored Interrupt Controller (VIC), and can have its own interrupt service routine. The other status interrupts from all of the CAN
controllers, and the Acceptance Filter LUTerr condition, are OR-ed into one VIC channel.
CHAPTER 4
of the ADC0808, ADC0809 has been optimized by incorporating the most desirable aspects of several A/D conversion techniques. The ADC0808, ADC0809 offers high speed, high accuracy, minimal temperature dependence, excellent long-term accuracy
and repeatability, and consumes minimal power. These features make this device
ideally suited to applications from process and machine control to consumer and automotive applications. For 16-channel multiplexer with common output (sample/hold port) see ADC0816 data sheet. (See AN-247 for more information.).
4.1 Features
Easy interface to all microprocessors Operates ratio metrically or with 5 VDC or a span adjusted voltage reference No zero or full-scale adjust required 8-channel multiplexer with address logic 0V to 5V input range with single 5V power supply Outputs meet TTL voltage level specifications Standard hermetic or molded 28-pin DIP package
28-pin molded chip carrier package ADC0808 equivalent to MM74C949 ADC0809 equivalent to MM74C949-1
4.2.1
Multiplexer
The device contains an 8-channel single-ended analog signal multiplexer. A
particular input channel is selected by using the address decoder. Table I shows the input states for the address lines to select any channel. The address is latched into the decoder on the low-to-high transition of the address latch enable signal.
Table 4.1
Figure 4.2:
The A/D converter's successive approximation register (SAR) is reset on the positive edge of the start conversion (SC) pulse. The conversion is begun on the falling edge of the start conversion pulse. A conversion in process will be interrupted by receipt of a new start conversion pulse. Continuous conversion may be accomplished by tying the end of conversion (EOC) output to the SC input. If used in this mode, an external start conversion pulse should be applied after power up. End-of-conversion will go low between and 8 clock pulses after the rising edge of start conversion. The most important section of the A/D converter is the comparator. It is this section which is responsible for the ultimate accuracy of the entire converter. It is also the comparator drift which has the greatest influence on the repeatability of the device. A chopper-stabilized comparator provides the most effective method of satisfying all the converter requirements.
The chopper-stabilized comparator converts the DC input signal into an AC signal. This signal is then fed through a high gain AC amplifier and has the DC level restored. This technique limits the drift component of the amplifier since the drift is a DC component which is not passed by the AC amplifier. This makes the entire A/D converter extremely insensitive to temperature, long term drift and input offset errors.
The A/D converter has either 4 or 8 multiplexed inputs depending on the variant
The A/D control register establishes the configuration of the converter & controls the start of conversion. The first step in configuring the converter is to set up the peripheral clock. As with all the other peripherals, the A/D clock is derived from the PCLK. This PCLK must be divided down to equal 4.5MHz. This is a maximum value and if PCLK cannot be divided down to equal 4.5MHz then the nearest value below 4.5MHz which can be achieved should be selected.
PCLK is divided by the value stored in the CLKDIV field plus one. Hence the equation for the A/D clock is as follows: CLKDIV = ( PCLK/Adclk) 1 As well as being able to stop the clock to the A/D converter in the peripheral power down register, the A/D has the ability to fully power down. This reduces the overall power consumption and the on-chip noise created by the A/D. On reset, the A/D is in power down mode, so as well as setting the clock rate the A/D must be switched on. This is controlled by the PDN bit in ADCR.
Logic one in this field enables the converter. Unlike other peripherals the A/D converter can make measurements of the external pins when they are configured as GPIO pins. However, by using the pinselect block to make the external pins dedicated to the A/D converter the overall conversion accuracy is increased Prior to a conversion the resolution of the result may be defined by programming the CLKS field. The A/D has a maximum resolution of 10 bits but can be programmed to give any resolution down to 3 bits. The conversion resolution is equal to the number of clock cycles per conversion minus one. Hence for a 10-bit result the A/D requires 11 ADCLK cycles and four for a 3bit result. Once you have configured the A/D resolution, a conversion can be made. The A/D has two conversion modes, hardware and software. The hardware mode allows you to select a number of channels and then set the A/D running. In this mode a conversion is made for each channel in turn until the converter is stopped. At the end of each conversion the result is available in the A/D data register.
At the end of a conversion the Done bit is set and an interrupt may also be generated. The conversion result is stored in the V/Vdda field as a ratio of the voltage on the analogue channel divided by the voltage on the analogue power supply pin. The number of the channel for which the conversion was made is also stored alongside the result. This value is stored in the CHN field. Finally, if the result of a conversion is not read before the next result is due, it will be overwritten by the fresh result and the OVERUN bit is set to one.
Table 4: The A/D may be started by a software event or it may be started by several hardware triggers
The A/D has a second software conversion mode. In this case, a channel is selected for conversion using the SEL bits and the conversion is started under software control by writing 0x01 to the START field. This causes the A/D to perform single conversion and store the results in the ADDR in the same fashion as the hardware mode. The end of conversion can be signaled by an interrupt, or by polling the done bit in the ADDR. In the software conversion mode it is possible to start a conversion when a match event occurs on timer zero or timer one. Or when a selected edge occurs on P0.16 or P0.22, the edge can be rising or falling, as selected by the EDGE field in the ADCR.
CHAPTER 5
UART IN ARM
The LPC2xxx devices currently have two on-chip UARTS. They are both identical to use, except UART1 has additional modem support. Both peripherals conform
to the 550 industry standard specification. Both have a built-in baud rate generator and 16 byte transmit and receive FIFOs.
First the pinselect block must be programmed to switch the processor pins from GPIO to the UART functions. Next the UART line control register is used to configure the format of the transmitter data character.
The character format is set to 8 bits, no parity and one stop bit. In the LCR there is an additional bit called DLAB, which is the divisor latch access bit. In order to be able to program the baud rate generator this bit must be set.
The baud rate generator is a sixteen bit prescaler which divides down Pclk to generate the UART clock which must run at 16 times the baud rate. Hence the formula used to calculate the UART baud rate is: Divisor = Pclk/16 x BAUD In our case at 15MHz: Divisor = 15,000,000/16 x 9600 = (approx) 97 or 0x62 This gives a true baud rate of 9665. Often it is not possible to get an exact baud rate for the UARTs however they will work with up to around a 5% error in the bit timing. So you have some leeway with the UART timings if you need to adjust the Pclk to get exact timings on other peripherals such as the CAN bit timings. The divisor value is held in two registers, Divisor latch MSB (DLM) and Divisor latch LSB (DLL). The first eight bits of both registers holds each half of the divisor as shown below. Finally the DLAB bit in the LCR register must be set back to zero to protect the contents of the divisor registers.
Once the UART is initialized, characters can be transmitted by writing to the Transmit Holding Register. Similarly, characters may be received by reading from the Receive Buffer Register. In fact both these registers occupy the same memory location,
writing a character places the character in the transmit FIFO and reading from this location loads a character from the Receive FIFO. The two routines shown below demonstrate handling of transmit and receive characters.
CHAPTER 6
5v DC, 12v DC. LPC2129-philips. CAN BUS. ULTRASONIC SENSORS in front-rear end,
SOFTWARE USED
Embedded C. Philips Flash utility Keil vision 3(IDE) C ARM Compiler (v2.32a) VB Software
For critical code size applications, the alternative 16-bit Thumb Mode reduces code by more than 30% with minimal performance penalty. With their compact 64 and 144 pin packages, low power consumption, various 32-bit timers, combination of 4channel 10-bit ADC and 2/4 advanced CAN channels or 8-channel 10-bit ADC and 2/4 advanced CAN channels (64 and 144 pin packages respectively), and up to 9 external interrupt pins these microcontrollers are particularly suitable for industrial control, medical systems, access control and point-of-sale. Number of available GPIOs goes up to 46 in 64 pin package. In 144 pin packages number of available GPIOs tops 76 (with external memory in use) through 112 (single-chip application). Being equipped wide range of serial communications interfaces, they are also very well suited for communication gateways, protocol converters and embedded soft modems as well as many other general-purpose applications. Number of Components Used: Two KNOWX ARM BOARDS
Features of LPC2129
16/32-bit ARM7TDMI-S microcontroller in a 64 or 144 pin package. 16 kB on-chip Static RAM 128/256 kB on-chip Flash Program Memory. 128-bit wide interface/accelerator enables high speed 60 MHz operation. External 8, 16 or 32-bit bus (144 pin package only) In-System Programming (ISP) and In-Application Programming (IAP) via onchip boot-loader software. Flash programming takes 1 ms per 512 byte line. Single sector or full chip erase takes 400 ms.
Embedded Trace Macrocell enables non-intrusive high speed real-time tracing of instruction execution. Two/four interconnected CAN interfaces with advanced acceptance filters. Four/eight channel (64/144 pin package) 10-bit A/D converter with conversion time as low as 2.44 ms. Two 32-bit timers (with 4 capture and 4 compare channels), PWM unit (6 outputs), Real Time Clock and Watchdog. Multiple serial interfaces including two UARTs (16C550), Fast I2C (400 kbits/s) and two SPIs. 60 MHz maximum CPU clock available from programmable on-chip PhaseLocked Loop. Vectored Interrupt Controller with configurable priorities and vector addresses. Up to forty-six (64 pin) and hundred-twelve (144 pin package) 5 V tolerant general purpose I/O pins. Up to 12 independent external interrupt pins available (EIN and CAP functions).
On-chip crystal oscillator with an operating range of 1 MHz to 30 MHz. Two low power modes, Idle and Power-down. Processor wake-up from Power-down mode via external interrupt
Device description
With 2.5V - 5.5V power the LV-MaxSonar- EZ1 provides very short to longrange detection and ranging, in an incredibly small package. The LV-MaxSonar-EZ1 detects objects from 0-inches to 254-inches (6.45-meters) and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution. Objects from 0inches to 6-inches range as 6-inches. The interface output formats included are pulse width output, analog voltage output, and serial digital output. Number of Components Used: Two
Features
Continuously variable gain for beam control and side lobe suppression Object detection includes zero range objects 2.5V to 5.5V supply with 2mA typical current draw Readings can occur up to every 50mS, (20-Hz rate) Free run operation can continually measure and output range information Triggered operation provides the range reading as desired All interfaces are active simultaneously Serial, 0 to Vcc
9600Baud, 81N Analog, (Vcc/512) / inch Pulse width, (147uS/inch) Learns ringdown pattern when commanded to start ranging Designed for protected indoor environments Sensor operates at 42KHz High output square wave sensor drive (double Vcc)
ANOutputs analog voltage with a scaling factor of (Vcc/512) per inch. A supply of 5V yields ~9.8mV/in. and 3.3V yields ~6.4mV/in. The output is buffered and corresponds to the most recent range data. PW This pin outputs a pulse width representation of range. To calculate distance use the scale factor of 147uS per inch. BW *Leave open or hold low for serial output on the TX output.
is fully compatible with the ISO-11898 standard, including 24V requirements. It will operate at speeds of up to 1Mb/s.Typically, each node in a CAN system must have a device to convert the digital signals generated by a CAN controller to signals suitable for transmission over the bus cabling (differential output). It also provides a buffer between the CAN controller and the high-voltage spikes that can be generated on the CAN bus by outside sources (EMI, ESD, electrical transients, etc.). Number of Components Used: Two
Figure (a)
Transmitter Function
The CAN bus has two states: Dominant and Recessive. A dominant state occurs when the differential voltage between CANH and CANL is greater than a defined voltage (e.g.,1.2V). A recessive state occurs when the differential voltage is less than a defined voltage (typically 0V). The dominant and recessive states correspond to the low and high state of the TXD input pin, respectively. However, a dominant state initiated by another CAN node will override a recessive state on the CAN bus.
Receiver Function
The RXD output pin reflects the differential bus voltage between CANH and CANL. The low and high states of the RXD output pin correspond to the dominant and recessive states of the CAN bus, respectively.
Features
Supports 1 Mb/s operation Implements ISO-11898 standard physical layer requirements Suitable for 12V and 24V systems Externally-controlled slope for reduced RFI emissions Detection of ground fault (permanent dominant) on TXD input Power-on reset and voltage brown-out protection
An unpowered node or brown-out event will not disturb the CAN bus Low current standby operation Protection against damage due to short-circuit conditions (positive or negative battery voltage). Protection against high-voltage transients Automatic thermal shutdown protection Up to 112 nodes can be connected High noise immunity due to differential bus implementation Temperature ranges: Industrial (I): -40C to +85C Extended (E): -40C to +125C
The Kalman filter produces estimates of the true values of measurements and their associated calculated values by predicting a value, estimating the uncertainty of the predicted value, and computing a weighted average of the predicted value and the measured value. The most weight is given to the value with the least uncertainty. The estimates produced by the method tend to be closer to the true values than the original measurements because the weighted average has a better estimated uncertainty than either of the values that went into the weighted average. From a theoretical standpoint, the Kalman filter is an algorithm for efficiently doing exact inference in a linear dynamical system, which is a Bayesian model similar to a hidden Markov model but where the state space of the latent variables is continuous and where all latent and observed variables have a Gaussian distribution (often a multivariate Gaussian distribution). The Kalman filter uses a system's dynamics model (i.e., physical laws of motion), known control inputs to that system, and measurements (such as from sensors) to form an estimate of the system's varying quantities (its state) that is better than the estimate obtained by using any one measurement alone. As such, it is a common sensor fusion algorithm. All measurements and calculations based on models are estimates to some degree. Noisy sensor data, approximations in the equations that describe how a system changes, and external factors that are not accounted for introduce some uncertainty about the inferred values for a system's state. The Kalman filter averages a prediction of a system's state with a new measurement using a weighted average. The purpose of the weights is that values with better (i.e., smaller) estimated uncertainty is "trusted" more. The weights are calculated from the covariance, a measure of the estimated uncertainty of the prediction of the system's state. The result of the weighted average is a new state estimate that lies in between the predicted and measured state, and has a better estimated uncertainty than either alone. This process is repeated every time step, with the new
estimate and its covariance informing the prediction used in the following iteration. This means that the Kalman filter works recursively and requires only the last "best guess" not the entire history - of a system's state to calculate a new state. When performing the actual calculations for the filter (as discussed below), the state estimate and covariances are coded into matrices to handle the multiple dimensions involved in a single set of calculations. This allows for representation of linear relationships between different state variables (such as position, velocity, and acceleration) in any of the transition models or covariances. The Kalman filter is used in sensor fusion and data fusion. Typically real time systems produce multiple sequential measurements rather than making a single measurement to obtain the state of the system. These multiple measurements are then combined mathematically to generate the system's state at that time instant. As an example application, consider the problem of determining the precise location of a truck. The truck can be equipped with a GPS unit that provides an estimate of the position within a few meters. The GPS estimate is likely to be noisy; readings 'jump around' rapidly, though always remaining within a few meters of the real position. The truck's position can also be estimated by integrating its speed and direction over time, determined by keeping track of the amount the accelerator is depressed and how much the steering wheel is turned. This is a technique known as dead reckoning. Typically, dead reckoning will provide a very smooth estimate of the truck's position, but it will drift over time as small errors accumulate. Additionally, the truck is expected to follow the laws of physics, so its position should be expected to change proportionally to its velocity. In this example, the Kalman filter can be thought of as operating in two distinct phases: predict and update. In the prediction phase, the truck's old position will be modified according to the physical laws of motion (the dynamic or "state transition" model) plus any changes produced by the accelerator pedal and steering wheel. Not only
will a new position estimate be calculated, but a new covariance will be calculated as well. Perhaps the covariance is proportional to the speed of the truck because we are more uncertain about the accuracy of the dead reckoning estimate at high speeds but very certain about the position when moving slowly. Next, in the update phase, a measurement of the truck's position is taken from the GPS unit. Along with this measurement comes some amount of uncertainty, and its covariance relative to that of the prediction from the previous phase determines how much the new measurement will affect the updated prediction. Ideally, if the dead reckoning estimates tend to drift away from the real position, the GPS measurement should pull the position estimate back towards the real position but not disturb it to the point of becoming rapidly changing and noisy. Data fusion using a Kalman filter can assist computers to track objects in videos with low latency. The tracking of objects is a dynamic problem, using data from sensor and camera images that always suffer from noise. This can sometimes be reduced by using higher quality cameras and sensors but can never be eliminated, so it is often desirable to use a noise reduction method. The iterative predictor-corrector nature of the Kalman filter can be helpful, because at each time instance only one constraint on the state variable need be considered. This process is repeated, considering a different constraint at every time instance. All the measured data are accumulated over time and help in predicting the state. Video can also be pre-processed, perhaps using a segmentation technique, to reduce the computation and hence latency. The Kalman filter is a recursive estimator. This means that only the estimated state from the previous time step and the current measurement are needed to compute the estimate for the current state. In contrast to batch estimation techniques, no history of observations and/or estimates is required. In what follows, the notation
\hat{\textbf{x}}_{n|m} represents the estimate of \textbf{x} at time n given observations up to, and including at time m.
The state of the filter is represented by two variables: * \hat{\textbf{x}}_{k|k}, the a posteriori state estimate at time k given observations up to and including at time k; * \textbf{P}_{k|k}, the a posteriori error covariance matrix (a measure of the estimated accuracy of the state estimate). The Kalman filter can be written as a single equation, however it is most often conceptualized as two distinct phases: Predict and Update. The predict phase uses the state estimate from the previous timestep to produce an estimate of the state at the current timestep. This predicted state estimate is also known as the a priori state estimate because, although it is an estimate of the state at the current timestep, it does not include observation information from the current timestep. In the update phase, the current a priori prediction is combined with current observation information to refine the state estimate. This improved estimate is termed the a posteriori state estimate. Typically, the two phases alternate, with the prediction advancing the state until the next scheduled observation, and the update incorporating the observation. However, this is not necessary; if an observation is unavailable for some reason, the update may be skipped and multiple prediction steps performed. Likewise, if multiple independent observations are available at the same time, multiple update steps may be performed (typically with different observation matrices Hk).
Predict
Predicted (a priori) state estimate \hat{\textbf{x}}_{k|k-1} = \textbf{F}_{k}\hat{\textbf{x}}_{k-1|k-1} + \textbf{B}_{k} \textbf{u}_{k} Predicted (a priori) estimate covariance
\textbf{P}_{k|k-1} = \textbf{F}_{k} \textbf{P}_{k-1|k-1} \textbf{F}_{k}^{\text{T}} + \textbf{Q}_{k} [edit] Update Innovation or measurement residual \tilde{\textbf{y}}_k = \textbf{z}_k - \textbf{H}_k\hat{\textbf{x}}_{k|k-1} Innovation (or residual) covariance \textbf{S}_k = \textbf{H}_k \textbf{P}_{k|k-1} \textbf{H}_k^\text{T} + \textbf{R}_k Optimal Kalman gain \textbf{K}_k = \textbf{P}_{k|k1}\textbf{H}_k^\text{T}\textbf{S}_k^{-1} Updated (a posteriori) state estimate \hat{\textbf{x}}_{k|k} = \hat{\textbf{x}}_{k|k-1} + \textbf{K}_k\tilde{\textbf{y}}_k Updated (a posteriori) estimate covariance \textbf{H}_k) \textbf{P}_{k|k-1} The formula for the updated estimate and covariance above is only valid for the optimal Kalman gain.Usage of other gain values require a more complex formula found in the derivations section. \textbf{P}_{k|k} = (I - \textbf{K}_k
Step7:
the code.
CHAPTER 7
APPLICATIONS
7.1 Real time application
Used as a Warning System to avoid Collision in National Highways. Used by Police to Track the speed of the approaching vehicles. Used to detect an object in Extreme conditions like Fog and misty areas. Can be implemented in Robotic Applications. Can be used in large vehicles like Trucks and buses Can be implemented in Aircraft and aerospace electronics Can be used in Passenger and cargo trains Can be implemented in Maritime electronics..
CHAPTER 8
RESULTS
If any object is very near to the vehicle then the vehicle will be stopped automatically. By using Kalman algorithm we can find out the relative speed between the near by vehicles and monitor it continously. All these information we are displaying on the lcd and at the same time we can send to a PC.
CHAPTER 9
CONCLUSION
This project CAN BASED ACCIDENT AVOIDANCE SYSTEM is intended for secure and smooth journey. The car/ vehicle itself is aware of its movement. If the driver himself is not concentrating on driving or any other parameters, which may cause damage to vehicle as well a life, this intelligent car/ vehicle warn the driver regarding the danger ahead. As the value of a human life is countless times more than the cost of this project, we are proud to be behind the success of this project.
CHAPTER 10
FUTURE ENHANCEMENT
As for the rear end, side-end end collision avoidance subsystem can be adopted with the use of the currently available ultrasonic sensors for vehicles. Further, the relative speed between two cars can be estimated by applying a one-dimension Kalman filter [5] with great efficiency. From experimental data, a D/V curve can be further obtained to reliably generate a warning signal in advance of the accidental collision. As the car in traffic with pretty low speed or in a waiting state at the intersection, the warning signals should be terminated after a certain time since no collision warning is required under such circumstances.
SOURCE CODE
#include <LPC21xx.H> void CAN1_TX(unsigned int); void CAN2_RX(void); void Delay(unsigned int itime) //Here we are generating { unsigned int i,j; for(i=0;i<itime;i++) for(j=0;j<1500;j++); } //=============================================== void lcd_init() { lcd_cmd(0x20); lcd_cmd(0x28); lcd_cmd(0x0C); lcd_cmd(0x01); lcd_cmd(0x06); lcd_cmd(0x80); } void lcd_cmd(unsigned char cmd) { unsigned char temp; temp = cmd; cmd &= 0xF0; cmd = cmd << 6; IOCLR0 = 0x00003C00; IOSET0 = cmd; IOCLR1 = 0x03000000; IOSET1 = 0x02000000; Delay(50); IOCLR1 = 0x02000000; Delay(50); cmd = temp; cmd &= 0x0F; cmd = cmd << 10; IOCLR0 = 0x00003C00; IOSET0 = cmd; IOCLR1 = 0x03000000; ms delay
//Display on/off control //Clear Display //Entry Mode set //sets the display position to starting
//left shifted by 6 times //Clear the Data Pins //Register Select Clear For Command //Enable Set //Enable Clear
//left shifted by 10 times //Clear the Data Pins //Register Select Clear For Command
} //=============================================== //THIS IS THE FUNCTION FOR WRITE THE DATAS IN DATA REG void lcd_char(unsigned int ch) { unsigned char temp; temp = ch; ch &= 0xF0; ch = ch << 6; //left shifted by 6 times IOCLR0 = 0x00003C00; //Clear the Data Pins IOSET0 = ch; IOCLR1 = 0x03000000; //Register Select Set For Data IOSET1 = 0x03000000; //Enable Set Delay(5); IOCLR1 = 0x02000000; //Enable Clear Delay(5); ch = temp; ch &= 0x0F; ch = ch << 10; //left shifted by 10 times IOCLR0 = 0x00003C00; //Clear the Data Pins IOSET0 = ch; IOCLR1 = 0x03000000; //Register Select Set For Data IOSET1 = 0x03000000; //Enable Set Delay(5); IOCLR1 = 0x02000000; //Enable Clear Delay(5); } //=============================================== //DISPLAY STRING OF DATA ON LCD void lcd_print(unsigned char *str) { while(*str) lcd_char(*str++); //Display String Data On LCD } /*******************************************************/ void Delay1(unsigned int itime) { unsigned int i,k=0; for(i=0;i<itime;i++) for(k=0;k<1000;k++); }
/*******************************************************/ int main(void) { unsigned int ch; IODIR0=0x00003C00; IODIR1=0x03000000; PINSEL1=0x00054000; lcd_init(); lcd_print("CAN ACCIDENT"); lcd_cmd(0xC0); lcd_print("AVOIDENCE SYSTEM"); Delay1(2000); Delay1(2000); Delay1(2000); Delay1(2000); lcd_cmd(0x01); /******************CAN1 intialization****************/ C1MOD=1;/*Reset CAN1 controller*/ C1BTR=0x001C001D;/*Set baud Rate for CAN*/ C1MOD=0;/*Enable CAN1 controller*/ lcd_cmd(0x01); lcd_print("CAN1 ENABLED"); Delay1(200); Delay1(200); Delay1(200); /******************CAN2 intialization***************/ C2MOD=1;/*Reset CAN2 controller*/ C2BTR=0x001C001D;/*Set baud Rate for CAN2*/ C2MOD=0;/*Enable CAN2 controller*/ lcd_cmd(0x01); lcd_print("CAN2 ENABLED"); Delay1(2000); Delay1(2000); Delay1(2000);
lcd_cmd(0x01); while(1) { if(IOPIN0 & 0x20000000 ) ch=0x01; else ch=0x02; if(ch==0x01 || ch==0x02) { CAN1_TX(ch); CAN2_RX(); } } }
//po.29
void CAN1_TX(unsigned int ch) { if(C1SR & 0x00000004) { C1TFI1=0x00040000;/*Set TX data length*/ C1TID1=C1RID;/*Set TX Identifier*/ C1TDA1 =ch; /*Load the Data to TX1 buffer*/ C1CMR=0x21; /*send the Data*/ Delay1(2000); } } void CAN2_RX() { int value; C2CMR=0X04; lcd_cmd(0x01); value=C2RDA; if(value==0x01) { lcd_cmd(0x01); lcd_cmd(0x80); lcd_print("OBSTACLE FAR"); lcd_cmd(0xC0); lcd_print(" ROAD CLEAR "); Delay1(2000);
Delay1(2000); Delay1(2000); } if(value==0x02) { lcd_cmd(0x01); lcd_cmd(0x80); lcd_print(" OBSTACLE NEAR"); lcd_cmd(0xC0); lcd_print(" GO SLOW "); Delay1(2000); Delay1(2000); Delay1(2000); } }
12.REFERENCES Books
[1]. ARM7TDMI datasheet ARM [2]. LPC2119/2129/2194/2292/2294 User Manual Philips [3]. ARM System on chip architecture Steve Furber [4]. Architecture Reference Manual David Seal [5]. ARM System developers guide Andrew N. Sloss, Domonic Symes, [6]. Chris Wright [7]. Micro C/OS-II Jean J. Labrosse GCC The complete reference Arthur Griffith
Websites
[1]. http://www.arm.com [2]. http://www.philips.com [3]. http://www.lpc2000.com [4]. http://www.semiconductors.philips.com/ [5]. http://ieeexplore.ieee.org [6]. http://ww.hitex.co.uk [7]. http://www.keil.co.uk [8]. http://www.ucos-ii.com [9]. http://www.ristancase.com [10]. http://gcc.gnu.org/onlinedocs/gcc/Evaluation Boards And Modules [11]. http://www.knox.com