From d2495d8dc996205a18e8aa29283520b32add6570 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 25 Dec 2017 23:57:14 +0100 Subject: ... --- fsm.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'fsm.go') 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 -- cgit v1.2.3