hybridgroup.gobot/platforms/sphero/README.md

77 lines
2.1 KiB
Markdown
Raw Normal View History

2014-06-10 10:01:53 +08:00
# Sphero
2014-06-10 10:01:53 +08:00
This package provides the Gobot adaptor and driver for the [Sphero](http://www.gosphero.com/) robot from Orbotix .
2014-06-10 10:01:53 +08:00
## Installing
```
2014-07-07 03:17:10 +08:00
go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/sphero
2014-06-10 10:01:53 +08:00
```
## How To Connect
### OSX
In order to allow Gobot running on your Mac to access the Sphero, go to "Bluetooth > Open Bluetooth Preferences > Sharing Setup" and make sure that "Bluetooth Sharing" is checked.
Now you must pair with the Sphero. Open System Preferences > Bluetooth. Now with the Bluetooth devices windows open, smack the Sphero until it starts flashing three colors. You should see "Sphero-XXX" pop up as available devices where "XXX" is the first letter of the three colors the sphero is flashing. Pair with that device. Once paired your Sphero will be accessable through the serial device similarly named as `/dev/tty.Sphero-XXX-RN-SPP`
### Ubuntu
Connecting to the Sphero from Ubuntu or any other Linux-based OS can be done entirely from the command line using [Gort](https://github.com/hybridgroup/gort) CLI commands. Here are the steps.
Find the address of the Sphero, by using:
```
gort scan bluetooth
```
Pair to Sphero using this command (substituting the actual address of your Sphero):
```
gort bluetooth pair <address>
```
2014-06-10 10:01:53 +08:00
Connect to the Sphero using this command (substituting the actual address of your Sphero):
```
gort bluetooth connect <address>
```
2014-06-10 10:01:53 +08:00
### Windows
2014-06-10 10:01:53 +08:00
You should be able to pair your Sphero using your normal system tray applet for Bluetooth, and then connect to the COM port that is bound to the device, such as `COM3`.
## Example
```go
package main
2014-06-10 10:01:53 +08:00
import (
2014-07-11 08:02:00 +08:00
"fmt"
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/sphero"
)
func main() {
2014-07-11 08:02:00 +08:00
gbot := gobot.NewGobot()
adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/rfcomm0")
driver := sphero.NewSpheroDriver(adaptor, "sphero")
2014-07-11 08:02:00 +08:00
work := func() {
gobot.Every(3*time.Second, func() {
driver.Roll(30, uint16(gobot.Rand(360)))
})
}
2014-07-11 08:02:00 +08:00
robot := gobot.NewRobot("sphero",
[]gobot.Connection{adaptor},
[]gobot.Device{driver},
work,
)
2014-07-11 08:02:00 +08:00
gbot.AddRobot(robot)
2014-07-11 08:02:00 +08:00
gbot.Start()
2014-06-10 10:01:53 +08:00
}
2014-07-11 08:02:00 +08:00
```