k230 machine code tracking

This tutorial is a comprehensive experiment combining multiple peripherals. You can first understand a single peripheral and then conduct this experiment.

1. Software-Hardware

k230 module: external

Download or simulate the development board

2. Brief principle

1. Hardware schematic

image-20231028102757858

2. Physical connection diagram

K230 wiring (Note: The wiring in the figure below is for position reference only. We are equipped with K230 dual-head PH2.0 4Pin all-black wire, with fool-proof design, no need to worry about wiring problems)

PixPin_2025-06-10_19-21-14

Motor wiring

image-20231031094208747

3. Control principle

Yes
No
Start
K230 detects target
K230 sends data according to specified protocol
MCU parses data and controls the trolley to respond
Trolley stops
ModuleFunction
k230 visual moduleIdentify machine code and send data to the microcontroller through the serial port

Communication protocol:

Start characterLengthDelimiterRoutine numberDelimiterxDelimiteryDelimiterwDelimiterhDelimiterIDDelimiterdegreesEnd character
$XX,04,XXX,XXX,XXX,XXX,XXX...$

id: The label number of the identified mechanical code degress: The angle of the identified mechanical code

The microcontroller receives the data sent by k230 through the serial port and processes the data. By judging whether the received data content is in the above frame format, we extract the data x, y, w, h after it meets the data frame format, and then track it

3. Main functions

Function: Pto_Data_Parse

Function prototypevoid Pto_Data_Parse(uint8_t *data_buf, uint8_t num)
FunctionParse the data information returned by K230
Input parameter 1Array pointer of received data
Input parameter 2Size of received data
Return valueNone

Function Car_Move**

Function prototypevoid Car_Move(void)
FunctionCar tracking logic control
Return valueNone

4. Partial code analysis

5. Experimental Phenomenon

After successfully downloading the program, we need to take a machine code and then put it under the lens of the k230 visual module for recognition. The car does not move when it does not recognize the machine code. When the machine code enters the camera acquisition range of the car, the car starts to follow the machine code and keep the machine code in the middle of the video screen. Due to the limited acquisition range of the camera, the machine code cannot be moved too fast, otherwise it will be out of the frame and cannot follow the machine code.

K230 Code Burning

Required tools: K230, SD card, CanMV IDE K230

We find the k230_track_recong.py file in the project folder, then drag it to CanMV IDE K230, and then choose to save the opened script as main.py to CanMV

PixPin_2025-06-10_19-59-03

Obtaining machine code:

Click Tools->Machine Vision->AprilTag Machine Code Generator on CanMV IDE

PixPin_2025-06-19_19-55-53