Documentation ¶
Overview ¶
Package gobot is the main point of entry in your Gobot application. A Gobot is typically composed of one or more robots that makes up a project.
Commands are a way to expose your robots functionality with the external world. A Gobot can be configured to expose a restful HTTP interface using the api package. You can define custom commands on your Gobot and interact with your application as a web service.
Basic Setup
package main import ( "fmt" "time" "github.com/hybridgroup/gobot" ) func main() { gbot := gobot.NewGobot() robot := gobot.NewRobot("Eve", func() { gobot.Every(500*time.Millisecond, func() { fmt.Println("Greeting Human") }) }) gbot.AddRobot(robot) gbot.Start() }
Web Enabled? You bet!
package main import ( "fmt" "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/api" ) func main() { gbot := gobot.NewGobot() // Starts the API server on default port 3000 api.NewAPI(gbot).Start() // Accessible via http://localhost:3000/api/commands/say_hello gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} { return "Master says hello!" }) hello := gbot.AddRobot(gobot.NewRobot("Eve")) // Accessible via http://localhost:3000/robots/Eve/commands/say_hello hello.AddCommand("say_hello", func(params map[string]interface{}) interface{} { return fmt.Sprintf("%v says hello!", hello.Name) }) gbot.Start() }
Blinking teh LED (Hello Eve!)
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("Eve", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
Index ¶
- func After(t time.Duration, f func())
- func Assert(t *testing.T, a interface{}, b interface{})
- func Every(t time.Duration, f func())
- func FromScale(input, min, max float64) float64
- func NewLoopbackAdaptor(name string) *loopbackAdaptor
- func NewPingDriver(adaptor *loopbackAdaptor, name string) *pingDriver
- func NewTestAdaptor(name string) *testAdaptor
- func NewTestDriver(name string, adaptor *testAdaptor) *testDriver
- func NewTestStruct() *testStruct
- func On(e *Event, f func(s interface{}))
- func Once(e *Event, f func(s interface{}))
- func Publish(e *Event, val interface{})
- func Rand(max int) int
- func Refute(t *testing.T, a interface{}, b interface{})
- func ToScale(input, min, max float64) float64
- func Version() string
- type Adaptor
- type AdaptorInterface
- type Connection
- type Device
- type Driver
- func (d *Driver) Adaptor() AdaptorInterface
- func (d *Driver) AddCommand(name string, f func(map[string]interface{}) interface{})
- func (d *Driver) AddEvent(name string)
- func (d *Driver) Command(name string) func(map[string]interface{}) interface{}
- func (d *Driver) Commands() map[string]func(map[string]interface{}) interface{}
- func (d *Driver) Event(name string) *Event
- func (d *Driver) Events() map[string]*Event
- func (d *Driver) Interval() time.Duration
- func (d *Driver) Name() string
- func (d *Driver) Pin() string
- func (d *Driver) SetInterval(t time.Duration)
- func (d *Driver) SetName(s string)
- func (d *Driver) SetPin(pin string)
- func (d *Driver) ToJSON() *JSONDevice
- func (d *Driver) Type() string
- type DriverInterface
- type Event
- type Gobot
- func (g *Gobot) AddCommand(name string, f func(map[string]interface{}) interface{})
- func (g *Gobot) AddRobot(r *Robot) *Robot
- func (g *Gobot) Command(name string) func(map[string]interface{}) interface{}
- func (g *Gobot) Commands() map[string]func(map[string]interface{}) interface{}
- func (g *Gobot) Robot(name string) *Robot
- func (g *Gobot) Robots() *robots
- func (g *Gobot) Start()
- func (g *Gobot) ToJSON() *JSONGobot
- type JSONConnection
- type JSONDevice
- type JSONGobot
- type JSONRobot
- type NullReadWriteCloser
- type Robot
- func (r *Robot) AddCommand(name string, f func(map[string]interface{}) interface{})
- func (r *Robot) AddConnection(c Connection) Connection
- func (r *Robot) AddDevice(d Device) Device
- func (r *Robot) Command(name string) func(map[string]interface{}) interface{}
- func (r *Robot) Commands() map[string]func(map[string]interface{}) interface{}
- func (r *Robot) Connection(name string) Connection
- func (r *Robot) Connections() *connections
- func (r *Robot) Device(name string) Device
- func (r *Robot) Devices() *devices
- func (r *Robot) Start()
- func (r *Robot) ToJSON() *JSONRobot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLoopbackAdaptor ¶
func NewLoopbackAdaptor(name string) *loopbackAdaptor
func NewPingDriver ¶
func NewPingDriver(adaptor *loopbackAdaptor, name string) *pingDriver
func NewTestAdaptor ¶
func NewTestAdaptor(name string) *testAdaptor
func NewTestDriver ¶
func NewTestDriver(name string, adaptor *testAdaptor) *testDriver
func NewTestStruct ¶
func NewTestStruct() *testStruct
Types ¶
type Adaptor ¶
type Adaptor struct {
// contains filtered or unexported fields
}
func NewAdaptor ¶
func (*Adaptor) SetConnected ¶
func (*Adaptor) ToJSON ¶
func (a *Adaptor) ToJSON() *JSONConnection
type AdaptorInterface ¶
type Connection ¶
type Connection AdaptorInterface
type Device ¶
type Device DriverInterface
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func (*Driver) Adaptor ¶
func (d *Driver) Adaptor() AdaptorInterface
func (*Driver) AddCommand ¶
func (*Driver) SetInterval ¶
func (*Driver) ToJSON ¶
func (d *Driver) ToJSON() *JSONDevice
type DriverInterface ¶
type DriverInterface interface { Start() bool Halt() bool Adaptor() AdaptorInterface SetInterval(time.Duration) Interval() time.Duration SetName(string) Name() string Pin() string SetPin(string) Command(string) func(map[string]interface{}) interface{} Commands() map[string]func(map[string]interface{}) interface{} AddCommand(string, func(map[string]interface{}) interface{}) Events() map[string]*Event Event(string) *Event AddEvent(string) Type() string ToJSON() *JSONDevice }
type Gobot ¶
type Gobot struct {
// contains filtered or unexported fields
}
Gobot is a container composed of one or more robots
func (*Gobot) AddCommand ¶
AddCommand creates a new command and adds it to the Gobot. This command will be available via HTTP using '/commands/name'
Example:
gbot.AddCommand( 'rollover', func( params map[string]interface{}) interface{} { fmt.Println( "Rolling over - Stand by...") }) With the api package setup, you can now get your Gobot to rollover using: http://localhost:3000/commands/rollover
type JSONConnection ¶
type JSONDevice ¶
type JSONRobot ¶
type JSONRobot struct { Name string `json:"name"` Commands []string `json:"commands"` Connections []*JSONConnection `json:"connections"` Devices []*JSONDevice `json:"devices"` }
JSONRobot a JSON representation of a robot.
type NullReadWriteCloser ¶
type NullReadWriteCloser struct{}
func (NullReadWriteCloser) Close ¶
func (NullReadWriteCloser) Close() error
type Robot ¶
type Robot struct { Name string Work func() // contains filtered or unexported fields }
Robot software representation of a physical board. A robot is a named entitity that manages multiple IO devices using a set of adaptors. Additionally a user can specificy custom commands to control a robot remotely.
func NewRobot ¶
NewRobot constructs a new named robot. Though a robot's name will be generated, we recommend that user take care of naming a robot for later access.
func NewTestRobot ¶
func (*Robot) AddCommand ¶
AddCommand setup a new command that we be made available via the REST api.
func (*Robot) AddConnection ¶
func (r *Robot) AddConnection(c Connection) Connection
AddConnection add a new connection on this robot.
func (*Robot) Connection ¶
func (r *Robot) Connection(name string) Connection
Connection finds a connection by name.
func (*Robot) Connections ¶
func (r *Robot) Connections() *connections
Connections retrieves all connections on this robot.
func (*Robot) Devices ¶
func (r *Robot) Devices() *devices
Devices retrieves all devices associated with this robot.