VISCORE
← All works

Robotics & EmbeddedJul 2026Completed

Steel-Ball Position Tracking

2026 electronics design contest, Problem H: track a steel ball inside a water pipe on a K230 in real time and send position and velocity errors to the controller for closed-loop control.

Vision leadTeam entry

Third Prize, Sichuan Provincial · 2026

  • K230 (Lushan Pi)
  • YOLOv8 kmodel
  • Kalman filter
  • UART
  • Wi-Fi RTSP
  • Python tkinter
Three steel balls detected on the board, each labelled 0.886
20 msSerial frame periodNormalised position and velocity errors, sent non-blocking

Background

The controller needs the ball’s live position and velocity for closed-loop control. Three things make that hard: velocity cannot be read from a single frame; detections jitter and drop out; and inference delay makes the control lag. At the venue it also had to be possible to look back at what happened in every frame.

What the system does

K230 capture→YOLOv8 detection→Kalman tracking→delay compensation→serial output to the controller

In parallel: K230→Wi-Fi RTSP→PC replay tool

  • Detects the ball in real time and converts it to a physical position
  • Tracks the ball, estimates velocity and recognises a change of direction
  • Outputs position and velocity errors after compensating for inference delay
  • Live video, recording, screenshots and replay on the PC

My work

  • Detection model: trained a single-class YOLOv8 and converted it to a kmodel for the K230. The input was reduced from 640×640 to 320×320 to gain frame rate.
  • Coordinate calibration: the track is a 25 cm water pipe with 0.1 cm graduations; calibration points convert pixel coordinates to centimetres.
  • Tracking and velocity: implemented a one-dimensional constant-velocity Kalman filter whose state is position and velocity. Detections are matched to the track by distance and confidence, and anything beyond the gate is rejected; the track is re-acquired automatically after a loss and can recognise the ball reversing.
  • Delay compensation: before output, the position is pushed forward by the inference time of the current frame to cancel the lag that inference introduces.
  • Serial link: normalised position and velocity errors go out every 20 ms, non-blocking; data returned by the controller is parsed by a byte-by-byte state machine that copes with split packets, concatenated packets and garbage bytes.
  • PC viewer: wrote an RTSP receiver with tkinter and OpenCV that supports reconnection, recording, screenshots and replay; recordings are written to disk asynchronously so the live view does not stall.

Problems and fixes

The sign kept flipping. When formatted, small negative numbers near zero print as negative zero, and the sign parsed by the controller flipped back and forth. Very small values are now set to zero before formatting.

What to send on a miss. After two consecutive misses the board stops sending instead of sending an “invalid frame”, and the controller applies its own timeout. Both sides agreed on this interface rule in advance.

Results

  • Third Prize, Undergraduate Group, 2026 Sichuan Provincial Undergraduate Electronics Design Contest.
  • Delivered the on-board program and the PC streaming and replay tool as one package.

Retrospective

  • Serial reception in the previous year’s aiming device was unstable with partial and concatenated packets; this time it was rewritten as a byte-by-byte state machine.

Project images

Touch tuning UI on the K230
Debug view with the overlay readouts at top left
Technical notes
  • Matching gate: a detection more than 140 px from the track is not matched.
  • Delay compensation: pushed forward by the current frame’s inference time, capped at 100 ms.
  • Frame format: 0x44 0x55 + "%+.4f,%+.4f,%d,%d" + 0x66; values are clamped to [−1, 1] first, one frame every 20 ms, non-blocking with timeout=0.
  • Negative zero: %+.4f can print -0.0000, so values with magnitude below 0.00005 are set to zero before formatting.