### Introduction to the topic* **Competition tasks** ![image.png]

* **Competition requirements** * ![image.png]

* ![image.png]

* **Competition track** ![image .png]

* **Game Performance Requirements** * ![image.png]

* ![image.png]

----------------------- ### Project Introduction This project is the 2021 National Electronic Design Competition-F-Smart Medicine Delivery Car* **Master Control**: NXP's RT1021 core board* **Visual**: K210 module* **Tracking**: 4 channels Analog grayscale sensor* **Driver**: TB6612 * **Communication**: Bluetooth---------------------- ### Project function introduction* Power supply System: * The total power supply comes from a 7.4V lithium battery, using a T-shaped plug to prevent reverse connection; ![image.png]

* **Hardware circuit:** Mainly divided into 3 parts: * Top plate of RT1021——**RT1021_Top* * *Power supply for RT1021 core board* Provide 6-channel ADC detection ports: including 4-channel grayscale sensor, 1-channel object detection, 1-channel backup interface* 4-channel USART interface: Bluetooth, K210, gyroscope, backup interface* 1-channel 5V power supply RGB light board interface* RT1021 base board - **RT1021_Bot** * DC-DC_to_5V * Peripheral power supply - 3V3 * Power outlet interface * 4-way motor driver - 2 TB6612 * RGB light board - **RGB_Board* * * Used to display the three colors of light required by the question: red, green, and yellow * Tracking module * Using an analog grayscale sensor, the channel is composed of white, red, and black. The digital infrared tube cannot be used without adjusting the threshold. Red and black colors are recognized under the condition, and the analog grayscale sensor can accurately identify different colors after processing the voltage data through software, and the acquisition and processing of voltage is relatively simple* **System block diagram** ![image.png ]

---------------------- ### Schematic circuit analysis * System power supply: * Use independent LDO power chip-RT1021_Top_LM1117-5.0, due to the power on of RT1021 The timing requirements are controlled by switch S1, and its power is directly supplied by the lithium battery! [image.png]

* All other peripheral power supplies are converted by the 5V of the SGM6132_DC-DC step-down output, and the lithium battery voltage of 7.4V is reduced to 7.4V through the DCDC circuit. 5V can reduce the loss of other LDOs, improve power supply materials, and ensure system stability. Since the power requirements of the entire system are not high, for the sake of the compactness of the board, the input and output capacitors of the DC power supply use Samsung's 22uF capacitors*![ image.png]

* The 6 ADCs are all powered by 3V3, powered by RT1201_Top_LM1117-3.3, and the interfaces are all XH2.54 * 3P![image.png]

* The RGB light board has a large current, powered by SGM6132_DC-DC_to_5V, and the interface uses Xh2 .54 * 4P, avoid reverse connection of power supply! [image.png]

* Other peripherals: such as Bluetooth, OLED, buzzer, etc. are all powered by RT1201_Top_LM1117-3.3. The buzzer is an inductive circuit, and the IO port driving capability of the microcontroller Insufficient, so transistor amplification is required. The commonly used S8050 NPN transistor is used, and a freewheeling diode 1N5819 is provided to provide a freewheeling circuit! [image.png]

* Motor drive: * The motor uses a DC reduction motor with an encoder, and the drive current is relatively small. Small, using TB6612 integrated H-bridge for power supply. Each TB6612 can provide 2 H-bridges for 2 motors. The 2 drivers on the board can improve system stability. If the driver is burned due to operation error, the interface can be directly replaced! [image.png ]

* Loading detection: * Made of 12mm photoresistor and 10K resistor, the ADC detects the voltage to determine whether the loading is completed. The basic principle is that the resistance of the photoresistor changes and is affected by light. It can be distinguished by comparing it with the 10K resistor. The voltage can be judged by collecting the voltage through ADC![image.png]

---------------------- ### Software* Logic block diagram: ![image.png] ]

* Data processing: * Normalization: The tracking module used by the car is an analog output. The output values are quite different on different floors and in different lighting environments, so the sensor needs to be calibrated before use. Obtain the reading ADC_L of the sensor on the white ground and the reading ADC_H of the red line, and normalize the ADC data according to the following formula. ![image.png]

Based on the deviation between the sensor and the red line, the PID algorithm can be used to implement the corrected output of the PWM duty cycle. Adding the basic speed, the duty cycle of the two motors during the tracking process can be calculated as. ![image.png]

Through this method, the robustness of the sensor in different environments is greatly improved, and the car can drive smoothly and smoothly. * ADC parameter declaration: ``` C float ADC_Filter[ADC_NUM]; float ADC_calibrate[ADC_NUM]; uint16 Calibration_Tab[2][ADC_NUM] = { {268, 212, 245, 387}, {1890, 1640, 1950, 2010} };//Calibration table ``` * Get the calibrated ADC value: ``` C void Get_adc(void) { uint8 i; for(i = 0; i < ADC_NUM; i++) { ADC_Filter[i] = adc_mean_filter( ADCN_num[i], ADC_num[i], 10); ADC_calibrate[i] = (ADC_Filter[i] - Calibration_Tab[0][i]) * 1000.0 / Calibration_Tab[1][i]; //Data normalization if (ADC_calibrate[i] < 0) ADC_calibrate[i] = 0; else if(ADC_calibrate[i] > 1000) ADC_calibrate[i] = 1000; if(ADC_calibrate[i] > ADC_threshold_H)ADC_OutLine[i] = 1; else if (ADC_calibrate[i] < ADC_threshold_H)ADC_OutLine[i] = 0; } } ``` ----------------------- ### Vision* using YOLO model As a digital detection model, the YOLO model is trained by collecting a large number of digital images, and the trained model is deployed on the K210 to achieve digital detection. A portion of the digital data set is shown below. ![1639828301(1).jpg]

* While training, measure the quality of model prediction by observing the size of the loss function. The loss function during the training process is shown in Figure 2-2. Deploy the model to k210 and compare the numbers. Detection is performed, and the prediction effect is shown in Figure 2-3 * Figure 2-2: Loss function during training! [image.png]

* Figure 2-3: Digital detection prediction effect! [image.png]

------ ---------------- ### Picture* Signal & Power: * All interfaces use XH2.54 anti-fool interfaces to improve overall safety and avoid irreparable damage caused by human error. Loss![image.png]

* RT1021_Top: ![image.png]

* RT1021_Bot: ![image.png]

* RGB_Board: ![image.png]

Place schematics, PCBs, 3D drawings, physical objects and engineering-related Pictures and GIFs. ----------------------- ### Demonstration Video## [F-Smart Medicine Delivery Car-National First Prize-Effect Demonstration](https:// www.bilibili.com/video/BV1Kq4y1B7mK?spm_id_from=333.999.0.0)![Car model.jpg]