-
Notifications
You must be signed in to change notification settings - Fork 5
/
lights.go
57 lines (49 loc) · 1.1 KB
/
lights.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
package main
import (
"github.com/aler9/goroslib"
"github.com/aler9/goroslib/pkg/msg"
)
type adjustLightRequest struct {
Cmd int32 `ros:"cmd int32"`
}
type adjustLightResponse struct {
}
type adjustLightService struct {
msg.Package `ros:"/CoreNode/adjust_light"`
Request adjustLightRequest
Response adjustLightResponse
}
// call the /CoreNode/adjust_light service with a value of 1 to turn on the light
func turnOnLight(lightValue int32) {
// create a node and connect to the master
n, err := goroslib.NewNode(goroslib.NodeConf{
Name: "scout-lights",
MasterAddress: *flagROSHostAddress,
})
if err != nil {
panic(err)
}
defer n.Close()
// create a service client
cl, err := goroslib.NewServiceClient(goroslib.ServiceClientConf{
Node: n,
Name: "/CoreNode/adjust_light",
Srv: &adjustLightService{
Request: adjustLightRequest{
Cmd: lightValue,
},
}})
if err != nil {
panic(err)
}
defer cl.Close()
// call the service
req := adjustLightRequest{
Cmd: lightValue,
}
res := adjustLightResponse{}
err = cl.Call(&req, &res)
if err != nil {
panic(err)
}
}