forked from bluenviron/goroslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (38 loc) · 904 Bytes
/
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
package main
import (
"fmt"
"os"
"os/signal"
"github.com/aler9/goroslib"
"github.com/aler9/goroslib/pkg/msgs/sensor_msgs"
)
func onMessage(msg *sensor_msgs.Imu) {
fmt.Printf("Incoming: %+v\n", msg)
}
func main() {
// create a node and connect to the master.
// the master's IPv6 must be inserted into square brackets.
// remember to start the master with the ROS_IPV6=on environment variable.
n, err := goroslib.NewNode(goroslib.NodeConf{
Name: "goroslib_sub",
MasterAddress: "[4501:47d7:fc41:5099:e0cb:7560:2196:0647]:11311",
})
if err != nil {
panic(err)
}
defer n.Close()
// create a subscriber
sub, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
Node: n,
Topic: "test_topic",
Callback: onMessage,
})
if err != nil {
panic(err)
}
defer sub.Close()
// wait for CTRL-C
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
}