From f90689b1707dc9f5f07a823dcb95175d6a0e3903 Mon Sep 17 00:00:00 2001 From: randhid <35934754+randhid@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:05:18 -0500 Subject: [PATCH] Add check for Position Supported in dualgps creator (#4527) Co-authored-by: martha-johnston <106617924+martha-johnston@users.noreply.github.com> --- components/movementsensor/dualgps/dualgps.go | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/components/movementsensor/dualgps/dualgps.go b/components/movementsensor/dualgps/dualgps.go index 19f99a409d3..8fdde97b398 100644 --- a/components/movementsensor/dualgps/dualgps.go +++ b/components/movementsensor/dualgps/dualgps.go @@ -5,11 +5,13 @@ package dualgps import ( "context" "errors" + "fmt" "math" "sync" "github.com/golang/geo/r3" geo "github.com/kellydunn/golang-geo" + "go.uber.org/multierr" "go.viam.com/rdk/components/movementsensor" "go.viam.com/rdk/logging" @@ -114,14 +116,41 @@ func (dg *dualGPS) Reconfigure(ctx context.Context, deps resource.Dependencies, if err != nil { return err } + + firstProps, err := first.Properties(ctx, nil) + if err != nil { + return err + } dg.gps1 = first second, err := movementsensor.FromDependencies(deps, newConf.Gps2) if err != nil { return err } + secondProps, err := second.Properties(ctx, nil) + if err != nil { + return err + } dg.gps2 = second + var errs error + if !firstProps.PositionSupported { + errs = multierr.Combine( + errs, + fmt.Errorf( + "configured movement sensor %v does not support reporting its Position, it cannot be used for dual-gps calculations", + first.Name().ShortName())) + } + if !secondProps.PositionSupported { + errs = multierr.Combine(errs, + fmt.Errorf( + "configured movement sensor %v does not support reporting its Position, it cannot be used for dual-gps calculations", + second.Name().ShortName())) + } + if errs != nil { + return errs + } + dg.offset = defaultOffsetDegrees if newConf.Offset != nil { dg.offset = *newConf.Offset