yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0G3519 Development Board📖
1. Introduction to MSPM0
  • 1. Introduction to MSPM0
2. Development environment construction
  • 1. CCS Theia Development
  • 2. MDK Arm Development
  • 3. UniFlash Downloader
  • 4. DAP-LINK download program
  • 5. Program Simulation and Debugging
  • 6. Engineering transplantation
3. Keil basic case
  • 1. Turn on the LED light
  • 2. System Delay
  • 3. Button Control
  • 4. External Interruption
  • 5. Serial Communication
  • 6. Timer
  • 7. PWM Breathing Light
  • 8. ADC Acquisition
  • 9. DMA Transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
4. CCS basic case
  • 1. Turn on the LED light
  • 2. System Delay
  • 3. Button Control
  • 4. External Interruption
  • 5. Serial Communication
  • 6. Timer
  • 7. PWM Breathing Light
  • 8. ADC Acquisition
  • 9. DMA Transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
5. MSPM0 Robot Expansion Board
  • 1. MSPM0 Robot Expansion Board Introduction
  • 2. Custom Buttons
  • 3. Drive Buzzer
6. MSPM0-K230Vision module application
  • 1. K230 Color Recognition
  • 2. K230 Barcode Recognition
  • 3. K230 QR Code Recognition
  • 4. K230 Apriltag Code Recognition
  • 5. K230 DM 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. K230 OCR Character Recognition
  • 14. K230 Object Detection
  • 15. K230 Target Tracking
  • 16. K230 Self-learning Object Recognition
  • 17. K230 License Plate Recognition
7. MSPM0-K210Vision module application
  • 0. K210 Prerequisites For Making A Coprocessor - Must-see
  • 1. MSPM0_K210 Color Recognition
  • 2. MSPM0_K210 Barcode Recognition
  • 3. MSPM0_K210 QR Code Recognition
  • 4. MSPM0_K210 Mechanical Code Recognition
  • 5. MSPM0_K210 Face Detection
  • 6. MSPM0_K210 Facial Feature Detection
  • 7. MSPM0_K210 Mask Detection
  • 8. MSPM0_K210 Face Recognition
  • 9. MSPM0_K210 Object Detection
  • 10. MSPM0_K210 Self-study Classification
  • 11. MSPM0_K210 Handwritten Digit Recognition
8. Expansion case
  • 1. Autonomous Driving Car
  • 2. Vehicle-mounted Balance Ball Motion Control System
Download
  • Code
  • Hardware_Info
  • Software_Tools
Download ZIP

Welcome to MSPM0G3519 Development Board repository

2. Vehicle-mounted Balance Ball Motion Control System

MSPM0G3519 Competition Car Tutorial - Ball Control + Eight-Channel Line Tracking Comprehensive

MSPM0G3519 Competition Car Tutorial - Ball Control + Eight-Channel Line Tracking Comprehensive1. Hardware Platform2. Software Environment3. Structure Description3.1 Component List and Material Preparation3.2 Physical Appearance3.3 Assembly Instructions4. Brief Principles4.1 Wiring Pins4.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 Task Detailed Description8. Key Code Analysis8.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 Flow


1. Hardware Platform

ComponentModel/Description
Main ControlMSPM0G3519 Development Board
CameraK230 AI Vision Module (YOLOv8 Ball Detection)
Line TrackingEight-Channel Red Tracking Module (I2C 0x12)
DisplayOLED 128×32 (I2C)
Servo9G Servo (Ball Tilt Control)
MotorTwo-Wheel L-Type 520 Encoder Motors (Serial Driver Board)
ButtonExpansion Board K1 Single Button 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 Part: Black metal etched baseplate, drive motors, wheels. The chassis has reserved screw holes and wire routing holes.

  • Robotic Arm Structure: Blue/black metal servo bracket, metal connecting rods, metal L-type/linear connectors, servo, metal flange.

  • Horizontal Ruler Slide: Transparent acrylic shell, handwritten digital ruler and zero reference line, internal transmission guide/screw rod.

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

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

Note: In addition to the v2 chassis kit accessories, 9g servo, K230 and tracking module can be purchased from our store. Other connecting rods, rulers, water pipes, and those connecting hardware accessories need to be obtained by yourself.

3.2 Physical Appearance

@lQLPJx8RYRl5bCfNA6HNBT6w8rPy_BkRQcIKUYuO1gRyAA

ae9b7260db4e4bed8d8dd752c203d026

1493eddb3c6347c3b743de79e5a664c5

da29de28f01f47fe8c4dd38d841e27e2

93d7a0a9f11847aba187362f984033ce

5e42f4f515c44121ac4bca0f289242a8

6c016275f2e04be0b60c8a08ca993df5

 

3.3 Assembly Instructions

Step 1: Install Mobile Chassis and Motors

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

  • Install the main control board MSPM0G3519, using screws to fix it at the reserved position on the chassis. Note that the main control board should avoid the wheel and motor rotation space.

Step 2: Build Horizontal Ruler and Translation Slide

  • Reference Figure 5: Assemble the transparent acrylic shell and embed the scaled paper board inside. This structure is fixed at the front of the chassis.

  • Note that the guide or screw rod inside the slide needs to remain horizontal, which is the key reference for subsequent robotic arm coordinate calibration.

Step 3: Assemble Robotic Arm Joints

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

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

  • Reference Figure 7 to build the end effector (connector/claw part). In the image, this part uses more 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.

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

Step 4: Install Vertical Metal Bracket

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

  • When using screws to fix, 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: Install the K230 module with the back facing outward. Use transparent acrylic L-bracket and M3 screws to fix 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. Brief Principles

4.1 Wiring Pins

Four-Channel Motor Driver Board:

Motor Driver BoardMSPM0G3519
RX2PB6
TX2PB7
GNDGND
5V5V

Motor Wiring:

MotorDriver Board
M2M-
V3V3
AH1B
BH1A
GGND
M1M+

Eight-Channel Line Tracking Module:

Line Tracking ModuleMSPM0G3519
5V5V
SCLPA15
SDAPA16
GNDGND

OLED:

OLEDMSPM0G3519
VCC5V
GNDGND
SDAPA28
SCLPA31

K230 Camera:

K230MSPM0G3519
5V5V
GNDGND
TXDPA3
RXDPA2

4.2 Physical Wiring Diagram

Your paragraph text (12)

4.3 Control Principle

Car Line Tracking Control Process:

Flowchart

  1. Eight-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/switch state

PID Control Parameter Description:

PID ParameterFunctionAdjustment Direction
P (Proportional)Determines response speed, large output when deviation is largeToo large: Oscillating serpentine; Too small: Weak turning
I (Integral)Eliminates steady-state deviation, cumulative error correctionToo large: Overshoot; Too small: Cannot return from one side
D (Derivative)Suppresses oscillation, early decelerationToo large: Jitter; Too small: Cannot brake

5. Project File Structure

Competition_PJ/
├── main.c                     # Main program: peripheral initialization, main loop, state machine distribution
├── 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         # One-dimensional Kalman filter
│   └── app_servo.c/h          # Servo PWM drive
├── BSP/
│   ├── Eight_Tracking/
│   │   └── app_irtracking.c/h # Eight-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 board 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           # Timer 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, large = aggressive 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  // Water pipe half length (cm), full length 25cm

#define DEADBAND_PX      3.0f  // Deadband (px), error <3px no action
#define RATE_LIMIT       6.0f  // Single frame CC change limit, prevent servo sudden turn
#define KALMAN_Q         1.0f  // Kalman process noise (large = fast response)
#define KALMAN_R         0.3f  // Kalman measurement noise (large = smooth)

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:

PhenomenonAdjust WhatDirectionDescription
Ball wobbles back and forth near center↑ KDIncrease dampingLarger KD brakes earlier
Ball stops before reaching target↑ KPIncrease pushLarger KP pushes farther
Ball overshoots target far↓ KPDecrease push 
Ball stays to one side after stabilizing↑ 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:

PhenomenonAdjust WhatDirection
Not turning enough / pressing line↑ KPIncrease
Serpentine movement↑ KD or ↓ KPDamping/reduce push
Always deviating to one side↑ KIStrengthen integral

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

xxxxxxxxxx
#define BALL_INERTIA_FWD   -0.8f  // Forward inertia compensation (cm), larger = ball pushes more forward
#define BALL_INERTIA_TURN  -0.8f  // Turn inertia compensation (cm)
#define BALL_START_COMP    -5.0f  // Start compensation (cm), car accelerates ball lags
#define BALL_STOP_COMP      5.0f  // Stop compensation (cm), car stops ball overshoots
#define RAMP_TIME_MS       3000   // Start slow acceleration 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 slow acceleration 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 stabilization 8s timeout
#define TASK4_MAX_MS   30000    // Task 4 one lap+ball stabilization 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:

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

Sub State:

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

7.2 Task Detailed Description

Task 1 (Pure Tracking):

  • Line tracking only, no ball control

  • Speed: TASK1_SPEED = 316 mm/s

  • Passes 4 waypoints (A/B/C/D) then stops at A

  • Timeout 20s auto stop

Task 2 (Ball Control):

  • Car stays still, servo control only

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

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

  • Timeout 5s

  • After task completion, ball continues to hold at -5cm position

Task 3 (A→B + Ball Control):

  • Line tracking + servo ball control simultaneously

  • Speed: TASK3_SPEED = 130 mm/s

  • Depart from A point, pass 1 waypoint to reach B

  • Ball stabilized at center O during driving

  • Timeout 8s stop, ball control continues after stop

Task 4 (One Lap + Ball Control):

  • Line tracking + servo ball control simultaneously

  • Speed: TASK4_SPEED = 222 mm/s

  • Clockwise one lap, pass 4 waypoints back to A

  • Ball stabilized at center O during driving

  • Timeout 30s stop, ball control continues after stop

Task 5 (Specified Position + Ball Control):

  • Same as Task 4, but ball target position can be specified (Target_Position)

  • Speed: TASK5_SPEED = 222 mm/s

  • Timeout 30s stop, ball control continues after stop


8. Key Code Analysis

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 limit + 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 limit + CC limit ...
    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 eight-channel infrared

    if (x4 == 0 || x5 == 0) err = 0; // Center black line, go straight
    else if (x3 == 0)       err = -1; // Left deviation, turn right
    else if (x6 == 0)       err =  1; // Right deviation, 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 + turn
    float compensated = ball_target_cm;
    compensated -= BALL_INERTIA_FWD;
    if (pid_output_IRR > 0)
        compensated -= BALL_INERTIA_TURN * pid_output_IRR / 5000.0f;

    // Start slow acceleration: speed gradually increases from 0 over RAMP_TIME_MS milliseconds
    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
    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(hold -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) {     // Each phase 1.8 seconds
        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);    // Keep ball at -5cm position
    break;

9. Operation Flow

  1. After wiring, power on, OLED displays "K230 Init..." waiting 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 entering current mode

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

  6. Short press K1 during task: pause; Long press K1: exit to mode selection

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

  8. Long press K1 to exit to mode selection

Autonomous Driving Car

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/中文