Skip to content

Commit

Permalink
Do not scale gantry collector returns from Lengths and Positions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
randhid authored Sep 16, 2024
1 parent c286163 commit 7d7a34a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
12 changes: 2 additions & 10 deletions components/gantry/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newPositionCollector(resource interface{}, params data.CollectorParams) (da
return nil, data.FailedToReadErr(params.ComponentName, position.String(), err)
}
return pb.GetPositionResponse{
PositionsMm: scaleMetersToMm(v),
PositionsMm: v,
}, nil
})
return data.NewCollector(cFunc, params)
Expand All @@ -71,20 +71,12 @@ func newLengthsCollector(resource interface{}, params data.CollectorParams) (dat
return nil, data.FailedToReadErr(params.ComponentName, lengths.String(), err)
}
return pb.GetLengthsResponse{
LengthsMm: scaleMetersToMm(v),
LengthsMm: v,
}, nil
})
return data.NewCollector(cFunc, params)
}

func scaleMetersToMm(meters []float64) []float64 {
ret := make([]float64, len(meters))
for i := range ret {
ret[i] = meters[i] * 1000
}
return ret
}

func assertGantry(resource interface{}) (Gantry, error) {
gantry, ok := resource.(Gantry)
if !ok {
Expand Down
15 changes: 4 additions & 11 deletions components/gantry/collectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (
numRetries = 5
)

var floatList = []float64{1.0, 2.0, 3.0}
// floatList is a lit of floats in units of millimeters.
var floatList = []float64{1000, 2000, 3000}

func TestGantryCollectors(t *testing.T) {
tests := []struct {
Expand All @@ -34,14 +35,14 @@ func TestGantryCollectors(t *testing.T) {
name: "Length collector should write a lengths response",
collector: gantry.NewLengthsCollector,
expected: tu.ToProtoMapIgnoreOmitEmpty(pb.GetLengthsResponse{
LengthsMm: scaleMetersToMm(floatList),
LengthsMm: floatList,
}),
},
{
name: "Position collector should write a list of positions",
collector: gantry.NewPositionCollector,
expected: tu.ToProtoMapIgnoreOmitEmpty(pb.GetPositionResponse{
PositionsMm: scaleMetersToMm(floatList),
PositionsMm: floatList,
}),
},
}
Expand Down Expand Up @@ -85,11 +86,3 @@ func newGantry() gantry.Gantry {
}
return g
}

func scaleMetersToMm(meters []float64) []float64 {
ret := make([]float64, len(meters))
for i := range ret {
ret[i] = meters[i] * 1000
}
return ret
}

0 comments on commit 7d7a34a

Please sign in to comment.