2013-11-14 12:49:57 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-04-27 09:07:04 +08:00
|
|
|
"fmt"
|
2014-07-10 00:38:43 +08:00
|
|
|
"time"
|
|
|
|
|
2013-12-03 16:48:20 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
2014-05-23 12:20:16 +08:00
|
|
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
2013-11-14 12:49:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-23 12:20:16 +08:00
|
|
|
gbot := gobot.NewGobot()
|
2013-11-14 12:49:57 +08:00
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
adaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/rfcomm0")
|
|
|
|
spheroDriver := sphero.NewSpheroDriver(adaptor, "sphero")
|
2013-11-14 12:49:57 +08:00
|
|
|
|
|
|
|
work := func() {
|
2014-12-26 00:32:24 +08:00
|
|
|
spheroDriver.SetDataStreaming(sphero.DefaultDataStreamingConfig())
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
spheroDriver.On(sphero.Collision, func(data interface{}) {
|
2014-12-26 00:32:24 +08:00
|
|
|
fmt.Printf("Collision! %+v\n", data)
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
spheroDriver.On(sphero.SensorData, func(data interface{}) {
|
2014-12-26 00:32:24 +08:00
|
|
|
fmt.Printf("Streaming Data! %+v\n", data)
|
2014-04-27 09:07:04 +08:00
|
|
|
})
|
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
gobot.Every(3*time.Second, func() {
|
2014-04-29 02:40:20 +08:00
|
|
|
spheroDriver.Roll(30, uint16(gobot.Rand(360)))
|
2014-04-27 09:07:04 +08:00
|
|
|
})
|
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
gobot.Every(1*time.Second, func() {
|
2014-04-27 09:07:04 +08:00
|
|
|
r := uint8(gobot.Rand(255))
|
|
|
|
g := uint8(gobot.Rand(255))
|
|
|
|
b := uint8(gobot.Rand(255))
|
2014-04-29 02:40:20 +08:00
|
|
|
spheroDriver.SetRGB(r, g, b)
|
2013-11-14 12:49:57 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot("sphero",
|
|
|
|
[]gobot.Connection{adaptor},
|
|
|
|
[]gobot.Device{spheroDriver},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
2013-11-14 12:49:57 +08:00
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
gbot.Start()
|
2013-11-14 12:49:57 +08:00
|
|
|
}
|