Tutorial 6: a train between two depots
Goal: a train hauls a container from one depot to another.
What you need
This is an investment, not a first-day project: locomotive (45 000 MT), 2 wagon (4 000 each), 2 train_stop (1 500 each), 32 track (6 each), 2 container (900 each), 4 battery_48v, 20 cable_6, a robot with a crane (75 000 MT, 2 ports), two depot and a power station.
Steps
- Lay a closed loop; trains cannot reverse or turn around. Corners are the pieces
curve_es,curve_sw,curve_wn,curve_ne; sides arestraight_ewandstraight_ns. Pick the piece in the build bar (structure_placewithitem: "track",choice).
x0 x0+1 x0+2 ... x0+11
row y0 es ew ew ... ew sw
row y0+1 ns ns
...
row y0+5 ne ew ew ... ew wn
- Place stop A just above the top side and stop B just below the bottom side, each 2×2 touching the track. Put a depot near each. The power station must touch stop A, next to the yard slot you will use for the battery (slots are numbered row by row from the stop's top left).
- On stop A, build the battery container in the slot that touches the station, here called slot 1 (Build;
battery_container_buildwithstop,slot). Set a cargo container in slot 2 (Set down;container_set_down). - Wait for the battery to charge. It charges only beside a switched-on station.
- Assemble 2 wagons (
train_assemblewithstop,wagons: 2). - Attach the crane to a robot parked touching stop A and on the station's dock side, so the station can pay: a lift plus a placing costs 6 kWh. Save (use your slot numbers):
def tick():
crane.lift("yard:1")
crane.place("wagon:1")
Once wagon 1 is loaded, change both numbers to 2.
- Load cargo:
depot_unload(depot to hold), thencontainer_loadwithid,item,quantity. - The train's default script shuttles between the first two stops:
WAIT_TURNS = 3
def tick():
stops = train.stops()
if len(stops) < 2:
return
status = train.status()
if status["destination"] != None or status["wait"] > 0 or status["state"] in ["moving", "waiting"]:
return
target = memory.get("target", 1)
if status["stop"] == stops[target]["id"]:
# Arrived: wait here once, then head for the other stop.
if memory.get("waited", -1) != target:
memory.set("waited", target)
train.wait(WAIT_TURNS)
return
target = 1 - target
memory.set("target", target)
train.go_to(stops[target]["id"])
- At stop B,
container_unload, thendepot_load. Your spacecraft must be in range for each of these.
What you should see
train_list shows moving, then at_stop. It covers 2 cells a turn, spending 200 Wh plus 20 Wh per wagon each cell.
Three common mistakes
- A straight line. The train ends at
dead_end. - No battery on wagon 1. State
no_power. A stop alone charges nothing. - A robot on the track. The train shows
blockedand waits.