-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·76 lines (60 loc) · 1.4 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
71
72
73
74
75
76
package main
import (
"io/ioutil"
"log"
"net/http"
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func main() {
app := app.New()
w := app.NewWindow("Hello")
w.SetContent(widget.NewVBox(
widget.NewLabel("JetSon Nano 24V Car GUI for Control!"),
widget.NewButton("Forward", func() {
//cmd := exec.Command("rostopic pub stop_motor std_msgs/Empty --once")
//_, err := exec.Command("/bin/sh", "run.sh").Output()
//if err != nil {
// panic(err)
//}
//fmt.Println("Script executed successfully")
RunMotor()
}),
widget.NewButton("Stop", func() {
//cmd := exec.Command("rostopic pub stop_motor std_msgs/Empty --once")
//cmd := exec.Command("rostopic pub stop_motor std_msgs/Empty --once")
//_, err := exec.Command("/bin/sh", "stop.sh").Output()
//if err != nil {
// panic(err)
//}
//sfmt.Println("Script executed successfully")
StopMotor()
}),
widget.NewButton("Quit", func() {
app.Quit()
}),
))
w.ShowAndRun()
}
func RunMotor() {
resp, err := http.Get("http://127.0.0.1:8000/motor_run")
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
log.Println(string(body))
}
func StopMotor() {
resp, err := http.Get("http://127.0.0.1:8000/motor_stop")
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
log.Println(string(body))
}