3.6 Examples

The folder examples of the runtime has four example models outside the lamp domain. Each folder has a metamodel, a model, one state machine, event definitions in EVENTS.kmeta and a README.md with the steps to run it. The lamp itself is in the folder examples/lamp of the IDE, and a room with spare bulbs whose state machines objects get at run time, as 3.1.13 State machine management and lifecycle describes, in the folder examples/spares of the IDE.

FolderWhat it showsObject of the state machineEvents
single_robot_exampleA cleaning robot that drives around a room and steers away from obstacles and walls: nested states, NOT LOOPING, EVAL conditions, SETOBJ on a knows relation, WITH ... AS, macros with numpy, events raised by the state machineturtlestart in domain public. EVENTS.kmeta also defines setSpeed and teleport, which the state machine does not use
delivery_drone_exampleA delivery drone driven by events with payloads: conditions on payload fields, $(event->...) in ENTRY blocks, IF IN SCOPE, payload values copied into the modelscoutassignDelivery, setCruiseSpeed, recall in domain control
autonomous_car_exampleA car that tests three subsystems in parallel before it drives: SPLIT into three branches and JOIN backav-1powerOn in domain ignition
drone_swarm_exampleA swarm that grows, reshapes and shrinks its fleet: APPENDOBJ, SETOBJ, DROPOBJ, SETLIST, DROPLIST, WITH ... ASalpha-swarmdeploy, droneDown, recall in domain swarm
FolderFiles
single_robot_examplecleaning_robot.kmeta, cleaning_robot.kmodel, cleaning_robot.kstates, EVENTS.kmeta
delivery_drone_exampledelivery_drone.kmeta, delivery_drone.kmodel, delivery_drone.kstates, EVENTS.kmeta
autonomous_car_exampleautonomous_car.kmeta, autonomous_car.kmodel, autonomous_car.kstates, EVENTS.kmeta
drone_swarm_exampledrone_swarm.kmeta, drone_swarm.kmodel, drone_swarm.kstates, EVENTS.kmeta

All four use EVAL blocks or macros, so run them with Python at hand. The macros of the robot import numpy. The Docker image of 3.3.3 Running in Docker has both.

To run an example:

  1. Start the runtime as 3.3 Running the runtime describes.
  2. In the folder of the example, create an environment and upload the files. For the car:
    ENV=$(curl -s -X POST http://127.0.0.1:8080/createEnvironment)
    curl -X PUT "http://127.0.0.1:8080/setMetamodel?envKey=$ENV" --data-binary @autonomous_car.kmeta
    curl -X PUT "http://127.0.0.1:8080/setModel?envKey=$ENV" --data-binary @autonomous_car.kmodel
    curl -X PUT "http://127.0.0.1:8080/setEventDefinitions?envKey=$ENV" --data-binary @EVENTS.kmeta
    curl -X PUT "http://127.0.0.1:8080/setStateMachine?envKey=$ENV&attachedTo=av-1" --data-binary @autonomous_car.kstates
    curl -X POST "http://127.0.0.1:8080/setTickDelay?envKey=$ENV&milliseconds=300"
    
  3. Register a WebSocket client and an observer of the object of the state machine:
    KEY=$(curl -s -X POST "http://127.0.0.1:8080/registerClientForWebSocket?clientId=viewer&envKey=$ENV")
    curl -X POST "http://127.0.0.1:8080/registerObjectObserver?envKey=$ENV&clientId=viewer&objectId=av-1"
    
  4. Run and start the environment:
    curl -X POST "http://127.0.0.1:8080/runEnvironment?envKey=$ENV"
    curl -X POST "http://127.0.0.1:8080/startEnvironment?envKey=$ENV"
    
  5. Connect the client to ws://127.0.0.1:8080/ws, send viewer:<ENV>:<KEY> as the first frame and then the event that starts the example:
    {"environmentKey": "ignition", "messageType": "powerOn", "payload": ""}
    

The client gets objectChanged for the car each time an action block changes it. The README of each example names its events and payloads. The connection and the messages are in 3.5 WebSocket.

Source: this page on GitHub at commit 3b6029f, refreshed 16 November 2026. The whole reference as a PDF.