-
Notifications
You must be signed in to change notification settings - Fork 3
/
base_scenes.go
147 lines (129 loc) · 5.44 KB
/
base_scenes.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"bytes"
"context"
"os"
"path/filepath"
geo "github.com/kellydunn/golang-geo"
"github.com/golang/geo/r3"
"go.viam.com/rdk/components/base"
"go.viam.com/rdk/components/base/fake"
"go.viam.com/rdk/components/base/kinematicbase"
"go.viam.com/rdk/components/movementsensor"
"go.viam.com/rdk/motionplan"
"go.viam.com/rdk/pointcloud"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/services/motion"
"go.viam.com/rdk/services/slam"
"go.viam.com/rdk/spatialmath"
"go.viam.com/rdk/testutils/inject"
"go.viam.com/utils"
"go.viam.com/utils/artifact"
)
func getPointCloudMap(path string) (func() ([]byte, error), error) {
const chunkSizeBytes = 1 * 1024 * 1024
file, err := os.Open(path)
if err != nil {
return nil, err
}
chunk := make([]byte, chunkSizeBytes)
f := func() ([]byte, error) {
bytesRead, err := file.Read(chunk)
if err != nil {
defer utils.UncheckedErrorFunc(file.Close)
return nil, err
}
return chunk[:bytesRead], err
}
return f, nil
}
func createBaseSceneConfig(
startInput []referenceframe.Input,
goalPose spatialmath.Pose,
artifactPath string,
) (*motionplan.PlanRequest, error) {
injectSlam := inject.NewSLAMService("test_slam")
injectSlam.PointCloudMapFunc = func(ctx context.Context, returnEditedMap bool) (func() ([]byte, error), error) {
return getPointCloudMap(filepath.Clean(artifact.MustPath(artifactPath)))
}
injectSlam.PositionFunc = func(ctx context.Context) (spatialmath.Pose, error) {
return spatialmath.NewZeroPose(), nil
}
// create fake base
baseCfg := resource.Config{
Name: "test_base",
API: base.API,
Frame: &referenceframe.LinkConfig{Geometry: &spatialmath.GeometryConfig{R: 20}},
}
ms := inject.NewMovementSensor("movement_sensor")
gpOrigin := geo.NewPoint(0, 0)
ms.PositionFunc = func(ctx context.Context, extra map[string]interface{}) (*geo.Point, float64, error) {
return gpOrigin, 0, nil
}
ms.CompassHeadingFunc = func(ctx context.Context, extra map[string]interface{}) (float64, error) {
return 0, nil
}
ms.PropertiesFunc = func(ctx context.Context, extra map[string]interface{}) (*movementsensor.Properties, error) {
return &movementsensor.Properties{CompassHeadingSupported: true}, nil
}
localizer := motion.NewMovementSensorLocalizer(ms, gpOrigin, spatialmath.NewZeroPose())
fakeBase, _ := fake.NewBase(context.Background(), nil, baseCfg, logger)
kb, _ := kinematicbase.WrapWithKinematics(
context.Background(),
fakeBase.(*fake.Base),
logger,
localizer,
nil,
kinematicbase.NewKinematicBaseOptions(),
)
// Add frame system and needed frames
fs := referenceframe.NewEmptyFrameSystem("test")
fs.AddFrame(kb.Kinematics(), fs.World())
// get point cloud data in the form of bytes from pcd
pointCloudData, _ := slam.PointCloudMapFull(context.Background(), injectSlam, false)
// store slam point cloud data in the form of a recursive octree for collision checking
octree, _ := pointcloud.ReadPCDToBasicOctree(bytes.NewReader(pointCloudData))
worldState, _ := referenceframe.NewWorldState([]*referenceframe.GeometriesInFrame{
referenceframe.NewGeometriesInFrame(referenceframe.World, []spatialmath.Geometry{octree}),
}, nil)
startMap := referenceframe.StartPositions(fs)
return &motionplan.PlanRequest{
StartConfiguration: startMap,
Goal: referenceframe.NewPoseInFrame(referenceframe.World, goalPose),
Frame: kb.Kinematics(),
WorldState: worldState,
FrameSystem: fs,
StartPose: spatialmath.NewZeroPose(),
}, nil
}
func scene13() (*motionplan.PlanRequest, error) {
startInput := referenceframe.FloatsToInputs([]float64{0, 0, 0})
goalPose := spatialmath.NewPoseFromPoint(r3.Vector{X: 0.277 * 1000, Y: 0.593 * 1000})
return createBaseSceneConfig(startInput, goalPose, "pointcloud/octagonspace.pcd")
}
func scene14() (*motionplan.PlanRequest, error) {
startInput := referenceframe.FloatsToInputs([]float64{0, 0, 0})
goalPose := spatialmath.NewPoseFromPoint(r3.Vector{X: 1.32 * 1000, Y: 0})
return createBaseSceneConfig(startInput, goalPose, "pointcloud/octagonspace.pcd")
}
func scene15() (*motionplan.PlanRequest, error) {
startInput := referenceframe.FloatsToInputs([]float64{-6.905 * 1000, 0.623 * 1000, 0})
goalPose := spatialmath.NewPoseFromPoint(r3.Vector{X: -29.164 * 1000, Y: 3.433 * 1000})
return createBaseSceneConfig(startInput, goalPose, "slam/example_cartographer_outputs/viam-office-02-22-3/pointcloud/pointcloud_4.pcd")
}
func scene16() (*motionplan.PlanRequest, error) {
startInput := referenceframe.FloatsToInputs([]float64{-19.376 * 1000, 2.305 * 1000, 0})
goalPose := spatialmath.NewPoseFromPoint(r3.Vector{X: -27.946 * 1000, Y: -4.406 * 1000})
return createBaseSceneConfig(startInput, goalPose, "slam/example_cartographer_outputs/viam-office-02-22-3/pointcloud/pointcloud_4.pcd")
}
func scene17() (*motionplan.PlanRequest, error) {
startInput := referenceframe.FloatsToInputs([]float64{0, 0, 0})
goalPose := spatialmath.NewPoseFromPoint(r3.Vector{X: -5.959 * 1000, Y: -5.542 * 1000})
return createBaseSceneConfig(startInput, goalPose, "slam/example_cartographer_outputs/viam-office-02-22-3/pointcloud/pointcloud_4.pcd")
}
func scene18() (*motionplan.PlanRequest, error) {
startInput := referenceframe.FloatsToInputs([]float64{0, 0, 0})
goalPose := spatialmath.NewPoseFromPoint(r3.Vector{X: -52.555 * 1000, Y: -27.215 * 1000})
return createBaseSceneConfig(startInput, goalPose, "slam/example_cartographer_outputs/viam-office-02-22-3/pointcloud/pointcloud_4.pcd")
}