Skip to content

Commit

Permalink
Rsdk-2806: Movement sensor distance to meters (viamrobotics#2275)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebriskin authored Apr 25, 2023
1 parent d78da27 commit d31e0ee
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions components/movementsensor/adxl345/adxl345.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ func toLinearAcceleration(data []byte) r3.Vector {
y := int(rutils.Int16FromBytesLE(data[2:4]))
z := int(rutils.Int16FromBytesLE(data[4:6]))

// The default scale is +/- 2G's, but our units should be mm/sec/sec.
maxAcceleration := 2.0 * 9.81 /* m/sec/sec */ * 1000.0 /* mm/m */
// The default scale is +/- 2G's, but our units should be m/sec/sec.
maxAcceleration := 2.0 * 9.81 /* m/sec/sec */
return r3.Vector{
X: setScale(x, maxAcceleration),
Y: setScale(y, maxAcceleration),
Expand Down
4 changes: 2 additions & 2 deletions components/movementsensor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *client) Position(ctx context.Context, extra map[string]interface{}) (*g
return nil, 0, err
}
return geo.NewPoint(resp.Coordinate.Latitude, resp.Coordinate.Longitude),
float64(resp.AltitudeMm),
float64(resp.AltitudeM),
nil
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (c *client) Accuracy(ctx context.Context, extra map[string]interface{}) (ma
if err != nil {
return nil, err
}
return resp.AccuracyMm, nil
return resp.Accuracy, nil
}

func (c *client) Properties(ctx context.Context, extra map[string]interface{}) (*Properties, error) {
Expand Down
10 changes: 5 additions & 5 deletions components/movementsensor/gpsnmea/nmeaParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

const (
knotsToMmPerSec = 514.44
kphToMmPerSec = 277.78
knotsToMPerSec = 0.51444
kphToMPerSec = 0.27778
)

type gpsData struct {
location *geo.Point
alt float64
speed float64 // ground speed in mm per sec
speed float64 // ground speed in m per sec
vDOP float64 // vertical accuracy
hDOP float64 // horizontal accuracy
satsInView int // quantity satellites in view
Expand Down Expand Up @@ -60,7 +60,7 @@ func (g *gpsData) parseAndUpdate(line string) error {
errs = multierr.Combine(errs, errInvalidFix(rmc.Type, rmc.Validity, "A"))
}
if g.valid {
g.speed = rmc.Speed * knotsToMmPerSec
g.speed = rmc.Speed * knotsToMPerSec
g.location = geo.NewPoint(rmc.Latitude, rmc.Longitude)
}
} else if gsa, ok := s.(nmea.GSA); ok {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (g *gpsData) parseAndUpdate(line string) error {
g.location = now
} else if vtg, ok := s.(nmea.VTG); ok {
// VTG provides ground speed
g.speed = vtg.GroundSpeedKPH * kphToMmPerSec
g.speed = vtg.GroundSpeedKPH * kphToMPerSec
} else if gns, ok := s.(nmea.GNS); ok {
// GNS Provides approximately the same information as GGA
for _, mode := range gns.Mode {
Expand Down
4 changes: 2 additions & 2 deletions components/movementsensor/gpsnmea/nmeaParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func TestParsing(t *testing.T) {
nmeaSentence = "$GNVTG,176.25,T,,M,0.13,N,0.25,K,A*21"
err = data.parseAndUpdate(nmeaSentence)
test.That(t, err, test.ShouldBeNil)
test.That(t, data.speed, test.ShouldEqual, 69.445)
test.That(t, data.speed, test.ShouldEqual, 0.069445)

// Test RMC, should update speed and position
nmeaSentence = "$GNRMC,191352.000,A,4503.4656,N,13118.7951,W,0.04,90.29,011021,,,A*59"
err = data.parseAndUpdate(nmeaSentence)
test.That(t, err, test.ShouldBeNil)
test.That(t, data.speed, test.ShouldAlmostEqual, 20.5776)
test.That(t, data.speed, test.ShouldAlmostEqual, 0.0205776)
test.That(t, data.location.Lat(), test.ShouldAlmostEqual, 45.05776, 0.001)
test.That(t, data.location.Lng(), test.ShouldAlmostEqual, -131.31325, 0.001)

Expand Down
8 changes: 4 additions & 4 deletions components/movementsensor/movementsensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func Named(name string) resource.Name {
// A MovementSensor reports information about the robot's direction, position and speed.
type MovementSensor interface {
sensor.Sensor
Position(ctx context.Context, extra map[string]interface{}) (*geo.Point, float64, error) // (lat, long), altitude (mm)
LinearVelocity(ctx context.Context, extra map[string]interface{}) (r3.Vector, error) // mm / sec
AngularVelocity(ctx context.Context, extra map[string]interface{}) (spatialmath.AngularVelocity, error) // radians / sec
Position(ctx context.Context, extra map[string]interface{}) (*geo.Point, float64, error) // (lat, long), altitude (m)
LinearVelocity(ctx context.Context, extra map[string]interface{}) (r3.Vector, error) // m / sec
AngularVelocity(ctx context.Context, extra map[string]interface{}) (spatialmath.AngularVelocity, error) // deg / sec
LinearAcceleration(ctx context.Context, extra map[string]interface{}) (r3.Vector, error)
CompassHeading(ctx context.Context, extra map[string]interface{}) (float64, error) // [0->360)
Orientation(ctx context.Context, extra map[string]interface{}) (spatialmath.Orientation, error)
Properties(ctx context.Context, extra map[string]interface{}) (*Properties, error)
Accuracy(ctx context.Context, extra map[string]interface{}) (map[string]float32, error) // in mm
Accuracy(ctx context.Context, extra map[string]interface{}) (map[string]float32, error)
}

// FromDependencies is a helper for getting the named movementsensor from a collection of
Expand Down
4 changes: 2 additions & 2 deletions components/movementsensor/mpu6050/mpu6050.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func toLinearAcceleration(data []byte) r3.Vector {
y := int(rutils.Int16FromBytesBE(data[2:4]))
z := int(rutils.Int16FromBytesBE(data[4:6]))

// The scale is +/- 2G's, but our units should be mm/sec/sec.
maxAcceleration := 2.0 * 9.81 /* m/sec/sec */ * 1000.0 /* mm/m */
// The scale is +/- 2G's, but our units should be m/sec/sec.
maxAcceleration := 2.0 * 9.81 /* m/sec/sec */
return r3.Vector{
X: setScale(x, maxAcceleration),
Y: setScale(y, maxAcceleration),
Expand Down
6 changes: 3 additions & 3 deletions components/movementsensor/mpu6050/mpu6050_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ func TestLinearAcceleration(t *testing.T) {
// x-accel
linearAccelMockData[0] = 64
linearAccelMockData[1] = 0
expectedAccelX := 9810.0
expectedAccelX := 9.81
// y-accel
linearAccelMockData[2] = 32
linearAccelMockData[3] = 0
expectedAccelY := 4905.0
expectedAccelY := 4.905
// z-accel
linearAccelMockData[4] = 16
linearAccelMockData[5] = 0
expectedAccelZ := 2452.5
expectedAccelZ := 2.4525

logger := golog.NewTestLogger(t)
cfg, deps := setupDependencies(linearAccelMockData)
Expand Down
4 changes: 2 additions & 2 deletions components/movementsensor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *serviceServer) GetPosition(
}
return &pb.GetPositionResponse{
Coordinate: &commonpb.GeoPoint{Latitude: loc.Lat(), Longitude: loc.Lng()},
AltitudeMm: float32(altitide),
AltitudeM: float32(altitide),
}, nil
}

Expand Down Expand Up @@ -128,7 +128,7 @@ func (s *serviceServer) GetAccuracy(
return nil, err
}
acc, err := msDevice.Accuracy(ctx, req.Extra.AsMap())
return &pb.GetAccuracyResponse{AccuracyMm: acc}, err
return &pb.GetAccuracyResponse{Accuracy: acc}, err
}

func (s *serviceServer) GetLinearAcceleration(
Expand Down
4 changes: 2 additions & 2 deletions components/movementsensor/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestServer(t *testing.T) {
resp, err := gpsServer.GetPosition(context.Background(), &pb.GetPositionRequest{Name: testMovementSensorName, Extra: ext})
test.That(t, err, test.ShouldBeNil)
test.That(t, resp.Coordinate, test.ShouldResemble, &commonpb.GeoPoint{Latitude: loc.Lat(), Longitude: loc.Lng()})
test.That(t, resp.AltitudeMm, test.ShouldEqual, alt)
test.That(t, resp.AltitudeM, test.ShouldEqual, alt)
test.That(t, injectMovementSensor.PositionFuncExtraCap, test.ShouldResemble, map[string]interface{}{"foo": "bar"})

_, err = gpsServer.GetPosition(context.Background(), &pb.GetPositionRequest{Name: failMovementSensorName})
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestServer(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
resp, err := gpsServer.GetAccuracy(context.Background(), &pb.GetAccuracyRequest{Name: testMovementSensorName, Extra: ext})
test.That(t, err, test.ShouldBeNil)
test.That(t, resp.AccuracyMm, test.ShouldResemble, acc)
test.That(t, resp.Accuracy, test.ShouldResemble, acc)
test.That(t, injectMovementSensor.AccuracyFuncExtraCap, test.ShouldResemble, map[string]interface{}{"foo": "bar"})

_, err = gpsServer.GetAccuracy(context.Background(), &pb.GetAccuracyRequest{Name: failMovementSensorName})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ require (
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
go.viam.com/api v0.1.115
go.viam.com/api v0.1.116
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2
go.viam.com/utils v0.1.20-0.20230424163529-ce35a14fc60f
goji.io v2.0.2+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,8 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
go.viam.com/api v0.1.115 h1:IxAYIeqmXa50rDoxzYJFFgnnahvkUw+IZSPrG12NLEM=
go.viam.com/api v0.1.115/go.mod h1:NQC9FZnerAfIPJLJ42vgzQMoe1WAQRuVoQEf1JauxtQ=
go.viam.com/api v0.1.116 h1:SCbdbupYffojulWFcVfNjXXxqvPm0czytfCg4H2ZbE0=
go.viam.com/api v0.1.116/go.mod h1:NQC9FZnerAfIPJLJ42vgzQMoe1WAQRuVoQEf1JauxtQ=
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 h1:oBiK580EnEIzgFLU4lHOXmGAE3MxnVbeR7s1wp/F3Ps=
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2/go.mod h1:XM0tej6riszsiNLT16uoyq1YjuYPWlRBweTPRDanIts=
go.viam.com/utils v0.1.20-0.20230424163529-ce35a14fc60f h1:wvJ/Au+UfSgXRj9RgoapLGYK/ZLj2pSKbq6DbPw3tqM=
Expand Down
32 changes: 16 additions & 16 deletions web/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions web/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"peerDependencies": {
"@viamrobotics/sdk": "0.0.44"
"@viamrobotics/sdk": "^0.0.47"
},
"dependencies": {
"@fontsource/space-mono": "^4.5.12",
Expand All @@ -33,7 +33,7 @@
"@types/google.maps": "^3.52.4",
"@types/three": "^0.150.1",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@viamrobotics/sdk": "0.0.44",
"@viamrobotics/sdk": "^0.0.47",
"@vitejs/plugin-vue": "^4.1.0",
"cypress": "^10.10.0",
"eslint": "^8.37.0",
Expand Down Expand Up @@ -68,4 +68,4 @@
"cypress": "cypress open",
"test:unit": "echo \"no tests exist yet\""
}
}
}
12 changes: 6 additions & 6 deletions web/frontend/src/components/movement-sensor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let linearVelocity = $ref<commonApi.Vector3.AsObject | undefined>();
let linearAcceleration = $ref<commonApi.Vector3.AsObject | undefined>();
let compassHeading = $ref<number | undefined>();
let coordinate = $ref<commonApi.GeoPoint.AsObject | undefined>();
let altitudeMm = $ref<number | undefined>();
let altitudeM = $ref<number | undefined>();
let properties = $ref<movementsensorApi.GetPropertiesResponse.AsObject | undefined>();
let refreshId = -1;
Expand Down Expand Up @@ -151,7 +151,7 @@ const refresh = async () => {
const temp = resp!.toObject();
coordinate = temp.coordinate;
altitudeMm = temp.altitudeMm;
altitudeM = temp.altitudeM;
}
);
}
Expand Down Expand Up @@ -206,10 +206,10 @@ onUnmounted(() => {
</tr>
<tr>
<th class="border-border-1 border p-2">
Altitide
Altitide (m)
</th>
<td class="border-border-1 border p-2">
{{ altitudeMm?.toFixed(2) }}
{{ altitudeM?.toFixed(2) }}
</td>
</tr>
</table>
Expand Down Expand Up @@ -304,7 +304,7 @@ onUnmounted(() => {
class="overflow-auto"
>
<h3 class="mb-1">
Linear Velocity
Linear Velocity (m/s)
</h3>
<table class="border-border-1 w-full border border-t-0 p-4">
<tr>
Expand Down Expand Up @@ -339,7 +339,7 @@ onUnmounted(() => {
class="overflow-auto"
>
<h3 class="mb-1">
Linear Acceleration (mm/second^2)
Linear Acceleration (m/second^2)
</h3>
<table class="border-border-1 w-full border border-t-0 p-4">
<tr>
Expand Down

0 comments on commit d31e0ee

Please sign in to comment.