Since I have never been involved in this kind of design before, the goal of this project is to incorporate certain practical functions based on the official cases as much as possible. Considering that there are generally no black lines for the car to follow in real life, the goal of this project is to design a car that can automatically drive along the wall.
## 1. Requirements Analysis1
. Main control: LiChuang Liangshanpai GD32F470ZGT6 development board2
. Power supply: 18650 lithium battery x2, LDO step-down to 5V3
. Drive: N20 motor (6V 500R) x4Driver chip: RZ7899x4Use pwm to control speed4
. Ultrasonic ranging: HC-SR04 ultrasonic module x25
. Control:
1. Bluetooth remote control: HC-052
. Independent button control
## Schematic diagram design descriptionNote
: The power supply current of the GPIO port of the development board is limited. Devices that require high current drive need to be indirectly controlled by devices such as transistors
#### 1. The power supply
adopts two 18650s in series, which has sufficient drive current and large capacity. Use Schottky diodes to prevent battery reverse connectionThe
battery output 7.4V directly drives RZ7899, and LDO is used to step down to 5V to supply the development board and other devices.
![Power.jpg]

#### 2. Driver
![Driver.jpg]

When designing, pay attention to the input truth table of RZ7899:
![rz.jpg]

When connecting the control tube angle of rz7899, pay attention to connecting to the pins of the development board that support PWM output
![Snipaste_2023-02-26_10-11-13.jpg]

#### 3. Ultrasonic ranging
This project uses two HC-SR04 modules to measure the distance to obstacles in front and on the side, and correct the posture of the car.
I originally hoped to practice IIC communication with the new version of the HC-SR04 module, but the merchant sent the old version, so it can only be controlled through GPIO
![Ultrasonic module.jpg]

#### 4. Bluetooth
Bluetooth is connected to the development board through the serial port protocol, receives data through DMA, and connects to the pins that support UART/USART. When connecting, pay attention to the cross-connection of RX/TX on the module with RX/TX on the development board
![Snipaste_2023-02-26_10-14-00.jpg]

## Defects
1. Two ultrasonic rangefinders are not enough to meet the needs of driving along the wall.
1. The viewing angle of each ultrasonic rangefinder is limited. If an obstacle deviates from the central axis of the car, it may be impossible to detect it.
2. An ultrasonic rangefinder on the side can only get the distance from the wall, and cannot get the angle between the car body and the wall, so it can only roughly adjust the posture according to the threshold
. 3. The number of ultrasonic rangefinders can be increased by increasing the PCB size in the future.
## Physical display
![IMG_20230226_095143.jpg]

![IMG_20230226_092403.jpg]

## Demonstration video