about the author
National Second Prize in the "Electronic Product Design and Production" National Vocational College Skills Competition in August 2022
1 Question requirements
Design an intelligent loading and transportation engineering vehicle, which is required to be able to clamp objects and transport objects from point A to point B. At the same time, the vehicle body is equipped with a variety of obstacle avoidance sensors. It can plan its own routes. It is powered by lithium batteries and uses a self-designed vehicle model. , may not purchase finished products .
1-2 Question Analysis
The question requirements are not difficult. There are many similar obstacle avoidance cars on the market, but there is no such transport car, especially when objects need to be clamped. We need to consider the mechanical structure. I plan to use aluminum alloy plates to build the car body. The motor uses a 12V DC motor with large torque, and the battery uses 3 18650 lithium batteries. For obstacle avoidance, a variety of sensors are used to meet the requirements of the question.
2 Overall design plan
The first design solution is to reduce the voltage of the battery so that the microcontroller can work at a stable voltage. At the same time, a TTL downloader is integrated around the microcontroller to facilitate downloading of our debugging programs. The microcontroller is driven by a motor, which drives the motor to control the movement of the car up, down, left, and right. The sensor and camera will Obstacle avoidance information is sent to the microcontroller for processing. When an object that can be clamped is recognized, the microcontroller then controls the servo clamp to clamp the object.
3 Schematic design
3-1 Microcontroller circuit
This system uses STC's 8A8K64S4A12 microcontroller, which is simple to program and supports 3.3V-5V power supply.
SMD packaging, small footprint and powerful pin functions. Since STM32 is too expensive, we chose STC's 8A series between STC and STM32. The function is not worse than that of STM32, and it supports domestic production!
3-2 Object detection circuit
The object detection circuit uses an infrared emitting tube, a phototransistor and a peripheral comparison circuit. The infrared emitting tube emits infrared invisible light. When there is no object outside, the infrared light emits, and the phototransistor does not conduct. When the object blocks it, the photoelectric The transistor is conducting. The LM393 is used for comparison and outputs a high level to detect whether there is an object in front. The function of the R5 adjustable resistor is to adjust the sensitivity and prevent accidental touches.
3-3 Peripheral circuit
The peripherals adopt ultrasonic ranging, camera tracking, and clip servo interface. The peripherals are rich and meet a variety of requirements.
3-4 Motor drive circuit
The motor drive circuit uses 4 RZ7899 motor drive chips to control 4 wheels. RZ7899 is a DC bidirectional motor drive circuit. It is suitable for motor drives of toys, automatic valve motor drives, electromagnetic door lock drives, etc. It has two logic input terminals to control the motor forward, backward and braking. This circuit has good anti-interference, small standby current, and low output internal resistance. At the same time , it also has a built-in diode that can release the reverse impact current of inductive loads.
3-5 USB to TTL circuit
CH340 is a USB bus adapter chip that realizes USB to serial port or USB to print port.
In serial port mode, CH340 provides commonly used MODEM communication signals to expand asynchronous serial ports for computers.
Special note is that the CH340 chip supports 5V power supply voltage or 3.3V power supply voltage. When using a 5V working voltage, the VCC pin of the CH340 chip inputs an external 5V power supply, and the V3 pin should be connected to an external power supply decoupling capacitor with a capacity of 0.1uF. When using 3.3V working voltage, the V3 pin of the CH340 chip should be connected to the VCC pin, and an external 3.3V power supply should be input at the same time, and the working voltage of other circuits connected to the CH340 chip should not exceed 3.3V.
3-6 Microcontroller reset and power supply circuit
The principle of the microcontroller reset circuit is to give the RESET pin of the microcontroller a high level time of 20us.
The power supply of the microcontroller and the equipment uses the LM2596 fixed voltage output. The advantage of using DC-DC step-down is: since our car is powered by a battery, making full use of electric energy is an important way for us to improve battery life. The efficiency of LM2596 can reach up to 90%, which greatly saves us battery energy and improves our battery life.
The battery uses three 18650 batteries, and the full voltage is 14.7V.
Due to the higher power of the camera we cannot use the 7805
3-7 Schematic display
4-1 PCB design instructions
5 Software introduction
5-1 Software flow chart
5-2 Core code analysis
def check_cross(img): #白色背景识别
left_y=0
right_y=0
for blob in img.find_blobs([(100,200)], pixel_threshold=500,merge=True, margin=5,roi=(0,0,60,120)):
img.draw_rectangle(blob.rect())
left_y=blob.cy()
img.draw_cross(blob.cx(), blob.cy())
for blob in img.find_blobs([(100,200)], pixel_threshold=500,merge=True, margin=5,roi=(100,0,60,120)):
img.draw_rectangle(blob.rect())
right_y=blob.cy()
img.draw_cross(blob.cx(), blob.cy())
if(left_y and right_y):
if(math.fabs(left_y-right_y)<20):
return 1
return 0
find_cross_flag=1
THRESHOLD = (0, 20, -33, 13, -16, 20) # Grayscale threshold for dark things...
import sensor, image, time
from pyb import LED
import car
from pyb import UART
from pid import PID
#以传感器修正图像的中心向正上方为y轴,中心向右边为x轴,中心在正下方的投影点为原点建系
rho_pid = PID(p=1, i=0.1) #循迹时地面的直线在传感器中的位置可能不过中心,此时该PID修正中心偏离程度,相当于y=kx+b ,的b
theta_pid = PID(p=0.5, i=0) #该PID相当于k,是直线偏离中心的角度(假设k=0,b=0时为理想角度,此时err为0)
uart = UART(3,115200) #启用串口3,波特率115200
#LED(1).on()#补光灯
#LED(2).on()
#LED(3).on()
sensor.reset()#重启
sensor.set_vflip(True)#垂直方向翻转
sensor.set_hmirror(True)#水平方向翻转
sensor.set_pixformat(sensor.RGB565) # 将传感器的颜色数据格式化为RGB565格式
sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
#sensor.set_windowing([0,20,80,40])
sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds
clock = time.clock() # to process a frame sometimes.
while(True):
clock.tick()
img = sensor.snapshot().binary([THRESHOLD])#将阈值像素二值化输出
line = img.get_regression([(100,100)], robust = True)#调用线性回归绘制直线
if (line):
rho_err = abs(line.rho())-img.width()/2 #计算偏离原点的误差
if line.theta()>90: #计算倾斜度误差
theta_err = line.theta()-180
else:
theta_err = line.theta()#霍夫变换后的直线角度0-179
img.draw_line(line.line(), color = 127)#画出直线
print(rho_err,line.magnitude(),rho_err)
if line.magnitude()>1: #霍夫变换后的直线长度,值越大效果越好
#if -40<b_err<40 and -30<t_err<30:
rho_output = rho_pid.get_pid(rho_err,1) #得到PID的输出值
theta_output = theta_pid.get_pid(theta_err,1)
output = rho_output+theta_output #简单的参数融合
#car.run(50+output, 50-output) #OpenMV控制小车
str1 = str(int(output*10)) #将数据化为整数
uart.write('A'+','+str1)#将数据发给单片机格式:[A,outputValue],第一个字母表示类型,'A'表示识别正常,并发送输出值
print(str1)#打印调试数据
else:
#car.run(15,12)#线性回归效果不好,向目标直走
uart.write('B') #'B'表示PID融合输出的结果不好
else:
#car.run(20,-20)#原地旋转寻目标
uart.write('C') #'C'表示未找目标
pass
#print(clock.fps())#调试时输出帧率
The above code is part of the code for the servo control and camera. Especially when the car is moving, you must reduce the speed, that is, reduce the duty cycle I marked in red, otherwise the life of the motor will be shortened.
There is also a part of the code that is OPENMV code written in python. I will put this code in the attachment. Currently, it can only recognize two different colors. The subsequent algorithm will be improved and the workload is heavy. Please be patient.
6 Physical display instructions
7 things to note
Note on hardware:
Short circuit of lithium batteries is very dangerous. We should pay attention to the storage and use of lithium batteries.
A capacitor must be connected in parallel at the output end of the motor, otherwise it is easy to burn the driver chip, or even the microcontroller!
When debugging, pay attention to the positive and negative poles of the motor, and do not solder too much tin when welding, as it may cause a short circuit on the board.
At the same time, check whether the board is short-circuited before powering on, otherwise you will be responsible for the consequences!
Note on software:
Be sure to connect the serial port wiring between the camera and the microcontroller, otherwise we will not be responsible for burning out the camera. First download the camera program, then download the car program, and finally install it.
Since the camera and motor have high power, you must remember to charge them. The camera uses OPENMV of H750. There are many similar tutorials on the Internet, you can find them.
Finally I wish everyone all the best
8 Demonstration Video
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet