aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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