-
Notifications
You must be signed in to change notification settings - Fork 5
/
gohome.go
53 lines (46 loc) · 1.08 KB
/
gohome.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
package main
import (
"log"
"github.com/aler9/goroslib"
"github.com/aler9/goroslib/pkg/msg"
)
type goHomeRequest struct {
}
type goHomeResponse struct {
}
type goHomeService struct {
msg.Package `ros:"/nav_low_bat"`
Request goHomeRequest
Response goHomeResponse
}
// call the /CoreNode/adjust_light service with a value of 1 to turn on the light
func scoutGoHome() {
// create a node and connect to the master
n, err := goroslib.NewNode(goroslib.NodeConf{
Name: "scout-go-home",
MasterAddress: *flagROSHostAddress,
})
if err != nil {
panic(err)
}
defer n.Close()
// create a service client
cl, err := goroslib.NewServiceClient(goroslib.ServiceClientConf{
Node: n,
Name: "/nav_low_bat",
Srv: &goHomeService{
Request: goHomeRequest{},
}})
if err != nil {
log.Println("An error occured while trying to send the bot home", err)
}
defer cl.Close()
// call the service
req := goHomeRequest{}
res := goHomeResponse{}
err = cl.Call(&req, &res)
if err != nil {
panic(err)
}
log.Println("Command received: Scout returning home in 5 seconds")
}