[ble] Implement Ollie Roll command
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
8fa839081f
commit
11a49b64f3
|
@ -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()
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue