Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/elevator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RM_R = rm -rf
CP = cp
MKDIR_P = mkdir -p
DOXYGEN = doxygen
DOT = dot


SRC_DIRS = .
Expand All @@ -26,6 +27,8 @@ INCLUDE = -I ../../include
SRCS = $(wildcard $(addsuffix /*.cpp, $(SRC_DIRS)))
OBJS = $(SRCS:.cpp=.o)
DEPENDS = $(OBJS:.o=.d)
DOT_FILES = $(wildcard $(addsuffix /*.dot, $(SRC_DIRS)))
PNG_FILES = $(DOT_FILES:.dot=.png)

EXE = $(PROJECT)
MAP = $(PROJECT).map
Expand Down Expand Up @@ -80,7 +83,7 @@ LDFLAGS += -fno-rtti

.PHONY: all clean

all: $(EXE)
all: $(EXE) $(PNG_FILES)

$(EXE): $(OBJS)
$(LD) $(OBJS) $(LDFLAGS) -o $(EXE)
Expand All @@ -89,6 +92,9 @@ $(EXE): $(OBJS)
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) -o $@ $<

%.png: %.dot
$(DOT) -Tpng $^ -o $@

clean:
$(RM) *.o
$(RM) *.d
Expand Down
3 changes: 3 additions & 0 deletions examples/elevator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ each other:
- State: Moving
- State: Panic

![Elevator states](./elevator_state.png)

2. Motor
- State: Stopped
- State: Up
- State: Down

![Machine states](./machine_state.png)

A good state machine design avoids circular dependencies at all
cost: While the elevator sends events to the motor, the motor NEVER
Expand Down
13 changes: 13 additions & 0 deletions examples/elevator/elevator_state.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
digraph "G" {
// Colour palette from https://venngage.com/blog/color-blind-friendly-palette/

"Idle" -> "Idle" [label="Call" color="#601A4A" fontcolor="#601A4A"]
"Idle" -> "Moving" [label="Call" color="#601A4A" fontcolor="#601A4A"]
"Idle" -> "Panic" [label="Alarm" color="#EE442F" fontcolor="#EE442F"]

"Moving" -> "Panic" [label="FloorSensor" color="#63ACBE" fontcolor="#63ACBE"]
"Moving" -> "Idle" [label="FloorSensor" color="#63ACBE" fontcolor="#63ACBE"]

"Panic" -> "Panic" [label="Alarm" color="#EE442F" fontcolor="#EE442F"]

}
Binary file added examples/elevator/elevator_state.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/elevator/machine_state.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
digraph "G" {
// Colour palette from https://venngage.com/blog/color-blind-friendly-palette/

"Up" -> "Stopped" [label="MotorStop" color="#F5793A" fontcolor="#F5793A" ]
"Down" -> "Stopped" [label="MotorStop" color="#F5793A" fontcolor="#F5793A" ]
"Stopped" -> "Stopped" [label="MotorStop" color="#F5793A" fontcolor="#F5793A" ]

"Up" -> "Up" [label="MotorUp" color="#A95AA1" fontcolor="#A95AA1" ]
"Down" -> "Up" [label="MotorUp" color="#A95AA1" fontcolor="#A95AA1" ]
"Stopped" -> "Up" [label="MotorUp" color="#A95AA1" fontcolor="#A95AA1" ]

"Up" -> "Down" [label="MotorDown" color="#0F2080" fontcolor="#0F2080" ]
"Down" -> "Down" [label="MotorDown" color="#0F2080" fontcolor="#0F2080" ]
"Stopped" -> "Down" [label="MotorDown" color="#0F2080" fontcolor="#0F2080" ]
}
Binary file added examples/elevator/machine_state.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.