From 20701c89786ec440766369e9497fa24ba3d707b2 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 4 Sep 2017 21:28:40 +0200 Subject: ... --- fsm.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'fsm.go') diff --git a/fsm.go b/fsm.go index 772a73d..3a65198 100644 --- a/fsm.go +++ b/fsm.go @@ -53,5 +53,24 @@ func (f *FSM) Start() { } func (f *FSM) initalState() stateFn { + f.command <- &Command{Direction: 85} + return f.readDistance +} + +func (f *FSM) readDistance() stateFn { + ev := <-f.events + if ev.Distance < 20 { + return f.stop + } + return f.moveAhead +} + +func (f *FSM) moveAhead() stateFn { + f.command <- &Command{SpeedL: 200, SpeedR: 200} + return f.readDistance +} + +func (f *FSM) stop() stateFn { + f.command <- &Command{Stop: true} return nil } -- cgit v1.2.3