-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathcollector.go
74 lines (61 loc) · 1.82 KB
/
collector.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
package slam
import (
"context"
pb "go.viam.com/api/service/slam/v1"
"google.golang.org/protobuf/types/known/anypb"
"go.viam.com/rdk/data"
"go.viam.com/rdk/spatialmath"
)
type method int64
const (
getPosition method = iota
getPointCloudMap
)
func (m method) String() string {
if m == getPosition {
return "GetPosition"
}
if m == getPointCloudMap {
return "GetPointCloudMap"
}
return "Unknown"
}
func newGetPositionCollector(resource interface{}, params data.CollectorParams) (data.Collector, error) {
slam, err := assertSLAM(resource)
if err != nil {
return nil, err
}
cFunc := data.CaptureFunc(func(ctx context.Context, _ map[string]*anypb.Any) (interface{}, error) {
pose, componentRef, err := slam.GetPosition(ctx)
if err != nil {
return nil, data.FailedToReadErr(params.ComponentName, getPosition.String(), err)
}
return &pb.GetPositionResponse{Pose: spatialmath.PoseToProtobuf(pose), ComponentReference: componentRef}, nil
})
return data.NewCollector(cFunc, params)
}
func newGetPointCloudMapCollector(resource interface{}, params data.CollectorParams) (data.Collector, error) {
slam, err := assertSLAM(resource)
if err != nil {
return nil, err
}
cFunc := data.CaptureFunc(func(ctx context.Context, _ map[string]*anypb.Any) (interface{}, error) {
f, err := slam.GetPointCloudMap(ctx)
if err != nil {
return nil, data.FailedToReadErr(params.ComponentName, getPointCloudMap.String(), err)
}
pcd, err := HelperConcatenateChunksToFull(f)
if err != nil {
return nil, data.FailedToReadErr(params.ComponentName, getPointCloudMap.String(), err)
}
return pcd, nil
})
return data.NewCollector(cFunc, params)
}
func assertSLAM(resource interface{}) (Service, error) {
slamService, ok := resource.(Service)
if !ok {
return nil, data.InvalidInterfaceErr(API)
}
return slamService, nil
}