2015-03-28 00:55:44 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2015-03-28 00:55:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
|
|
|
lidar := i2c.NewLIDARLiteDriver(firmataAdaptor)
|
2015-03-28 00:55:44 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
|
|
|
distance, _ := lidar.Distance()
|
|
|
|
fmt.Println("Distance", distance)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("lidarbot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{lidar},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2015-03-28 00:55:44 +08:00
|
|
|
}
|