2014-04-26 18:11:51 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-05-23 12:20:16 +08:00
|
|
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
|
|
|
"time"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-23 12:20:16 +08:00
|
|
|
master := gobot.NewGobot()
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
spheros := []string{
|
|
|
|
"/dev/rfcomm0",
|
|
|
|
"/dev/rfcomm1",
|
|
|
|
"/dev/rfcomm2",
|
|
|
|
"/dev/rfcomm3",
|
|
|
|
}
|
|
|
|
|
|
|
|
for s := range spheros {
|
2014-05-23 12:20:16 +08:00
|
|
|
spheroAdaptor := sphero.NewSpheroAdaptor("Sphero", spheros[s])
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "Sphero"+spheros[s])
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
work := func() {
|
2014-04-29 02:40:20 +08:00
|
|
|
spheroDriver.Stop()
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-29 02:40:20 +08:00
|
|
|
gobot.On(spheroDriver.Events["Collision"], func(data interface{}) {
|
2014-04-26 18:11:51 +08:00
|
|
|
fmt.Println("Collision Detected!")
|
|
|
|
})
|
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
gobot.Every(1*time.Second, func() {
|
2014-04-29 02:40:20 +08:00
|
|
|
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
|
2014-04-26 18:11:51 +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.SetRGB(uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255)))
|
2014-04-26 18:11:51 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
master.Robots = append(master.Robots,
|
|
|
|
gobot.NewRobot("sphero", []gobot.Connection{spheroAdaptor}, []gobot.Device{spheroDriver}, work))
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
master.Start()
|
|
|
|
}
|