diff --git a/Makefile b/Makefile index 96fe573e..bb2e6d2c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PACKAGES := gobot gobot/api gobot/drivers/gpio gobot/drivers/i2c gobot/platforms/firmata/client gobot/platforms/intel-iot/edison gobot/platforms/intel-iot/joule gobot/platforms/parrot/ardrone gobot/platforms/parrot/bebop gobot/platforms/parrot/minidrone gobot/sysfs $(shell ls ./platforms | sed -e 's/^/gobot\/platforms\//') +PACKAGES := gobot gobot/api gobot/drivers/gpio gobot/drivers/i2c gobot/platforms/firmata/client gobot/platforms/intel-iot/edison gobot/platforms/intel-iot/joule gobot/platforms/parrot/ardrone gobot/platforms/parrot/bebop gobot/platforms/parrot/minidrone gobot/platforms/sphero/ollie gobot/platforms/sphero/bb8 gobot/sysfs $(shell ls ./platforms | sed -e 's/^/gobot\/platforms\//') .PHONY: test cover robeaux examples test: diff --git a/README.md b/README.md index 28e7e08a..d90c68c1 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ Gobot has a extensible system for connecting to hardware devices. The following - [Pebble](https://www.getpebble.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/pebble) - [Raspberry Pi](http://www.raspberrypi.org/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/raspi) - [Sphero](http://www.sphero.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero) +- [Sphero BB-8](http://www.sphero.com/bb8) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/bb8) - [Sphero Ollie](http://www.sphero.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/ollie) Support for many devices that use General Purpose Input/Output (GPIO) have diff --git a/ci/travis.sh b/ci/travis.sh index dfbab4cd..59df84d8 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -1,5 +1,5 @@ #!/bin/bash -PACKAGES=('gobot' 'gobot/api' 'gobot/sysfs' 'gobot/drivers/gpio' 'gobot/drivers/i2c' 'gobot/platforms/firmata/client' 'gobot/platforms/intel-iot/edison' 'gobot/platforms/intel-iot/joule' 'gobot/platforms/parrot/ardrone' 'gobot/platforms/parrot/bebop' 'gobot/platforms/parrot/minidrone' 'gobot/platforms/sphero/ollie' $(ls ./platforms | sed -e 's/^/gobot\/platforms\//')) +PACKAGES=('gobot' 'gobot/api' 'gobot/sysfs' 'gobot/drivers/gpio' 'gobot/drivers/i2c' 'gobot/platforms/firmata/client' 'gobot/platforms/intel-iot/edison' 'gobot/platforms/intel-iot/joule' 'gobot/platforms/parrot/ardrone' 'gobot/platforms/parrot/bebop' 'gobot/platforms/parrot/minidrone' 'gobot/platforms/sphero/ollie' 'gobot/platforms/sphero/bb8' $(ls ./platforms | sed -e 's/^/gobot\/platforms\//')) EXITCODE=0 echo "mode: set" > profile.cov diff --git a/examples/bb8.go b/examples/bb8.go new file mode 100644 index 00000000..95de1e81 --- /dev/null +++ b/examples/bb8.go @@ -0,0 +1,32 @@ +package main + +import ( + "os" + "time" + + "gobot.io/x/gobot" + "gobot.io/x/gobot/platforms/ble" + "gobot.io/x/gobot/platforms/sphero/bb8" +) + +func main() { + bleAdaptor := ble.NewClientAdaptor(os.Args[1]) + bb8 := bb8.NewDriver(bleAdaptor) + + work := func() { + gobot.Every(1*time.Second, func() { + r := uint8(gobot.Rand(255)) + g := uint8(gobot.Rand(255)) + b := uint8(gobot.Rand(255)) + bb8.SetRGB(r, g, b) + }) + } + + robot := gobot.NewRobot("bbBot", + []gobot.Connection{bleAdaptor}, + []gobot.Device{bb8}, + work, + ) + + robot.Start() +} diff --git a/platforms/sphero/bb8/LICENSE b/platforms/sphero/bb8/LICENSE new file mode 100644 index 00000000..933acbb0 --- /dev/null +++ b/platforms/sphero/bb8/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2014-2016 The Hybrid Group + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/platforms/sphero/bb8/README.md b/platforms/sphero/bb8/README.md new file mode 100644 index 00000000..20b444ba --- /dev/null +++ b/platforms/sphero/bb8/README.md @@ -0,0 +1,73 @@ +# Sphero BB-8 + +The Sphero BB-8 is a toy robot from Sphero that is controlled using Bluetooth LE. For more information, go to [http://www.sphero.com/bb8](http://www.sphero.com/bb8) + +## How to Install +``` +go get -d -u gobot.io/x/gobot/... && go install gobot.io/x/gobot/platforms/ble +``` + +## How to Use +```go +package main + +import ( + "os" + "time" + + "gobot.io/x/gobot" + "gobot.io/x/gobot/platforms/ble" + "gobot.io/x/gobot/platforms/sphero/bb8" +) + +func main() { + bleAdaptor := ble.NewClientAdaptor(os.Args[1]) + bb8 := bb8.NewDriver(bleAdaptor) + + work := func() { + gobot.Every(1*time.Second, func() { + r := uint8(gobot.Rand(255)) + g := uint8(gobot.Rand(255)) + b := uint8(gobot.Rand(255)) + bb8.SetRGB(r, g, b) + }) + } + + robot := gobot.NewRobot("bb", + []gobot.Connection{bleAdaptor}, + []gobot.Device{bb8}, + work, + ) + + robot.Start() +} +``` + +## How to Connect + +The Sphero BB-8 is a Bluetooth LE device. + +You need to know the BLE ID of the BB-8 you want to connect to. The Gobot BLE client adaptor also lets you connect by friendly name, aka "BB-1247". + +### OSX + +To run any of the Gobot BLE code you must use the `GODEBUG=cgocheck=0` flag in order to get around some of the issues in the CGo-based implementation. + +For example: + + GODEBUG=cgocheck=0 go run examples/bb8.go BB-1247 + +OSX uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces provided by OSX, so as a result does not need to run under sudo. + +### Ubuntu + +On Linux the BLE code will need to run as a root user account. The easiest way to accomplish this is probably to use `go build` to build your program, and then to run the requesting executable using `sudo`. + +For example: + + go build examples/bb8.go + sudo ./bb8 BB-1247 + +### Windows + +Hopefully coming soon... diff --git a/platforms/sphero/bb8/bb8_driver.go b/platforms/sphero/bb8/bb8_driver.go new file mode 100644 index 00000000..8e0cd45e --- /dev/null +++ b/platforms/sphero/bb8/bb8_driver.go @@ -0,0 +1,10 @@ +package bb8 + +import ( + "gobot.io/x/gobot/platforms/sphero/ollie" +) + +// Driver represents a Sphero BB-8 +type Driver struct { + *ollie.Driver +} diff --git a/platforms/sphero/bb8/bb8_driver_test.go b/platforms/sphero/bb8/bb8_driver_test.go new file mode 100644 index 00000000..b84bbfb3 --- /dev/null +++ b/platforms/sphero/bb8/bb8_driver_test.go @@ -0,0 +1,5 @@ +package bb8 + +import "gobot.io/x/gobot" + +var _ gobot.Driver = (*Driver)(nil) diff --git a/platforms/sphero/bb8/doc.go b/platforms/sphero/bb8/doc.go new file mode 100644 index 00000000..b70cce91 --- /dev/null +++ b/platforms/sphero/bb8/doc.go @@ -0,0 +1,7 @@ +/* +Package bb8 contains the Gobot driver for the Sphero BB-8. + +For more information refer to the BB-8 README: +https://gobot.io/x/gobot/blob/master/platforms/sphero/bb8/README.md +*/ +package bb8 // import "gobot.io/x/gobot/platforms/sphero/bb8"