-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
112 lines (99 loc) · 2.6 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"fmt"
"go-voxblox/proto"
"go-voxblox/voxblox"
"log"
"net"
"os"
"os/signal"
"google.golang.org/grpc"
"github.com/aler9/goroslib"
"github.com/aler9/goroslib/pkg/msgs/geometry_msgs"
"github.com/aler9/goroslib/pkg/msgs/sensor_msgs"
)
// onPointCloud2 is called when a PointCloud2 message is received.
// Converts the message to a Voxblox PointCloud and integrates it.
func onPointCloud2(
msg *sensor_msgs.PointCloud2,
tsdfIntegrator voxblox.TsdfIntegrator,
tf *TransformListener,
) {
transform, err := tf.LookupTransform(msg.Header.Stamp)
if err != nil {
log.Println(err)
return
}
voxbloxPointCloud := PointCloud2ToPointCloud(msg)
tsdfIntegrator.IntegratePointCloud(*transform, voxbloxPointCloud)
}
func main() {
config, err := voxblox.ReadConfig("voxblox.yaml")
if err != nil {
panic(err)
}
// Create a node and connect to the master
n, err := goroslib.NewNode(goroslib.NodeConf{
Name: "go-voxblox",
MasterAddress: config.RosMaster,
})
if err != nil {
panic(err)
}
defer n.Close()
// Transformer
tfListener := NewTransformListener(voxblox.Transform{
Rotation: config.Rotation,
Translation: config.Translation,
})
// Integrators
tsdfLayer := voxblox.NewTsdfLayer(config.VoxelSize, config.VoxelsPerSide)
tsdfIntegrator := voxblox.NewFastTsdfIntegrator(&config, tsdfLayer)
meshLayer := voxblox.NewMeshLayer(tsdfLayer)
meshIntegrator := voxblox.NewMeshIntegrator(config, tsdfLayer, meshLayer)
// PointCloud2 subscriber
sub, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
Node: n,
Topic: config.TopicPointCloud2,
Callback: func(msg *sensor_msgs.PointCloud2) {
onPointCloud2(msg, tsdfIntegrator, tfListener)
},
})
if err != nil {
panic(err)
}
defer sub.Close()
// Transform subscriber
sub, err = goroslib.NewSubscriber(goroslib.SubscriberConf{
Node: n,
Topic: config.TopicTransform,
Callback: func(msg *geometry_msgs.TransformStamped) {
tfListener.addTransform(msg)
},
})
if err != nil {
panic(err)
}
defer sub.Close()
// gRPC mesh server
meshServer := NewMeshServer(&meshIntegrator)
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", 50051))
if err != nil {
panic(err)
}
grpcServer := grpc.NewServer()
proto.RegisterMeshServiceServer(grpcServer, meshServer)
go func() {
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("Failed to serve gRPC server: %v", err)
}
}()
defer grpcServer.Stop()
// Wait for CTRL-C
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
// TODO: This is temporary.
meshIntegrator.Integrate()
voxblox.WriteMeshLayerToObjFiles(meshLayer, "output")
}