/
main.go
70 lines (51 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"log"
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
"github.com/mbrumlow/dartbot/tank"
"github.com/mbrumlow/webbot/webbot"
)
var host = flag.String("host", "ws://localhost:8080/robot", "Robot Web Control (rwc) host.")
var video = flag.String("video", "/dev/video0", "Path to video device.")
var pass = flag.String("pass", "", "Password to rwc host")
var maxspeed = flag.Int("maxspeed", 255, "max speed")
var maxrotate = flag.Int("maxrotate", 255, "max rotate")
func main() {
flag.Parse()
gbot := gobot.NewGobot()
e := edison.NewEdisonAdaptor("edison")
pwmA := gpio.NewDirectPinDriver(e, "pwmA", "3")
breakA := gpio.NewDirectPinDriver(e, "breakA", "9")
dirA := gpio.NewDirectPinDriver(e, "dirA", "12")
pwmB := gpio.NewDirectPinDriver(e, "pwmB", "5")
breakB := gpio.NewDirectPinDriver(e, "breakB", "8")
dirB := gpio.NewDirectPinDriver(e, "dirB", "13")
work := func() {
tank := tank.NewTank(pwmA, breakA, dirA, pwmB, breakB, dirB, *maxspeed, *maxrotate)
go func() {
wb := webbot.New(*host, *video, *pass, tank)
for {
if err := wb.Run(); err != nil {
log.Printf("RUN ERROR: %v\n", err.Error())
}
time.Sleep(1 * time.Second)
}
}()
}
robot := gobot.NewRobot("dartBot",
[]gobot.Connection{e},
[]gobot.Device{pwmA},
[]gobot.Device{breakA},
[]gobot.Device{dirA},
[]gobot.Device{pwmB},
[]gobot.Device{dirB},
[]gobot.Device{breakB},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}