diff --git a/examples/ollie_roll.go b/examples/ollie_roll.go new file mode 100644 index 00000000..ef3c56a6 --- /dev/null +++ b/examples/ollie_roll.go @@ -0,0 +1,43 @@ +package main + +import ( + "os" + "time" + "fmt" + + "github.com/hybridgroup/gobot" + "github.com/hybridgroup/gobot/platforms/ble" +) + +func main() { + gbot := gobot.NewGobot() + + bleAdaptor := ble.NewBLEClientAdaptor("ble", os.Args[1]) + ollie := ble.NewSpheroOllieDriver(bleAdaptor, "ollie") + + work := func() { + ollie.SetRGB(255, 0, 255) + gobot.After(1*time.Second, func() { + fmt.Println("fwd") + ollie.Roll(60, 0) + }) + gobot.After(3*time.Second, func() { + fmt.Println("back") + ollie.Roll(60, 180) + }) + gobot.After(5*time.Second, func() { + fmt.Println("stop") + ollie.Stop() + }) + } + + robot := gobot.NewRobot("ollieBot", + []gobot.Connection{bleAdaptor}, + []gobot.Device{ollie}, + work, + ) + + gbot.AddRobot(robot) + + gbot.Start() +} diff --git a/platforms/ble/ollie.go b/platforms/ble/ollie.go index 82ffe5a6..41384877 100644 --- a/platforms/ble/ollie.go +++ b/platforms/ble/ollie.go @@ -91,7 +91,7 @@ func (b *SpheroOllieDriver) Init() (err error) { b.Wake() // subscribe to Sphero response notifications - b.adaptor().Subscribe(RobotControlService, ResponseCharacteristic, b.HandleResponses) + //b.adaptor().Subscribe(RobotControlService, ResponseCharacteristic, b.HandleResponses) return } @@ -151,7 +151,7 @@ func (s *SpheroOllieDriver) SetRGB(r uint8, g uint8, b uint8) { // Tells the Ollie to roll func (s *SpheroOllieDriver) Roll(speed uint8, heading uint16) { - fmt.Println("roll", speed, heading) + s.packetChannel <- s.craftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30) } // Tells the Ollie to stop