func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	accel := i2c.NewGroveAccelerometerDriver(board, "accel")

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			if x, y, z, err := accel.XYZ(); err == nil {
				fmt.Println(x, y, z)
				fmt.Println(accel.Acceleration(x, y, z))
			} else {
				fmt.Println(err)
			}
		})
	}

	robot := gobot.NewRobot("accelBot",
		[]gobot.Connection{board},
		[]gobot.Device{accel},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Пример #2
0
func main() {
	gbot := gobot.NewGobot()

	adaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/rfcomm0")
	board := edison.NewEdisonAdaptor("edison")
	spheroDriver := sphero.NewSpheroDriver(adaptor, "sphero")
	sensorAccel := i2c.NewGroveAccelerometerDriver(board, "accel")

	work := func() {
		gobot.Every(time.Millisecond*20, func() {
			if x, y, z, err := sensorAccel.XYZ(); err == nil {
				degree := math.Sin(y/x) * 360
				spheroDriver.Roll(uint8(100+z), uint16(degree))
			}
		})
	}

	robot := gobot.NewRobot("sphero",
		[]gobot.Connection{adaptor, board},
		[]gobot.Device{sensorAccel, spheroDriver},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}