コード例 #1
0
ファイル: firmata_cat_toy.go プロジェクト: hybridgroup/gobot
func main() {
	firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
	servo1 := gpio.NewServoDriver(firmataAdaptor, "5")
	servo2 := gpio.NewServoDriver(firmataAdaptor, "3")

	leapAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	leapDriver := leap.NewDriver(leapAdaptor)

	work := func() {
		x := 90.0
		z := 90.0
		leapDriver.On(leap.MessageEvent, func(data interface{}) {
			if len(data.(leap.Frame).Hands) > 0 {
				hand := data.(leap.Frame).Hands[0]
				x = gobot.ToScale(gobot.FromScale(hand.X(), -300, 300), 30, 150)
				z = gobot.ToScale(gobot.FromScale(hand.Z(), -300, 300), 30, 150)
			}
		})
		gobot.Every(10*time.Millisecond, func() {
			servo1.Move(uint8(x))
			servo2.Move(uint8(z))
			fmt.Println("Current Angle: ", servo1.CurrentAngle, ",", servo2.CurrentAngle)
		})
	}

	robot := gobot.NewRobot("pwmBot",
		[]gobot.Connection{firmataAdaptor, leapAdaptor},
		[]gobot.Device{servo1, servo2, leapDriver},
		work,
	)

	robot.Start()
}
コード例 #2
0
ファイル: leap_sphero.go プロジェクト: hybridgroup/gobot
func main() {
	leapAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	spheroAdaptor := sphero.NewAdaptor("/dev/tty.Sphero-YBW-RN-SPP")

	leapDriver := leap.NewDriver(leapAdaptor)
	spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)

	work := func() {
		leapDriver.On(leap.MessageEvent, func(data interface{}) {
			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,
	)

	robot.Start()
}
コード例 #3
0
ファイル: leap_motion.go プロジェクト: hybridgroup/gobot
func main() {
	leapMotionAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	l := leap.NewDriver(leapMotionAdaptor)

	work := func() {
		l.On(leap.MessageEvent, func(data interface{}) {
			fmt.Println(data.(leap.Frame))
		})
	}

	robot := gobot.NewRobot("leapBot",
		[]gobot.Connection{leapMotionAdaptor},
		[]gobot.Device{l},
		work,
	)

	robot.Start()
}
コード例 #4
0
ファイル: leap_servos.go プロジェクト: hybridgroup/gobot
// Video: https://www.youtube.com/watch?v=ayNMyUfdAqc
func main() {
	firmataAdaptor := firmata.NewAdaptor("/dev/tty.usbmodem1451")
	servo1 := gpio.NewServoDriver(firmataAdaptor, "3")
	servo2 := gpio.NewServoDriver(firmataAdaptor, "4")
	servo3 := gpio.NewServoDriver(firmataAdaptor, "5")
	servo4 := gpio.NewServoDriver(firmataAdaptor, "6")
	servo5 := gpio.NewServoDriver(firmataAdaptor, "7")

	leapMotionAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	l := leap.NewDriver(leapMotionAdaptor)

	work := func() {
		fist := false
		l.On(leap.MessageEvent, func(data interface{}) {
			handIsOpen := len(data.(leap.Frame).Pointables) > 0
			if handIsOpen && fist {
				servo1.Move(0)
				servo2.Move(0)
				servo3.Move(0)
				servo4.Move(0)
				servo5.Move(0)
				fist = false
			} else if !handIsOpen && !fist {
				servo1.Move(120)
				servo2.Move(120)
				servo3.Move(120)
				servo4.Move(120)
				servo5.Move(120)
				fist = true
			}
		})
	}

	robot := gobot.NewRobot("servoBot",
		[]gobot.Connection{firmataAdaptor, leapMotionAdaptor},
		[]gobot.Device{servo1, servo2, servo3, servo4, servo5, l},
		work,
	)

	robot.Start()
}