Skip to content

Commit a685e25

Browse files
committed
fix broken geometry and resulting broken tests for fake gantry
1 parent dd7a404 commit a685e25

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

components/gantry/fake/gantry.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fake
33

44
import (
55
"context"
6+
"fmt"
67

78
"github.com/golang/geo/r3"
89

@@ -34,22 +35,18 @@ func init() {
3435
func NewGantry(name resource.Name, logger logging.Logger) gantry.Gantry {
3536
m := referenceframe.NewSimpleModel("test_gantry")
3637
pose := spatialmath.NewZeroPose()
37-
baseRailGeom, err := spatialmath.NewBox(pose, r3.Vector{500, 100, 100}, "base_rail")
38+
carriageGeom, err := spatialmath.NewBox(pose, r3.Vector{150, 150, 10}, "carriage")
3839
if err != nil {
39-
logger.CErrorf(context.Background(), "could not create base rail geometry: %v", err)
40+
logger.CErrorf(context.Background(), "could not create carriage geometry: %v", err)
4041
}
41-
f, err := referenceframe.NewStaticFrameWithGeometry("base_rail", pose, baseRailGeom)
42+
f, err := referenceframe.NewStaticFrameWithGeometry("carriage", pose, carriageGeom)
4243
if err != nil {
4344
logger.CErrorf(context.Background(), "could not create static frame: %v", err)
4445
}
4546
m.SetOrdTransforms(append(m.OrdTransforms(), f))
4647

47-
carriageGeom, err := spatialmath.NewBox(pose, r3.Vector{150, 120, 10}, "carriage")
48-
if err != nil {
49-
logger.CErrorf(context.Background(), "could not create carriage geometry: %v", err)
50-
}
51-
f, err = referenceframe.NewTranslationalFrameWithGeometry(
52-
"carriage", r3.Vector{1, 0, 0}, referenceframe.Limit{Min: 0, Max: 500}, carriageGeom)
48+
f, err = referenceframe.NewTranslationalFrame(
49+
"gantry_joint", r3.Vector{1, 0, 0}, referenceframe.Limit{Min: 0, Max: 350})
5350
if err != nil {
5451
logger.CErrorf(context.Background(), "could not create translational frame: %v", err)
5552
}
@@ -59,10 +56,9 @@ func NewGantry(name resource.Name, logger logging.Logger) gantry.Gantry {
5956
testutils.NewUnimplementedResource(name),
6057
resource.TriviallyReconfigurable{},
6158
resource.TriviallyCloseable{},
62-
[]float64{1.2},
6359
[]float64{120},
64-
[]float64{5},
65-
2,
60+
[]float64{120},
61+
[]float64{350},
6662
m,
6763
logger,
6864
}
@@ -75,8 +71,7 @@ type Gantry struct {
7571
resource.TriviallyCloseable
7672
positionsMm []float64
7773
speedsMmPerSec []float64
78-
lengths []float64
79-
lengthMeters float64
74+
lengthsMm []float64
8075
model referenceframe.Model
8176
logger logging.Logger
8277
}
@@ -88,7 +83,7 @@ func (g *Gantry) Position(ctx context.Context, extra map[string]interface{}) ([]
8883

8984
// Lengths returns the position in meters.
9085
func (g *Gantry) Lengths(ctx context.Context, extra map[string]interface{}) ([]float64, error) {
91-
return g.lengths, nil
86+
return g.lengthsMm, nil
9287
}
9388

9489
// Home runs the homing sequence of the gantry and returns true once completed.
@@ -99,6 +94,12 @@ func (g *Gantry) Home(ctx context.Context, extra map[string]interface{}) (bool,
9994

10095
// MoveToPosition is in meters.
10196
func (g *Gantry) MoveToPosition(ctx context.Context, positionsMm, speedsMmPerSec []float64, extra map[string]interface{}) error {
97+
for i, position := range positionsMm {
98+
if position < 0 || position > g.lengthsMm[i] {
99+
return fmt.Errorf("position %v out of range [0, %v]", position, g.lengthsMm[i])
100+
}
101+
}
102+
102103
g.positionsMm = positionsMm
103104
g.speedsMmPerSec = speedsMmPerSec
104105
return nil

services/motion/builtin/builtin_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ func TestGetPose(t *testing.T) {
193193
pose, err := ms.GetPose(context.Background(), "gantry1", "", nil, map[string]interface{}{})
194194
test.That(t, err, test.ShouldBeNil)
195195
test.That(t, pose.Parent(), test.ShouldEqual, referenceframe.World)
196-
test.That(t, pose.Pose().Point().X, test.ShouldAlmostEqual, 1.2)
196+
test.That(t, pose.Pose().Point().X, test.ShouldAlmostEqual, 120)
197197
test.That(t, pose.Pose().Point().Y, test.ShouldAlmostEqual, 0)
198198
test.That(t, pose.Pose().Point().Z, test.ShouldAlmostEqual, 0)
199199

200200
pose, err = ms.GetPose(context.Background(), "arm1", "", nil, map[string]interface{}{})
201201
test.That(t, err, test.ShouldBeNil)
202202
test.That(t, pose.Parent(), test.ShouldEqual, referenceframe.World)
203-
test.That(t, pose.Pose().Point().X, test.ShouldAlmostEqual, 501.2)
203+
test.That(t, pose.Pose().Point().X, test.ShouldAlmostEqual, 620)
204204
test.That(t, pose.Pose().Point().Y, test.ShouldAlmostEqual, 0)
205205
test.That(t, pose.Pose().Point().Z, test.ShouldAlmostEqual, 300)
206206

@@ -233,7 +233,7 @@ func TestGetPose(t *testing.T) {
233233

234234
pose, err = ms.GetPose(context.Background(), "arm1", "testFrame2", transforms, map[string]interface{}{})
235235
test.That(t, err, test.ShouldBeNil)
236-
test.That(t, pose.Pose().Point().X, test.ShouldAlmostEqual, -501.2)
236+
test.That(t, pose.Pose().Point().X, test.ShouldAlmostEqual, -620)
237237
test.That(t, pose.Pose().Point().Y, test.ShouldAlmostEqual, 0)
238238
test.That(t, pose.Pose().Point().Z, test.ShouldAlmostEqual, -300)
239239
test.That(t, pose.Pose().Orientation().AxisAngles().RX, test.ShouldEqual, 0)

0 commit comments

Comments
 (0)