Skip to content

CodeBros-UCF/TACO

Repository files navigation

πŸ€– Robot Tracking System - Setup Guide

Prerequisites

βœ… LEGO Hub Requirements:

  • Hub is powered ON
  • Hub is named "test" (or update name in robot_runner.py line 9)
  • Hub is within Bluetooth range (3-10 feet from computer)
  • Hub has Pybricks firmware installed

βœ… Motor Connections:

  • Port A: Base motor (rotates left/right)
  • Port F: Shoulder motor (moves up/down)

Step-by-Step Instructions

Step 1: Clear the Commands File

python -c "open('commands.txt', 'w', encoding='utf-8').write('')"

Step 2: Start the Robot Bridge (Terminal 1)

python robot_runner.py

Expected output:

[Runner] πŸ€– Robot command runner started
[Runner] πŸ“‚ Monitoring: commands.txt

⚠️ Keep this terminal running - don't close it!


Step 3: Start the Vision System (Terminal 2)

Open a new terminal and run:

python main.py --use_robot --target_object bottle

Expected output:

πŸ€– Robot control enabled
[STARTUP] Target object: bottle
[STARTUP] Center zone: 256.0 to 384.0

Step 4: Test the Tracking

  1. Hold a bottle in front of the camera
  2. Move it left or right
  3. Watch the robot rotate to track it!

Expected Behavior

Terminal 1 (robot_runner.py):

[Runner] Running on hub (attempt 1/3): BASE:40
[Runner] βœ“ Command successful: BASE:40

Terminal 2 (main.py):

⬅️  LEFT
πŸ“€ SENT: BASE:-40

➑️  RIGHT
πŸ“€ SENT: BASE:40

System Configuration

Setting Value
BASE movement Β±40Β°
SHOULDER movement Β±20Β°
Motor speed 1500 deg/s
Command cooldown 0.05s (20 commands/sec)
Center threshold 20% of frame width

Troubleshooting

❌ UTF-8 Encoding Errors

[Runner] Error: 'utf-8' codec can't decode byte 0xff

Fix:

python -c "open('commands.txt', 'w', encoding='utf-8').write('')"

❌ Hub Not Found

[HUB] TimeoutError
[HUB] Searching for test...

Fix:

  • Check hub is powered ON
  • Check hub name is "test"
  • Move hub closer to computer (within 10 feet)
  • Make sure hub isn't connected to another device

❌ Camera Not Opening

Could not open camera at index 0

Fix:

python webcam.py  # Find correct camera index
python main.py --use_robot --target_object bottle --camera_index 1  # Use different index

❌ No Movement

Checklist:

  • Both terminals are running
  • robot_runner.py shows "βœ“ Command successful"
  • Hub motors are in correct ports (A=base, F=shoulder)
  • Bottle is visible in camera feed
  • Bluetooth connection is stable

Files in the System

File Purpose
main.py Vision detection and command generation
robot_runner.py Bluetooth bridge to send commands to hub
robot_hub.py Hub-side script that controls motors
commands.txt Temporary file for command communication
commands_log.txt Log of all commands sent (optional)

Quick Reference - Command Format

Commands written to commands.txt:

BASE:40       # Rotate base right 40Β°
BASE:-40      # Rotate base left 40Β°
SHOULDER_UP   # Move shoulder up 20Β°
SHOULDER_DOWN # Move shoulder down 20Β°
STOP          # Stop all motors

Notes

⚠️ Never use echo to write to commands.txt - it creates UTF-16 files which cause errors

βœ… Only let Python write to the file, or use:

python -c "open('commands.txt', 'w', encoding='utf-8').write('BASE:40')"

Installation

Install Python Dependencies

pip install -r requirements.txt

Required Packages:

  • ultralytics - YOLOv8 object detection
  • opencv-python - Computer vision and camera handling
  • pybricksdev - LEGO hub Bluetooth communication
  • supervision - Detection utilities

Support

If issues persist:

  1. Restart both terminals
  2. Power cycle the LEGO hub
  3. Clear commands file again
  4. Check Bluetooth connectivity

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Camera    │─────── β–Άβ”‚   main.py    │────────▢│commands.txt β”‚
β”‚  (Bottle)   β”‚          β”‚  (YOLOv8)    β”‚         β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                                                         β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
                        β”‚robot_runner  β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚    .py       β”‚
                        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚ Bluetooth
                        β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                        β”‚  LEGO Hub    β”‚
                        β”‚ (robot_hub)  β”‚
                        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                        β”‚    Motors    β”‚
                        β”‚ A=Base F=Arm β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

License

MIT License - Feel free to use and modify!

Contributors

Built with ❀️ for LEGO Mindstorms robot tracking

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors