aboutsummaryrefslogtreecommitdiff
path: root/fsm.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-09-04 21:28:40 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-09-04 21:28:40 +0200
commit20701c89786ec440766369e9497fa24ba3d707b2 (patch)
treedef4991570cdf51522cc8248b7b2391ec1864389 /fsm.go
parent528d38d82ff62aaa282812ae8b7a9fcc30691213 (diff)
...
Diffstat (limited to 'fsm.go')
-rw-r--r--fsm.go19
1 files changed, 19 insertions, 0 deletions
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
}