aboutsummaryrefslogtreecommitdiff
path: root/fsm.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-12-25 23:57:14 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-12-25 23:57:14 +0100
commitd2495d8dc996205a18e8aa29283520b32add6570 (patch)
tree9028f5c20ba62012126367d7758884c8f8298d64 /fsm.go
parentf4444fb60de726072c2daf83b56b5ccf3608815c (diff)
...
Diffstat (limited to 'fsm.go')
-rw-r--r--fsm.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/fsm.go b/fsm.go
index a0fe3b9..a7cbda6 100644
--- a/fsm.go
+++ b/fsm.go
@@ -15,6 +15,10 @@ type FSM struct {
Speed *Speed
}
+type Behaviour interface {
+ Behave(*Event) *Command
+}
+
func NewFSM(rw io.ReadWriter) *FSM {
events := make(chan *Event)
commands := make(chan *Command)
@@ -65,7 +69,8 @@ func (f *FSM) readDistance() stateFn {
if ev.Head != nil && ev.Head.Distance < 50 {
return f.stop
}
- return f.moveAhead
+ //return f.moveAhead
+ return f.lookLeft
}
func (f *FSM) moveAhead() stateFn {
@@ -73,6 +78,30 @@ func (f *FSM) moveAhead() stateFn {
return f.readDistance
}
+func (f *FSM) lookLeft() stateFn {
+ f.SetDirection(-60)
+ time.Sleep(time.Second)
+ return f.lookAheadFromLeft
+}
+
+func (f *FSM) lookAheadFromLeft() stateFn {
+ f.SetDirection(0)
+ time.Sleep(time.Second)
+ return f.lookRight
+}
+
+func (f *FSM) lookRight() stateFn {
+ f.SetDirection(60)
+ time.Sleep(time.Second)
+ return f.lookAheadFromRight
+}
+
+func (f *FSM) lookAheadFromRight() stateFn {
+ f.SetDirection(0)
+ time.Sleep(time.Second)
+ return f.lookLeft
+}
+
func (f *FSM) stop() stateFn {
f.SetSpeed(0, 0, 0)
return f.readDistance