1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00

docs: Describe Classic Gobot, Metal Gobot, and Master Gobot

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-10-18 19:32:11 +02:00
parent 527f27a968
commit a0b3a7934c

View File

@ -114,7 +114,7 @@ func main() {
#### "Master" Gobot #### "Master" Gobot
You can also use the "Master Gobot" to control swarms of robots. For example: You can also use the full capabilities of the framework aka "Master Gobot" to control swarms of robots or other features such as the built-in API server. For example:
```go ```go
package main package main
@ -127,8 +127,39 @@ import (
"github.com/hybridgroup/gobot/platforms/sphero" "github.com/hybridgroup/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() { func main() {
// creates the Master
master := gobot.NewMaster() master := gobot.NewMaster()
spheros := []string{ spheros := []string{
@ -139,39 +170,9 @@ func main() {
} }
for _, port := range spheros { for _, port := range spheros {
spheroAdaptor := sphero.NewAdaptor(port) master.AddRobot(NewSwarmBot(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,
)
master.AddRobot(robot)
} }
// starts all the robots at once
master.Start() master.Start()
} }
``` ```