ultron-control

command module
v0.0.0-...-6431184 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 3 Imported by: 0

README ยถ

Ultron Control

A ComputerCraft turtle control system with real-time command execution and comprehensive API.

๐Ÿš€ Quick Start

Start the Server
go run main.go
# Server runs on http://localhost:3300
Execute Commands (Synchronous - Default)
# Get turtle status
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method GET

# Execute command with immediate result (default behavior)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.getFuelLevel()'

# Queue command for background execution (legacy mode)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Headers @{"X-Execution-Mode"="async"} -Body 'print("Background task")'

๐ŸŽฏ Key Features

โšก Real-Time Command Execution (Default)
  • Synchronous execution: Commands execute immediately with real-time results
  • 30-second timeout: Automatic timeout protection
  • Error handling: Immediate error feedback and debugging
  • Interactive: Perfect for data retrieval and interactive operations
๐Ÿ“‹ Queue-Based Execution (Legacy)
  • Asynchronous execution: Commands queue for background processing
  • Batch operations: Multiple commands in sequence
  • Long-running tasks: No timeout limitations
  • Fire-and-forget: Ideal for automation and background tasks
๐Ÿ”— WebSocket Connection Tracking
  • Enhanced connection management: Real-time turtle connection monitoring
  • Automatic cleanup: Proper disconnection handling
  • Debug logging: Comprehensive WebSocket event logging
  • Turtle ID 0 support: Full support for all turtle IDs including 0

๐Ÿ“– API Documentation

Execution Modes
Mode Default Header Required Use Case Response Time
Synchronous โœ… Yes None (or X-Execution-Mode: sync) Data retrieval, interactive commands Immediate
Asynchronous โŒ No X-Execution-Mode: async Batch operations, long tasks Queue confirmation
Basic API Endpoints
  • GET /api/turtle - List all turtles
  • GET /api/turtle/{id} - Get turtle data
  • POST /api/turtle/{id} - Execute command (sync by default)
  • GET /api/turtle/usage - API usage documentation
Command Examples
Synchronous Commands (Default)
# Get fuel level (immediate result)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.getFuelLevel()'

# Get inventory (immediate result)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.list()'

# Move turtle (immediate success/failure)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.forward()'
Asynchronous Commands (Legacy)
# Queue multiple commands
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "application/json" -Headers @{"X-Execution-Mode"="async"} -Body '["turtle.forward()", "turtle.turnRight()", "turtle.forward()"]'

# Background task
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Headers @{"X-Execution-Mode"="async"} -Body 'for i=1,10 do turtle.forward() end'

๐Ÿ—๏ธ Architecture

Server Components
  • Go HTTP Server: RESTful API with Gorilla mux
  • WebSocket Handler: Real-time turtle communication
  • Connection Tracking: Active connection management per turtle
  • Command Execution: Hybrid sync/async execution engine
Client Components
  • ComputerCraft Lua: Enhanced turtle scripts
  • WebSocket Client: Real-time server communication
  • Command Processing: Structured command handling
  • Result Formatting: Comprehensive execution metadata
Communication Protocol
  • Legacy Messages: JSON turtle data updates
  • Structured Messages: Type-based message handling
  • Command Responses: Request/response correlation
  • Connection Management: Registration and cleanup

๐Ÿ“ Project Structure

โ”œโ”€โ”€ main.go                 # Application entry point
โ”œโ”€โ”€ config.toml            # Configuration file
โ”œโ”€โ”€ api/
โ”‚   โ”œโ”€โ”€ init.go           # Connection management & sync execution
โ”‚   โ”œโ”€โ”€ turtle.go         # Main turtle API handlers
โ”‚   โ”œโ”€โ”€ global.go         # Shared data structures
โ”‚   โ””โ”€โ”€ setup.go          # API route setup
โ”œโ”€โ”€ static/
โ”‚   โ”œโ”€โ”€ turtle.lua        # Main turtle program
โ”‚   โ”œโ”€โ”€ ultron.lua        # Enhanced turtle library
โ”‚   โ”œโ”€โ”€ pastebin.lua      # Auto-update utility
โ”‚   โ””โ”€โ”€ startup.lua       # Turtle startup script
โ””โ”€โ”€ .copilot/
    โ”œโ”€โ”€ api-documentation.md    # Complete API documentation
    โ”œโ”€โ”€ test-commands.md        # Test commands and results
    โ””โ”€โ”€ session-notes.md        # Development notes

๐Ÿงช Testing

Automated Tests
# Test basic turtle status
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle" -Method GET

# Test default sync execution
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return "test"'

# Test legacy async execution  
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Headers @{"X-Execution-Mode"="async"} -Body 'print("test")'
Development Tools
  • Air: Live reload development server
  • PowerShell: Windows-compatible testing commands
  • VS Code: Integrated development environment
  • ComputerCraft: Minecraft mod for turtle execution

๐Ÿ”ง Configuration

Server Configuration (config.toml)
[server]
port = 3300
static_dir = "static"
work_dir = "workdir"
Environment Setup
  1. Install Go 1.19+
  2. Install ComputerCraft mod
  3. Configure turtle scripts
  4. Start development server with Air

๐Ÿš€ Deployment

Development
# Install Air for live reload
go install github.com/cosmtrek/air@latest

# Start development server
air
Production
# Build binary
go build -o ultron-control

# Run server
./ultron-control

๐ŸŽฎ ComputerCraft Setup

Turtle Installation
-- Run this in ComputerCraft turtle to install Ultron scripts
shell.run("rm", "startup.lua")
shell.run("pastebin", "get", "XWDutV7S", "startup.lua")
shell.run("startup.lua")
Turtle Requirements
  • ComputerCraft mod installed
  • Turtle with networking capability
  • Connection to server (localhost:3300)

๐Ÿ“ Recent Updates

v2.0 - Synchronous Default
  • โšก Default Mode Change: Synchronous execution is now default
  • ๐Ÿ”— Enhanced WebSocket: Improved connection tracking and cleanup
  • ๐Ÿ› Turtle ID 0 Fix: Full support for turtle ID 0
  • ๐Ÿ“‹ Better Logging: Comprehensive debug output
  • ๐Ÿ“š Documentation: Complete API documentation and examples
v1.0 - Foundation
  • ๐Ÿ—๏ธ Core API: Basic turtle control API
  • ๐Ÿ”„ Async Commands: Queue-based command execution
  • ๐Ÿ“ก WebSocket Communication: Real-time turtle communication
  • ๐ŸŽฎ ComputerCraft Integration: Lua script integration

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™‹โ€โ™‚๏ธ Support

For questions, issues, or contributions:

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Directories ยถ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL