Arduino Graduation Project - Design and Implementation of Self-Driving Car Control System Based on Arduino+PID+AI (Graduation Thesis + Program Source Code) - Self-Driving Car Control System

Design and implementation of self-driving car control system based on Arduino+PID+AI (Graduation thesis + program source code)

Hello everyone, today I will introduce to you the design and implementation of a self-driving car control system based on Arduino+PID+AI. At the end of the article, the thesis and source code download address of this graduation project are attached. Friends who need to download the proposal report PPT template and thesis defense PPT template, etc., can go to my blog homepage to view the self-service download method in the bottom column on the left.

Article directory:

1. Project introduction

  1. In recent years, all walks of life have undergone profound changes. With the continuous development of electronics and AI technology, mankind has entered the era of artificial intelligence. Artificial intelligence is constantly optimizing and replacing traditional industries, constantly improving the efficiency of human office work, and greatly facilitating people's production and life. The application of artificial intelligence in autonomous driving at home and abroad is also constantly improving, and autonomous driving has broad prospects in the future. As an important part of autonomous driving technology, automatic control plays a decisive role and is of great significance to the research on automatic control. This article mainly designs the self-driving car control system independently and combines it with artificial intelligence. The main research contents of this article are as follows:
    (1) Propose the overall design plan of the self-driving car, conduct dynamic analysis, and finally determine the control objectives of the system and design the plan.
    (2) Carry out model simulation design for the control objectives of the system, use Matlab to simulate the PID control system, and analyze and adjust the control process. Use SolidWorks to accurately simulate each module and shape of the car.
    (3) Analyze the functional requirements of the hardware part of the system, determine the main control as Arduino, select the motor driver and other sensors, and design the system circuit.
    (4) Design the system software part, analyze the main control parts, design the control flow chart, complete the main program of the system and the programming of each module, and complete testing.
    (5) Conduct overall testing and optimization of the completed autonomous driving car control system. The speed of each motor of the car reaches the target value within ±0.3cm/s within 0.5s, and the system can perfectly realize the speed and angle adjustment set by the system.


2. Resource details

Project Difficulty: Medium Difficulty
Applicable Scenario: Graduation Project Thesis on Related Topics
Word Count: 20,766 words, 57 pages
Contains: Full set of source code + complete thesis
proposal report, thesis defense, project report, etc. ppt templates Recommended download method:
Insert image description here


3. Keywords

Autonomous driving control system motor control Arduino

4. Introduction to Bishe

Tip: The following is a brief introduction to the graduation thesis. The complete source code of the project and the download address of the complete graduation thesis can be found at the end of the article.

Chapter 1 Introduction
1.1 Purpose and significance of the research
In today's society, with the continuous development of science and technology, the industry has undergone profound changes. With the development of electronics and AI technology, mankind has entered the era of artificial intelligence. With the advent of the third wave of artificial intelligence, artificial intelligence is bound to cause major changes in various industries. AI has become a popular research direction in the new era. Artificial intelligence is constantly optimizing and replacing traditional industries, constantly improving the efficiency of human office work, and greatly facilitating people's production and life. The application of artificial intelligence in autonomous driving at home and abroad is also constantly improving, and autonomous driving has broad prospects in the future. As an important part of autonomous driving technology, automatic control plays a decisive role and is of great significance to the research of autonomous driving.

Through this question, you can not only understand the general process of scientific research, exercise the ability to analyze and solve problems, master the basic processes and knowledge skills of artificial intelligence learning, master the principles of automatic control, but also combine the control and artificial intelligence processes. , have an in-depth understanding of the latest applications of artificial intelligence such as autonomous driving.

1.2 Current status of research on self-driving cars
1.2.1 Current status of self-driving cars at home and abroad
Omitted

1.3 Main research content and technical process
This article mainly independently designs a car with certain functions (including remote control) and combines the control and artificial intelligence processes to gain a deeper understanding of the latest artificial intelligence applications such as autonomous driving. The main research contents are as follows:
Propose the overall design plan of the self-driving car, conduct dynamic analysis, and finally determine the control objectives of the system and design the system-related plans.
Carry out model simulation design for the control objectives of the system, use Matlab to simulate the PID control system, and analyze and adjust the control process. Use SolidWorks to accurately simulate each module and shape of the car.
Build the hardware part of the system, determine the selection of main control chips, drive motors, drive modules, sensors, etc., and design the system circuit part.
Design the system software part, analyze the main controls, design the control flow chart, complete the main program design of the system and the program design of each module, and complete writing and testing.
Conduct overall testing and optimization of the completed autonomous driving car control system. The speed of each motor of the car reaches the target value within ±0.3cm/s within 0.5s. The control system can perfectly realize the speed and angle adjustment set by the system.

1.4 Main work
According to the research content, the main work of this article is shown in Figure 1.3
Insert image description here

Figure 1.3 Main work

Chapter 2 Overall Scheme Design of the Autonomous Driving Car System
2.1 Overall System Scheme
The autonomous driving car system based on artificial intelligence is a supporting system that can be combined with the automatic driving algorithm program to realize automatic driving. The system consists of chassis, remote control, processor and various peripherals. The chassis is driven by four wheels, driven by the main control and motor, and coupled with sensors such as gyroscopes and encoders to achieve precise movement of the car. The remote control uses a Bluetooth module to communicate with the chassis, and the system can use image recognition to control the movement of the car, including forward, backward, left and right turns, acceleration and deceleration, etc. As a vehicle-mounted computing platform, the processor needs to have certain image processing capabilities to calculate the real-time parameters of the movement speed and angle target values ​​of the car during operation through the real-time images captured by the camera. Peripherals include cameras that provide real-time image data, mouse, keyboard and screen required to control the processor, etc. The renderings of the car and remote control of the automatic driving car system are shown in Figure 2.1 and Figure 2.2.
Insert image description here

Figure 2.1 Car chassis renderings
Insert image description here

Figure 2.2 Remote control rendering.
The self-driving car system first uses the image data collected by the camera as a data set and combines it with the self-driving artificial intelligence framework for model training. During the operation of the self-driving car, the processor calculates the real-time speed and angle target values ​​​​by combining the received image data with the existing framework, and then transmits these data to the main control of the chassis to finally realize the control of the self-driving car system. Finally complete the route preset on the map as shown in Figure 2.3 (green and blue are the trigger areas, red is the end area, in addition to the starting point, end point and ordinary road surface, it also includes a zebra crossing).
Insert image description here

Figure 2.3 Map
2.2 System Requirements Analysis
According to the analysis of the system's operating process, in order for the system to complete the verification of the automatic driving function, it must be able to drive in a straight line and accurately turn. In order to ensure that the car accurately follows the preset route on the map, accurate angle and speed data must be obtained and adjusted and controlled. Now we will analyze the design requirements of the automatic driving car system.
(1) In terms of system control performance, timeliness and accuracy are required. After receiving instructions from the processor, the entire system must respond correctly, quickly, and stably.
(2) When driving in a straight line, the wheel speeds on both sides of the self-driving car must be consistent. When turning, the rotation speed of the wheel responsible for steering must be kept stable, that is, the angle turned per unit time is constant.
(3) During the operation of the system, the actual values ​​of speed and angle must reach near the target value within 0.5s at most, so that real-time control can be achieved to complete various operating goals.
(4) The self-driving car system must be scalable and portable, so that other sensors and modules can be added later to improve functions.

2.3 Control analysis
In the design process of the autonomous driving car system, the system under different working conditions should first be analyzed to make corresponding adjustments. Accurate adjustments require mathematical modeling of the system, combined with kinematics and dynamics models. Carry out analysis and calculation to provide a theoretical basis for the control of the automatic driving car system.
Because the actual situation is more complicated, two approximations are made here. The direct driving force for the operation of the car is the friction between the wheels and the ground. The motor drives the wheels to rotate and the wheels rub against the ground to produce friction in the opposite direction of rotation. This friction is divided into two parts: static friction and sliding friction. From:
F1 = F (2-1)
The magnitude of the static friction force is equal to the magnitude of the force of the motor driving the wheel to rotate. From:
F2 = k * Fn (2-2)
Sliding friction is positively related to positive pressure. In actual analysis, we do not consider the influence of this small part of sliding friction, that is, the speed of the car is only related to the rotation of the motor. Speed ​​related.
At the same time, due to factors such as motor differences and voltage fluctuations, some motor control algorithms must be adopted to make the actual speed of the motor the same as the target value. Therefore, these factors are not considered when performing kinematics and mechanics analysis here. It is considered that the motor speed is equal to our target value.
When the car runs in a straight line, it is relatively simple. All four wheels can rotate in the same direction. In this way, the four powers and the resultant force of the car are always facing forward, and the car moves forward (Figure 2.4).
Insert image description here

Figure 2.4 Analysis of the forward force of the car.
When the car needs to turn, since the four wheels and the motor are exactly the same and the directions are parallel to each other, it is necessary to control the speed and direction of the motor rotation to generate a motor differential to achieve the car's rotation. Turn. As shown in the figure, for example, when turning right, the two wheels on the left side of the car rotate forward, and the two wheels on the right side rotate backward (Figure 2.5). At the same time, it is best for the centers of the four wheels to form a square, so as to ensure the consistency of the body position and image collection results when the car turns.
Insert image description here

Figure 2.5 Analysis of the left-turn force of the car
. When the car stops, just reduce the speed of all motors to 0. The car itself is not fast, so there is no need to set up a braking system and braking algorithm.
2.4 Scheme Design
Based on the overall scheme of the automatic driving car system and the analysis of the control objects, combined with the main hardware equipment of the working process, the production process is divided into the control process block diagram 2.6 shown in the figure. -
Insert image description here

Figure 2.6 Schematic design block diagram
The main control object of the control system is the drive motor of the system. The main control parameters are: motor rotation direction, rotation speed, etc. The control system mainly obtains the system's operating mode and operating status data through sensors such as encoders and gyroscopes. These data are then processed, and based on this, different motors are accurately controlled so that the system runs according to the route set in advance.
In the specific control process, the sensor used to measure the speed of the brushless DC motor receives speed data in real time, converts the analog data into digital data through the AD conversion program, and supplements and adjusts it through the control program and related algorithms. Then the control data is transmitted to the motor through the PWM controller, thereby controlling the brushless DC motor.
For the actual value of the motor, it cannot be equal to the target value only through PWM control. The PID algorithm is used for control, and the PWM value required to change to the target value is calculated in real time to achieve real-time adjustment of the motor speed. The same is true for the car turning process. Setting the target angle for the car to turn and then adjusting it in real time with the help of the PID algorithm can quickly and accurately bring the actual value close to the target value.

2.5 Summary of this Chapter
This chapter first introduces the overall structure and working principle of the self-driving car. Then the system control was analyzed, the dynamic model of the system was established, and the main control parameters and control objectives were determined. Then the needs and requirements of the control system were analyzed, mainly including accuracy and timeliness, security, portability, etc. Finally, the overall scheme of the control system was designed, and the main objectives and methods of control were determined. When controlling the speed of the motor travel drive, PWM control and PID control algorithms were introduced for precise control [4].

Chapter 3 System Model Simulation
In the design process of the self-driving car system, since it involves a variety of working parts and sensors, the traditional design process is complex and requires multiple actual debuggings to achieve the ideal effect. In order to reduce the workload, design difficulty and To shorten the design process, modeling and simulation technology is needed. As the name suggests, it uses simulation software to complete the construction of mathematical models and physical models in the software, and uses computers to perform calculations and solutions to obtain control methods suitable for the designed system. This can greatly improve the efficiency of system design. The simulation design of the drive motor is an important part of the control system design and the theoretical basis for the construction of the control system.
During the operation of the self-driving car system, the main motion states are straight driving and turning, which are realized through the speed control of the brushless DC motor. Therefore, during the simulation process of the control system, the motor is driven mainly through the SIMULINK module in MATLAB. The PID control method carries out logic construction and simulation. By giving relevant parameters to the system, simulation analysis is performed, and finally effective control conditions and relevant parameters are obtained, which provides conditions for the program design and prototype production of the control system.
At the same time, for physical construction, system structure and layout simulation are also essential. Through SolidWorks, all structures and modules of the system can be simulated in three dimensions, and the running process of the car on the map can be simulated. This is very important and necessary for physical construction and system debugging, and lays a solid foundation for the final realization of autonomous driving.
3.1 PID control method and simulation
3.1.1 PID principle
PID controller is widely used in various industrial process controls because of its simple structure, easy implementation, and strong robustness. As an extensive control law, PID control has not been eliminated due to the emergence of various advanced control algorithms for a long period of time. On the contrary, after the test of time, PID control still accounts for a large share of various control technologies. dominant position [5].
The PID controller is an effective and simple control algorithm based on the estimation of deviation "past, present and future" information. The principle of the conventional PID control system is shown in Figure 3.1.
Insert image description here

Figure 3.1 Schematic diagram of PID control system
The entire system mainly consists of PID controller and controlled objects. Then the deviation is proportional, integral and differential to form a control quantity through linear combination to control the controlled object. From Figure 3-1, the ideal algorithm of the PID controller (e(t) is the deviation between the target value and the actual output value) is:
u(t)=Kp[e(t)+1/T_i ∫_0^∞▒〖 e(t)dt+T_d (de(t))/dt〗] (3-1)
According to the formula, we can know and understand the three parameters of PID:
proportional control Kp can improve the dynamic response speed of the system and quickly reflect errors , thereby reducing the error, but it cannot eliminate the error. Simply put, the larger the value, the faster it is. The smaller value is slower, but it may overshoot or be too slow, which has many disadvantages. If it is too large, it will be unstable.
Integral control Ki generally eliminates steady-state errors. As long as there is an error in the system, the integral effect will continue to accumulate, and the control value is output to eliminate the error. If the deviation is zero, the integration will stop. However, if the integral effect is too strong, the overshoot will increase. , or even cause the system to oscillate. To predict this oscillation, we need the differential of the third term.
Differential control Kd. Differential is obviously related to the change rate. It can reduce the overshoot to overcome the oscillation, improve the stability of the system, and speed up the response speed, making the system faster and with better dynamic performance. It can be judged based on the change rate. Whether the system is about to rise or fall, the control amount of the system is changed in advance, which complements the integral effect, so that the system is almost perfect [6].
The above part is an analysis of the PID algorithm of a continuous system, but computer control is discontinuous, so when writing a program, it is necessary to convert mathematical expressions, use summation instead of integral, use backward difference instead of differential, and finally form a simulated PID algorithm. Discretize difference equations.

u(t)u(k)								(3-2)
e(t)e(k)									(3-3)
∫_0^t▒〖e(t)dt=_(i=0)^k▒〖e(i)〗 ∆t=_(i=0)^k▒〖Te(i)〗〗			(3-4)
(de(t))/dt≈(e(k)-e(k-1))/∆t=(e(k)-e(k-1))/T							(3-4)
然后得到增量式PID的计算公式:
{
    
    (∆U_0 (n)=K_p {
    
    [ε(n)-ε(n-1)]+T_D/T[ε(n)-2ε(n-1)+ε(n-2)]}@U(k)=u(k)+U(k-1))(3-5){
    
    (∆U_0 (n)=K_p [ε(n)-ε(n-1)]+K_i ε(n)+K_d [ε(n)-2ε(n-1)+ε(n-2)]}@U(k) =u(k)+U(k-1))(3-6)

3.1.2 Simulink simulation and parameter adjustment of PID.
First set the transfer function and the parameters of any PID controller. According to the experience of PID parameter adjustment, the values ​​​​of Ki and Kd are generally not too large. They are both set to 0 first, and Kp is optional. Set one, this time set to 6. With the help of Matlab's Simulink function, the step function is used as the signal source, and an oscilloscope is added at the end to observe the results to simulate the results.
Insert image description here

Figure 3.2 Simulink simulation process
Double-click the oscilloscope to generate a waveform. Adjust the parameters according to the waveform to get the ideal waveform. Adjust the parameters according to the found parameter adjustment method:
(1) Determine the proportional coefficient Kp.
When determining the proportional coefficient Kp, first remove the integral term and differential term of the PID. You can set Ti=0 and Td=0 to make it a pure proportion. adjust. The input is set to 60% to 70% of the maximum allowable output of the system. The proportional coefficient Kp gradually increases from 0 until the system oscillates; conversely, the proportional coefficient Kp gradually decreases from this time until the system oscillation disappears. Record the proportional coefficient Kp at this time, and set the PID proportional coefficient Kp to 60% to 70% of the current value.
(2) Determine the integral time constant Ti.
After determining the proportional coefficient Kp, set a larger integral time constant Ti, then gradually decrease Ti until the system oscillates, and then in turn, gradually increase Ti until the system oscillation disappears. . Record the Ti at this time, and set the PID integration time constant Ti to 150% to 180% of the current value.
(3) Determine the differential time constant Td.
Generally, the differential time constant Td does not need to be set. It can be 0. At this time, PID adjustment is converted into PI adjustment. If it needs to be set, it is the same as the method for determining Kp, taking 30% of its value when there is no oscillation [7].
The final parameters are Kp = 8, Kd = 0.5, Ki = 0.1. The oscilloscope image is shown in Figure 3.3.
Insert image description here

Figure 3.3 Simulink oscilloscope image
3.2 System structure and layout simulation
The system structure and layout simulation mainly uses SolidWorks to perform one-to-one three-dimensional model simulation. Simulate the actual situation in as much detail as possible to pave the way for the realization and optimization of autonomous driving functions.
The simulation structure of the car model is relatively simple, mainly including wheels, batteries, main control boards and other components, as shown in Figures 3.4 and 3.5.
Insert image description here

Figure 3.4 Car model view 1
Insert image description here

Figure 3.5 Car model view 2
The remote control model is complete. Because the model during the conception process was not saved, the model shown is exactly the same as the actual object, including acrylic shell, main control board, battery, switch, Bluetooth module, etc. . As shown in Figures 3.6 and 3.7.
Insert image description here

Figure 3.6 Remote control model view 1
Insert image description here

Figure 3.7 Remote control model view 2
3.3 Summary of this chapter
This chapter mainly simulates the PID parameter adjustment process and three-dimensional model of the automatic driving car system, and analyzes the relevant results, which provides theoretical support for the software and hardware design of the control system and the entire project. lay a good foundation for the smooth progress of the project.

Chapter 4 Control System Hardware Design
Based on the simulation results, select the hardware part of the system, including main control chip, motor, sensor, etc. And design the power supply circuit, motor drive circuit, and serial communication circuit.
4.1 Control system hardware constitutes
the design of the autonomous driving car system. The design of the hardware part is the basis for the implementation of the control system. The processor needs to process the collected images and run the designed artificial intelligence framework to control the chassis. The chassis master control The chip on board can run the programs required to control the entire system, and then the end of the system, such as motors, indicators, etc., are strictly executed. It also needs to obtain real-time status data of the car from sensors. These parts together constitute the hardware part of the self-driving car.

4.2 Selection of car main control chip
As the core of the automatic driving car system, the main control chip plays a vital role in the entire control system. The entire process of realizing autonomous driving requires the main control chip to respond in a timely manner and control each part to respond correctly, ensuring efficient and safe control at low cost, and the operation difficulty should not be too high. Therefore, after comprehensive consideration of performance, price, operability, etc., I finally chose Arduino Mega 2560.
The first is the platform advantage of Arduino. Arduino has a highly complex hardware system, but its structure is highly modular and easy to use. It communicates with a PC through a USB interface. It is an excellent electronic design platform that integrates hardware (Arduino board) and software (Arduino IDE). Arduino is an open source-based software and hardware platform built on the open source Simple I/O interface, and the coding language used is C++. Most Arduino development boards are 8-bit microcontrollers based on AVR, and there are currently many models. Common ones include Uno, Nano, Mini based on Atmega328p chip and Mega2560 based on Atmega2560 chip.
However, with the development of technology, 8-bit microcontrollers can no longer meet people's needs. 32-bit processors have entered the stage. Therefore, Arduino launched the 32-bit ARM-based model DUE. At the same time, in order to adapt to the arrival of the Internet of Things era, it launched YUN[8] that can be connected to Ethernet.
The four motors of the car plus numerous sensors require an Arduino model with multiple interfaces. After comparing Uno and Mega 2560, the following table 4.1 is shown.
Table 4.1 Comparison between Mega2560 and Uno
Digital pin PWM pin Analog pin External interrupt pin
Uno 14 6 6 2 3
Mega2560 54 15 15 2 3 21 20 19 18
In the end, Mega 2560 with more interrupt pins and digital pins was chosen As the main controller of the car.

4.3 Motor and motor drive selection
The main working components of the automatic driving car system are mainly DC brushless motors, as well as sensor components such as encoders and gyroscopes that can obtain the motion status of the car. Therefore, when selecting a motor, a DC brushless motor with an encoder can not only provide forward power to the system, but also obtain important parameters such as the motor rotation direction and motor speed by analyzing the encoder data. Choosing the appropriate sensor can improve The accuracy and efficiency of system control can also save costs and system space.
4.3.1 Drive motor selection
As a type of synchronous motor, the brushless DC motor’s rotor speed is affected by the speed of its stator’s rotating magnetic field and the number of rotor poles. Brushless DC motors not only have a series of advantages of AC motors such as simple structure, reliable operation, and convenient maintenance, but also have many advantages of DC motors such as high operating efficiency and good speed regulation performance. The most important part of the brushless DC motor is its control structure. Its driver can control the rotor to maintain a certain speed, making the performance more stable. Brushless DC motors are widely used in modern production equipment, instrumentation, computer peripherals and advanced household appliances. It has the advantages of high efficiency, long life and low noise. High efficiency: The efficiency of general brushless DC motors can reach more than 96%, while the efficiency of traditional DC motors is generally about 75%; high efficiency means high energy conversion, and the conversion of electrical energy into mechanical rotational energy of the motor is high, which can It is very energy-saving. As a driver for an autonomous car system, it can significantly reduce energy consumption compared with other motors. Long life: Generally, traditional motors with brushes need to be replaced every once in a while due to the wear and tear of the carbon brushes, resulting in frequent maintenance. However, brushless DC motors generally have a service life of more than 20,000 hours. Under normal working conditions, It will basically not be damaged after more than 5 years of use, so the lifespan of a brushless DC motor is 5 times that of a traditional motor. Low noise, brushless DC motor has a simple structure, the parts can be installed with precision, the operation is relatively smooth, and the operating sound is below 50db. Many medical equipment use brushless DC motors because of their silent performance.
At the same time, the brushless DC motor can be used with an encoder. The encoder is a rotary sensor that converts angular displacement or angular velocity into a series of electrical digital pulses. We can measure the bottom displacement or speed information through the encoder. Encoders can be divided into optical, magnetic, inductive and capacitive types according to the detection principle. The most common ones are photoelectric encoders (optical type) and Hall encoders (magnetic type); according to the movement mode, they can be divided into rotary encoders or It is a linear encoder. Rotary encoders can be divided into incremental encoders and absolute encoders according to their working principles: incremental rotary encoders only output pulses when the motor rotates. To use an incremental encoder to determine the shaft position, you The starting position must be known and an external circuit used to calculate the number of output pulses; an absolute rotary encoder outputs a digital code corresponding to the angle of rotation, eliminating the need to count pulses to know the position of the motor shaft.
Incremental encoders can obtain the direction of motor rotation through quadrature encoding. Quadrature encoding is an incremental signal. After the incremental encoder rotates, it can produce two square wave outputs A and B; these signals together constitute the orthogonal output of the incremental encoder. For most encoders, these square waves A and B are both 90 degrees out of phase. By observing the changing state of the A and B outputs, the direction of the encoder is determined. There are two channels: Channel A and Channel B.
At the same time, the motor must ensure a certain driving force, and a suitable motor reduction ratio needs to be selected. The power supply voltage should not be too high or too low, and should be around 12V.
Based on the above reasons, I chose a DC deceleration brushless motor JGB37-52 motor with a Hall encoder (incremental encoder). The motor parameters are as shown in Figure 4.1 and Table 4.2.
Insert image description here

Figure 4.1 Motor product dimensions

Model reduction ratio no-load speed rated torque stall current length
JGB37-52 1: 56 178 6.5N/m 2.3A 24mm
Table 4.2 Motor product parameters
Encoder parameters are as shown in Figure 4.2.
Insert image description here

Figure 4.2 Encoder parameters
4.3.2 Selection of motor driver
The positive and negative poles of the motor can be connected to the power supply. However, if you want to change the direction of the motor without changing the circuit structure, you must use the motor drive. At the same time, the motor driver can make the motor drive through PWM. It becomes possible to control the motor with signals, and it becomes more convenient to adjust the motor speed.
Considering factors such as price and frequency of use by other developers, I finally chose the L298N motor driver board module.
This module uses ST's L298N dual H-bridge DC motor driver chip as the main control driver chip, which has the characteristics of strong driving capability, low heat generation and strong anti-interference ability. The module power supply part uses the built-in 78M05, which can protect the chip (when the driving voltage is greater than 12V, use an external 5V logic power supply). The module also uses large-capacity filter capacitors and freewheeling protection diodes to improve reliability [9].
The specific parameters of the drive module are as shown in Table 4.3.
Table 4.3 Main parameters of L298N
Model chip driver power supply range Logic end power supply range Maximum power consumption
L298N module L298N dual H-bridge DC motor driver chip 5V-35V 5V-7V, 20W

4.4 Sensor selection
In the process of controlling the automatic driving car system, in addition to reading and calculating the motor speed and rotation direction through the encoder that comes with the selected motor, it is also necessary to read the car's rotation angle in real time to achieve It can complete turns and assist the car to move forward.
The gyroscope is designed based on the principle of the special motion of the gyroscope after being acted upon by external torque during rotation. A rigid body that rotates around a fulcrum at high speed is called a gyroscope. When the gyroscope is working, a force must be given to it to make it rotate quickly. It can generally reach hundreds of thousands of revolutions per minute and can work for a long time. Then use various methods to read the direction indicated by the axis, and automatically transmit the data signal to the control system. There are many types of gyroscopes, which can be divided into three-degree-of-freedom gyroscopes and two-degree-of-freedom gyroscopes according to the number of frames and the form of support [10].
For the time being, the driverless car system only needs to know the real-time rotation angle of the system's Yaw axis (that is, the gyroscope's Z axis) to implement the function (that is, it only needs a two-axis gyroscope). However, since the gyroscope is purchased at one's own expense, only the two-axis gyroscope is purchased. It can reduce the cost of the car, but it is not conducive to my continuing to conduct other experiments in the future, so I finally chose the six-axis attitude angle sensor produced and sold by Shenzhen Weite Intelligent Technology, product model JY61. The product parameters are as follows in Table 4.4: Table
4.4 Gyroscope parameters
Model Power supply voltage Working current Communication method Angle range Angle accuracy Baud rate
JY61 3.3-5V <10mA TTL, IIC ±180 0.1° 9600/20Hz
JY61 module includes gyroscope acceleration Including MPU6050, voltage stabilizing circuit and STM8 microcontroller. MPU6050 is the core of the module, which consists of four parts: accelerometer, gyroscope DMP, and temperature sensor. STM8 reads the measurement data of DMP in MPU6050 through IIC and then outputs it through the serial port, like this. Users can either directly read values ​​through the serial port or directly access the IIC interface of the underlying MPU6050 to obtain binary data. The official name of MPU6050 is a six-axis motion attitude gyro sensor. The reason why it is six-axis is that it not only contains a three-degree-of-freedom gyroscope but also an accelerometer that can measure three-dimensional acceleration. Combined with the attitude fusion algorithm, it can finally be directly Output the acceleration, angular velocity and angle of the three axes.

MPU6050 also has some problems. Since the module does not contain a three-axis electronic compass, there is no reference for the angle on the Z axis, so the absolute angle of the Yaw axis cannot be obtained. It is obtained by integrating the speed of the accelerometer, so the gyro The meter will have zero drift on the Yaw axis. This angle is exactly the angle required by our system. Fortunately, the JY61 module has optimized this problem in two aspects. First, the module will clear the Yaw axis angle every time it is powered on. Thanks to this measure, angle problems will not accumulate all the time. Secondly, the module manufacturer Vit Intelligent has set the option of static detection threshold in the host computer supporting the product. When the angle deflection is within a small value range, the angle is considered to have not changed, and this threshold can be adjusted with multiple options. This can minimize the impact caused by zero drift. (In actual testing, the accuracy of this module is very high. After multiple rounds of testing, the car can move freely for about 10 minutes with power on, and the angle error is only 0.3 degrees. The accuracy is acceptable.)

4.5 Processor Selection
Through the market research and analysis of common processors used in self-driving cars in the introduction, we found that the general car processors are Jetson Nano and Raspberry Pi 4. Raspberry Pi is an excellent small computer and IoT development motherboard. It is not only a low-power IoT device, but also a good prototyping tool and can even be used to build IoT-related devices. It has been upgraded to the fourth generation. NVIDIA has released many kinds of IoT motherboards, among which NVIDIA Jetson Nano is the latest motherboard. This board serves as a development kit providing all the inputs and connections required when prototyping IoT solutions. By searching for information, we made the following comparison between the two processors, as shown in Table 4.5 below: Table 4.5 Comparison
of the two processors
Model CPU Memory USB port GPU
Raspberry Pi 4b Quad-core
Cortex-A72 LPDDR4
4GB 2 USB2
2
USB3 Dual 4K graphics card
Jetson Nano Quad-core
Cortex-A57 LPDDR4
4GB 4*USB3 NVIDIA Maxwell
The biggest difference between the two is that the NVIDIA Jetson Nano contains a higher-performance and more powerful GPU (graphics processing unit), while the Raspberry Pi 4 has a low-power VideoCore multimedia processor. Therefore, for image processing and running artificial intelligence frameworks of artificial intelligence autonomous driving systems, although Jetson Nano is more expensive, it is more suitable as a processor for artificial intelligence autonomous driving systems. I finally chose Jetson Nano as the processor of the car (Figure 4.3)
Insert image description here

Figure 4.3 Jestson Nano product introduction diagram

4.6 Remote control hardware selection
Main control chip selection: Arduino Nano. Arduino Nano is a development board similar to Arduino UNO. The difference is that Nano is smaller in size and is based on ATmega328P development board. Arduino Nano is very similar to Arduino Uno. The difference between it and Uno is that Nano does not have a DC voltage power supply interface and Nano is connected to the computer through Mini-B USB interface. The main technical parameters are as follows Table 4.6: Table 4.6 Main parameters of
Arduino Nano
Model Input voltage Digital pin PWM Analog input pin
Arduino Nano 7-12V 22 6 8
joystick module: The solution adopted by the remote control is a single joystick plus multiple buttons. In order to facilitate development and reduce the size of the remote control, the joystick module Joystick Shield for Arduino was selected. The rocker module provides seven push-button switches (six individual buttons and the button below the rocker) and a thumb stick with two potentiometers. At the same time, the module also provides an interface for the Bluetooth module (the actual picture of the joystick module is shown in Figure 4.4)
Insert image description here

Figure 4.4 Actual picture of the joystick module
Bluetooth module: The Bluetooth module is a module integrated with a Bluetooth chip, used for wireless communication and data transmission, etc. It is different from the "Bluetooth" we usually use in mobile phones and computers, which refers to a Bluetooth adapter. For users, the Bluetooth adapter is more convenient to use, and the Bluetooth module can obtain the initial data transmitted. Simply put, the Bluetooth module is an incomplete semi-finished product and the Bluetooth adapter is a complete product. Bluetooth generally communicates through a specific Bluetooth protocol. After Bluetooth is connected, Bluetooth can be used directly as a serial port. Bluetooth distinguishes between the transmitter and the receiver during the communication process, that is, the transmitter is the master and the receiver is the slave. I chose the HC05 master-slave all-in-one module. Its parameters are as follows in Table 4.7:

Table 4.7 Main parameters of Bluetooth module Model
Working voltage Default baud rate mode Communication method
HC05 3-3.6V 9600 Master-slave integrated duplex serial port, no protocol required
Bluetooth HC05 is a master-slave integrated Bluetooth serial port module. Simply put, when Bluetooth After the device is successfully paired and connected with the Bluetooth device, we can ignore the internal communication protocol of Bluetooth and directly use Bluetooth as a serial port. When a connection is established, the two devices share a channel, that is, the same serial port. One device sends data to the channel, and the other device can receive the data in the channel [11]. When used specifically, the host module is connected to the handle, and the slave module is connected to the main control of the car. It transmits some signals representing different motion instructions through the Bluetooth serial port to realize the control of the car by the handle.

4.7 Control circuit design
Due to tight time and limited processing capacity, the circuit design is mainly based on modules that can be purchased on the market. This greatly improves the development efficiency and shortens the development cycle. At the same time, the stability of the system is more guaranteed. When encountering various The probability of hardware problems is small and it is convenient to find similar problems for reference and solutions.
4.7.1 Car power supply circuit
The entire power supply circuit is divided into two parts: battery and power module.
For the car, the battery uses 9 18650-cell customized 12V 8400mAh lithium batteries. The 12V voltage can directly power the L298N module and motor. The large capacity of 8400mAh can sufficiently support the power requirements of the entire system including the processor. At the same time, customizing it into a long shape is more conducive to the overall space arrangement of the car.
The power module uses an adjustable automatic boost module purchased online (the main parameters are shown in Table 4.8). The module uses a buck-boost chip as the main controller, an external 60V 75A MOS tube as a switch tube, and dual 60V 5A SS56 Schottky Do rectification. It can achieve a wide voltage input of 5-30V and a wide voltage output of 0.5V-30V. It can both step up and step down. It has a wide range of applications and good effects. It has three functions. First, it can be used as a stable boost module with over-current protection capability. It can also be used as a battery charger with constant current output. Finally, it can be used as a high-power LED constant current drive module. Perfect matching directly supplies power to the processor, and the processor directly supplies power to the main control.

Table 4.8 Main parameters of the power module
Input voltage Output voltage Output current Output power Working frequency
5-30V 0.5-30V Stable 3A Natural heat dissipation 35W 180KHZ
For the remote control, the battery uses a 18650 rechargeable 3.7V lithium battery with a capacity of 2000mAh. The power module uses a 3.7V to 5V/9V adjustable module purchased online (the main parameters of the module are shown in Table 4.9). The 3.7V voltage provided by the battery is raised to 9V to power the Arduino Nano, and then the main control supplies power to the handle module. Power supply, the handle module supplies power to the Bluetooth module. The battery parameters are as shown in Table 4.10.
Support battery input voltage Output voltage Output power Rush current
3.7V lithium battery 4.8-8V 4.3-25V Constant 7W 1A (max)
Table 4.9 Main parameters of boost module
Table 4.10 Main parameters of 18650 battery
Model Minimum discharge voltage Charging voltage Nominal voltage Diameter Height
18650 lithium cobalt oxide battery 2.75V 4.2V 3.7V 18mm 65mm

4.7.2 Motor drive circuit
The six-wire AB phase DC reduction motor selected for this design cannot be directly driven by DC power supply, so it needs to be connected to the corresponding driver. The L298N is chosen here, and then the L298N pin and the main control pin are directly connected to each other, so that the microcontroller can be used for corresponding control. Each L298N driver has two sets of outputs, OUTA and OUTB, which can control two motors, so the car needs a total of Two L298Ns.
The drive module can also perform more precise control through the PWM output port and strictly control the motor speed to improve the control accuracy of the system. Pull out the onboard 5V jumper cap, the battery directly supplies power to the motor, and the main control supplies power to the encoder. IN1 2 3 4 is connected to the main control digital pins, and the encoder output is connected to the main control interrupt port.
Insert image description here

Figure 4.5 Car chassis hardware connection diagram

4.7.3 Remote control circuit design
The module of the remote control is relatively simple. The battery is fixed in the battery holder. After being boosted by the boost module, it supplies power to the main control. The main control then supplies power to the handle module. The Bluetooth module is directly connected to the interface provided by the module. , the whole is exposed outside the casing, which is helpful for transmitting Bluetooth signals and observing the status of the indicator light.
Insert image description here

Figure 4.6 Remote control hardware connection Figure
4.6 Summary of this chapter
This chapter mainly selects hardware devices based on the main requirements of the system, combined with factors such as time cost in the development process. In addition to the selection of the processor Jetson Nano, for the car, the first is Arduino The choice of Mega2560 main control, followed by the choice of DC brushless motor - six-wire AB phase motor JGB37-520 with Hall incremental encoder, the other is the motor drive module L298N, and finally the 6-axis gyroscope and battery power module s Choice. For the remote control, I chose the main control Arduino Nano, the handle module Joystick Shield for Arduino, the Bluetooth module, the battery power module, etc.

Chapter 5 Control System Software Design
5.1 Control Process Design
The control of the automatic driving car system is divided into two parts: car movement control and remote control, which correspond to the two parts of the car's autonomous movement and image acquisition respectively.
5.1.1 Image acquisition
In the process of image acquisition, the processor first runs the image acquisition program. The program only includes the work of turning on the camera and saving the image and establishing contact with the processor. At the same time, the Bluetooth of the remote control and the Bluetooth of the car are successfully paired. The remote control can control the car's straight and turning movements through the joystick and buttons. At the same time, the main control transmits the real-time image and the corresponding angle and speed of the current car back to the processor for recording. . When the number of collected images or the collection time reaches the requirements set by the program, the processor will send a termination signal to the main control, the car will stop moving and remain still, and then stop the image collection work. The flow chart is shown in Figure 5.1:
Insert image description here

Figure 5.1 Image acquisition flow chart
5.1.2 Autonomous movement
After the image acquisition is completed, all images of the car during its driving process and the corresponding real-time angle and speed are obtained. Use part of these data as a data set for artificial intelligence model training (this part is not my main job, so I won’t go into details). After the model is trained, it can analyze the angle and speed of images during autonomous movement. Feedback makes it possible for the car to move autonomously.
During the process of autonomous movement, after starting to run the autonomous movement program, the processor first establishes communication with the car's main control through the serial port. The car's default state should be to move straight forward at a certain speed and start to continuously take real-time photos and submit them to the processor. After analysis, the processor calculates the current target speed and target angle of the car based on the previously trained framework. The main control program will make real-time adjustments according to the target value, complete the necessary operations for correcting automatic driving such as straight driving, turning, parking, etc., and verify the automatic driving function. Flowchart 5.2 of the autonomous movement process:
Insert image description here

Figure 5.2 Autonomous mobility flow chart
5.2 Main program design
The main program is the main program in the control of the automatic driving car system and is the main process for controlling the entire system. It is a program executed after the main control is powered on. Since the logic of the microcontroller determines that the main program runs through the entire control process, it will be executed repeatedly. At the same time, the main program controls the programs of each module at a macro level, which is very important for the control process of the automatic driving car system. The flow chart of the main program is shown in Figure 5.3:
Insert image description here

Figure 5.3 Main program flow chart
The main program covers the entire process of control program execution. The main program first performs the initialization process. This process includes serial port initialization, soft serial port initialization used by Bluetooth, initialization of scheduled interrupts, initialization of various parameter variables, etc. . Then it begins to enter the loop process. The program logic is: the entire system determines the status of the car through the four wheel speeds. At the beginning of the loop function, the PWM values ​​corresponding to the four motors are calculated and assigned based on the target values. Then the car is based on The received information is adjusted. If it is in the process of autonomous movement, it needs to continuously receive the information sent by the processor through the serial port and adjust according to the information, and finally complete the target task.

5.3 Program module design
After the main program has been adjusted and controlled as a whole, the functions of each module need to be designed and improved separately. The motor algorithm control program of the car is a very important part of the program design. This part should be done separately as the motor algorithm program part. It is explained that other modules such as motor drive, Bluetooth module initialization and communication, the overall programming of the remote control and the programming of various movements of the car are all very important parts of the overall control algorithm.
5.3.1 Motor driver program design
The motor driver program is one of the most important programs in the control system. Because each motor and the matching L298N drive module have many interfaces, a two-dimensional array Motor_Pins with four rows and five columns is set up to represent all the ports of the four motors. The four ports in each row are IN1, IN2, PWM, EncodeA, EncodeB (i.e. mid-end A and interrupt B), (but in the actual programming process, due to the limited number of Mega2560 external interrupt interfaces, only the interrupt A of each motor is used.
When it is necessary to drive the motor, first Port initialization, IN1, IN2, PWM are set to OUTPUT and the default state is LOW, and the interrupt is set to INPUT. The range of PWM is 0-255. The motor speed can be determined by controlling the size of the input PWM value (after testing, the no-load speed is within 0-50, the corresponding PWM value is 40-255). IN1 and IN2 can determine whether the motor rotates forward, reversely, or not according to the L298N truth table.
Table 5.1 L298N truth table
Motor rotation mode IN1 IN2
forward rotation High Low
Reverse Low High
Stop Low Low

5.3.2 Car motion program design
After the motor is driven, the car can have different motion states according to the different speeds of the four motors. According to the actual situation of the automatic driving car, two states are mainly written: going straight and turning left and right.
When driving straight, just ensure that the four motors rotate at the same speed, that is, all four motors input the same PWM value. However, the actual operation is more complicated due to uneven mass distribution of the car, individual differences between the four motors, etc. , it is difficult to ensure that the four wheels rotate at the same speed when directly inputting the same PWM. Of course, straight driving will also be very difficult.
When turning, the attitude of the car is changed mainly through the differential speed between the four wheels. After the previous simulation analysis, we have adopted the method of making the two wheels on the same side rotate in the same direction, and the two wheels on different sides rotate in opposite directions. Methods. Because the car only has a turning component and basically no forward component, it is easier to analyze the turning angle and its impact on the state of the car.
The implementation of the program is also relatively simple. When turning left, you only need to invert the IN1 and IN2 ports of wheels 1 and 2 of the car. Conversely, when turning right, you only need to change the IN1 and IN2 values ​​of wheels 0 and 4. .

5.3.3 Bluetooth module programming
As an important module for remote control and master control communication, the Bluetooth module plays a very important role in the entire system. As mentioned earlier, HC05 is a master-slave machine and can be set to be a master, a slave, or self-connected. Detection, all this requires long pressing the enable switch after powering on, and then using AT commands to modify the baud rate, mode setting, address setting, password modification and other initialization processes of the module, and then pairing and success can be used. Next Bluetooth will automatically connect when powered on for the first time. At the same time, AT commands can also be used to clear the pairing list, modify the Bluetooth name, etc.
First select one of the two purchased modules to configure as the host. After connecting the host with the USB to serial port module, enter the following command in the sending box of the serial port debugging assistant to set it up. AT+NAME=BT-Master sets the Bluetooth name to BT-Master; AT+ROLE=1 sets the Bluetooth module to the main mode. Each step will return OK if the settings are correct. In the same way, set another module as a slave and change the name to BT-Slave. The Bluetooth password, baud rate, connection address, etc. are all the same by default. If it is a newly purchased Bluetooth module, you do not need to modify it.
After both modules are set up, return to the working mode and power on again. The modules will first flash quickly separately, and then start flashing slowly synchronously, indicating that the Bluetooth connection is successful, and then they can be used directly as a serial port.

5.3.4 Remote control program design
As one of the important parts of controlling the car during the image collection stage, the remote control is very important. The remote control controls the car's forward, backward, left turn, right turn and other movement modes through the joystick. The joystick transmits data through two analog ports to represent the current position of the joystick. When the joystick is at the bottom left corner, A0 and A1 are both 0. When the joystick is at the top right corner, the values ​​of A0 and A1 change with the voltage. It varies, the value is 720 when powered by 3.3V. Define a state variable style. When style is 0-4, it represents five different states. When X is between 200 and 500 and Y is between 200 and 500, the state is 0, which means the car is not moving. At the same time, because Theoretically, there is no forward component when the car turns, so when X is less than 200 and Y is between 200 and 500, the status is 4, which means the car turns left. As shown in Figure 5.4:
Insert image description here

Figure 5.4 Schematic diagram of rocker operation

5.4 Motor algorithm program
5.4.1 Calculate motor speed
Because a motor with an encoder is used, the pulse frequency of the motor can be read by using the external interrupt of the main control, and combined with information such as the acceleration ratio of the motor, the motor's speed can be calculated Rotating speed.
External interrupt, in layman's terms, means that the main control monitors the point status of certain ports. When the potential meets certain trigger conditions, it can be detected and the interrupt function can be run. The common Arduino Uno only has two external interrupt pins. The Mega2560 used this time has 6 interrupt pins, but it still does not meet the needs of four motors, so each motor is only connected to one of the two outputs of the encoder. But it's enough.
To use the Arduino external interrupt, use the function attachInterrupt(interrupt, function, RISING) to detect signal pulses on the rising edge. The function sets the MotorCount variable to count the number of pulses within 50ms.
Final speed v = ((MotorCount / (11 * 56)) * 6.5 * PI) / 0.05 where 11 means that the motor has 11 pulses per revolution, the motor reduction ratio is 56, the diameter of the wheel is 6.5cm, 0.05 Expressed within 50ms.

5.4.2 PID control algorithm
PID is the abbreviation of Proportional (proportional), Integral (integral) and Differential (differential). PID adjustment is the most technically mature and widely used adjustment method in continuous control systems. The essence of PID adjustment is to perform operations according to the functional relationship of proportion, integral, and differential according to the input deviation value, and the operation results are used to control the output. There are two types of PID: incremental PID and positional PID. Since we are using incremental Hall encoders, we focus on incremental PID. Use the second formula of the incremental PID mentioned earlier:
△U0(n)=K_p {[ε(n)-ε(n-1)]+K_i ε(n) + K_d [ε(n)-2ε (n-1)+ ε(n-2)]}
(5-1)
U(k)= △u(k)+U(k-1) (5-2)
When implementing the code, PWMInc represents The increment of PWM, Ek represents the difference between the target value and the current value, Ek1 and Ek2 save the Ek value of the previous step, Kp, Ki, and Kd are the three coefficients of proportion, integral, and differential respectively. The calculation expression is PWMInc=Kp Ek- Ki Ek1+Kd*EK2.
Plus a time interrupt every 5ms using the millis() function. 
Then, before each main program cycle starts, PWM = PWM + PWMInc is continuously updated to change the speed of different motors.
Adjustment of PID parameters. The adjustment of the three PID parameters has a great impact on the control effect of the motor and the three parameters will affect each other. According to the parameter adjustment formula and simulation effect mentioned in the previous chapter, the final parameter position Kp=5 is determined. Ki=0.3.Kd=0.5.
5.5 Summary of this chapter
This chapter mainly designs the software part of the artificial intelligence car control system, draws the control flow chart, and then writes the main program of the control system, as well as program modularization, motor algorithm program, and remote control program design.

Chapter 6 Testing and Optimization
6.1 Control System Testing and Optimization
From program evaluation, to simulation testing, to software and hardware design, and then through material processing, assembly, debugging, and maintenance, the complete artificial intelligence control system is finally completed, and the actual car The picture is as shown in Figure 6.1, and the actual picture of the remote control is as shown in Figure 6.2. The next very important part is to test and optimize the system.
Insert image description here

Figure 6.1 Actual car
Insert image description here

Figure 6.2 Actual remote control
The test site is in the E-building experimental building of Xi'an University of Electronic Science and Technology as shown in Figure 6.3. The site is composed of several modules. The length and width of each module are 1200mm. The site is designed according to 1/10 of the standard road size. Green and blue are the trigger areas, and red is the end area. In addition to the starting point, end point and ordinary roads, it also contains a section of zebra crossing. Each module is made using matte spray painting technology to perfectly simulate common roads. The entire road is divided into straight driving, intersection turning, zebra crossing parking, etc., and multiple autonomous driving functions are verified respectively.
Insert image description here

Figure 6.3 Test site map
6.1.1 Test plan
After the artificial intelligence self-driving car control system was built, the control system was tested first. Due to time constraints, we chose to test the two most basic movement modes of the car, and formulated two corresponding Test plan:
Plan 1, straight driving test. The car continuously advances two meters without the angle calibration provided by the gyroscope. Measure the lateral distance between the position of the car when it reaches the end point and the starting position of the car. Determine the status of the four motors of the car based on the distance and the speed of the motor.
Option 2, turning test. When the car is running in a straight line and there is no excessive error in the motor, set the rotation target value to 90 degrees, and judge whether the angular velocity of the car when rotating is uniform through the fitting curve trend of the host computer in the gyroscope supporting information.
6.1.2 Test results and analysis
Option 1: After the car travels straight for two meters, the lateral deviation is 10cm to the left. Since the car relies on the differential speed of its four wheels to turn, the most likely cause of deflection during the straight test is the deviation of the motor speed. The data of each motor output through the main control serial port was analyzed, and a set of data was intercepted and displayed, as shown in Table 6.1: Table 6.1
Linear test data
Serial number 1 2 3 4 5 6 7 8 9 10
Motor0 4.97 13.77 20.35 33.87 38.11 38.45 38.33 39.14 41.44 39.58
Motor1 10.34 19.38 27.85 34.56 38.25 38.14 38.14 39.78 40.32 41.45
Motor2 7.35 16.33 24.76 33.28 38.44 38.11 38.04 38.89 39.12 42.53
Motor 3 5.12 14.47 21.88 33.78 37.98 37.99 37.99 38.97 40.44 38.24

Analyzing the data, it can be seen that when the motor is first driven, the motor speed difference is large, and the rotation speed is ordered in order of speed: Motor1 > Motor2 > Motor3 > Motor0. The speeds of motors 1 and 2 on the right side of the car are slightly greater than those on the left side. The speeds of the two motors No. 0 and 3; at the same time, as time goes by, the speeds of the four motors stabilize to near the target value of 40 in the program, but the fluctuations are slightly larger.
Option 2: After the car is stable, it turns and turns 90 degrees. According to the Z-axis angle curve of the host computer (Figure 6.4), the curve goes from 0 degrees to 90 degrees very smoothly over time. It can be seen that the car is rotating. The speed is very stable and far exceeds expectations. In the actual autonomous movement process, the angle is not only assisted by PID adjustment but also visual recognition lane line detection, so the actual effect will be better than the test results and meet expectations.
Insert image description here

Figure 6.4 Gyroscope host computer waveform

6.1.3 Solve the problems in the test
After analysis, there were two problems in the test of option one, while option two met the expectations, so we focus on solving the two problems that appeared in option one.
Problem 1: There is a large speed difference when the motor is just started, causing the body to deflect.
After a series of tests, it was found that due to the large individual differences between the four motors of the car, continuous testing was carried out using the dichotomy method. From the sound of the motor encoder buzzer to the PWM value that can just start the motor: Motor0 is 40. Motor1 is 25, Motor2 is 34, and Motor3 is 27. The order of the required PWM values ​​is Motor1 < Motor2 < Motor3 < Motor0, which is completely consistent with the results of the experimental test.
In order to solve this problem, when the program initializes the motor, the initial value of the PWM is no longer set to 0, but the initial value of the PWM is directly set to a value that has the smallest gap with the minimum starting PWM of all motors, and will not let the car The value to start movement. After repeated dichotomy test testing, the PWM initial value was finally set to 30. The corrected speed data of each motor is as shown in Table 6.2, which fully meets the conditions for automatic driving control.
Table 6.2 Linear correction data
No. 1 2 3 4 5 6 7 8 9 10
Motor0 7.97 17.77 25.35 33.89 38.51 38.95 39.33 40.14 41.84 40.38
Motor1 9.34 19.45 27.85 34.36 37.35 37.34 39.88 41.78 40.38 41.54
Motor2 8.34 16.33 24.76 33.76 38.44 38.55 38.92 40.89 39.82 40.39
Motor3 8.12 17.47 24.88 33.28 38.98 39.05 39.58 40.97 40.74 40.88

Question 2: After the speed of each motor approaches stability, the deviation is still large.
After various reasons and data inquiries, it was finally determined that all motors share a set of PID parameters. However, due to individual differences in motors, this set of parameters cannot perfectly adapt to all motors, so some motor speeds appear slightly. overshoot and long stabilization time.
In order to solve this problem, we use the output imaging function of Arduino IDE to generate the output images of each motor one by one, and set the PID in the program as an array. Each set of PID values ​​corresponds to motors with different serial numbers. After modification, the simulation results are as shown in Figure 6.5.
Insert image description here

Figure 6.5 Motor speed simulation diagram

6.2 Industrial Design Optimization
Although the functions of the self-driving car control system introduced earlier have been basically realized, it is still far behind some self-driving car series products as educational kits in the market. I think some optimizations need to be done in the design. I have already optimized part of it myself, and I have also put forward optimization ideas for the rest: the
optimizations that have been made have significant effects. Let me give some simple examples: the battery switch facilitates turning off the power supply. It is convenient for testing and use. The power supply voltage display module displays the battery voltage in real time to facilitate troubleshooting and timely charging. The car function indicator light shows the various states and modes of the car. The main control installation position exposes the serial port, making it convenient to place it on the car chassis. Processor communication, etc., as well as the remote control, a complete acrylic shell is made, and important components such as switches are added, and the positions of all components are reasonably arranged, making it very convenient to use. Although these are small optimizations, they are extremely important for functional implementation and testing.

For some other necessary and more complex optimizations, I have also listed solutions. For those who need air, because the structure is simple and has been optimized very completely, it will be better to do some beautification work later. For a car, the structure is complex, and as the main body of autonomous driving, it requires a lot of optimization. The car uses many finished modules, such as power supply voltage stabilizing modules, motor drive modules, etc., which not only requires many wires to be connected, causing inconvenience, but also takes up a lot of space in the car. It is planned to integrate all module chips, corresponding circuits, indicator lights and The main control chip and so on are integrated into the customized PCB, which can enhance the integrity and reliability of the system. Regarding the mechanical structure of the car, appropriate suspension is added to the chassis wheel set to increase the stability of the car on uneven roads. The design car has both a beautiful and practical shell and overall design, making the entire car system more like a real product.

6.3 Summary of this chapter
In this chapter, by testing the basic functions of the car and analyzing and solving problems that arise during the test, with the help of Arduino simulation tools and host computers, the efficiency of problem-solving means and methods has been significantly improved. At the same time, the industrial design of the car has been improved and optimized to provide conditions for the realization of the functions of the self-driving car.

Chapter 7 Conclusion and Outlook
7.1 Conclusion
This article aims to complete the control of the self-driving car system by itself, and then combine it with the self-driving program to realize the self-driving function, so as to understand the development process of self-driving and artificial intelligence, an advanced technology. The main conclusions obtained are as follows:
(1) The overall design scheme of the self-driving car was determined, and dynamic analysis was conducted, and the control objectives of the system were finally determined and the system-related schemes were designed.
(2) Completed the simulation design of the model for the control objectives of the system, used Matlab to conduct simulation modeling of the control process, and used Solid Works to complete the simulation of the appearance and layout of each module.
(3) The hardware part of the system was built, the main control chip, drive motor, drive module, sensor, etc. were selected, and the system circuit part was designed.
(4) Completed the design of the system software part, analyzed the main controls, designed the control flow chart, and completed the system program design and writing.
(5) Test the completed control system, solve problems, and optimize it at the same time.

However, there are some regrets in the implementation of the automatic driving function. I have not been able to conduct a complete automatic driving verification. After finishing writing the paper, I will continue to work hard and complete the algorithm part of artificial intelligence automatic driving, and strive to build a car. An artificial intelligence self-driving car with a very complete structure and function.
7.2 Outlook
From 1885, when the first car studied by Karl Benz was born in Germany, to after the end of World War II, the development of industrial technology drove the vigorous development of automobiles, to after the 1970s, the rapid development of electronic information technology made automobile technology more perfect. , to the proposal and implementation of new energy vehicles more than ten years ago, to the emergence of artificial intelligence-assisted autonomous driving technology and a group of new power car companies in recent years, the entire history of automobile development is a microcosm of the development of industrial technology. Through the design of the artificial intelligence self-driving car control system, I have a comprehensive understanding of the entire artificial intelligence development process and the important role of each part in the process.


Acknowledgments omitted

References
[1] Fang Min, Zhang Lixin, Yu Xingsheng. A brief discussion on the development of intelligent connected vehicles [J]. Internal Combustion Engines and Accessories, 2020.
[2] Anonymous. 5G commercial use may speed up autonomous driving [N]. Information Times, 2019-06-20.
[3] China Association for Science and Technology, China Society of Automation. Control Science and Engineering Discipline Development Report 2007-2008[M]. China Science and Technology Press: Beijing, 2008:1.
[4] Wang Ruifeng . Design of control system for traveling devices on large-span paddy fields [D]. Shenyang Agricultural University, 2020.
[5] He Zhiqiang. Research on PID controller parameter tuning method and its application [D]. Zhejiang University, 2005.
[6] Fan Linan, Li Xuefei. Computer control technology [M]. Machinery Industry Press: Beijing, 2009: 1.
[7] Wang Xiaojian, Hu Changsheng, Chen Ning, et al. Design and application of single-chip microcomputer [M]. Tsinghua University Press: Beijing, 2011: 83 .
[8] Li Xin, Wang Shengquan. Elucidate the advantages of Arduino by realizing its basic functions [J]. Industrial Control Computer, 2019, 32(01): 100-101. [3] Xu Jialu. Automatically follow the shopping basket [J]. Science and Technology Innovation, 2019.
[9] Xu Jialu. Automatically follow the shopping basket [J]. Science and Technology Innovation, 2019, 1:1.
[10] Wang Qing, Dai Jianfeng, Li Weixue. Physical principles and engineering technology [M]. National Defense Industry Press: Beijing, 2008: 22.
[11] Zhu Peng. Design and implementation of Bluetooth communication between ARDUINIO development board and ANDROID mobile phone [J]. Computer Knowledge and Technology, 2016.


5. Resource download

The source code and complete paper of this project are as follows. Friends in need can click to download. If the link does not work, you can click on the card below to scan the code and download it yourself.

serial number A complete set of graduation project resources (click to download)
Source code of this project Design and implementation of self-driving car control system based on Arduino+PID+AI (source code + documentation)_Arduino_self-driving car control system.zip

Guess you like

Origin blog.csdn.net/m0_66238867/article/details/131063729