Categorygithub.com/hybridgroup/gobot
modulepackage
0.13.0
Repository: https://github.com/hybridgroup/gobot.git
Documentation: pkg.go.dev

# README

Gobot

Gobot (http://gobot.io/) is a framework using the Go programming language (http://golang.org/) for robotics, physical computing, and the Internet of Things.

It provides a simple, yet powerful way to create solutions that incorporate multiple, different hardware devices at the same time.

Want to use Javascript robotics? Check out our sister project Cylon.js (http://cylonjs.com/)

Want to use Ruby on robots? Check out our sister project Artoo (http://artoo.io)

GoDoc Build Status Coverage Status Go Report Card

Getting Started

Get the Gobot source with: go get -d -u github.com/hybridgroup/gobot/...

Examples

Gobot with Arduino

package main

import (
	"time"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/firmata"
	"github.com/hybridgroup/gobot/platforms/gpio"
)

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

	firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
	led := gpio.NewLedDriver(firmataAdaptor, "led", "13")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("bot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}

Gobot with Sphero

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()
}

"Metal" Gobot

You can use the entire Gobot framework as shown in the examples above ("Classic" Gobot), or you can pick and choose from the various Gobot packages to control hardware with nothing but pure idiomatic Golang code ("Metal" Gobot). For example:

package main

import (
	"github.com/hybridgroup/gobot/platforms/gpio"
	"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
	"time"
)

func main() {
	e := edison.NewEdisonAdaptor("edison")
	e.Connect()

	led := gpio.NewLedDriver(e, "led", "13")
	led.Start()

	for {
		led.Toggle()
		time.Sleep(1000 * time.Millisecond)
	}
}

Hardware Support

Gobot has a extensible system for connecting to hardware devices. The following robotics and physical computing platforms are currently supported:

Support for many devices that use General Purpose Input/Output (GPIO) have a shared set of drivers provided using the gobot/platforms/gpio package:

  • GPIO <=> Drivers
    • Analog Sensor
    • Button
    • Buzzer
    • Direct Pin
    • Grove Button
    • Grove Buzzer
    • Grove LED
    • Grove Light Sensor
    • Grove Piezo Vibration Sensor
    • Grove Relay
    • Grove Rotary Dial
    • Grove Sound Sensor
    • Grove Temperature Sensor
    • Grove Touch Sensor
    • LED
    • Makey Button
    • Motor
    • Relay
    • RGB LED
    • Servo

Support for devices that use Inter-Integrated Circuit (I2C) have a shared set of drivers provided using the gobot/platforms/i2c package:

  • I2C <=> Drivers
    • BlinkM
    • Grove Digital Accelerometer
    • Grove RGB LCD
    • HMC6352 Compass
    • JHD1313M1 RGB LCD Display
    • LIDAR-Lite
    • MCP23017 Port Expander
    • MMA7660 3-Axis Accelerometer
    • MPL115A2 Barometer
    • MPU6050 Accelerometer/Gyroscope
    • Wii Nunchuck Controller

More platforms and drivers are coming soon...

API:

Gobot includes a RESTful API to query the status of any robot running within a group, including the connection and device status, and execute device commands.

To activate the API, require the github.com/hybridgroup/gobot/api package and instantiate the API like this:

  gbot := gobot.NewGobot()
  api.NewAPI(gbot).Start()

You can also specify the api host and port, and turn on authentication:

  gbot := gobot.NewGobot()
  server := api.NewAPI(gbot)
  server.Port = "4000"
  server.AddHandler(api.BasicAuth("gort", "klatuu"))
  server.Start()

You may access the robeaux React.js interface with Gobot by navigating to http://localhost:3000/index.html.

Documentation

We're busy adding documentation to our web site at http://gobot.io/ please check there as we continue to work on Gobot

Thank you!

Need help?

Contributing

For our contribution guidelines, please go to https://github.com/hybridgroup/gobot/blob/master/CONTRIBUTING.md .

License

Copyright (c) 2013-2016 The Hybrid Group. Licensed under the Apache 2.0 license.

# Packages

Package api provides a webserver to interact with your Gobot program over the network.
CLI tool for generating new Gobot projects.
Package sysfs provides generic access to linux gpio.

# Functions

After triggers f after t duration.
Every triggers f every t time until the end of days, or when a bool value is sent to the channel returned by the Every function.
FromScale returns a converted input from min, max to 0.0...1.0.
NewCommander returns a new Commander.
NewEvent returns a new Event and its associated data.
NewEventer returns a new Eventer.
NewGobot returns a new Gobot.
NewJSONConnection returns a JSONConnection given a Connection.
NewJSONDevice returns a JSONDevice given a Device.
NewJSONGobot returns a JSONGobt given a Gobot.
NewJSONRobot returns a JSONRobot given a Robot.
NewRobot returns a new Robot given a name and optionally accepts: []Connection: Connections which are automatically started and stopped with the robot []Device: Devices which are automatically started and stopped with the robot func(): The work routine the robot will execute once all devices and connections have been initialized and started A name will be automaically generated if no name is supplied.
Rand returns a positive random int up to max.
ToScale returns a converted input from 0...1 to min...max scale.
Version returns the current Gobot version.

# Variables

ErrUnknownEvent is the error resulting if the specified Event does not exist.

# Structs

Event represents when something asyncronous happens in a Driver or Adaptor.
Gobot is the main type of your Gobot application and contains a collection of Robots, API commands and Events.
JSONConnection is a JSON representation of a Connection.
JSONDevice is a JSON representation of a Device.
JSONGobot is a JSON representation of a Gobot.
JSONRobot a JSON representation of a Robot.
Robot is a named entity that manages a collection of connections and devices.

# Interfaces

Adaptor is the interface that describes an adaptor in gobot.
Commander is the interface which describes the behaviour for a Driver or Adaptor which exposes API commands.
Driver is the interface that describes a driver in gobot.
Eventer is the interface which describes how a Driver or Adaptor handles events.
Pinner is the interface that describes a driver's pin.
Porter is the interface that describes an adaptor's port.

# Type aliases

A Connection is an instance of an Adaptor.
Connections represents a collection of Connection.
A Device is an instnace of a Driver.
Devices represents a collection of Device.
Robots is a collection of Robot.