Palm tracking

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 Palm_tracking.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. 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 the palm. After waiting for three seconds, the robot will start to track the palm.

Notice:

If you are not satisfied with the tracking effect, you can modify the PID value of the app_motor.c file in the ProtocolHub project.

image-20250530182310179

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.

Hand_Track: After recognizing the palm, it will wait for three seconds, then record the area of the palm at this time, set it as the area size to be tracked later, then calculate the difference between the x-axis and the area, and then control the car to reduce the difference to achieve the tracking effect.

5. Experimental Phenomenon

Turn on the power switch and wait for the system to initialize. The screen will display the camera image. After the palm is recognized, a frame will appear. After waiting for three seconds, the robot will track the palm and keep it in the center of the screen.

hand