2014-10-22 01:15:32 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
This package provides the Gobot adaptor and driver for the Sphero (http://www.gosphero.com/) robot from Orbotix .
|
|
|
|
|
|
|
|
Installing:
|
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/sphero
|
2014-10-22 01:15:32 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
package main
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
|
|
|
)
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/rfcomm0")
|
|
|
|
driver := sphero.NewSpheroDriver(adaptor, "sphero")
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
work := func() {
|
|
|
|
gobot.Every(3*time.Second, func() {
|
|
|
|
driver.Roll(30, uint16(gobot.Rand(360)))
|
|
|
|
})
|
|
|
|
}
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
robot := gobot.NewRobot("sphero",
|
|
|
|
[]gobot.Connection{adaptor},
|
|
|
|
[]gobot.Device{driver},
|
|
|
|
work,
|
|
|
|
)
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
gbot.AddRobot(robot)
|
2014-10-22 01:15:32 +08:00
|
|
|
|
2014-10-22 01:30:06 +08:00
|
|
|
gbot.Start()
|
|
|
|
}
|
2014-10-22 01:15:32 +08:00
|
|
|
|
|
|
|
For futher information refer to sphero readme:
|
|
|
|
https://github.com/hybridgroup/gobot/blob/master/platforms/sphero/README.md
|
|
|
|
*/
|
|
|
|
package sphero
|