Skip to content

Latest commit

 

History

History

fleet

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

The fleet

The fleet at work

The scene from the README: a control computer with a monitor wall, four GPS hosts, and three turtles at work. Each turtle reports what it's doing on the fleet rednet protocol, and the control computer draws them all. Two of the programs are Rust and two are Lua. They share one protocol, so any mix works.

Program Language Runs on Does
fleet-dashboard Rust A computer with a monitor and a modem Shows every turtle that reports: name, job, status, position, fuel and its tally.
fleet-quarry Rust A turtle with a pickaxe and a modem Digs a 5 × 5 pit, 8 layers deep. Unloads into a chest behind it when full.
tower.lua Lua A turtle with a modem and building blocks Builds a hollow 3 × 3 tower.
lumberjack.lua Lua A turtle with an axe and a modem Walks a row of trees, felling each one.
fleet.lua Lua The Lua turtles' shared code: rednet, GPS, fuel and reporting.

The protocol

Every turtle broadcasts a table on the fleet protocol each time it makes progress:

{
  name = "Digger",        -- the turtle's label
  job = "Quarry",         -- what kind of work
  status = "Layer 2 of 8",
  count = 41,             -- the job's own tally: blocks dug, placed, logs cut
  fuel = 5230, fuelLimit = 20000,
  x = 21, y = 62, z = 73, -- from GPS, if it has a fix
}

The dashboard greys out a turtle it hasn't heard from in 10 seconds and drops it after 30. Add your own turtle by broadcasting the same table.

Set it up

  1. GPS. Build four GPS hosts within 64 blocks of where the turtles work, at different heights, and run gps host <x> <y> <z> on each from startup.lua. See GPS.

  2. Build the Rust programs.

    cd guest
    cargo build --release --target wasm32-unknown-unknown -p fleet-dashboard -p fleet-quarry
  3. The control computer. Attach a wireless modem and a monitor (the scene uses 5 × 4 blocks). Copy fleet_dashboard.wasm into its folder and give it a startup.lua:

    shell.run("wasm", "fleet_dashboard.wasm")
  4. The quarry. A turtle with a pickaxe and a wireless modem (craft a Mining Turtle, then equip a modem on its other side), coal in its inventory, and a chest behind it. Copy fleet_quarry.wasm into its folder, label it, and start it the same way.

  5. The Lua turtles. Copy fleet.lua and tower.lua or lumberjack.lua into each turtle's folder, give it fuel (and blocks, for the tower), and start it from startup.lua:

    shell.run("tower", 12)

Turtle folders are wasmcraft/computer/<id>/ in the world; run id on a turtle to find its ID.

Reading the code

Start with fleet-quarry. It's the kind of program that earns Rust: it keeps its own position and heading, reasons about fuel against the distance home, leaves the pit and comes back to the exact spot, and reports world coordinates without a GPS round trip on every step. tower.lua is the opposite end: twenty-five lines you could type at the terminal.