I'm glad to have found this minecraft mod, I am completely a noob in programming, I had zero knowledge, but little by little I made some steps and I am trying to learn.
I always play minecraft with my favorite mods like industrialcraft, buildcraft, forestry, railcraft and traincraft.
I really love Traincraft and I have build a quite important and long railroad system in my world, so I have decided to take a little challenge, to set up a computercraft-controlled railroad system.
What I'm trying to do is a system as more modular as possible, network-based and with multiple levels of functions, which can be easily adapted to various scenarios, so different kinds of stations, yards, conditions, purposes, and can be easily modified on-the-fly in one or more components.
I'm talking of multiple computers running highly specific tasks to make all system works.
This is what I thought would be the best solution, I'm working on this project, now I think I am in a really early stage, but I would like to share and discuss with all of you
and I'm here exactly to do this, you are far better than me and I would really appreciate any kind of suggestions and help from you.
Let's take a look at a train station, for example starting from the case of a terminal station
What I first made is the definition of the system in its modules, having basically two important levels, one of basic imputs, activators, detectors, peripherals etc etc and one of managers, basically where the "intelligence" of system resides.
All the system works with rednet messages that are commands, requests about states, updates, events etc etc
Here is what I have defined, I will translate and explain:
gestore_annunci
gestore_arrivi
gestore_display
gestore_partenze
gestore_scambi
gestore_segnali
gestore_stati
gestore_tragitti
gestore_transiti
gestore_annunci is "ads_manager", it is the component responsible for listening to all the messages in station network, which are so many, and just separate the ones important for the public from the service messages, commands etc etc and translate from system language to something formal and informative, basically listening to "medium level" and "low level" messages and converting to "high level" messages, that can then be later displayed on station monitors for public or just joining "low level" and "medium level" messages and redirecting to technical consoles .
gestore_arrivi is "arrivals_manager", it is the component responsible for managing all incoming trains and takes in consideration the possibility or not to enter in the station and other things, inquirying sensors and listening to them. It informs the network of all arrivals and its properties in "medium level" messages.
gestore_display is "display_manager", it is the component responsible for managing all different monitors on station, organizing ads and informations in a ordered and graphical way.
gestore_partenze is "departures_manager", it is the component responsible for managing all outgoing trains, analog behaviour as "arrivals_manager".
gestore_scambi is "switch_manager", it is the component which controls all switches, that are some sort of "slave" components. it listens to "medium level" commands and sends "low level" commands.
gestore_segnali is "signposting_manager", it is the component which controls all the "traffic lights" stuff and signs etc etc. Like switch_manager it listens to "medium level" commands from other managers (like for example "gestore_tragitti", really important) and sends "low level" commands to "slave" units which phisically control single lights and so on.
gestore_stati is "states_manager", it is a core component because It is where all states of components are stored (for example if a switch is on or off, if a binary is occupied or not, if a light or a crossing is enabled or disabled and so on). It costantly listen to "low level" or "medium level" (depends on situations, certain kinds of scenarios have a further level of state interpretatation and broadcasting, lower, that then get send in a "medium level" language to "states_manager", for example long binary with multiple detectors to determine if train is just passing or stops there) and keeps updates all variables to responds to all requests of states from other managers , that uses them to elaborate the procedures and send commands or just to determine if a light must be on or off and so on.
It also has a local display, just to have updated visualization of states.
gestore_tragitti is "route_manager", it is very important, the most complex and "intelligent" part beacause it is involved when a train has to arrive, leave or just pass, in fact this component has to collect informations (from states_manager or other detectors) and define the route train has to follow to complete its intent. If a train for example is arriving (and can enter the station) it has to determine at which binary the train can stops and then send instructiond to switch_manager, that sets up all switches in correct way following iys embedded functions, and to signposting_manager, that sets up signs.
It reads and sends "medium level" messages and commands.
gestore_transiti is "passing_manager" and it is intended for non-terminal stations or for yard and switches along railway, where a train doesn't stop but has to pass. It is like gestore_arrivi and gestore_partenze and interacts with gestore_tragitti.
Then there are all the "slave" stuffs, which I don't write, because are simple low-end controllers that manage a single physical component.
I have written different managers and they are working fine in testing stage, sending and receiveing messages and commands, storing values and printing all the stuff.
I need some help with the gestore_tragitti, here is part of my code, it has to be intended as a sample, it is not complete, I need to understand the best way to go on and to write correctly the bottom part.
I want the program to check the state of first binary (all with use of network and inquiryng that involve states_manager) and if it is empty it can execute the function (that I will lately define) that sends commands to switch_manager and sets all switches to make train go to first binary (then the stop and timing etc etc will be apart), else will check next binary, the second one, and do the same, sending train here if possible by setting switches or going on to third switch and so on.
Basically it chooses the first possible arrival/departure/passing mode and makes switch_master and signposting_master execute specific instruction set defined for that route and contained in these.
Spoiler
rednet.open("back")
rednet.host("tragitti","gestore_tragitti")
local monitor = peripheral.wrap("top")
function configura_tragitto_arrivo_X()
rednet.broadcast("configura_tragitto_arrivo_X")
end
function configura_tragitto_arrivo_Y()
rednet.broadcast("configura_tragitto_arrivo_Y")
end
function configura_tragitto_arrivo_Z()
rednet.broadcast("configura_tragitto_arrivo_Z")
end
function configura_tragitto_arrivo_001()
rednet.broadcast("configura_tragitto_arrivo_001")
end
function configura_tragitto_arrivo_002()
rednet.broadcast("configura_tragitto_arrivo_002")
end
function configura_tragitto_arrivo_003()
rednet.broadcast("configura_tragitto_arrivo_003")
end
function configura_tragitto_arrivo_004()
rednet.broadcast("configura_tragitto_arrivo_004")
end
function configura_tragitto_arrivo_005()
rednet.broadcast("configura_tragitto_arrivo_005")
end
function configura_tragitto_arrivo_006()
rednet.broadcast("configura_tragitto_arrivo_006")
end
function configura_tragitto_arrivo_007()
rednet.broadcast("configura_tragitto_arrivo_007")
end
function configura_tragitto_arrivo_008()
rednet.broadcast("configura_tragitto_arrivo_008")
end
function configura_tragitto_arrivo_009()
rednet.broadcast("configura_tragitto_arrivo_009")
end
function configura_tragitto_partenza_X()
rednet.broadcast("configura_tragitto_partenza_X")
end
function configura_tragitto_partenza_Y()
rednet.broadcast("configura_tragitto_partenza_Y")
end
function configura_tragitto_partenza_Z()
rednet.broadcast("configura_tragitto_partenza_Z")
end
function configura_tragitto_partenza_001()
rednet.broadcast("configura_tragitto_partenza_001")
end
function configura_tragitto_partenza_002()
rednet.broadcast("configura_tragitto_partenza_002")
end
function configura_tragitto_partenza_003()
rednet.broadcast("configura_tragitto_partenza_003")
end
function configura_tragitto_partenza_004()
rednet.broadcast("configura_tragitto_partenza_004")
end
function configura_tragitto_partenza_005()
rednet.broadcast("configura_tragitto_partenza_005")
end
function configura_tragitto_partenza_006()
rednet.broadcast("configura_tragitto_partenza_006")
end
function configura_tragitto_partenza_007()
rednet.broadcast("configura_tragitto_partenza_007")
end
function configura_tragitto_partenza_008()
rednet.broadcast("configura_tragitto_partenza_008")
end
function configura_tragitto_partenza_009()
rednet.broadcast("configura_tragitto_partenza_009")
end
function configura_tragitto_transito_X()
rednet.broadcast("configura_tragitto_transito_X")
end
function configura_tragitto_transito_Y()
rednet.broadcast("configura_tragitto_transito_Y")
end
function configura_tragitto_transito_Z()
rednet.broadcast("configura_tragitto_transito_Z")
end
function configura_tragitto_transito_001()
rednet.broadcast("configura_tragitto_transito_001")
end
function configura_tragitto_transito_002()
rednet.broadcast("configura_tragitto_transito_002")
end
function configura_tragitto_transito_003()
rednet.broadcast("configura_tragitto_transito_003")
end
function configura_tragitto_transito_004()
rednet.broadcast("configura_tragitto_transito_004")
end
function configura_tragitto_transito_005()
rednet.broadcast("configura_tragitto_transito_005")
end
function configura_tragitto_transito_006()
rednet.broadcast("configura_tragitto_transito_006")
end
function configura_tragitto_transito_007()
rednet.broadcast("configura_tragitto_transito_007")
end
function configura_tragitto_transito_008()
rednet.broadcast("configura_tragitto_transito_008")
end
function configura_tragitto_transito_009()
rednet.broadcast("configura_tragitto_transito_009")
end
function stato_binario_X()
rednet.broadcast("stato_binario_X")
end
function stato_binario_Y()
rednet.broadcast("stato_binario_Y")
end
function stato_binario_Z()
rednet.broadcast("stato_binario_Z")
end
function stato_binario_001()
rednet.broadcast("stato_binario_001")
end
function stato_binario_002()
rednet.broadcast("stato_binario_002")
end
function stato_binario_003()
rednet.broadcast("stato_binario_003")
end
function stato_binario_004()
rednet.broadcast("stato_binario_004")
end
function stato_binario_005()
rednet.broadcast("stato_binario_005")
end
function stato_binario_006()
rednet.broadcast("stato_binario_006")
end
function stato_binario_007()
rednet.broadcast("stato_binario_007")
end
function stato_binario_008()
rednet.broadcast("stato_binario_008")
end
function stato_binario_009()
rednet.broadcast("stato_binario_009")
end
while true do
event, id, message, distance, protocol = os.pullEvent("rednet_message")
if message == "aggiornamento_arrivo" then
stato_binario_001()
if message == "binario_001_libero" then
configura_tragitto_arrivo_001()
else stato_binario_002()
if message == "binario_002_libero" then
configura_tragitto_arrivo_002()
else stato_binario_003()
if message == "binario_003_libero" then
configura_tragitto_arrivo_003()
else stato_binario_004()
if message == "binario_004_libero" then
configura_tragitto_arrivo_004()
else stato_binario_005()
if message == "binario_005_libero" then
configura_tragitto_arrivo_005()
else
etc etc etc
end
end
I probably have made things in a stupid way, I tryed my best, and there is a better way to get the same things with twenty times less lines.
I don't really think it is correct what I've written, beacuse I am not sure if every time system request for a binary state from rednet and the states_master responds this program is still listening and can continue operation
I would appreciate any kind of help.
Sorry for long thread and for my errors, I'm learning english as much as programming.