sphero

package
v0.0.0-...-df99c63 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2014 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

README

Sphero

Sphero is a sophisticated and programmable robot housed in a polycarbonate sphere shell.

The gobot-sphero adaptor makes it easy to interact with Sphero using Go, once you have your Sphero setup and connected to your computer you can start writing code to make Sphero move, change direction, speed and colors, or detect Sphero events and execute some code when they occur.

Learn more about the Sphero robot from Orbotix here.

How to Install

go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/sphero

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 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>

Connect to the Sphero using this command (substituting the actual address of your Sphero):

gort bluetooth connect <address>
Windows

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.

How to Use

Example of a simple program that makes the Sphero roll.

package main

import (
	"fmt"
	"time"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/sphero"
)

func main() {
	gbot := gobot.NewGobot()

	adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/rfcomm0")
	driver := sphero.NewSpheroDriver(adaptor, "sphero")

	work := func() {
		gobot.Every(3*time.Second, func() {
			driver.Roll(30, uint16(gobot.Rand(360)))
		})
	}

	robot := gobot.NewRobot("sphero",
		[]gobot.Connection{adaptor},
		[]gobot.Device{driver},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}

Documentation

Overview

Package sphero provides the Gobot adaptor and driver for the Sphero.

Installing:

go get github.com/hybridgroup/gobot/platforms/sphero

Example:

package main

import (
	"fmt"
	"time"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/sphero"
)

func main() {
	gbot := gobot.NewGobot()

	adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/rfcomm0")
	driver := sphero.NewSpheroDriver(adaptor, "sphero")

	work := func() {
		gobot.Every(3*time.Second, func() {
			driver.Roll(30, uint16(gobot.Rand(360)))
		})
	}

	robot := gobot.NewRobot("sphero",
		[]gobot.Connection{adaptor},
		[]gobot.Device{driver},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}

For futher information refer to sphero readme: https://github.com/hybridgroup/gobot/blob/master/platforms/sphero/README.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collision

type Collision struct {
	// Normalized impact components (direction of the collision event):
	X, Y, Z int16
	// Thresholds exceeded by X (1h) and/or Y (2h) axis (bitmask):
	Axis byte
	// Power that cross threshold Xt + Xs:
	XMagnitude, YMagnitude int16
	// Sphero's speed when impact detected:
	Speed uint8
	// Millisecond timer
	Timestamp uint32
}

type SpheroAdaptor

type SpheroAdaptor struct {
	gobot.Adaptor
	// contains filtered or unexported fields
}

Represents a Connection to a Sphero

func NewSpheroAdaptor

func NewSpheroAdaptor(name string, port string) *SpheroAdaptor

NewSpheroAdaptor returns a new SpheroAdaptor given a name and port

func (*SpheroAdaptor) Connect

func (a *SpheroAdaptor) Connect() bool

Connect initiates a connection to the Sphero. Returns true on successful connection.

func (*SpheroAdaptor) Disconnect

func (a *SpheroAdaptor) Disconnect() bool

Disconnect terminates the connection to the Sphero. Returns true on successful disconnect.

func (*SpheroAdaptor) Finalize

func (a *SpheroAdaptor) Finalize() bool

Finalize finalizes the SpheroAdaptor

func (*SpheroAdaptor) Reconnect

func (a *SpheroAdaptor) Reconnect() bool

Reconnect attempts to reconnect to the Sphero. If the Sphero has an active connection it will first close that connection and then establish a new connection. Returns true on Successful reconnection

type SpheroDriver

type SpheroDriver struct {
	gobot.Driver
	// contains filtered or unexported fields
}

Represents a Sphero

func NewSpheroDriver

func NewSpheroDriver(a *SpheroAdaptor, name string) *SpheroDriver

NewSpheroDriver returns a new SpheroDriver given a SpheroAdaptor and name.

Adds the following API Commands:

"Roll" - See SpheroDriver.Roll
"Stop" - See SpheroDriver.Stop
"GetRGB" - See SpheroDriver.GetRGB
"SetBackLED" - See SpheroDriver.SetBackLED
"SetHeading" - See SpheroDriver.SetHeading
"SetStabilization" - See SpheroDriver.SetStabilization

func (*SpheroDriver) GetRGB

func (s *SpheroDriver) GetRGB() []uint8

GetRGB returns the current r, g, b value of the Sphero

func (*SpheroDriver) Halt

func (s *SpheroDriver) Halt() bool

Halt halts the SpheroDriver and sends a SpheroDriver.Stop command to the Sphero. Returns true on successful halt.

func (*SpheroDriver) Roll

func (s *SpheroDriver) Roll(speed uint8, heading uint16)

Roll sends a roll command to the Sphero gives a speed and heading

func (*SpheroDriver) SetBackLED

func (s *SpheroDriver) SetBackLED(level uint8)

SetBackLED sets the Sphero Back LED to the specified brightness

func (*SpheroDriver) SetHeading

func (s *SpheroDriver) SetHeading(heading uint16)

SetHeading sets the heading of the Sphero

func (*SpheroDriver) SetRGB

func (s *SpheroDriver) SetRGB(r uint8, g uint8, b uint8)

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

func (*SpheroDriver) SetStabilization

func (s *SpheroDriver) SetStabilization(on bool)

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

func (*SpheroDriver) Start

func (s *SpheroDriver) Start() bool

Start starts the SpheroDriver and enables Collision Detection. Returns true on successful start.

Emits the Events:

"collision" SpheroDriver.Collision - On Collision Detected

func (*SpheroDriver) Stop

func (s *SpheroDriver) Stop()

Stop sets the Sphero to a roll speed of 0

Jump to

Keyboard shortcuts

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