17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-03 15:30:21 +01:00
Files
maszyna/tools/vehicle_graph/examples/vectron-logic.vhg

89 lines
7.9 KiB
Plaintext

// cab logic of an electric locomotive with induction motors, modelled after the Vectron .fiz.
// stage 1 of the vehicle graph: only logic and cab blocks are available, so the pantograph, the main circuit
// and the inverters are represented by timers and constants. the combined power/brake lever goes through a lua
// block, which gives a traction demand and an electrodynamic brake demand for the inverter blocks of the next stages
{
"format": "maszyna-vehicle-graph",
"version": 2,
"vehicle": { "name": "Vectron (logic test)" },
"settings": { "low_voltage_simulation": false },
"nodes": [
{ "id": "bat", "type": "cab.switch", "title": "Battery", "params": { "behaviour": "bistable", "submodel": "battery_sw:", "command": "batterytoggle" } },
{ "id": "pant_sel", "type": "cab.switch", "title": "Pantograph selector", "params": { "behaviour": "multi", "positions": 4, "min": 0, "max": 3, "default": 1, "labels": "rear;front;both;rear", "step": 30, "submodel": "pantselect_sw:" } },
{ "id": "pant_raise", "type": "cab.switch", "title": "Raise pantographs", "params": { "behaviour": "monostable", "animation": "move", "step": 4, "submodel": "pantselectedraise_bt:", "command": "pantographraiseselected" } },
{ "id": "pant_lower", "type": "cab.switch", "title": "Lower pantographs", "params": { "behaviour": "monostable", "animation": "move", "step": 4, "submodel": "pantselectedlower_bt:", "command": "pantographlowerselected" } },
{ "id": "main_sw", "type": "cab.switch", "title": "Main switch", "params": { "behaviour": "multi", "positions": 3, "min": -1, "max": 1, "default": 0, "spring": true, "labels": "off;0;on", "step": 40, "offset": -40, "submodel": "main_sw:" } },
{ "id": "reverser", "type": "cab.switch", "title": "Direction", "params": { "behaviour": "multi", "positions": 3, "min": -1, "max": 1, "default": 0, "labels": "back;0;forward", "step": 45, "offset": -45, "submodel": "dirkey:" } },
{ "id": "lever", "type": "cab.switch", "title": "Power/brake lever", "params": { "behaviour": "multi", "positions": 31, "min": -1, "max": 1, "default": 0, "step": 2, "offset": -30, "submodel": "jointctrl:" } },
{ "id": "pant_cmd", "type": "logic.sr", "title": "Pantographs commanded up" },
{ "id": "pant_cmd_on", "type": "logic.and", "title": "Raising with battery" },
{ "id": "pant_cmd_off", "type": "logic.nand", "title": "Lowering or battery off" },
{ "id": "no_lower", "type": "logic.not", "title": "Lower button released" },
{ "id": "pant_up", "type": "logic.ton", "title": "Pantograph raising", "params": { "time": 5.0 } },
{ "id": "hv_nominal", "type": "logic.const", "title": "Catenary voltage", "params": { "value": 3000 } },
{ "id": "hv", "type": "logic.math", "title": "Voltage behind the pantograph", "params": { "op": "mul" } },
{ "id": "hv_ok", "type": "logic.hyst", "title": "Voltage above minimum", "params": { "lo": 1800, "hi": 1900 } },
{ "id": "ms_on_req", "type": "logic.compare", "title": "Main switch to on", "params": { "op": "gt", "value": 0 } },
{ "id": "ms_off_req", "type": "logic.compare", "title": "Main switch to off", "params": { "op": "lt", "value": 0 } },
{ "id": "ms_init", "type": "logic.ton", "title": "Main circuit initialisation", "params": { "time": 10.0 } },
{ "id": "ms_close", "type": "logic.and", "title": "Closing allowed" },
{ "id": "ms_lost", "type": "logic.nand", "title": "Battery or voltage missing" },
{ "id": "ms_open", "type": "logic.or", "title": "Opening" },
{ "id": "ms", "type": "logic.sr", "title": "Main circuit breaker" },
{ "id": "ms_lamp_on", "type": "logic.not", "title": "Main circuit open" },
{ "id": "dir_set", "type": "logic.compare", "title": "Direction selected", "params": { "op": "ne", "value": 0 } },
{ "id": "drive_ok", "type": "logic.and", "title": "Ready to drive" },
{ "id": "demand", "type": "lua.block", "title": "Power/brake demand", "params": { "lua.ramp_up": 0.5, "lua.ramp_down": 1.0 }, "lua": "-- combined power/brake lever of the Vectron: forward of zero sets the traction demand, back of zero the\n-- electrodynamic brake demand. both follow the lever with limited rates, and drop to zero when the locomotive\n-- isn't ready to drive (no direction selected or main circuit open)\nlocal function approach(value, target, up, down, dt)\n if target > value then\n return math.min(target, value + up * dt)\n end\n return math.max(target, value - down * dt)\nend\n\nblock \"power_brake\" {\n inputs = { lever = \"float\", ready = \"bool\" },\n outputs = { traction = \"float\", ed_brake = \"float\" },\n params = { ramp_up = 0.5, ramp_down = 1.0 }, -- per second\n state = { t = 0.0, b = 0.0 },\n\n update = function(self, i, o, dt)\n local want_t, want_b = 0.0, 0.0\n if i.ready then\n want_t = math.max(i.lever, 0.0)\n want_b = math.max(-i.lever, 0.0)\n end\n self.t = approach(self.t, want_t, self.ramp_up, self.ramp_down, dt)\n self.b = approach(self.b, want_b, self.ramp_up, self.ramp_down, dt)\n o.traction = self.t\n o.ed_brake = self.b\n end,\n}\n" },
{ "id": "lamp_ms", "type": "fb.lamp", "title": "Main circuit lamp", "params": { "color": "red", "submodel": "i-mainbreaker:" } },
{ "id": "lamp_pant", "type": "fb.lamp", "title": "Pantograph lamp", "params": { "color": "yellow", "blink": true, "blink_period": 1.0, "submodel": "i-pantraising:" } },
{ "id": "pant_moving", "type": "logic.and", "title": "Pantograph moving" },
{ "id": "pant_not_up", "type": "logic.not", "title": "Pantograph not up yet" },
{ "id": "v_hv", "type": "fb.gauge", "title": "Catenary voltage", "params": { "min": 0, "max": 4000, "unit": "V", "angle_min": 0, "angle_max": 270, "submodel": "hvoltage:" } },
{ "id": "v_demand", "type": "fb.gauge", "title": "Traction demand", "params": { "min": 0, "max": 1, "angle_min": 0, "angle_max": 270, "submodel": "tractionforce:" } },
{ "id": "snd_base", "type": "logic.const", "title": "Idle volume", "params": { "value": 0.3 } },
{ "id": "snd_gain", "type": "logic.math", "title": "Volume rising with demand", "params": { "op": "add" } },
{ "id": "snd_inverter", "type": "fb.sound", "title": "Inverters", "params": { "file": "vectron-inverter.wav", "placement": "engine", "loop": true } }
],
"connections": [
{ "from": "pant_raise.pos", "to": "pant_cmd_on.a" },
{ "from": "bat.pos", "to": "pant_cmd_on.b" },
{ "from": "pant_lower.pos", "to": "no_lower.a" },
{ "from": "no_lower.q", "to": "pant_cmd_off.a" },
{ "from": "bat.pos", "to": "pant_cmd_off.b" },
{ "from": "pant_cmd_on.q", "to": "pant_cmd.s" },
{ "from": "pant_cmd_off.q", "to": "pant_cmd.r" },
{ "from": "pant_cmd.q", "to": "pant_up.a" },
{ "from": "hv_nominal.q", "to": "hv.a" },
{ "from": "pant_up.q", "to": "hv.b" },
{ "from": "hv.q", "to": "hv_ok.a" },
{ "from": "hv.q", "to": "v_hv.value" },
{ "from": "pant_up.q", "to": "pant_not_up.a" },
{ "from": "pant_cmd.q", "to": "pant_moving.a" },
{ "from": "pant_not_up.q", "to": "pant_moving.b" },
{ "from": "pant_moving.q", "to": "lamp_pant.on" },
{ "from": "main_sw.pos", "to": "ms_on_req.a" },
{ "from": "main_sw.pos", "to": "ms_off_req.a" },
{ "from": "hv_ok.q", "to": "ms_init.a" },
{ "from": "ms_on_req.q", "to": "ms_close.a" },
{ "from": "ms_init.q", "to": "ms_close.b" },
{ "from": "bat.pos", "to": "ms_lost.a" },
{ "from": "hv_ok.q", "to": "ms_lost.b" },
{ "from": "ms_off_req.q", "to": "ms_open.a" },
{ "from": "ms_lost.q", "to": "ms_open.b" },
{ "from": "ms_close.q", "to": "ms.s" },
{ "from": "ms_open.q", "to": "ms.r" },
{ "from": "ms.q", "to": "ms_lamp_on.a" },
{ "from": "ms_lamp_on.q", "to": "lamp_ms.on" },
{ "from": "lever.pos", "to": "demand.lever" },
{ "from": "reverser.pos", "to": "dir_set.a" },
{ "from": "dir_set.q", "to": "drive_ok.a" },
{ "from": "drive_ok.q", "to": "demand.ready" },
{ "from": "ms.q", "to": "drive_ok.b" },
{ "from": "demand.traction", "to": "v_demand.value" },
{ "from": "ms.q", "to": "snd_inverter.play" },
{ "from": "snd_base.q", "to": "snd_gain.a" },
{ "from": "demand.traction", "to": "snd_gain.b" },
{ "from": "snd_gain.q", "to": "snd_inverter.volume" }
]
}