Road sign recognition

1. Opening Statement

The motor driver board used in this case is the four-way motor driver board of Yaboom. If you use this driver board, please read the "Motor Introduction and Usage" in the four-way motor driver board document first to understand the motor parameters, wiring method, and power supply voltage you are currently using. This will avoid burning out the motherboard or motor.

2. Experimental Preparation

Wheeled car chassis, 4*L520 motors, 12V lithium battery, K230 vision module, Yaboom STM32F103C8T6 core board.

The relationship between the 4 motor interfaces and the car is as follows:

M1 -> Upper left motor (left front wheel of the car) M3 -> upper right motor (right front wheel of the car)

M2 -> Lower left motor (left rear wheel of the car) M4 -> Lower right motor (right rear wheel of the car)

Hardware Wiring

image-20250603170101160

Wiring Pins

Four-way motor driver boardSTM32F103C8T6
5V5V
GNDGND
SCLPB10
SDAPB11

The following takes the M1 motor as an example, and other motors are similar:

MotorFour-way motor driver board (Motor)
M2M1-
VCC3V3
AH1A
BH1B
GNDGND
M1M1+
K230STM32F103C8T6
5V5V
GNDGND
TXDPA3
RXDPA2

3. Experimental Operation

  1. Follow the hardware wiring instructions in the tutorial to connect.

  2. Open the ProtocolHub project used by STM32, first check the beginning of the main.c file, the first thing to do is to change the number of MOTOR_TYPE to the motor you are using, after the modification is correct, compile and burn, and finally reset or power on.

  3. Place Road_sign_rec.py in the root directory of K230's sdcard and rename it to main.py, then reset or power on.

If you are not sure how to burn the program into K230, please read the K230 Quick Start tutorial first.

  1. Place the car in front of the road sign. If you use a screen to display the road sign, avoid using a pure white background, which will reduce the recognition rate. Move the K230 module bracket to a suitable angle and connect the power supply.

  2. After K230 is initialized successfully, it will start to recognize road signs and take corresponding actions.

4. Code analysis

MOTOR_TYPE: Used to set the motor type to be used. Modify the corresponding number according to the comments based on the motor you are currently using.

color_mode: Use 1 when running the visual line patrol case, and use 2 for the color tracking case

Car_Auto_Drive: Controls the car to move forward automatically after initialization. The default value is 0, which means the car does not move forward automatically. This function only needs to be enabled when using the autonomous avoidance case.

BSP_init: Hardware initialization

Set_Motor: Communicate with the four-way motor driver board and set motor related parameters

Pto_Loop: Continuously processes the received K230 messages.

Parse the received data that conforms to the protocol, obtain the function ID number and the data information carried in the data, and execute the processing function of the corresponding function. This project uses the metadata parsing method. The core idea is to separate the description of the protocol format (field position, type, etc.) from the parsing logic, define the protocol format through data structures (such as structure arrays), and the parsing function automatically processes the data based on these descriptions.

The protocol contains different types of data that can also be parsed. If you want to know the implementation details, you can study it yourself. I won't give too many answers. This function has been adapted to all K230 communication protocols in our store, and you can use it normally without fully understanding it.

control_speed : Controls the speed of the motor. It splits the four motor speed values into high and low bytes, and then sends them to the motor controller via the I2C protocol to set the motor speed.

control_pwm : controls the PWM (pulse width modulation) value of the motor. It splits the incoming PWM values of the four motors into high and low bytes and sends them to the motor controller via the I2C protocol to control the speed and direction of the motor.

Motion_Car_Control: A function used to control the car. The input parameter value will be used to control the speed of the motor with encoder, and the motor without encoder will control the pwm value.

RoadSign_Rec: If a straight ahead sign is recognized, the vehicle will drive forward for 2 seconds. If a right turn sign is recognized, the vehicle will turn right for 2 seconds. If a speed limit sign is recognized, the vehicle will reduce its speed to half of the straight ahead speed. If a stop sign is recognized, the vehicle will stop.

5. Experimental Phenomenon

Turn on the power switch and wait for the system to initialize. The screen will display the camera image, and it will begin to recognize road signs and take corresponding actions.

guidedetect

Road sign pictures

go_straight:

0

turn_right:

1

speed_limit:

4

stop:

5