mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-01 13:48:57 +08:00
docs: Describe Classic Gobot, Metal Gobot, and Master Gobot
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
91aa54d37b
commit
6ad9862a3e
76
README.md
76
README.md
@ -28,13 +28,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hybridgroup/gobot"
|
"github.com/hybridgroup/gobot"
|
||||||
"github.com/hybridgroup/gobot/platforms/firmata"
|
|
||||||
"github.com/hybridgroup/gobot/drivers/gpio"
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
||||||
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
master := gobot.NewMaster()
|
|
||||||
|
|
||||||
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
||||||
led := gpio.NewLedDriver(firmataAdaptor, "13")
|
led := gpio.NewLedDriver(firmataAdaptor, "13")
|
||||||
|
|
||||||
@ -50,9 +48,7 @@ func main() {
|
|||||||
work,
|
work,
|
||||||
)
|
)
|
||||||
|
|
||||||
master.AddRobot(robot)
|
robot.Start()
|
||||||
|
|
||||||
master.Start()
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -70,8 +66,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
master := gobot.NewMaster()
|
|
||||||
|
|
||||||
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
|
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
|
||||||
driver := sphero.NewSpheroDriver(adaptor)
|
driver := sphero.NewSpheroDriver(adaptor)
|
||||||
|
|
||||||
@ -87,9 +81,7 @@ func main() {
|
|||||||
work,
|
work,
|
||||||
)
|
)
|
||||||
|
|
||||||
master.AddRobot(robot)
|
robot.Start()
|
||||||
|
|
||||||
master.Start()
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -120,6 +112,68 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### "Master" Gobot
|
||||||
|
|
||||||
|
You can also use the "Master Gobot" to control swarms of robots. For example:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hybridgroup/gobot"
|
||||||
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
master := gobot.NewMaster()
|
||||||
|
|
||||||
|
spheros := []string{
|
||||||
|
"/dev/rfcomm0",
|
||||||
|
"/dev/rfcomm1",
|
||||||
|
"/dev/rfcomm2",
|
||||||
|
"/dev/rfcomm3",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, port := range spheros {
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
master.AddRobot(robot)
|
||||||
|
}
|
||||||
|
|
||||||
|
master.Start()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Hardware Support
|
## Hardware Support
|
||||||
Gobot has a extensible system for connecting to hardware devices. The following robotics and physical computing platforms are currently supported:
|
Gobot has a extensible system for connecting to hardware devices. The following robotics and physical computing platforms are currently supported:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user