2014-09-02 11:48:23 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/leap"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-15 20:02:54 +02:00
|
|
|
gbot := gobot.NewMaster()
|
2014-09-02 11:48:23 -05:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
leapAdaptor := leap.NewAdaptor("127.0.0.1:6437")
|
|
|
|
spheroAdaptor := sphero.NewAdaptor("/dev/tty.Sphero-YBW-RN-SPP")
|
2014-09-02 11:48:23 -05:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
leapDriver := leap.NewDriver(leapAdaptor)
|
|
|
|
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
|
2014-09-02 11:48:23 -05:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 12:17:43 +02:00
|
|
|
leapDriver.On(leap.MessageEvent, func(data interface{}) {
|
2014-09-02 11:48:23 -05:00
|
|
|
hands := data.(leap.Frame).Hands
|
|
|
|
|
|
|
|
if len(hands) > 0 {
|
|
|
|
x := math.Abs(hands[0].Direction[0])
|
|
|
|
y := math.Abs(hands[0].Direction[1])
|
|
|
|
z := math.Abs(hands[0].Direction[2])
|
|
|
|
spheroDriver.SetRGB(scale(x), scale(y), scale(z))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("leapBot",
|
|
|
|
[]gobot.Connection{leapAdaptor, spheroAdaptor},
|
|
|
|
[]gobot.Device{leapDriver, spheroDriver},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func scale(position float64) uint8 {
|
|
|
|
return uint8(gobot.ToScale(gobot.FromScale(position, 0, 1), 0, 255))
|
|
|
|
}
|