Skip to content

Commit

Permalink
docs: update main doc.go for godocs generation
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 19, 2016
1 parent 20659c0 commit 686dc89
Showing 1 changed file with 77 additions and 41 deletions.
118 changes: 77 additions & 41 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
// Copyright 2014-2016 The Hybrid Group. All rights reserved.

/*
Package gobot provides a framework for robotics, physical computing and the internet of things.
It is the main point of entry for your Gobot application. A Gobot program
is typically composed of one or more robots that makes up a project.
Package gobot is the primary entrypoint for Gobot (http://gobot.io), a framework for robotics, physical computing, and the Internet of Things written using the Go programming language .
Basic Setup
It provides a simple, yet powerful way to create solutions that incorporate multiple, different hardware devices at the same time.
package main
import (
"fmt"
"time"
Classic Gobot
"gobot.io/x/gobot"
)
func main() {
robot := gobot.NewRobot("Eve", func() {
gobot.Every(500*time.Millisecond, func() {
fmt.Println("Greeting Human")
})
})
robot.Start()
}
Blinking an LED (Hello Eve!)
Here is a "Classic Gobot" program that blinks an LED using an Arduino:
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
Expand All @@ -48,7 +29,7 @@ Blinking an LED (Hello Eve!)
})
}
robot := gobot.NewRobot("Eve",
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
Expand All @@ -57,41 +38,96 @@ Blinking an LED (Hello Eve!)
robot.Start()
}
Web Enabled? You bet! Gobot can be configured to expose a restful HTTP interface
using the api package. You can define custom commands on your robots, in addition
to the built-in device driver commands, and interact with your application as a
web service.
Metal Gobot
You can also use Metal Gobot and pick and choose from the various Gobot packages to control hardware with nothing but pure idiomatic Golang code. For example:
package main
import (
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/intel-iot/edison"
"time"
)
func main() {
e := edison.NewAdaptor()
e.Connect()
led := gpio.NewLedDriver(e, "13")
led.Start()
for {
led.Toggle()
time.Sleep(1000 * time.Millisecond)
}
}
Master Gobot
Finally, you can use Master Gobot to add the complete Gobot API or control swarms of Robots:
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
"gobot.io/x/gobot/platforms/sphero"
)
func NewSwarmBot(port string) *gobot.Robot {
spheroAdaptor := sphero.NewAdaptor(port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)
work := func() {
spheroDriver.Stop()
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
return robot
}
func main() {
master := gobot.NewMaster()
// Starts the API server on default port 3000
api.NewAPI(master).Start()
// Accessible via http://localhost:3000/api/commands/say_hello
master.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
return "Master says hello!"
})
hello := master.AddRobot(gobot.NewRobot("Eve"))
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
// 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)
})
for _, port := range spheros {
master.AddRobot(NewSwarmBot(port))
}
master.Start()
}
Copyright (c) 2013-2016 The Hybrid Group. Licensed under the Apache 2.0 license.
*/
package gobot // import "gobot.io/x/gobot"

0 comments on commit 686dc89

Please sign in to comment.