-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathptgKinematics_test.go
103 lines (81 loc) · 3.15 KB
/
ptgKinematics_test.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
// Package kinematicbase contains wrappers that augment bases with information needed for higher level
// control over the base
package kinematicbase
import (
"context"
"testing"
"github.com/edaniels/golog"
"github.com/golang/geo/r3"
"go.viam.com/test"
"go.viam.com/rdk/components/base/fake"
"go.viam.com/rdk/motionplan"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
)
func TestPTGKinematics(t *testing.T) {
logger := golog.NewTestLogger(t)
name, err := resource.NewFromString("is:a:fakebase")
test.That(t, err, test.ShouldBeNil)
b := &fake.Base{
Named: name.AsNamed(),
Geometry: []spatialmath.Geometry{},
WidthMeters: 0.2,
TurningRadius: 0.3,
}
ctx := context.Background()
kb, err := WrapWithKinematics(ctx, b, logger, nil, nil, NewKinematicBaseOptions())
test.That(t, err, test.ShouldBeNil)
test.That(t, kb, test.ShouldNotBeNil)
ptgBase, ok := kb.(*ptgBaseKinematics)
test.That(t, ok, test.ShouldBeTrue)
test.That(t, ptgBase, test.ShouldNotBeNil)
dstPIF := referenceframe.NewPoseInFrame(referenceframe.World, spatialmath.NewPoseFromPoint(r3.Vector{X: 999, Y: 0, Z: 0}))
fs := referenceframe.NewEmptyFrameSystem("test")
f := kb.Kinematics()
test.That(t, err, test.ShouldBeNil)
fs.AddFrame(f, fs.World())
inputMap := referenceframe.StartPositions(fs)
plan, err := motionplan.PlanMotion(ctx, logger, dstPIF, f, inputMap, fs, nil, nil, nil)
test.That(t, err, test.ShouldBeNil)
test.That(t, plan, test.ShouldNotBeNil)
}
func TestPTGKinematicsWithGeom(t *testing.T) {
logger := golog.NewTestLogger(t)
name, err := resource.NewFromString("is:a:fakebase")
test.That(t, err, test.ShouldBeNil)
baseGeom, err := spatialmath.NewBox(spatialmath.NewZeroPose(), r3.Vector{1, 1, 1}, "")
test.That(t, err, test.ShouldBeNil)
b := &fake.Base{
Named: name.AsNamed(),
Geometry: []spatialmath.Geometry{baseGeom},
WidthMeters: 0.2,
TurningRadius: 0.3,
}
ctx := context.Background()
kbOpt := NewKinematicBaseOptions()
kbOpt.AngularVelocityDegsPerSec = 0
kb, err := WrapWithKinematics(ctx, b, logger, nil, nil, kbOpt)
test.That(t, err, test.ShouldBeNil)
test.That(t, kb, test.ShouldNotBeNil)
ptgBase, ok := kb.(*ptgBaseKinematics)
test.That(t, ok, test.ShouldBeTrue)
test.That(t, ptgBase, test.ShouldNotBeNil)
dstPIF := referenceframe.NewPoseInFrame(referenceframe.World, spatialmath.NewPoseFromPoint(r3.Vector{X: 2000, Y: 0, Z: 0}))
fs := referenceframe.NewEmptyFrameSystem("test")
f := kb.Kinematics()
test.That(t, err, test.ShouldBeNil)
fs.AddFrame(f, fs.World())
inputMap := referenceframe.StartPositions(fs)
obstacle, err := spatialmath.NewBox(spatialmath.NewPoseFromPoint(r3.Vector{1000, 0, 0}), r3.Vector{1, 1, 1}, "")
test.That(t, err, test.ShouldBeNil)
geoms := []spatialmath.Geometry{obstacle}
worldState, err := referenceframe.NewWorldState(
[]*referenceframe.GeometriesInFrame{referenceframe.NewGeometriesInFrame(referenceframe.World, geoms)},
nil,
)
test.That(t, err, test.ShouldBeNil)
plan, err := motionplan.PlanMotion(ctx, logger, dstPIF, f, inputMap, fs, worldState, nil, nil)
test.That(t, err, test.ShouldBeNil)
test.That(t, plan, test.ShouldNotBeNil)
}