Create kinetic blocks
Speed, stress and capacity of any Create block that turns, and a Rotation Speed Controller under program control.
Every Create block that turns is a peripheral of type kinetic: shafts and cogwheels, motors, water wheels, presses, mixers, fans, millstones, crushing wheels, gauges... A program reads its speed, the stress of its whole network and what the network can give, and knows when it is overstressed, all without a Stressometer or Engineer's Goggles. On a Rotation Speed Controller, the program also sets the speed.
local press = peripheral.wrap("left")
print(press.speed() .. " RPM")
print(press.stress() .. " / " .. press.capacity() .. " SU")machine.speed() | How fast the block turns, in rotations per minute. |
machine.stress() | The total stress of the network this block belongs to: what a Stressometer shows as used. |
machine.capacity() | The total capacity of the network: what its motors, water wheels, windmills and engines give at their current speed. |
machine.overstressed() | Whether the network is overstressed, as Create decides it. |
machine.set_speed(rpm) | Sets the target speed of a Rotation Speed Controller: the speed of the large cogwheel on top of it. |
Setting up
Against the computer. Any kinetic block against a face of the computer is a peripheral, plain shafts included. The shaft that drives the computer counts too: it enters from the back (from below on a Microcontroller), so peripheral.wrap("back") reads the very network that powers your computer.
On a Data Cable (Minicomputer and newer), machines are named like kinetic@120,64,-35. Plain transmission parts are left out on purpose, so that a cable running along a gear train does not fill peripheral.list() with them: shafts, cogwheels, encased shafts and cogwheels, gearboxes, clutches and gearshifts. Put one of them against the computer if you want it, or read any machine of the same network instead: they all give the same stress and capacity.
Blocks with several jobs. A Millstone turns and holds items: it is both kinetic and an inventory, with the methods of both. Its type, and its name on a cable, is kinetic, and peripheral.find("inventory") finds it too. See Peripherals.
Stress units. Create counts in stress units (SU). Each machine draws its stress impact times its speed; motors, water wheels and engines give a capacity, also growing with speed. When the machines draw more than the sources give, the network is overstressed: everything on it stops until you remove load or add power.
Readings
How fast the block turns, in rotations per minute.
- number
- the speed of the block in RPM, negative when it turns the other way, 0 when it stands still
The sign tells the direction, as Create sees it: a cogwheel meshing with another turns the opposite way, so one reads 64 and the other -64. Use math.abs when only the speed matters. Speeds go up to 256 RPM unless the server changed Create's limit.
local drive = peripheral.wrap("back") -- the shaft that turns the computer
local rpm = math.abs(drive.speed())
print("processor at " .. math.floor(math.min(rpm, 256) / 256 * 100) .. " %")A computer runs at full speed at 256 RPM, so this little program shows how fast its own processor goes.
speed() reads 0 while the network is overstressed, since Create stops it. On a Rotation Speed Controller, it is the speed of the shaft that runs through the controller (its input), not of the cogwheel on top.
When the block is not a kinetic block any more (broken, replaced), every method of this page stops the program with not a kinetic block anymore.
See also kinetic.set_speed()
The total stress of the network this block belongs to: what a Stressometer shows as used.
- number
- the stress the machines of the network draw, in SU, 0 when the block is on no network
Any block of the network gives the same answer, so wrap whichever is handy. The call walks through every block of the network, which costs one instruction per block: on a factory of 2000 kinetic blocks, a Tube Computer waits a while for the answer. Read it every second or so, not in a tight loop.
local machine = peripheral.wrap("left")
local used = machine.stress()
local cap = machine.capacity()
print(used .. " SU used, " .. (cap - used) .. " SU free")See also kinetic.capacity() kinetic.overstressed()
The total capacity of the network: what its motors, water wheels, windmills and engines give at their current speed.
- number
- the stress the sources of the network can give, in SU, 0 when the block is on no network
The ratio stress() / capacity() is the load of the network, 1 meaning full. Check that the capacity is above 0 before dividing: a block that no source drives has a capacity of 0.
local machine = peripheral.wrap("left")
local cap = machine.capacity()
if cap > 0 then
print("load: " .. math.floor(machine.stress() / cap * 100) .. " %")
else
print("nothing drives this network")
endSee also kinetic.stress() kinetic.overstressed()
Whether the network is overstressed, as Create decides it.
- boolean
truewhen the network draws more stress than it can give, and has stopped
This is the same state that makes Create's machines stop and the goggles show a warning. It costs nothing to ask, unlike stress() and capacity():
local machine = peripheral.wrap("left")
if machine.overstressed() then
rs.set("top", true) -- the warning lamp
endSpeed controller
machine.set_speed(rpm)
Sets the target speed of a Rotation Speed Controller: the speed of the large cogwheel on top of it.
rpmnumber- the target speed, a whole number of RPM, negative to turn the other way
It does what turning the controller's value by hand does: the new value stays in the controller after the program ends. 0 stops the output, a negative speed reverses it. Values beyond Create's limit (256 RPM) are brought back to it. The controller still needs rotation on its input shaft to drive anything.
local controller = peripheral.wrap("right")
controller.set_speed(64)
controller.set_speed(-64) -- the other wayA new speed rebuilds the kinetic network, so it is applied at the end of the program's tick, once, with the last value asked: a loop that changes the speed many times a tick costs the world a single update. For the same reason, reading the speed of the output in the same tick still shows the old one.
When it fails:
- on any other kinetic block:
set_speed needs a Rotation Speed Controller; - with a number that has decimals:
bad argument #1 to 'set_speed' (number has no integer representation). Round it first withmath.round.
See also kinetic.speed()
Examples
An overstress early warning
Create only tells you when it is too late. This program lights an amber lamp when the network is over 80 % of its capacity, and a red lamp with a bell when it is overstressed. The wrapped block can be any machine of the network.
local machine = peripheral.wrap("left")
while true do
local cap = machine.capacity()
local load = 0
if cap > 0 then
load = machine.stress() / cap
end
rs.set("top", load > 0.8) -- amber lamp
rs.set("right", machine.overstressed()) -- red lamp and bell
display.set({"Load " .. math.floor(load * 100) .. " %", math.floor(cap) .. " SU available"})
sleep(1)
endThe Overstress guard recipe builds a complete guard on this idea.
A press line that follows its stock
A Rotation Speed Controller drives a Mechanical Press line that makes iron sheets into a Create Item Vault. The emptier the vault, the faster the presses; at the target stock, they stop and draw no stress at all.
local vault = peripheral.wrap("left")
local controller = peripheral.wrap("right")
local TARGET = 2000 -- iron sheets to keep in stock
local MAX = 128 -- top speed of the line, in RPM
while true do
local sheets = vault.count("create:iron_sheet")
local missing = math.max(0, TARGET - sheets)
local rpm = math.round(MAX * missing / TARGET)
controller.set_speed(rpm)
print(sheets .. " sheets, presses at " .. rpm .. " RPM")
sleep(5)
endThe built-in speed program does the simplest version: fast while a redstone input is on, slow otherwise.