mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-24 13:48:49 +08:00
Update READMEs
This commit is contained in:
parent
129bb7041a
commit
1d24bd8866
79
README.md
79
README.md
@ -18,28 +18,34 @@ Want to use Ruby or Javascript on robots? Check out our sister projects Artoo (h
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/firmata"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"time"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/firmata"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
adaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
|
||||
led := gpio.NewLedDriver(adaptor, "myLed", "13")
|
||||
firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
|
||||
led := gpio.NewLedDriver(firmataAdaptor, "led", "13")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("blink", []gobot.Connection{adaptor}, []gobot.Device{led}, work))
|
||||
robot := gobot.NewRobot("bot",
|
||||
[]gobot.Connection{firmataAdaptor},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.Start()
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
|
||||
@ -49,27 +55,34 @@ func main() {
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/sphero"
|
||||
"time"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/sphero"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
adaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/rfcomm0")
|
||||
ball := sphero.NewSpheroDriver(adaptor, "sphero")
|
||||
adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/rfcomm0")
|
||||
driver := sphero.NewSpheroDriver(adaptor, "sphero")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(3*time.Second, func() {
|
||||
ball.Roll(30, uint16(gobot.Rand(360)))
|
||||
})
|
||||
}
|
||||
work := func() {
|
||||
gobot.Every(3*time.Second, func() {
|
||||
driver.Roll(30, uint16(gobot.Rand(360)))
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("sphero", []gobot.Connection{adaptor}, []gobot.Device{ball}, work))
|
||||
robot := gobot.NewRobot("sphero",
|
||||
[]gobot.Connection{adaptor},
|
||||
[]gobot.Device{driver},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.Start()
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
|
||||
@ -121,14 +134,14 @@ Gobot includes a RESTful API to query the status of any robot running within a g
|
||||
To activate the API, require the `github.com/hybridgroup/gobot/api` package and instantiate the `API` like this:
|
||||
|
||||
```go
|
||||
master := gobot.NewGobot()
|
||||
api.NewAPI(master).Start()
|
||||
gbot := gobot.NewGobot()
|
||||
api.NewAPI(gbot).Start()
|
||||
```
|
||||
|
||||
You can also specify the api host and port, and turn on authentication:
|
||||
```go
|
||||
master := gobot.NewGobot()
|
||||
server := api.NewAPI(master)
|
||||
gbot := gobot.NewGobot()
|
||||
server := api.NewAPI(gbot)
|
||||
server.Port = "4000"
|
||||
server.Username = "Gort"
|
||||
server.Password = "klaatu"
|
||||
|
@ -16,28 +16,34 @@ go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/p
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/ardrone"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
adaptor := ardrone.NewArdroneAdaptor("Drone")
|
||||
drone := ardrone.NewArdroneDriver(adaptor, "Drone")
|
||||
|
||||
ardroneAdaptor := ardrone.NewArdroneAdaptor("Drone")
|
||||
drone := ardrone.NewArdroneDriver(ardroneAdaptor, "Drone")
|
||||
|
||||
work := func() {
|
||||
drone.TakeOff()
|
||||
gobot.On(drone.Events["Flying"], func(data interface{}) {
|
||||
gobot.On(drone.Event("flying"), func(data interface{}) {
|
||||
gobot.After(3*time.Second, func() {
|
||||
drone.Land()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("drone", []gobot.Connection{adaptor}, []gobot.Device{drone}, work))
|
||||
robot := gobot.NewRobot("drone",
|
||||
[]gobot.Connection{ardroneAdaptor},
|
||||
[]gobot.Device{drone},
|
||||
work,
|
||||
)
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -34,26 +34,33 @@ $ ssh -t root@192.168.7.2 "./beaglebone_blink"
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"time"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
adaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
|
||||
led := gpio.NewLedDriver(adaptor, "led", "P9_12")
|
||||
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
|
||||
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_12")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("blinkBot", []gobot.Connection{adaptor}, []gobot.Device{led}, work))
|
||||
gbot.Start()
|
||||
robot := gobot.NewRobot("blinkBot",
|
||||
[]gobot.Connection{beagleboneAdaptor},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -32,28 +32,35 @@ go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/p
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/digispark"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"time"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/digispark"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
adaptor := digispark.NewDigisparkAdaptor("Digispark")
|
||||
led := gpio.NewLedDriver(adaptor, "led", "0")
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
|
||||
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("blinkBot", []gobot.Connection{adaptor}, []gobot.Device{led}, work))
|
||||
gbot.Start()
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("blinkBot",
|
||||
[]gobot.Connection{digisparkAdaptor},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
|
||||
```
|
||||
## Connecting to Digispark
|
||||
|
||||
@ -102,4 +109,4 @@ KERNEL=="ttyACM*", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="066
|
||||
|
||||
Thanks to [@bluebie](https://github.com/Bluebie) for these instructions! (https://github.com/Bluebie/micronucleus-t85/wiki/Ubuntu-Linux)
|
||||
|
||||
Now plug the Digispark into your computer via the USB port.
|
||||
Now plug the Digispark into your computer via the USB port.
|
||||
|
@ -14,23 +14,33 @@ go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/p
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/firmata"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
adaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
|
||||
led := gpio.NewLedDriver(adaptor, "myLed", "13")
|
||||
|
||||
firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
|
||||
led := gpio.NewLedDriver(firmataAdaptor, "led", "13")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("blinkBot", []gobot.Connection{adaptor}, []gobot.Device{led}, work))
|
||||
|
||||
robot := gobot.NewRobot("bot",
|
||||
[]gobot.Connection{firmataAdaptor},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
@ -40,4 +50,4 @@ The following firmata devices have been tested and are currently supported:
|
||||
- [Arduino uno r3](http://arduino.cc/en/Main/arduinoBoardUno)
|
||||
- [Teensy 3.0](http://www.pjrc.com/store/teensy3.html)
|
||||
|
||||
More devices are coming soon...
|
||||
More devices are coming soon...
|
||||
|
@ -128,46 +128,56 @@ Controller configurations are stored in JSON format. Here's an example configura
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/joystick"
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/joystick"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
|
||||
joystickDriver := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json")
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
work := func() {
|
||||
gobot.On(joystickDriver.Events["square_press"], func(data interface{}) {
|
||||
fmt.Println("square_press")
|
||||
})
|
||||
gobot.On(joystickDriver.Events["square_release"], func(data interface{}) {
|
||||
fmt.Println("square_release")
|
||||
})
|
||||
gobot.On(joystickDriver.Events["triangle_press"], func(data interface{}) {
|
||||
fmt.Println("triangle_press")
|
||||
})
|
||||
gobot.On(joystickDriver.Events["triangle_release"], func(data interface{}) {
|
||||
fmt.Println("triangle_release")
|
||||
})
|
||||
gobot.On(joystickDriver.Events["left_x"], func(data interface{}) {
|
||||
fmt.Println("left_x", data)
|
||||
})
|
||||
gobot.On(joystickDriver.Events["left_y"], func(data interface{}) {
|
||||
fmt.Println("left_y", data)
|
||||
})
|
||||
gobot.On(joystickDriver.Events["right_x"], func(data interface{}) {
|
||||
fmt.Println("right_x", data)
|
||||
})
|
||||
gobot.On(joystickDriver.Events["right_y"], func(data interface{}) {
|
||||
fmt.Println("right_y", data)
|
||||
})
|
||||
}
|
||||
joystickAdaptor := joystick.NewJoystickAdaptor("ps3")
|
||||
joystick := joystick.NewJoystickDriver(joystickAdaptor,
|
||||
"ps3",
|
||||
"./platforms/joystick/configs/dualshock3.json",
|
||||
)
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystickDriver}, work))
|
||||
work := func() {
|
||||
gobot.On(joystick.Event("square_press"), func(data interface{}) {
|
||||
fmt.Println("square_press")
|
||||
})
|
||||
gobot.On(joystick.Event("square_release"), func(data interface{}) {
|
||||
fmt.Println("square_release")
|
||||
})
|
||||
gobot.On(joystick.Event("triangle_press"), func(data interface{}) {
|
||||
fmt.Println("triangle_press")
|
||||
})
|
||||
gobot.On(joystick.Event("triangle_release"), func(data interface{}) {
|
||||
fmt.Println("triangle_release")
|
||||
})
|
||||
gobot.On(joystick.Event("left_x"), func(data interface{}) {
|
||||
fmt.Println("left_x", data)
|
||||
})
|
||||
gobot.On(joystick.Event("left_y"), func(data interface{}) {
|
||||
fmt.Println("left_y", data)
|
||||
})
|
||||
gobot.On(joystick.Event("right_x"), func(data interface{}) {
|
||||
fmt.Println("right_x", data)
|
||||
})
|
||||
gobot.On(joystick.Event("right_y"), func(data interface{}) {
|
||||
fmt.Println("right_y", data)
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Start()
|
||||
robot := gobot.NewRobot("joystickBot",
|
||||
[]gobot.Connection{joystickAdaptor},
|
||||
[]gobot.Device{joystick},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -18,24 +18,31 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/leap"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
adaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
|
||||
l := leap.NewLeapMotionDriver(adaptor, "leap")
|
||||
|
||||
leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
|
||||
l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")
|
||||
|
||||
work := func() {
|
||||
gobot.On(l.Events["Message"], func(data interface{}) {
|
||||
gobot.On(l.Event("message"), func(data interface{}) {
|
||||
fmt.Println(data.(leap.Frame))
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots, gobot.NewRobot(
|
||||
"leapBot", []gobot.Connection{adaptor}, []gobot.Device{l}, work))
|
||||
robot := gobot.NewRobot("leapBot",
|
||||
[]gobot.Connection{leapMotionAdaptor},
|
||||
[]gobot.Device{l},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -41,56 +41,62 @@ You should be able to pair your Mindwave using your normal system tray applet fo
|
||||
## Examples
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/neurosky"
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/neurosky"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
adaptor := neurosky.NewNeuroskyAdaptor("neurosky", "/dev/rfcomm0")
|
||||
neuro := neurosky.NewNeuroskyDriver(adaptor, "neuro")
|
||||
adaptor := neurosky.NewNeuroskyAdaptor("neurosky", "/dev/rfcomm0")
|
||||
neuro := neurosky.NewNeuroskyDriver(adaptor, "neuro")
|
||||
|
||||
work := func() {
|
||||
gobot.On(neuro.Events["Extended"], func(data interface{}) {
|
||||
fmt.Println("Extended", data)
|
||||
})
|
||||
gobot.On(neuro.Events["Signal"], func(data interface{}) {
|
||||
fmt.Println("Signal", data)
|
||||
})
|
||||
gobot.On(neuro.Events["Attention"], func(data interface{}) {
|
||||
fmt.Println("Attention", data)
|
||||
})
|
||||
gobot.On(neuro.Events["Meditation"], func(data interface{}) {
|
||||
fmt.Println("Meditation", data)
|
||||
})
|
||||
gobot.On(neuro.Events["Blink"], func(data interface{}) {
|
||||
fmt.Println("Blink", data)
|
||||
})
|
||||
gobot.On(neuro.Events["Wave"], func(data interface{}) {
|
||||
fmt.Println("Wave", data)
|
||||
})
|
||||
gobot.On(neuro.Events["EEG"], func(data interface{}) {
|
||||
eeg := data.(gobotNeurosky.EEG)kj
|
||||
fmt.Println("Delta", eeg.Delta)
|
||||
fmt.Println("Theta", eeg.Theta)
|
||||
fmt.Println("LoAlpha", eeg.LoAlpha)
|
||||
fmt.Println("HiAlpha", eeg.HiAlpha)
|
||||
fmt.Println("LoBeta", eeg.LoBeta)
|
||||
fmt.Println("HiBeta", eeg.HiBeta)
|
||||
fmt.Println("LoGamma", eeg.LoGamma)
|
||||
fmt.Println("MidGamma", eeg.MidGamma)
|
||||
fmt.Println("\n")
|
||||
})
|
||||
}
|
||||
work := func() {
|
||||
gobot.On(neuro.Event("extended"), func(data interface{}) {
|
||||
fmt.Println("Extended", data)
|
||||
})
|
||||
gobot.On(neuro.Event("signal"), func(data interface{}) {
|
||||
fmt.Println("Signal", data)
|
||||
})
|
||||
gobot.On(neuro.Event("attention"), func(data interface{}) {
|
||||
fmt.Println("Attention", data)
|
||||
})
|
||||
gobot.On(neuro.Event("meditation"), func(data interface{}) {
|
||||
fmt.Println("Meditation", data)
|
||||
})
|
||||
gobot.On(neuro.Event("blink"), func(data interface{}) {
|
||||
fmt.Println("Blink", data)
|
||||
})
|
||||
gobot.On(neuro.Event("wave"), func(data interface{}) {
|
||||
fmt.Println("Wave", data)
|
||||
})
|
||||
gobot.On(neuro.Event("eeg"), func(data interface{}) {
|
||||
eeg := data.(neurosky.EEG)
|
||||
fmt.Println("Delta", eeg.Delta)
|
||||
fmt.Println("Theta", eeg.Theta)
|
||||
fmt.Println("LoAlpha", eeg.LoAlpha)
|
||||
fmt.Println("HiAlpha", eeg.HiAlpha)
|
||||
fmt.Println("LoBeta", eeg.LoBeta)
|
||||
fmt.Println("HiBeta", eeg.HiBeta)
|
||||
fmt.Println("LoGamma", eeg.LoGamma)
|
||||
fmt.Println("MidGamma", eeg.MidGamma)
|
||||
fmt.Println("\n")
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("brainBot", []gobot.Connection{adaptor}, []gobot.Device{neuro}, work))
|
||||
robot := gobot.NewRobot("brainBot",
|
||||
[]gobot.Connection{adaptor},
|
||||
[]gobot.Device{neuro},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.Start()
|
||||
gbot.AddRobot(robot)
|
||||
gbot.Start()
|
||||
}
|
||||
|
||||
```
|
||||
|
@ -45,13 +45,17 @@ func main() {
|
||||
camera := opencv.NewCameraDriver("camera", 0)
|
||||
|
||||
work := func() {
|
||||
gobot.On(camera.Events["Frame"], func(data interface{}) {
|
||||
gobot.On(camera.Event("frame"), func(data interface{}) {
|
||||
window.ShowImage(data.(*cv.IplImage))
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("cameraBot", []gobot.Connection{}, []gobot.Device{window, camera}, work))
|
||||
robot := gobot.NewRobot("cameraBot",
|
||||
[]gobot.Device{window, camera},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ has been installed on the Pebble watch.
|
||||
For more information about Gobot, check out the github repo at
|
||||
https://github.com/hybridgroup/gobot
|
||||
|
||||
[](http://travis-ci.org/hybridgroup/gobot-pebble)
|
||||
|
||||
## Installing
|
||||
|
||||
@ -25,39 +24,46 @@ https://github.com/hybridgroup/gobot
|
||||
in example, api host is your computer IP, robot name is 'pebble', robot api port is 8080 and publish command is PublishEventC and
|
||||
message command is PendingMessageC
|
||||
|
||||
```
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/api"
|
||||
"github.com/hybridgroup/gobot/platforms/pebble"
|
||||
)
|
||||
|
||||
func main() {
|
||||
master := gobot.NewGobot()
|
||||
api.NewAPI(master).Start()
|
||||
gbot := gobot.NewGobot()
|
||||
api.NewAPI(gbot).Start()
|
||||
|
||||
pebbleAdaptor := pebble.NewPebbleAdaptor("pebble")
|
||||
pebbleDriver := pebble.NewPebbleDriver(pebbleAdaptor, "pebble")
|
||||
|
||||
work := func() {
|
||||
pebbleDriver.SendNotification("Hello Pebble!")
|
||||
gobot.On(pebbleDriver.Events["button"], func(data interface{}) {
|
||||
gobot.On(pebbleDriver.Event("button"), func(data interface{}) {
|
||||
fmt.Println("Button pushed: " + data.(string))
|
||||
})
|
||||
|
||||
gobot.On(pebbleDriver.Events["tap"], func(data interface{}) {
|
||||
gobot.On(pebbleDriver.Event("tap"), func(data interface{}) {
|
||||
fmt.Println("Tap event detected")
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work)
|
||||
robot := gobot.NewRobot("pebble",
|
||||
[]gobot.Connection{pebbleAdaptor},
|
||||
[]gobot.Device{pebbleDriver},
|
||||
work,
|
||||
)
|
||||
|
||||
master.Robots = append(master.Robots, robot)
|
||||
master.Start()
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Supported Features
|
||||
|
@ -13,27 +13,33 @@ go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/p
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/spark"
|
||||
"time"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/spark"
|
||||
)
|
||||
|
||||
func main() {
|
||||
master := gobot.NewGobot()
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
|
||||
led := gpio.NewLedDriver(sparkCore, "led", "D7")
|
||||
sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
|
||||
led := gpio.NewLedDriver(sparkCore, "led", "D7")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
master.Robots = append(master.Robots,
|
||||
gobot.NewRobot("spark", []gobot.Connection{sparkCore}, []gobot.Device{led}, work))
|
||||
robot := gobot.NewRobot("spark",
|
||||
[]gobot.Connection{sparkCore},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
master.Start()
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -44,26 +44,33 @@ You should be able to pair your Sphero using your normal system tray applet for
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/sphero"
|
||||
"time"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/sphero"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
adaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/rfcomm0")
|
||||
ball := sphero.NewSpheroDriver(adaptor, "sphero")
|
||||
adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/rfcomm0")
|
||||
driver := sphero.NewSpheroDriver(adaptor, "sphero")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(3*time.Second, func() {
|
||||
ball.Roll(30, uint16(gobot.Rand(360)))
|
||||
})
|
||||
}
|
||||
work := func() {
|
||||
gobot.Every(3*time.Second, func() {
|
||||
driver.Roll(30, uint16(gobot.Rand(360)))
|
||||
})
|
||||
}
|
||||
|
||||
gbot.Robots = append(gbot.Robots,
|
||||
gobot.NewRobot("sphero", []gobot.Connection{adaptor}, []gobot.Device{ball}, work))
|
||||
robot := gobot.NewRobot("sphero",
|
||||
[]gobot.Connection{adaptor},
|
||||
[]gobot.Device{driver},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.Start()
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user