v1.16.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2022 License: Apache-2.0, Apache-2.0, Apache-2.0 Imports: 8 Imported by: 74


Sphero Ollie

The Sphero Ollie is a toy robot from Sphero that is controlled using Bluetooth LE. For more information, go to http://www.sphero.com/ollie

How to Install

go get -d -u gobot.io/x/gobot/...

How to Use

package main

import (


func main() {
	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
	ollie := ollie.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))
			ollie.SetRGB(r, g, b)

	robot := gobot.NewRobot("ollieBot",


How to Connect

The Sphero Ollie is a Bluetooth LE device.

You need to know the BLE ID of the Ollie you want to connect to. The Gobot BLE client adaptor also lets you connect by friendly name, aka "2B-1247".


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.

If you connect by name, then you do not need to worry about the Bluetooth LE ID. However, if you want to connect by ID, OS X 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.

For example:

GODEBUG=cgocheck=0 go run examples/ollie.go 2B-1247

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/ollie.go
sudo ./minidrone 2B-1247

Hopefully coming soon...



Package ollie contains the Gobot driver for the Sphero Ollie.

For more information refer to the Ollie README: https://github.com/hybridgroup/gobot/blob/master/platforms/sphero/ollie/README.md



View Source
const (

	// SensorData event
	SensorData = "sensordata"

	// Collision event
	Collision = "collision"

	// Error event
	Error = "error"

	// Packet header size
	PacketHeaderSize = 5

	// Response packet max size
	ResponsePacketMaxSize = 20

	// Collision Packet data size: The number of bytes following the DLEN field through the end of the packet
	CollisionDataSize = 17

	// Full size of the collision response
	CollisionResponseSize = PacketHeaderSize + CollisionDataSize


This section is empty.


func DefaultCollisionConfig added in v1.2.0

func DefaultCollisionConfig() sphero.CollisionConfig

DefaultCollisionConfig returns a CollisionConfig with sensible collision defaults


type DataStreamingPacket added in v1.13.0

type DataStreamingPacket struct {
	// 8000 0000h	accelerometer axis X, raw	-2048 to 2047	4mG
	RawAccX int16
	// 4000 0000h	accelerometer axis Y, raw	-2048 to 2047	4mG
	RawAccY int16
	// 2000 0000h	accelerometer axis Z, raw	-2048 to 2047	4mG
	RawAccZ int16
	// 1000 0000h	gyro axis X, raw	-32768 to 32767	0.068 degrees
	RawGyroX int16
	// 0800 0000h	gyro axis Y, raw	-32768 to 32767	0.068 degrees
	RawGyroY int16
	// 0400 0000h	gyro axis Z, raw	-32768 to 32767	0.068 degrees
	RawGyroZ int16
	// 0200 0000h	Reserved
	Rsrv1 int16
	// 0100 0000h	Reserved
	Rsrv2 int16
	// 0080 0000h	Reserved
	Rsrv3 int16
	// 0040 0000h	right motor back EMF, raw	-32768 to 32767	22.5 cm
	RawRMotorBack int16
	// 0020 0000h	left motor back EMF, raw	-32768 to 32767	22.5 cm
	RawLMotorBack int16
	// 0010 0000h	left motor, PWM, raw	-2048 to 2047	duty cycle
	RawLMotor int16
	// 0008 0000h	right motor, PWM raw	-2048 to 2047	duty cycle
	RawRMotor int16
	// 0004 0000h	IMU pitch angle, filtered	-179 to 180	degrees
	FiltPitch int16
	// 0002 0000h	IMU roll angle, filtered	-179 to 180	degrees
	FiltRoll int16
	// 0001 0000h	IMU yaw angle, filtered	-179 to 180	degrees
	FiltYaw int16
	// 0000 8000h	accelerometer axis X, filtered	-32768 to 32767	1/4096 G
	FiltAccX int16
	// 0000 4000h	accelerometer axis Y, filtered	-32768 to 32767	1/4096 G
	FiltAccY int16
	// 0000 2000h	accelerometer axis Z, filtered	-32768 to 32767	1/4096 G
	FiltAccZ int16
	// 0000 1000h	gyro axis X, filtered	-20000 to 20000	0.1 dps
	FiltGyroX int16
	// 0000 0800h	gyro axis Y, filtered	-20000 to 20000	0.1 dps
	FiltGyroY int16
	// 0000 0400h	gyro axis Z, filtered	-20000 to 20000	0.1 dps
	FiltGyroZ int16
	// 0000 0200h	Reserved
	Rsrv4 int16
	// 0000 0100h	Reserved
	Rsrv5 int16
	// 0000 0080h	Reserved
	Rsrv6 int16
	// 0000 0040h	right motor back EMF, filtered	-32768 to 32767	22.5 cm
	FiltRMotorBack int16
	// 0000 0020h	left motor back EMF, filtered	-32768 to 32767	22.5 cm
	FiltLMotorBack int16
	// 0000 0010h	Reserved 1
	Rsrv7 int16
	// 0000 0008h	Reserved 2
	Rsrv8 int16
	// // 0000 0004h	Reserved 3
	// Rsrv9 int16
	// // 0000 0002h	Reserved 4
	// Rsrv10 int16
	// // 0000 0001h	Reserved 5
	// Rsrv11 int16
	// 8000 0000h	Quaternion Q0	-10000 to 10000	1/10000 Q
	Quat0 int16
	// 4000 0000h	Quaternion Q1	-10000 to 10000	1/10000 Q
	Quat1 int16
	// 2000 0000h	Quaternion Q2	-10000 to 10000	1/10000 Q
	Quat2 int16
	// 1000 0000h	Quaternion Q3	-10000 to 10000	1/10000 Q
	Quat3 int16
	// 0800 0000h	Odometer X	-32768 to 32767	cm
	OdomX int16
	// 0400 0000h	Odometer Y	-32768 to 32767	cm
	OdomY int16
	// 0200 0000h	AccelOne	0 to 8000	1 mG
	AccelOne int16
	// 0100 0000h	Velocity X	-32768 to 32767	mm/s
	VeloX int16
	// 0080 0000h	Velocity Y	-32768 to 32767	mm/s
	VeloY int16

DataStreamingPacket represents the response from a Data Streaming event

type Driver

type Driver struct {
	// contains filtered or unexported fields

Driver is the Gobot driver for the Sphero Ollie robot

func NewDriver

func NewDriver(a ble.BLEConnector) *Driver

NewDriver creates a Driver for a Sphero Ollie

func (*Driver) AntiDOSOff

func (b *Driver) AntiDOSOff() (err error)

AntiDOSOff turns off Anti-DOS code so we can control Ollie

func (*Driver) Boost added in v1.9.0

func (b *Driver) Boost(state bool)

Boost executes the boost macro from within the SSB which takes a 1 byte parameter which is either 01h to begin boosting or 00h to stop.

func (*Driver) ConfigureCollisionDetection added in v1.2.0

func (b *Driver) ConfigureCollisionDetection(cc sphero.CollisionConfig)

ConfigureCollisionDetection configures the sensitivity of the detection.

func (*Driver) Connection

func (b *Driver) Connection() gobot.Connection

Connection returns the connection to this Ollie

func (*Driver) EnableStopOnDisconnect

func (b *Driver) EnableStopOnDisconnect()

EnableStopOnDisconnect auto-sends a Stop command after losing the connection

func (*Driver) GetLocatorData added in v1.13.0

func (b *Driver) GetLocatorData(f func(p Point2D))

GetLocatorData calls the passed function with the data from the locator

func (*Driver) GetPowerState added in v1.13.0

func (b *Driver) GetPowerState(f func(p PowerStatePacket))

GetPowerState calls the passed function with the Power State information from the sphero

func (*Driver) Halt

func (b *Driver) Halt() (err error)

Halt stops Ollie driver (void)

func (*Driver) HandleResponses

func (b *Driver) HandleResponses(data []byte, e error)

HandleResponses handles responses returned from Ollie

func (*Driver) Init

func (b *Driver) Init() (err error)

Init is used to initialize the Ollie

func (*Driver) Name

func (b *Driver) Name() string

Name returns the name for the Driver

func (*Driver) PacketChannel added in v1.13.0

func (b *Driver) PacketChannel() chan *Packet

PacketChannel returns the channel for packets to be sent to the sp

func (*Driver) Roll

func (b *Driver) Roll(speed uint8, heading uint16)

Roll tells the Ollie to roll

func (*Driver) Sequence added in v1.13.0

func (b *Driver) Sequence() uint8

Sequence returns the Sequence number of the current packet

func (*Driver) SetBackLEDOutput added in v1.9.0

func (b *Driver) SetBackLEDOutput(value uint8)

SetBackLEDOutput allows you to control the brightness of the back(tail) LED.

func (*Driver) SetDataStreamingConfig added in v1.13.0

func (b *Driver) SetDataStreamingConfig(d sphero.DataStreamingConfig)

SetDataStreamingConfig passes the config to the sphero to stream sensor data

func (*Driver) SetName

func (b *Driver) SetName(n string)

SetName sets the Name for the Driver

func (*Driver) SetRGB

func (b *Driver) SetRGB(r uint8, g uint8, bl uint8)

SetRGB sets the Ollie to the given r, g, and b values

func (*Driver) SetRawMotorValues added in v1.9.0

func (b *Driver) SetRawMotorValues(lmode MotorModes, lpower uint8, rmode MotorModes, rpower uint8)

SetRawMotorValues allows you to take over one or both of the motor output values, instead of having the stabilization system control them. Each motor (left and right) requires a mode and a power value from 0-255

func (*Driver) SetRotationRate added in v1.9.0

func (b *Driver) SetRotationRate(speed uint8)

SetRotationRate allows you to control the rotation rate that Sphero will use to meet new heading commands. A value of 255 jumps to the maximum (currently 400 degrees/sec). A value of zero doesn't make much sense so it's interpreted as 1, the minimum.

func (*Driver) SetStabilization added in v1.9.0

func (b *Driver) SetStabilization(state bool)

SetStabilization enables or disables the built-in auto stabilizing features of the Ollie

func (*Driver) SetTXPower

func (b *Driver) SetTXPower(level int) (err error)

SetTXPower sets transmit level

func (*Driver) Sleep

func (b *Driver) Sleep()

Sleep says Go to sleep

func (*Driver) Start

func (b *Driver) Start() (err error)

Start tells driver to get ready to do work

func (*Driver) Stop

func (b *Driver) Stop()

Stop tells the Ollie to stop

func (*Driver) Wake

func (b *Driver) Wake() (err error)

Wake wakes Ollie up so we can play

type MotorModes added in v1.9.0

type MotorModes uint8

MotorModes is used to configure the motor

const (
	Off MotorModes = iota

MotorModes required for SetRawMotorValues command

type Packet added in v1.13.0

type Packet struct {
	Header   []uint8
	Body     []uint8
	Checksum uint8

Packet describes head, body and checksum for a data package to be sent to the sphero.

type Point2D added in v1.13.0

type Point2D struct {
	X int16
	Y int16

Point2D represents a koordinate in 2-Dimensional space

type PowerStatePacket added in v1.13.0

type PowerStatePacket struct {
	// record Version Code
	RecVer uint8
	// High-Level State of the Battery; 1=charging, 2=battery ok, 3=battery low, 4=battery critical
	PowerState uint8
	// Battery Voltage, scaled in 100th of a Volt, 0x02EF would be 7.51 volts
	BattVoltage uint16
	// Number of charges in the total lifetime of the sphero
	NumCharges uint16
	//Seconds awake since last charge
	TimeSinceChg uint16

PowerStatePacket contains all data relevant to the power state of the sphero

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL