17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-04 12:35:54 +01:00

Add vehicle graph core: .vhg loader, logic and cab blocks, -graph-run and -graph-catalog

This commit is contained in:
2026-10-13 10:55:53 +02:00
parent c26041f2e7
commit 70abf879b3
42 changed files with 4693 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
// expect: error has to be one of
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "sw", "type": "cab.switch", "params": { "behaviour": "bistabilny" } } ] }

View File

@@ -0,0 +1,2 @@
// expect: error has to be a number
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "sw", "type": "cab.switch", "params": { "positions": "3" } } ] }

View File

@@ -0,0 +1,36 @@
time;x.q;y.q;and.q;or.q;xor.q;nand.q;nor.q;not.q;sr.q;sr_set.q;ton.q;tof.q;delay.q;hyst.q;le.q;div.q;min.q;sel.q;button.pos;button.index;lever.pos;lever.index;sr:state;sr_set:state;ton:elapsed;tof:elapsed;button:position;lever:position
0.1;1;0;0;1;1;1;0;0;1;1;0;1;1;0;1;0;0;1;0;0;0;2;1;1;0.1;0;0;2
0.2;1;0;0;1;1;1;0;0;1;1;0;1;1;0;1;0;0;1;0;0;0;2;1;1;0.2;0;0;2
0.3;1;0;0;1;1;1;0;0;1;1;0;1;1;0;1;0;0;1;0;0;0;2;1;1;0.3;0;0;2
0.4;1;1;1;1;0;0;0;0;0;1;0;1;1;0;1;1;1;1;0;0;0;2;0;1;0.4;0;0;2
0.5;1;1;1;1;0;0;0;0;0;1;1;1;1;0;1;1;1;1;0;0;0;2;0;1;0.5;0;0;2
0.6;1;1;1;1;0;0;0;0;0;1;1;1;1;0;1;1;1;1;0;0;0;2;0;1;0.5;0;0;2
0.7;0;1;0;1;1;1;0;1;0;0;0;1;0;0;1;0;0;0;0;0;0;2;0;0;0;0.1;0;2
0.8;0;1;0;1;1;1;0;1;0;0;0;1;0;0;1;0;0;2;1;1;2;4;0;0;0;0.2;1;4
0.9;0;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0;0;0;1;0;0;0;0;0;-2;0;1;1;0;0.5;0;0
2.6;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
2.7;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
2.8;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
2.9;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
3;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
3.1;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
3.2;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
3.3;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
3.4;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
3.5;0;0;0;0;0;1;1;1;1;1;0;0;0;0;1;0;0;-2;1;1;-2;0;1;1;0;0.5;1;0
1 time x.q y.q and.q or.q xor.q nand.q nor.q not.q sr.q sr_set.q ton.q tof.q delay.q hyst.q le.q div.q min.q sel.q button.pos button.index lever.pos lever.index sr:state sr_set:state ton:elapsed tof:elapsed button:position lever:position
2 0.1 1 0 0 1 1 1 0 0 1 1 0 1 1 0 1 0 0 1 0 0 0 2 1 1 0.1 0 0 2
3 0.2 1 0 0 1 1 1 0 0 1 1 0 1 1 0 1 0 0 1 0 0 0 2 1 1 0.2 0 0 2
4 0.3 1 0 0 1 1 1 0 0 1 1 0 1 1 0 1 0 0 1 0 0 0 2 1 1 0.3 0 0 2
5 0.4 1 1 1 1 0 0 0 0 0 1 0 1 1 0 1 1 1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,0 +1,16 @@
0.0 force x.q 1
0.3 force y.q 1
0.6 force x.q 0
0.7 press button
0.71 inc lever
0.72 inc lever
0.9 release button
1.0 release lever
1.1 force x.q 3
1.2 force x.q 5
1.3 force x.q 2.5
1.4 force x.q 1
1.5 force y.q 0
1.6 value lever -1.9
1.7 unforce x.q
2.5 toggle button

View File

@@ -0,0 +1,39 @@
// expect: ok
// every logic block driven by forced inputs; see blocks.script
{
"format": "maszyna-vehicle-graph", "version": 2,
"nodes": [
{ "id": "x", "type": "logic.const", "params": { "value": 0 } },
{ "id": "y", "type": "logic.const", "params": { "value": 0 } },
{ "id": "and", "type": "logic.and" }, { "id": "or", "type": "logic.or" }, { "id": "xor", "type": "logic.xor" },
{ "id": "nand", "type": "logic.nand" }, { "id": "nor", "type": "logic.nor" }, { "id": "not", "type": "logic.not" },
{ "id": "sr", "type": "logic.sr" },
{ "id": "sr_set", "type": "logic.sr", "params": { "reset_priority": false } },
{ "id": "ton", "type": "logic.ton", "params": { "time": 0.5 } },
{ "id": "tof", "type": "logic.tof", "params": { "time": 0.5 } },
{ "id": "delay", "type": "logic.delay", "params": { "initial": 7 } },
{ "id": "hyst", "type": "logic.hyst", "params": { "lo": 2, "hi": 4 } },
{ "id": "le", "type": "logic.compare", "params": { "op": "le", "value": 3 } },
{ "id": "div", "type": "logic.math", "params": { "op": "div" } },
{ "id": "min", "type": "logic.math", "params": { "op": "min" } },
{ "id": "sel", "type": "logic.select" },
{ "id": "button", "type": "cab.switch", "params": { "behaviour": "monostable" } },
{ "id": "lever", "type": "cab.switch", "params": { "behaviour": "multi", "positions": 5, "min": -2, "max": 2, "default": 0, "spring": true } }
],
"connections": [
{ "from": "x.q", "to": "and.a" }, { "from": "y.q", "to": "and.b" },
{ "from": "x.q", "to": "or.a" }, { "from": "y.q", "to": "or.b" },
{ "from": "x.q", "to": "xor.a" }, { "from": "y.q", "to": "xor.b" },
{ "from": "x.q", "to": "nand.a" }, { "from": "y.q", "to": "nand.b" },
{ "from": "x.q", "to": "nor.a" }, { "from": "y.q", "to": "nor.b" },
{ "from": "x.q", "to": "not.a" },
{ "from": "x.q", "to": "sr.s" }, { "from": "y.q", "to": "sr.r" },
{ "from": "x.q", "to": "sr_set.s" }, { "from": "y.q", "to": "sr_set.r" },
{ "from": "x.q", "to": "ton.a" }, { "from": "x.q", "to": "tof.a" },
{ "from": "x.q", "to": "delay.a" },
{ "from": "x.q", "to": "hyst.a" }, { "from": "x.q", "to": "le.a" },
{ "from": "x.q", "to": "div.a" }, { "from": "y.q", "to": "div.b" },
{ "from": "x.q", "to": "min.a" }, { "from": "y.q", "to": "min.b" },
{ "from": "button.pos", "to": "sel.sel" }, { "from": "x.q", "to": "sel.a" }, { "from": "lever.pos", "to": "sel.b" }
]
}

View File

@@ -0,0 +1,3 @@
// expect: error joins different domains
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "a", "type": "cab.switch" }, { "id": "lamp", "type": "fb.lamp" } ],
"connections": [ { "from": "a.pos", "to": "lamp.supply" } ] }

View File

@@ -0,0 +1,2 @@
// expect: error duplicate node id
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "a", "type": "logic.not" }, { "id": "a", "type": "logic.not" } ] }

View File

@@ -0,0 +1,15 @@
// expect: ok
// the same self-holding circuit as loop.vhg, closed through a unit delay
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [
{ "id": "start", "type": "cab.switch" },
{ "id": "hold", "type": "logic.or" },
{ "id": "coil", "type": "logic.and" },
{ "id": "stop", "type": "logic.const", "params": { "value": 1 } },
{ "id": "contact", "type": "logic.delay" }
], "connections": [
{ "from": "start.pos", "to": "hold.a" },
{ "from": "contact.q", "to": "hold.b" },
{ "from": "hold.q", "to": "coil.a" },
{ "from": "stop.q", "to": "coil.b" },
{ "from": "coil.q", "to": "contact.a" }
] }

View File

@@ -0,0 +1,12 @@
// expect: error loop without a deferred block
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [
{ "id": "start", "type": "cab.switch" },
{ "id": "hold", "type": "logic.or" },
{ "id": "coil", "type": "logic.and" },
{ "id": "stop", "type": "logic.const", "params": { "value": 1 } }
], "connections": [
{ "from": "start.pos", "to": "hold.a" },
{ "from": "coil.q", "to": "hold.b" },
{ "from": "hold.q", "to": "coil.a" },
{ "from": "stop.q", "to": "coil.b" }
] }

View File

@@ -0,0 +1,2 @@
// expect: error malformed file
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": 5, "type": "logic.not" } ] }

View File

@@ -0,0 +1,4 @@
// expect: error has more than one source
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [
{ "id": "a", "type": "cab.switch" }, { "id": "b", "type": "cab.switch" }, { "id": "n", "type": "logic.not" }
], "connections": [ { "from": "a.pos", "to": "n.a" }, { "from": "b.pos", "to": "n.a" } ] }

View File

@@ -0,0 +1,2 @@
// expect: warning required input "a" isn't connected
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "n", "type": "logic.not" } ] }

View File

@@ -0,0 +1,2 @@
// expect: error unknown block type
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "x", "type": "el.flux_capacitor" } ] }

View File

@@ -0,0 +1,2 @@
// expect: error unsupported file version 1
{ "format": "maszyna-vehicle-graph", "version": 1, "nodes": [] }

View File

@@ -0,0 +1,3 @@
// expect: error isn't an output
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "a", "type": "logic.not" }, { "id": "b", "type": "logic.not" } ],
"connections": [ { "from": "a.a", "to": "b.a" } ] }