forked from akio/rosgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (49 loc) · 1.01 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
package main
//go:generate gengo srv rospy_tutorials/AddTwoInts
import (
"fmt"
"github.com/akio/rosgo/ros"
"os"
"rospy_tutorials"
"strconv"
)
func main() {
if len(os.Args) != 3 {
fmt.Print("USAGE: test_client <int> <int>")
os.Exit(-1)
}
node, err := ros.NewNode("client", os.Args)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
defer node.Shutdown()
logger := node.Logger()
logger.SetSeverity(ros.LogLevelDebug)
cli := node.NewServiceClient("/add_two_ints", rospy_tutorials.SrvAddTwoInts)
defer cli.Shutdown()
var a, b int64
a, err = strconv.ParseInt(os.Args[1], 10, 32)
if err != nil {
fmt.Print(err)
fmt.Println()
os.Exit(1)
}
b, err = strconv.ParseInt(os.Args[2], 10, 32)
if err != nil {
fmt.Print(err)
fmt.Println()
os.Exit(1)
}
var srv rospy_tutorials.AddTwoInts
srv.Request.A = a
srv.Request.B = b
if err = cli.Call(&srv); err != nil {
fmt.Print(err)
fmt.Println()
} else {
fmt.Printf("%d + %d = %d",
srv.Request.A, srv.Request.B, srv.Response.Sum)
fmt.Println()
}
}