2015-03-27 09:55:44 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 16:58:43 +02:00
|
|
|
"github.com/hybridgroup/gobot/drivers/i2c"
|
2015-03-27 09:55:44 -07:00
|
|
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 16:58:43 +02:00
|
|
|
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
|
|
|
lidar := i2c.NewLIDARLiteDriver(firmataAdaptor)
|
2015-03-27 09:55:44 -07: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-18 21:08:25 +02:00
|
|
|
robot.Start()
|
2015-03-27 09:55:44 -07:00
|
|
|
}
|