{
- "Example Server": {
+ "Debug": {
"plugin": "WSServer",
"port": 8080,
"web": {
"location": "Debug" }
}
},
- "Lubrication Button": {
- "plugin": "Alias",
- "from": {
- "target": { "const": "Lubrication Button" },
- "command": { "const": "press" }
- },
- "to": {
- "event": "pressed"
- }
- },
"Engine Button": {
"plugin": "Alias",
"from": {
"event": "pressed"
}
},
- "Lubrication": {
- "plugin": "State"
- },
"Engine": {
"plugin": "State"
},
+ "Delay": {
+ "plugin": "Wait",
+ "seconds": 5
+ },
"Machine": {
"plugin": "StateMachine",
"init": "off",
"target": "Engine",
"command": "set state",
"new state": false
- },
- {
- "target": "Lubrication",
- "command": "set state",
- "new state": false
}
],
"transitions": [
"target": "Engine",
"command": "set state",
"new state": false
- },
- {
- "target": "Lubrication",
- "command": "set state",
- "new state": false
}
],
"transitions": [
},
{
"trigger": {
- "sender": { "const": "Lubrication Button" },
+ "sender": { "const": "Engine Button" },
"event": { "const": "pressed" }
},
- "to": "lubrication on"
+ "to": "on"
}
]
},
- "lubrication on": {
+ "on": {
"commands": [
{
"target": "Engine",
"command": "set state",
- "new state": false
- },
- {
- "target": "Lubrication",
- "command": "set state",
"new state": true
}
],
},
"to": "emergency"
},
- {
- "trigger": {
- "sender": { "const": "Lubrication Button" },
- "event": { "const": "pressed" }
- },
- "to": "off"
- },
{
"trigger": {
"sender": { "const": "Engine Button" },
"event": { "const": "pressed" }
},
- "to": "engine on"
+ "to": "delay"
}
]
},
- "engine on": {
+ "delay": {
"commands": [
{
- "target": "Engine",
- "command": "set state",
- "new state": true
- },
- {
- "target": "Lubrication",
- "command": "set state",
- "new state": true
+ "target": "Delay",
+ "command": "wait"
}
],
"transitions": [
},
{
"trigger": {
- "sender": { "const": "Engine Button" },
- "event": { "const": "pressed" }
+ "sender": { "const": "Delay" },
+ "event": { "const": "finished" }
},
- "to": "lubrication on"
+ "to": "off"
}
]
}
```
## Benutzung
-…
+Eine minimale ControlPi-Konfiguration, die dieses Plugin benutzt, ist im
+git-Repository enthalten:
+```json
+{
+ "Debug": {
+ "plugin": "WSServer",
+ "port": 8080,
+ "web": {
+ "/": { "module": "controlpi_plugins.wsserver",
+ "location": "Debug" }
+ }
+ },
+ "Engine Button": {
+ "plugin": "Alias",
+ "from": {
+ "target": { "const": "Engine Button" },
+ "command": { "const": "press" }
+ },
+ "to": {
+ "event": "pressed"
+ }
+ },
+ "Emergency Button": {
+ "plugin": "Alias",
+ "from": {
+ "target": { "const": "Emergency Button" },
+ "command": { "const": "press"}
+ },
+ "to": {
+ "event": "pressed"
+ }
+ },
+ "Engine": {
+ "plugin": "State"
+ },
+ "Delay": {
+ "plugin": "Wait",
+ "seconds": 5
+ },
+ "Machine": {
+ "plugin": "StateMachine",
+ "init": "off",
+ "states": {
+ "emergency": {
+ "commands": [
+ {
+ "target": "Engine",
+ "command": "set state",
+ "new state": false
+ }
+ ],
+ "transitions": [
+ {
+ "trigger": {
+ "sender": { "const": "Emergency Button" },
+ "event": { "const": "pressed" }
+ },
+ "to": "off"
+ }
+ ]
+ },
+ "off": {
+ "commands": [
+ {
+ "target": "Engine",
+ "command": "set state",
+ "new state": false
+ }
+ ],
+ "transitions": [
+ {
+ "trigger": {
+ "sender": { "const": "Emergency Button" },
+ "event": { "const": "pressed" }
+ },
+ "to": "emergency"
+ },
+ {
+ "trigger": {
+ "sender": { "const": "Engine Button" },
+ "event": { "const": "pressed" }
+ },
+ "to": "on"
+ }
+ ]
+ },
+ "on": {
+ "commands": [
+ {
+ "target": "Engine",
+ "command": "set state",
+ "new state": true
+ }
+ ],
+ "transitions": [
+ {
+ "trigger": {
+ "sender": { "const": "Emergency Button" },
+ "event": { "const": "pressed" }
+ },
+ "to": "emergency"
+ },
+ {
+ "trigger": {
+ "sender": { "const": "Engine Button" },
+ "event": { "const": "pressed" }
+ },
+ "to": "delay"
+ }
+ ]
+ },
+ "delay": {
+ "commands": [
+ {
+ "target": "Delay",
+ "command": "wait"
+ }
+ ],
+ "transitions": [
+ {
+ "trigger": {
+ "sender": { "const": "Emergency Button" },
+ "event": { "const": "pressed" }
+ },
+ "to": "emergency"
+ },
+ {
+ "trigger": {
+ "sender": { "const": "Delay" },
+ "event": { "const": "finished" }
+ },
+ "to": "off"
+ }
+ ]
+ }
+ }
+ }
+}
+```
+
+In der Debug-Oberfläche sieht das Beispiel folgendermaßen aus:
+
+
+Die beiden `Alias`-Instanzen simulieren Taster und die `State`-Instanz
+`Engine` einen Motor, der von der Statemachine gesteuert wird.
+Aus dem initialen Zustand `off` kann durch Drücken des `Engine Button` in
+den Zustand `on` gewechselt werden.
+
+Nochmaliges Drücken des `Engine Button` schaltet die Maschine aber nicht
+sofort ab, sondern wechelt in einen fünf-sekündigen Nachlauf im Zustand
+`delay`.
+Dies wird dadurch erreicht, dass beim Betreten des Zustands dem
+`Wait`-Plugin `Delay` das Kommando `wait` geschickt wird und der Zustand
+dann durch eine Transition, die auf das `finished`-Event reagiert verlassen
+wird.
+
+Außerdem kann die Maschine aus jedem Zustand heraus durch Drücken des
+`Emergency Button` sofort abgeschaltet werden, wobei in den Zustand
+`emergency` gewechselt wird.
+Dieser kann nur verlassen werden, wenn durch nochmaliges Drücken des
+`Emergency Button` bestätigt wird, dass die Gefahr vorüber ist.