Exemplo n.º 1
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	servo1 := gpio.NewServoDriver(firmataAdaptor, "servo", "5")
	servo2 := gpio.NewServoDriver(firmataAdaptor, "servo", "3")

	leapAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	leapDriver := leap.NewLeapMotionDriver(leapAdaptor, "leap")

	work := func() {
		x := 90.0
		z := 90.0
		gobot.On(leapDriver.Events["Message"], 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)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("pwmBot", []gobot.Connection{firmataAdaptor, leapAdaptor}, []gobot.Device{servo1, servo2, leapDriver}, work))
	gbot.Start()
}
Exemplo n.º 2
0
func main() {
	gbot := gobot.NewGobot()

	leapAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	spheroAdaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/tty.Sphero-YBW-RN-SPP")

	leapDriver := leap.NewLeapMotionDriver(leapAdaptor, "leap")
	spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "sphero")

	work := func() {
		gobot.On(leapDriver.Event("message"), 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,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 3
0
func main() {
	gbot := gobot.NewGobot()

	// create a ardrone adapter
	aAdapter := ardrone.NewArdroneAdaptor("Drone")
	// create a leap adaptor to connect to the leap motion via web socket.
	lAdapter := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	c := leapdrone.NewController(lAdapter, aAdapter)

	// implement leap worker
	leapWorker := func() {
		// NOTE: leap motion driver only add message event to it.
		gobot.On(c.LDriver.Event("message"), func(data interface{}) {
			lp := data.(leap.Frame)
			for _, v := range lp.Hands {
				// XXX: catch the first hand id and ignore other annoying hands
				hand := lb.NewHand(v, 200)
				if hand.IsForward() {
					fmt.Printf("moving forward\n")
				}
				if hand.IsBackward() {
					fmt.Printf("moving backward\n")
				}
				if hand.IsRight() {
					fmt.Printf("moving right\n")
				}
				if hand.IsLeft() {
					fmt.Printf("moving left\n")
				}
				if hand.IsUpward() {
					fmt.Printf("moving up\n")
				}
				if hand.IsDownward() {
					fmt.Printf("moving down\n")
				}
				continue
			}
		})
	}

	// implement ARDrone worker
	droneWorker := func() {
		c.ADriver.TakeOff()
		gobot.On(c.ADriver.Event("flying"), func(data interface{}) {
			gobot.After(3*time.Second, func() {
				c.ADriver.Land()
			})
		})
	}

	// add a leap robot to gobot
	gbot.AddRobot(c.LeapRobot(leapWorker))
	// add a ardrone robot to gobot
	// TODO: temporarily disable drone robot.
	// gbot.AddRobot(c.DroneRobot(droneWorker))
	_ = droneWorker

	// start
	gbot.Start()
}
Exemplo n.º 4
0
func main() {
	gbot := gobot.NewGobot()
	leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")

	work := func() {
		gobot.On(l.Events["Message"], func(data interface{}) {
			printHands(data.(leap.Frame))
		})
	}

	gbot.Robots = append(gbot.Robots, gobot.NewRobot(
		"leapBot", []gobot.Connection{leapMotionAdaptor}, []gobot.Device{l}, work))

	gbot.Start()
}
Exemplo n.º 5
0
// Video: https://www.youtube.com/watch?v=ayNMyUfdAqc
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/tty.usbmodem1451")
	servo1 := gpio.NewServoDriver(firmataAdaptor, "servo", "3")
	servo2 := gpio.NewServoDriver(firmataAdaptor, "servo", "4")
	servo3 := gpio.NewServoDriver(firmataAdaptor, "servo", "5")
	servo4 := gpio.NewServoDriver(firmataAdaptor, "servo", "6")
	servo5 := gpio.NewServoDriver(firmataAdaptor, "servo", "7")

	leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")

	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,
	)

	gbot.AddRobot(robot)
	gbot.Start()
}
Exemplo n.º 6
0
func main() {
	gbot := gobot.NewGobot()

	leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")

	work := func() {
		gobot.On(l.Event("gesture"), func(data interface{}) {
			printGesture(data.(leap.Gesture))
		})
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 7
0
func main() {
	gbot := gobot.NewGobot()

	leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")

	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,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}