yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
K230 Vision Module📖
1. Quick Start
  • 0.Get start
  • 1. K230 firmware download and burning
  • 2. Install the programming environment
  • 3. Debug and run routines
  • 4. Offline running routine
  • 5. Micropython Quick Start
  • 6. GUI Program Instructions
  • 7.K230 module bracket installation tutorial
  • 8.K230 module 2DOF PTZ installation tutorial
2. Basic Courses
  • 1.FPIOA pin assignment
  • 2.RGB lights
  • 3.Buzzer
  • 4.Buttons
  • 5.Serial communication
  • 6.I2C communication
  • 7.PWM
  • 8.WDT watchdog
  • 9.Timer
  • 10.Fourier Transform
  • 11.SHA256 encryption
  • 12.AES encryption
  • 13.Multithreading
  • 14.File reading and writing
  • 15.Image Display
  • 16.Touch Display
  • 17.Camera display
  • 18.Image Flip
  • 19.Camera
3. Draw the image
  • 1. Draw the lines
  • 2. Draw the circle
  • 3. Draw the rectangle
  • 4. Draw the ellipse
  • 5. Draw the arrow
  • 6. Draw the crosshairs
  • 7. Draw text
  • 8. Draw key points
4. Graphics detection
  • 1. Line segment detection
  • 2. Rectangle Detection
  • 3. Circle detection
  • 4. Object edge detection
  • 5. Line inspection basics:fast linear regression
5. Color recognition
  • 1. Color recognition
  • 2. Object Counting
  • 3. Multi-color recognition
  • 4. K230 Color Line Patrol
6.1 CV_lite Image Processing Special Topic
  • 1.Introduction to cv_litenew
  • 2.cv_lite API Reference Manualnew
  • 3.Color Block Recognition - Grayscale Imagenew
  • 4.Color Block Recognition - Color Imagenew
  • 5.Circle Recognition - Grayscale Imagenew
  • 6.Circle Recognition - Color Imagenew
  • 7.Corner Recognition - Grayscale Imagenew
  • 8.Corner Recognition - Color Imagenew
  • 9.Edge Recognition - Grayscale Imagenew
  • 10. Edge Recognition - Color Imagenew
  • 11. Rectangle Recognition - Grayscale Imagenew
  • 12.Rectangle Recognition - Color Imagenew
  • 13.Rectangle recognition combined with corner recognition - grayscale imagenew
  • 14.Rectangle recognition combined with corner recognition - color imagenew
  • 15.Image Binarization - Grayscalenew
  • 16.Image Binarization - Color Imagenew
  • 17.Exposure Adjustmentnew
  • 18.Image Black Hat Operationsnew
  • 19.Image Color Histogramnew
  • 20.Image Closingnew
  • 21.Image Expansionnew
  • 22.Image Corrosionnew
  • 23.Gaussian Blurnew
  • 24.Gradient Transformationnew
  • 25.Mean Fuzzynew
  • 26.Image Openingnew
  • 27.Image Top Hat Operationnew
  • 28.PnP rangingnew
  • 29.Find rectangles and measure distancesnew
  • 30.Image grayscale world white balancenew
6.2 OpenCV Image Processing Special Topicnew
  • 1. OpenCV Introduction
  • 2. OpenCV API Reference
  • 3. Image Basic Transforms
  • 4. Morphological Operations
  • 5. Color Segmentation and Shape Classification
  • 6. Corner and Centroid Detection
  • 7. Hough Circle Detection
  • 8. Hough Line Detection
  • 9. Contour Analysis
  • 10. Drawing Functions
  • 11. Template Matching
  • 12. Image Blur Filtering
  • 13. Edge Detection
  • 14. Thresholding
  • 15. Color Segmentation
  • 16. Histogram and Pixel Transformation
  • 17. Arithmetic and Bitwise Operations
  • 18. Channel Operation and Statistics
  • 19. Image File Read and Write
  • 20. Pixel Level Transformation
7. Code type recognition
  • 1.Barcode recognition
  • 2.QR code recognition
  • 3.AprilTag tag recognition
  • 4.DM code recognition
8. Face Recognition
  • 1.[Must-read] General code structure and prerequisite knowledge of AI vision routines
  • 2.Face Detection
  • 3.Facial key point recognition
  • 4.Face orientation detection
  • 5.Face 3D Network
  • 6.Gaze direction detection
  • 7.Register for face recognition
9. Human body characteristics
  • 1. Human body detection
  • 2. Human key point detection
  • 3. Human posture recognition
  • 4. Fall detection
  • 5. Palm detection
  • 6. Palm key point detection
  • 7. Palm key point classification
  • 8. Gesture Recognition
  • 9. Dynamic gesture recognition
  • 10. Rock, Paper, Scissors
10. Scenario Application
  • 1.OCR character detection
  • 2.OCR character recognition
  • 3.yolov8n target detection
  • 4.yolov8n segmentation
  • 5. Self-learning object recognition
  • 6. License plate detection
  • 7. License Plate Recognition
  • 8. Target Tracking
  • 9. Fruit classification
  • 10. Garbage classification
  • 11. Road sign recognition
11. Audio and video processing
  • 1. Audio Recording
  • 2. Play Audio
  • 3. Video Recording
  • 4. Play Video
  • 5. Keyword wake-up
12. Network Basics
  • 1. Wireless network connection
  • 2. AP hotspot mode
  • 3. TCP-Server Example
  • 4. TCP-Client Example
  • 5. UDP-Server Example
  • 6. UDP-Client Example
  • 7. HTTP-Server Example
  • 8. HTTP-Client Example
  • 9. MQTT Quick Start
  • 10. MQTT-Publisher
  • 11. MQTT-Subscriber
  • 12. RTSP real-time image transmission
  • 13. RTSP real-time image transmission combined with AIDemo
  • 14. Call OpenRouter large model aggregation service
  • 15. Open the Resource Monitoring Panel
13. LVGL Graphical Interface
  • 1. Introduction to LVGL
  • 2. Create a button
  • 3. Create a slider
  • 4. Create an Image
  • 5. Create a text box and keyboard
14. GUI Code Tutorial & Secondary Development
  • 01.GUI System Architecture
  • 02.Core Engine Initialization
  • 03.Application Discovery Mechanism in GUI
  • 04.Desktop Layout Algorithm
  • 05.Advanced UI Styling
  • 06.BaseApp Base Class Analysis
  • 07.Hello_World Practical
  • 08.GUI Application Lifecycle and Resource Management
15. Train your own model
  • 1. Local deployment of yolo training environment
  • 2. Use online platforms for training
16.Touch Course
  • 1.Touch point detectionnew
  • 2.Touch Paintingnew
  • 3.Touch to take a photonew
17. Multi-master communication (purchased separately)
ESP32-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
Jetson-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
MSPM0G3507-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
Pico-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
raspberrypi-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
RDK-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
STM32-K230
  • 1. stm32_k230 color recognition
  • 2. stm32_k230 barcode recognition
  • 3. stm32_k230 QR code recognition
  • 4. stm32_k230Apriltag code recognition
  • 5. stm32_k230DM code recognition
  • 6. stm32_k230 face detection
  • 7.stm32_k230 looking direction
  • 8. stm32_k230 face recognition
  • 9. stm32_k230 human body detection
  • 10. stm32_k230 fall detection
  • 11. stm32_k230 palm detection
  • 12. stm32_k230 gesture recognition
  • 13. stm32_k230OCR character recognition
  • 14. stm32_k230 object detection
  • 15. stm32_k230 target tracking
  • 16. stm32_k230 self-learning object recognition
  • 17.stm32_k230 license plate recognition
Arduino-K230
  • 1.arduino_k230 color recognition
  • 2.arduino_k230 barcode recognition
  • 3.arduino_k230 QR code recognition
  • 4.arduino_k230 Apriltag code recognition
  • 5.arduino_k230 DM code recognition
  • 6.arduino_k230 face detection
  • 7.arduino_k230 looking direction
  • 8.arduino_k230 face recognition
  • 9.arduino_k230 human body detection
  • 10.arduino_k230 fall detection
  • 11.arduino_k230 palm detection
  • 12.arduino_k230 gesture recognition
  • 13.arduino_k230 OCR character recognition
  • 14.arduino_k230 object detection
  • 15.arduino_k230 target tracking
  • 16.arduino_k230 self-learning object recognition
  • 17.arduino_k230 license plate recognition
Microbit-K230
  • 1.microbit_k230 color recognition
  • 2.microbit_k230 barcode recognition
  • 3.microbit_k230 QR code recognition
  • 4.microbit_k230 Apriltag code recognition
  • 5.microbit_k230 DM code recognition
  • 6.microbit_k230 face detection
  • 7.microbit_k230 looking direction
  • 8.microbit_k230 face recognition
  • 9.microbit_k230 human body detection
  • 10.microbit_k230 fall detection
  • 11.microbit_k230 palm detection
  • 12.microbit_k230 gesture recognition
  • 13.microbit_k230 OCR character recognition
  • 14.microbit_k230 object detection
  • 15.microbit_k230 target tracking
  • 16.microbit_k230 self-learning object recognition
  • 17.microbit_k230 license plate recognition
MSPM0G3519-K230
  • 1. K230 Color Recognitionnew
  • 2. K230 Barcode Recognitionnew
  • 3. K230 QR Code Recognitionnew
  • 4. K230 Apriltag Code Recognitionnew
  • 5. K230 DM Code Recognitionnew
  • 6. K230 Face Detectionnew
  • 7. K230 Gaze Directionnew
  • 8. K230 Face Recognitionnew
  • 9. K230 Human Body Detectionnew
  • 10. K230 Fall Detectionnew
  • 11. K230 Palm Detectionnew
  • 12. K230 Gesture Recognitionnew
  • 13. K230 OCR Character Recognitionnew
  • 14. K230 Object Detectionnew
  • 15. K230 Target Trackingnew
  • 16. K230 Self-learning Object Recognitionnew
  • 17. K230 License Plate Recognitionnew
18.Extension case (purchase separately)
For 2DOF Electric Platform
  • 1.Moving target control and automatic tracking system
  • 2.Human body recognition alarm
  • 3.Gesture Recognition
  • 4.Rock Paper Scissors
  • 5.Fruit sorting
  • 6.Color Tracking
  • 7.Face Tracking
MSPM0G3507 wheeled chassis V1/V2 combined with K230 application case
  • 1.Visual tracking
  • 2.Color tracking
  • 3.Color response
  • 4.Road sign recognition
  • 5.Machine code tracking
  • 6.QR code recognition action
  • 7.Autonomous avoid
  • 8.License plate tracking
  • 9.Face tracking
  • 10.Gaze direction tracking
  • 11.Palm tracking
  • 12.Target tracking
  • 13.Human body tracking
  • 14.OCR character recognition action
STM32 wheeled chassis V1/V2 combined with K230 application case
  • 1.Visual tracking
  • 2.Color tracking
  • 3.Color response
  • 4.Road sign recognition
  • 5.Machine code tracking
  • 6.QR code recognition action
  • 7.Autonomous avoid
  • 8.License plate tracking
  • 9.Face tracking
  • 10.Gaze direction tracking
  • 11.Palm tracking
  • 12.Target tracking
  • 13.Human body tracking
  • 14.OCR character recognition action
MSPM0G3519 wheeled chassis V1/V2 combined with K230 application case
  • 1.Visual trackingnew
  • 2.Color trackingnew
  • 3.Color responsenew
  • 4.Road sign recognitionnew
  • 5.Machine code trackingnew
  • 6.QR code recognition actionnew
  • 7.Autonomous avoidnew
  • 8.License plate trackingnew
  • 9.Face trackingnew
  • 10.Gaze direction trackingnew
  • 11.Palm trackingnew
  • 12.Target trackingnew
  • 13.Human body trackingnew
  • 14.OCR character recognition actionnew
19. Expansion case(purchase separately)new
  • 1.Motion target control and Auto track system
  • 2.Vehicle-mounted balance ball motion control system
Download
  • Manual
  • CanMV IDE
  • Software Tools
  • Firmware
  • Source Code
  • Appendix
Download ZIP

Welcome to K230 Vision Module repository

2.Vehicle-mounted balance ball motion control system

MSPM0G3507/MSPM0G3519 Competition Car Tutorial — Ball Control + 8-Channel Line Following

MSPM0G3507/MSPM0G3519 Competition Car Tutorial — Ball Control + 8-Channel Line Following1. Hardware Platform2. Software Environment3. Structure Description3.1 Component List and Material Preparation3.2 Physical Appearance3.3 Assembly Instructions4. Basic Principles4.1 Wiring Pinout4.2 Physical Wiring Diagram4.3 Control Principle5. Project File Structure6. Core Parameter Configuration6.1 Servo Ball Control PID (app_k230.c)6.2 Line Tracking PID (app_irtracking.c)6.3 Task Line Tracking Speeds (questions.c)6.4 Task Timeout Settings (questions.c)7. Task Description7.1 State Machine Structure (questions.h)7.2 Detailed Task Description8. Key Code Explanation8.1 K230 Ball Control — K230_Servo_Control() (app_k230.c)8.2 Line Tracking — LineWalking() (app_irtracking.c)8.3 Line Tracking + Ball Control Combined — LineWalking_WithBall() (app_irtracking.c)8.4 Task 2 Ball Reciprocation (questions.c)9. Operation Procedure


1. Hardware Platform

ComponentModel/Description
Main ControllerMSPM0G3507/MSPM0G3519 Development Board
CameraK230 AI Vision Module (YOLOv8 Ball Detection)
Line Tracking8-Channel Red Tracking Module (I2C 0x12)
DisplayOLED 128×32 (I2C)
Servo9G Servo (Ball Tilt Control)
MotorsTwo L-Type 520 Encoded Motors (Serial Driver Board)
ButtonExpansion Board K1 Single-Key Control

2. Software Environment

  • IDE: Keil MDK V5 (ARM Compiler V6.7)

  • SDK: TI MSPM0 SDK 2.02.00.05

3. Structure Description

3.1 Component List and Material Preparation

  • Chassis Parts: Black metal etched baseplate, drive motors, wheels. The chassis has reserved screw holes and wire routing holes.

  • Robotic Arm Structure: Blue/black metal servo brackets, metal connecting rods, metal L-type/linear connectors, servos, metal flanges.

  • Horizontal Ruler Slider: Transparent acrylic housing, handwritten digital ruler with zero reference line, internal transmission guide rails/screw rods.

  • Top Vision Bracket: Brushed metal strips (aluminum alloy/stainless steel), transparent acrylic L-brackets, K230 module.

  • Hardware Accessories: M2/M3 combo screws, nuts, washers, black cable ties, heat shrink tubing.

Note: In addition to the v2 chassis kit components, 9g servos, K230, and tracking modules can be purchased from our store. Other connecting rods, rulers, water pipes, and hardware accessories need to be obtained on your own.

3.2 Physical Appearance

@lQLPJx8RYRl5bCfNA6HNBT6w8rPy_BkRQcIKUYuO1gRyAA

ae9b7260db4e4bed8d8dd752c203d026

1493eddb3c6347c3b743de79e5a664c5

da29de28f01f47fe8c4dd38d841e27e2

93d7a0a9f11847aba187362f984033ce

5e42f4f515c44121ac4bca0f289242a8

6c016275f2e04be0b60c8a08ca993df5

3.3 Assembly Instructions

Step 1: Install Mobile Chassis and Motors

  • Install the two drive motors (with wheels) on both sides of the black metal baseplate. Ensure the wheels face the same direction and make full contact with the ground.

  • Install the main controller board MSPM0G3507/MSPM0G3519 and secure it with screws at the reserved position on the chassis. Note that the main controller board should avoid the wheel and motor rotation space.

Step 2: Build Horizontal Ruler and Translation Stage

  • Reference Figure 5: Assemble the transparent acrylic housing and insert the cardboard with the graduated ruler inside. This structure is fixed at the front of the chassis.

  • Note that the guide rails or screw rods inside the slider need to remain horizontal, which is the key reference for subsequent robotic arm coordinate calibration.

Step 3: Assemble Robotic Arm Joints

  • Reference Figures 3 and 7: Insert the green servo into the black metal bracket and secure it with matching screws.

  • Install the servo arm and connect the blue/black metal connecting rods.

  • Build the end effector (connector/claw) as shown in Figure 7. In the image, this component uses a lot of transparent acrylic and hot glue/resin for reinforcement. In actual assembly, it is recommended to use 3D printed parts or metal parts instead to ensure sufficient structural strength.

  • Secure the servo base to the rear of the chassis (refer to the layout position in Figure 7).

Step 4: Install Vertical Metal Bracket

  • Reference Figures 1, 4, and 6: Take the brushed metal strip and install it vertically into the fixed slot at the center or side-front of the chassis.

  • When securing with screws, ensure the metal strip is perpendicular to the chassis plane and does not wobble. The nuts in Figure 6 are locked through from the back.

Step 5: Install Top Vision Sensor

  • Reference Figure 35: Face the K230 module's back side outward. Use transparent acrylic L-brackets and M3 screws to secure the module at the top of the vertical metal bracket.

  • Note to adjust the sensor orientation to ensure it can see the track and ruler ahead.

4. Basic Principles

4.1 Wiring Pinout

4-Channel Motor Driver Board:

Motor DriverMSPM0G3507/MSPM0G3519
RX2PB6
TX2PB7
GNDGND
5V5V

Motor Wiring:

MotorDriver Board
M2M-
V3V3
AH1B
BH1A
GGND
M1M+

8-Channel Line Tracking Module:

Tracking ModuleMSPM0G3507/MSPM0G3519
5V5V
SCLPA15
SDAPA16
GNDGND

OLED:

OLEDMSPM0G3507/MSPM0G3519
VCC5V
GNDGND
SDAPA28
SCLPA31

K230 Camera:

K230MSPM0G3507/MSPM0G3519
5V5V
GNDGND
TXDPA3
RXDPA2

4.2 Physical Wiring Diagram

你的段落文字 (12)

4.3 Control Principle

Car Line Following Control Flow:

流程图

  1. 8-channel infrared sensor reads black line position -> Calculate deviation value

  2. PID controller calculates turn correction -> Control motor differential steering

  3. K230 camera detects ball position -> Servo PID controls rod angle

  4. Timer timeout or waypoint detection -> Stop/Clear state transition

PID Control Parameter Description:

PID ParameterFunctionAdjustment Direction
P (Proportional)Determines response speed, larger output when deviation is largeToo large: Oscillating snake pattern; Too small: Weak turns
I (Integral)Eliminates steady-state deviation, cumulative error correctionToo large: Overshoot; Too small: Drifts to one side
D (Derivative)Suppresses oscillation, early brakingToo large: Jitter; Too small: Can't stop in time

5. Project File Structure

Competition_PJ/
├── main.c                     # Main program: Peripheral initialization, main loop, state machine dispatch
├── APP/
│   ├── app_k230.c/h           # K230 serial protocol + PID servo ball control (core)
│   ├── app_pid.c/h            # PID controller (positional + incremental)
│   ├── app_kalman.c/h         # 1D Kalman filter
│   └── app_servo.c/h          # Servo PWM drive
├── BSP/
│   ├── Eight_Tracking/
│   │   └── app_irtracking.c/h # 8-channel line tracking + tracking PID + combined tasks (tracking + ball control)
│   ├── Motor/
│   │   ├── app_motor.c/h      # Car motion control (Motion_Car_Control)
│   │   └── app_motor_usart.c/h# Motor driver serial protocol
│   ├── OLED/
│   │   ├── oled.c/h           # OLED driver + display function OLED_time()
│   │   └── oledfont.h         # Font data
│   ├── Key/
│   │   └── key.c/h            # Button driver + mode selection state machine
│   ├── Questions/
│   │   └── questions.c/h      # Competition task state machine (Task 1~5)
│   ├── Task/
│   │   └── task.c/h           # Timed task scheduler (Scheduler_Run)
│   ├── Timer/
│   │   └── timer.c/h          # 1ms system clock Get_Time()
│   └── usart.c/h              # Serial initialization (UART0 debug, UART1 motor, UART3 K230)
└── ti_msp_dl_config.c/h       # TI driver library configuration (SysConfig generated)

6. Core Parameter Configuration

6.1 Servo Ball Control PID (app_k230.c)

​x
#define PID_KP         0.08f   // Proportional coefficient: Response force, larger = stronger push
#define PID_KI         0.003f  // Integral coefficient: Eliminate steady-state offset
#define PID_KD         2.86f  // Derivative coefficient: Main damping, suppress oscillation

#define K230_CENTER    360.0f  // K230 image center X pixel
#define K230_MIN        99.0f  // Left boundary pixel
#define K230_MAX       599.0f  // Right boundary pixel
#define FOV_CM          28.0f  // Camera field of view width (cm)
#define PIPE_HALF_CM    12.5f  // Pipe half-length (cm), full pipe length 25cm

#define DEADBAND_PX      3.0f  // Deadband (px), no action when error < 3px
#define RATE_LIMIT       6.0f  // Single frame CC change limit, prevent servo jerking
#define KALMAN_Q         1.0f  // Kalman process noise (larger = faster response)
#define KALMAN_R         0.3f  // Kalman measurement noise (larger = smoother)

Bidirectional px_per_cm Compensation (camera not perfectly centered):

xxxxxxxxxx
Target >= 0 (right side): px_per_cm = (599-360)/12.5 = 19.12
Target <  0 (left side): px_per_cm = (360-99)/12.5  = 20.88

PID Tuning Guide:

PhenomenonAdjustDirectionDescription
Ball oscillates near center↑ KDIncrease dampingLarger KD brakes earlier
Ball stops before reaching target↑ KPIncrease pushLarger KP pushes farther
Ball overshoots and bounces far↓ KPDecrease push 
Ball stable but biased to one side↑ KIStrengthen integralLarger integral returns to center faster
Servo jitters when ball is still↑ DEADBANDLoosen deadband 

6.2 Line Tracking PID (app_irtracking.c)

xxxxxxxxxx
#define IRTrack_Trun_KP   (150)   // Line tracking P: Larger = stronger correction
#define IRTrack_Trun_KI   (0.15)  // Line tracking I: Eliminate steady-state deviation
#define IRTrack_Trun_KD   (1.5)   // Line tracking D: Suppress oscillation
#define IRR_SPEED         250     // Line tracking default speed (mm/s)

Line Tracking Tuning Guide:

PhenomenonAdjustDirection
Insufficient turn / Pressing line↑ KPIncrease
Snake-like movement↑ KD or ↓ KPDamping / Reduce push
Constant drift to one side↑ KIStrengthen integral

Inertia Compensation (for combined tracking + ball control task):

xxxxxxxxxx
#define BALL_INERTIA_FWD   -0.8f  // Forward inertia compensation (cm), larger value pushes ball more forward
#define BALL_INERTIA_TURN  -0.8f  // Turn inertia compensation (cm)
#define BALL_START_COMP    -5.0f  // Start compensation (cm), push forward when car accelerates and ball lags
#define BALL_STOP_COMP      5.0f  // Stop compensation (cm), pull back when car stops and ball overshoots
#define RAMP_TIME_MS       3000   // Start ramp-up time (ms), larger = gentler start

6.3 Task Line Tracking Speeds (questions.c)

xxxxxxxxxx
#define TASK1_SPEED      316   // Task 1 pure tracking speed
#define TASK3_SPEED      130   // Task 3 A->B + ball control speed
#define TASK4_SPEED      222   // Task 4 one lap + ball control speed
#define TASK5_SPEED      222   // Task 5 specified position speed
#define RAMP_TIME_MS     3000  // Start ramp-up time

6.4 Task Timeout Settings (questions.c)

xxxxxxxxxx
#define TASK1_MAX_MS   20000    // Task 1 pure tracking 20s timeout
#define TASK2_MAX_MS    5000    // Task 2 ball reciprocation 5s timeout
#define TASK3_MAX_MS    8000    // Task 3 A->B + ball control 8s timeout
#define TASK4_MAX_MS   30000    // Task 4 one lap + ball control 30s timeout
#define TASK5_MAX_MS   30000    // Task 5 specified position 30s timeout

7. Task Description

7.1 State Machine Structure (questions.h)

Main State (Main_State):

MacroValueTask Description
STOP_STATE0Stop
TASK_LINE_LAP1Task 1: Pure tracking one lap return to A, ≤20s
TASK_BALL_CTRL2Task 2: Ball O→+5→0→-5 (stop), <5s
TASK_AB_STAB3Task 3: A→B + ball stable at O, ≤8s
TASK_LAP_STAB4Task 4: One lap return to A + ball stable at O, ≤30s
TASK_LAP_POS5Task 5: One lap return to A + ball at specified position, ≤30s

Sub State (Sub_State):

MacroValueDescription
SUB_IDLE0Idle
SUB_INIT1Initialize (set speed, start timer)
SUB_RUNNING2Running
SUB_DONE3Done (stop car but maintain ball control, timeout also enters this state)

7.2 Detailed Task Description

Task 1 (Pure Line Tracking):

  • Line tracking only, no ball control

  • Speed: TASK1_SPEED = 316 mm/s

  • Pass through 4 waypoints (A/B/C/D) and stop at point A

  • Auto-stop after 20s timeout

Task 2 (Ball Control):

  • Car stays still, servo control only

  • Flow: O → +5cm (stable) → 0cm (stable) → -5cm (stable)

  • Each phase waits for ball to approach target (≤0.5cm) for 30 consecutive frames before transitioning

  • 5s timeout

  • After task completion, maintain ball at -5cm position

Task 3 (A→B + Ball Control):

  • Line tracking + servo ball control simultaneously

  • Speed: TASK3_SPEED = 130 mm/s

  • Start from point A, pass through 1 waypoint to reach point B

  • Ball remains stable at center O during travel

  • Stop after 8s timeout, maintain ball control after stopping

Task 4 (One Lap + Ball Control):

  • Line tracking + servo ball control simultaneously

  • Speed: TASK4_SPEED = 222 mm/s

  • Clockwise one lap, pass through 4 waypoints and return to A

  • Ball remains stable at center O during travel

  • Stop after 30s timeout, maintain ball control after stopping

Task 5 (Specified Position + Ball Control):

  • Same as Task 4, but ball target position is configurable (Target_Position)

  • Speed: TASK5_SPEED = 222 mm/s

  • Stop after 30s timeout, maintain ball control after stopping


8. Key Code Explanation

8.1 K230 Ball Control — K230_Servo_Control() (app_k230.c)

xxxxxxxxxx
void K230_Servo_Control(float target_cm)
{
    // Parse K230 serial frame (UART3 interrupt auto-receives data)
    int r; do { r = parse_one(g_buf, g_wr); } while (r > 0);
    if (!g_valid) return;

    // Coordinate conversion cm -> pixels (bidirectional px/cm compensation)
    float px_per_cm;
    if (target_cm >= 0.0f)
        px_per_cm = (K230_MAX - K230_CENTER) / PIPE_HALF_CM;  // Right side
    else
        px_per_cm = (K230_CENTER - K230_MIN) / PIPE_HALF_CM;  // Left side
    float target_px = K230_CENTER + target_cm * px_per_cm;

    // Deadband + positional PID + rate limiting + PWM output
    float error = target_px - Kalman_Filter(&kf_x, g_x);
    if (error > -DEADBAND_PX && error < DEADBAND_PX) return;
    float cc = PID_To_CC_Pos(&g_pid, x_flt);
    // ... rate limiting + CC limits ...
    DL_TimerA_setCaptureCompareValue(PWM_Servo_INST, (uint16_t)cc, DL_TIMER_CC_0_INDEX);
}

PID Formula (Positional, app_pid.c): u = Kp*e + Ki*Integral(e) + Kd*(e - e_last)

8.2 Line Tracking — LineWalking() (app_irtracking.c)

xxxxxxxxxx
void LineWalking(void)
{
    static int8_t err = 0;
    static u8 x1~x8;
    deal_IRdata(&x1,...,&x8);        // I2C read 8-channel infrared

    if (x4 == 0 || x5 == 0) err = 0; // Center black line, go straight
    else if (x3 == 0)       err = -1; // Deviate left, turn right
    else if (x6 == 0)       err =  1; // Deviate right, turn left
    // ... more sensor combinations ...

    pid_output_IRR = (int)(PID_IR_Calc(err));
    Motion_Car_Control(g_line_speed, 0, pid_output_IRR);
}

8.3 Line Tracking + Ball Control Combined — LineWalking_WithBall() (app_irtracking.c)

xxxxxxxxxx
void LineWalking_WithBall(float ball_target_cm)
{
    // Inertia compensation: Forward + turning
    float compensated = ball_target_cm;
    compensated -= BALL_INERTIA_FWD;
    if (pid_output_IRR > 0)
        compensated -= BALL_INERTIA_TURN * pid_output_IRR / 5000.0f;

    // Start ramp-up: Over first RAMP_TIME_MS milliseconds, speed gradually increases from 0
    uint32_t et = Get_Time() - start_time;
    if (et < RAMP_TIME_MS) {
        float ramp = (float)et / RAMP_TIME_MS;
        g_line_speed = (int)(g_line_speed * ramp);
    }

    LineWalking();                      // Line tracking
    K230_Receive_Process();             // Receive K230 data
    K230_Servo_Control(compensated);    // Ball control
}

8.4 Task 2 Ball Reciprocation (questions.c)

xxxxxxxxxx
// Three phases: +5cm(1.8s) -> 0cm(1.8s) -> -5cm(1.8s) -> DONE(maintain -5)
case SUB_RUNNING: {
    static int phase = 0;
    static uint32_t t0 = 0;
    if (t0 == 0) t0 = Get_Time();

    float target_cm;
    if (phase == 0) target_cm = +5.0f;
    else if (phase == 1) target_cm = 0.0f;
    else target_cm = -5.0f;

    K230_Receive_Process();
    K230_Servo_Control(target_cm);

    if (Get_Time() - t0 >= 1800) {     // 1.8 seconds per phase
        t0 = Get_Time();
        if (phase == 0) phase = 1;
        else if (phase == 1) phase = 2;
        else { phase = 0; Sub_State = SUB_DONE; }
    }
    break;
}
case SUB_DONE:
    K230_Receive_Process();
    K230_Servo_Control(-5.0f);    // Maintain ball at -5cm position
    break;

9. Operation Procedure

  1. After wiring, power on. OLED displays "K230 Init..." and waits 4 seconds

  2. Enter mode selection interface, OLED displays "Mode:1"

  3. Long press K1 to switch modes (1~5)

  4. Short press K1 to confirm and enter current mode

  5. Car starts executing task, OLED displays task name + timer

  6. Short press K1 during task: Pause; Long press K1: Exit and return to mode selection

  7. After task completion/timeout, car stops but ball control task continues (ball stays at target position)

  8. Long press K1 to exit and return to mode selection

Motion target control and Auto track system

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文