forked from bluenviron/goroslib
/
main.go
76 lines (64 loc) · 1.39 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 (
"fmt"
"github.com/ROBTTO/goroslib"
"github.com/ROBTTO/goroslib/pkg/msg"
)
// define a custom action.
// unlike the standard library, a .action file is not needed.
type DoSomethingActionGoal struct {
Input uint32
}
type DoSomethingActionResult struct {
Output uint32
}
type DoSomethingActionFeedback struct {
PercentComplete float32
}
type DoSomethingAction struct {
msg.Package `ros:"shared_actions"`
DoSomethingActionGoal
DoSomethingActionResult
DoSomethingActionFeedback
}
func main() {
// create a node and connect to the master
n, err := goroslib.NewNode(goroslib.NodeConf{
Namespace: "/myns",
Name: "goroslib",
MasterAddress: "127.0.0.1:11311",
})
if err != nil {
panic(err)
}
defer n.Close()
// create a simple action client
sac, err := goroslib.NewSimpleActionClient(goroslib.SimpleActionClientConf{
Node: n,
Name: "test_action",
Action: &DoSomethingAction{},
})
if err != nil {
panic(err)
}
defer sac.Close()
// wait for the server
sac.WaitForServer()
// send a goal
err = sac.SendGoal(goroslib.SimpleActionClientGoalConf{
Goal: &DoSomethingActionGoal{
Input: 1234312,
},
OnDone: func(res *DoSomethingActionResult) {
fmt.Println("result:", res)
},
OnFeedback: func(fb *DoSomethingActionFeedback) {
fmt.Println("feedback", fb)
},
})
if err != nil {
panic(err)
}
// freeze main loop
select {}
}