Skip to content

Commit

Permalink
RSDK-3979 - Remove "Get" from slam service method names (viamrobotics…
Browse files Browse the repository at this point in the history
  • Loading branch information
kkufieta authored Aug 31, 2023
1 parent 307beb7 commit ddd4ef6
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 191 deletions.
4 changes: 2 additions & 2 deletions components/base/kinematicbase/differentialDrive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestErrorState(t *testing.T) {

// make injected slam service
slam := inject.NewSLAMService("the slammer")
slam.GetPositionFunc = func(ctx context.Context) (spatialmath.Pose, string, error) {
slam.PositionFunc = func(ctx context.Context) (spatialmath.Pose, string, error) {
return spatialmath.NewZeroPose(), "", nil
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func buildTestDDK(

// make a SLAM service and get its limits
fakeSLAM := fake.NewSLAM(slam.Named("test"), logger)
limits, err := fakeSLAM.GetLimits(ctx)
limits, err := fakeSLAM.Limits(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion components/base/kinematicbase/fake_kinematics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestNewFakeKinematics(t *testing.T) {
b, err := fakebase.NewBase(ctx, resource.Dependencies{}, conf, logger)
test.That(t, err, test.ShouldBeNil)
fakeSLAM := fake.NewSLAM(slam.Named("test"), logger)
limits, err := fakeSLAM.GetLimits(ctx)
limits, err := fakeSLAM.Limits(ctx)
test.That(t, err, test.ShouldBeNil)
limits = append(limits, referenceframe.Limit{-2 * math.Pi, 2 * math.Pi})

Expand Down
4 changes: 2 additions & 2 deletions services/motion/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (ms *builtIn) planMoveOnMap(
}

// gets the extents of the SLAM map
limits, err := slam.GetLimits(ctx, slamSvc)
limits, err := slam.Limits(ctx, slamSvc)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -492,7 +492,7 @@ func (ms *builtIn) planMoveOnMap(
}

// get point cloud data in the form of bytes from pcd
pointCloudData, err := slam.GetPointCloudMapFull(ctx, slamSvc)
pointCloudData, err := slam.PointCloudMapFull(ctx, slamSvc)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions services/motion/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ func createInjectedMovementSensor(name string, gpsPoint *geo.Point) *inject.Move

func createInjectedSlam(name, pcdPath string) *inject.SLAMService {
injectSlam := inject.NewSLAMService(name)
injectSlam.GetPointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
injectSlam.PointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
return getPointCloudMap(filepath.Clean(artifact.MustPath(pcdPath)))
}
injectSlam.GetPositionFunc = func(ctx context.Context) (spatialmath.Pose, string, error) {
injectSlam.PositionFunc = func(ctx context.Context) (spatialmath.Pose, string, error) {
return spatialmath.NewZeroPose(), "", nil
}
return injectSlam
Expand Down
2 changes: 1 addition & 1 deletion services/motion/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewSLAMLocalizer(slam slam.Service) Localizer {

// CurrentPosition returns slam's current position.
func (s *slamLocalizer) CurrentPosition(ctx context.Context) (*referenceframe.PoseInFrame, error) {
pose, _, err := s.GetPosition(ctx)
pose, _, err := s.Position(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion services/navigation/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestStartWaypoint(t *testing.T) {
test.That(t, err, test.ShouldBeNil)

fakeSlam := fakeslam.NewSLAM(slam.Named("foo"), logger)
limits, err := fakeSlam.GetLimits(ctx)
limits, err := fakeSlam.Limits(ctx)
test.That(t, err, test.ShouldBeNil)

localizer := motion.NewSLAMLocalizer(fakeSlam)
Expand Down
28 changes: 14 additions & 14 deletions services/slam/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func NewClientFromConn(
return c, nil
}

// GetPosition creates a request, calls the slam service GetPosition, and parses the response into a Pose with a component reference string.
func (c *client) GetPosition(ctx context.Context) (spatialmath.Pose, string, error) {
ctx, span := trace.StartSpan(ctx, "slam::client::GetPosition")
// Position creates a request, calls the slam service Position, and parses the response into a Pose with a component reference string.
func (c *client) Position(ctx context.Context) (spatialmath.Pose, string, error) {
ctx, span := trace.StartSpan(ctx, "slam::client::Position")
defer span.End()

req := &pb.GetPositionRequest{
Expand All @@ -64,28 +64,28 @@ func (c *client) GetPosition(ctx context.Context) (spatialmath.Pose, string, err
return spatialmath.NewPoseFromProtobuf(p), componentReference, nil
}

// GetPointCloudMap creates a request, calls the slam service GetPointCloudMap and returns a callback
// PointCloudMap creates a request, calls the slam service PointCloudMap and returns a callback
// function which will return the next chunk of the current pointcloud map when called.
func (c *client) GetPointCloudMap(ctx context.Context) (func() ([]byte, error), error) {
ctx, span := trace.StartSpan(ctx, "slam::client::GetPointCloudMap")
func (c *client) PointCloudMap(ctx context.Context) (func() ([]byte, error), error) {
ctx, span := trace.StartSpan(ctx, "slam::client::PointCloudMap")
defer span.End()

return grpchelper.GetPointCloudMapCallback(ctx, c.name, c.client)
return grpchelper.PointCloudMapCallback(ctx, c.name, c.client)
}

// GetInternalState creates a request, calls the slam service GetInternalState and returns a callback
// InternalState creates a request, calls the slam service InternalState and returns a callback
// function which will return the next chunk of the current internal state of the slam algo when called.
func (c *client) GetInternalState(ctx context.Context) (func() ([]byte, error), error) {
ctx, span := trace.StartSpan(ctx, "slam::client::GetInternalState")
func (c *client) InternalState(ctx context.Context) (func() ([]byte, error), error) {
ctx, span := trace.StartSpan(ctx, "slam::client::InternalState")
defer span.End()

return grpchelper.GetInternalStateCallback(ctx, c.name, c.client)
return grpchelper.InternalStateCallback(ctx, c.name, c.client)
}

// GetLatestMapInfo creates a request, calls the slam service GetLatestMapInfo, and
// LatestMapInfo creates a request, calls the slam service LatestMapInfo, and
// returns the timestamp of the last update to the map.
func (c *client) GetLatestMapInfo(ctx context.Context) (time.Time, error) {
ctx, span := trace.StartSpan(ctx, "slam::client::GetLatestMapInfo")
func (c *client) LatestMapInfo(ctx context.Context) (time.Time, error) {
ctx, span := trace.StartSpan(ctx, "slam::client::LatestMapInfo")
defer span.End()

req := &pb.GetLatestMapInfoRequest{
Expand Down
96 changes: 48 additions & 48 deletions services/slam/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func TestClientWorkingService(t *testing.T) {

workingSLAMService := &inject.SLAMService{}

workingSLAMService.GetPositionFunc = func(ctx context.Context) (spatial.Pose, string, error) {
workingSLAMService.PositionFunc = func(ctx context.Context) (spatial.Pose, string, error) {
return poseSucc, componentRefSucc, nil
}

workingSLAMService.GetPointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
workingSLAMService.PointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
reader := bytes.NewReader(pcd)
clientBuffer := make([]byte, chunkSizePointCloud)
f := func() ([]byte, error) {
Expand All @@ -74,7 +74,7 @@ func TestClientWorkingService(t *testing.T) {
return f, nil
}

workingSLAMService.GetInternalStateFunc = func(ctx context.Context) (func() ([]byte, error), error) {
workingSLAMService.InternalStateFunc = func(ctx context.Context) (func() ([]byte, error), error) {
reader := bytes.NewReader(internalStateSucc)
clientBuffer := make([]byte, chunkSizeInternalState)
f := func() ([]byte, error) {
Expand All @@ -88,7 +88,7 @@ func TestClientWorkingService(t *testing.T) {
return f, nil
}

workingSLAMService.GetLatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
workingSLAMService.LatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
return timestampSucc, nil
}

Expand Down Expand Up @@ -118,27 +118,27 @@ func TestClientWorkingService(t *testing.T) {

workingSLAMClient, err := slam.NewClientFromConn(context.Background(), conn, "", slam.Named(nameSucc), logger)
test.That(t, err, test.ShouldBeNil)
// test get position
pose, componentRef, err := workingSLAMClient.GetPosition(context.Background())
// test position
pose, componentRef, err := workingSLAMClient.Position(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, spatial.PoseAlmostEqual(poseSucc, pose), test.ShouldBeTrue)
test.That(t, componentRef, test.ShouldEqual, componentRefSucc)

// test get point cloud map
fullBytesPCD, err := slam.GetPointCloudMapFull(context.Background(), workingSLAMClient)
// test point cloud map
fullBytesPCD, err := slam.PointCloudMapFull(context.Background(), workingSLAMClient)
test.That(t, err, test.ShouldBeNil)
// comparing raw bytes to ensure order is correct
test.That(t, fullBytesPCD, test.ShouldResemble, pcd)
// comparing pointclouds to ensure PCDs are correct
testhelper.TestComparePointCloudsFromPCDs(t, fullBytesPCD, pcd)

// test get internal state
fullBytesInternalState, err := slam.GetInternalStateFull(context.Background(), workingSLAMClient)
// test internal state
fullBytesInternalState, err := slam.InternalStateFull(context.Background(), workingSLAMClient)
test.That(t, err, test.ShouldBeNil)
test.That(t, fullBytesInternalState, test.ShouldResemble, internalStateSucc)

// test get latest map info
timestamp, err := workingSLAMClient.GetLatestMapInfo(context.Background())
// test latest map info
timestamp, err := workingSLAMClient.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, timestamp, test.ShouldResemble, timestampSucc)

Expand All @@ -151,27 +151,27 @@ func TestClientWorkingService(t *testing.T) {
workingDialedClient, err := slam.NewClientFromConn(context.Background(), conn, "", slam.Named(nameSucc), logger)
test.That(t, err, test.ShouldBeNil)

// test get position
pose, componentRef, err := workingDialedClient.GetPosition(context.Background())
// test position
pose, componentRef, err := workingDialedClient.Position(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, spatial.PoseAlmostEqual(poseSucc, pose), test.ShouldBeTrue)
test.That(t, componentRef, test.ShouldEqual, componentRefSucc)

// test get point cloud map
fullBytesPCD, err := slam.GetPointCloudMapFull(context.Background(), workingDialedClient)
// test point cloud map
fullBytesPCD, err := slam.PointCloudMapFull(context.Background(), workingDialedClient)
test.That(t, err, test.ShouldBeNil)
// comparing raw bytes to ensure order is correct
test.That(t, fullBytesPCD, test.ShouldResemble, pcd)
// comparing pointclouds to ensure PCDs are correct
testhelper.TestComparePointCloudsFromPCDs(t, fullBytesPCD, pcd)

// test get internal state
fullBytesInternalState, err := slam.GetInternalStateFull(context.Background(), workingDialedClient)
// test internal state
fullBytesInternalState, err := slam.InternalStateFull(context.Background(), workingDialedClient)
test.That(t, err, test.ShouldBeNil)
test.That(t, fullBytesInternalState, test.ShouldResemble, internalStateSucc)

// test get latest map info
timestamp, err := workingDialedClient.GetLatestMapInfo(context.Background())
// test latest map info
timestamp, err := workingDialedClient.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, timestamp, test.ShouldResemble, timestampSucc)

Expand All @@ -192,27 +192,27 @@ func TestClientWorkingService(t *testing.T) {
dialedClient, err := resourceAPI.RPCClient(context.Background(), conn, "", slam.Named(nameSucc), logger)
test.That(t, err, test.ShouldBeNil)

// test get position
pose, componentRef, err := dialedClient.GetPosition(context.Background())
// test position
pose, componentRef, err := dialedClient.Position(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, spatial.PoseAlmostEqual(poseSucc, pose), test.ShouldBeTrue)
test.That(t, componentRef, test.ShouldEqual, componentRefSucc)

// test get point cloud map
fullBytesPCD, err := slam.GetPointCloudMapFull(context.Background(), dialedClient)
// test point cloud map
fullBytesPCD, err := slam.PointCloudMapFull(context.Background(), dialedClient)
test.That(t, err, test.ShouldBeNil)
// comparing raw bytes to ensure order is correct
test.That(t, fullBytesPCD, test.ShouldResemble, pcd)
// comparing pointclouds to ensure PCDs are correct
testhelper.TestComparePointCloudsFromPCDs(t, fullBytesPCD, pcd)

// test get internal state
fullBytesInternalState, err := slam.GetInternalStateFull(context.Background(), dialedClient)
// test internal state
fullBytesInternalState, err := slam.InternalStateFull(context.Background(), dialedClient)
test.That(t, err, test.ShouldBeNil)
test.That(t, fullBytesInternalState, test.ShouldResemble, internalStateSucc)

// test get latest map info
timestamp, err := dialedClient.GetLatestMapInfo(context.Background())
// test latest map info
timestamp, err := dialedClient.LatestMapInfo(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, timestamp, test.ShouldResemble, timestampSucc)

Expand All @@ -235,19 +235,19 @@ func TestFailingClient(t *testing.T) {

failingSLAMService := &inject.SLAMService{}

failingSLAMService.GetPositionFunc = func(ctx context.Context) (spatial.Pose, string, error) {
failingSLAMService.PositionFunc = func(ctx context.Context) (spatial.Pose, string, error) {
return nil, "", errors.New("failure to get position")
}

failingSLAMService.GetPointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
failingSLAMService.PointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
return nil, errors.New("failure during get pointcloud map")
}

failingSLAMService.GetInternalStateFunc = func(ctx context.Context) (func() ([]byte, error), error) {
failingSLAMService.InternalStateFunc = func(ctx context.Context) (func() ([]byte, error), error) {
return nil, errors.New("failure during get internal state")
}

failingSLAMService.GetLatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
failingSLAMService.LatestMapInfoFunc = func(ctx context.Context) (time.Time, error) {
return time.Time{}, errors.New("failure to get latest map info")
}

Expand All @@ -273,43 +273,43 @@ func TestFailingClient(t *testing.T) {
ctx := context.Background()
cancelCtx, cancelFunc := context.WithCancel(ctx)
cancelFunc()
_, err = failingSLAMClient.GetPointCloudMap(cancelCtx)
_, err = failingSLAMClient.PointCloudMap(cancelCtx)
test.That(t, err.Error(), test.ShouldContainSubstring, "context cancel")
_, err = failingSLAMClient.GetInternalState(cancelCtx)
_, err = failingSLAMClient.InternalState(cancelCtx)
test.That(t, err.Error(), test.ShouldContainSubstring, "context cancel")

// test get position
pose, componentRef, err := failingSLAMClient.GetPosition(context.Background())
// test position
pose, componentRef, err := failingSLAMClient.Position(context.Background())
test.That(t, err.Error(), test.ShouldContainSubstring, "failure to get position")
test.That(t, pose, test.ShouldBeNil)
test.That(t, componentRef, test.ShouldBeEmpty)

// test get pointcloud map
fullBytesPCD, err := slam.GetPointCloudMapFull(context.Background(), failingSLAMClient)
// test pointcloud map
fullBytesPCD, err := slam.PointCloudMapFull(context.Background(), failingSLAMClient)
test.That(t, err.Error(), test.ShouldContainSubstring, "failure during get pointcloud map")
test.That(t, fullBytesPCD, test.ShouldBeNil)

// test get internal state
fullBytesInternalState, err := slam.GetInternalStateFull(context.Background(), failingSLAMClient)
// test internal state
fullBytesInternalState, err := slam.InternalStateFull(context.Background(), failingSLAMClient)
test.That(t, err.Error(), test.ShouldContainSubstring, "failure during get internal state")
test.That(t, fullBytesInternalState, test.ShouldBeNil)

// test get latest map info
timestamp, err := failingSLAMClient.GetLatestMapInfo(context.Background())
// test latest map info
timestamp, err := failingSLAMClient.LatestMapInfo(context.Background())
test.That(t, err.Error(), test.ShouldContainSubstring, "failure to get latest map info")
test.That(t, timestamp, test.ShouldResemble, time.Time{})

test.That(t, conn.Close(), test.ShouldBeNil)
})

failingSLAMService.GetPointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
failingSLAMService.PointCloudMapFunc = func(ctx context.Context) (func() ([]byte, error), error) {
f := func() ([]byte, error) {
return nil, errors.New("failure during callback")
}
return f, nil
}

failingSLAMService.GetInternalStateFunc = func(ctx context.Context) (func() ([]byte, error), error) {
failingSLAMService.InternalStateFunc = func(ctx context.Context) (func() ([]byte, error), error) {
f := func() ([]byte, error) {
return nil, errors.New("failure during callback")
}
Expand All @@ -323,13 +323,13 @@ func TestFailingClient(t *testing.T) {
failingSLAMClient, err := slam.NewClientFromConn(context.Background(), conn, "", slam.Named(nameFail), logger)
test.That(t, err, test.ShouldBeNil)

// test get pointcloud map
fullBytesPCD, err := slam.GetPointCloudMapFull(context.Background(), failingSLAMClient)
// test pointcloud map
fullBytesPCD, err := slam.PointCloudMapFull(context.Background(), failingSLAMClient)
test.That(t, err.Error(), test.ShouldContainSubstring, "failure during callback")
test.That(t, fullBytesPCD, test.ShouldBeNil)

// test get internal state
fullBytesInternalState, err := slam.GetInternalStateFull(context.Background(), failingSLAMClient)
// test internal state
fullBytesInternalState, err := slam.InternalStateFull(context.Background(), failingSLAMClient)
test.That(t, err.Error(), test.ShouldContainSubstring, "failure during callback")
test.That(t, fullBytesInternalState, test.ShouldBeNil)

Expand Down
Loading

0 comments on commit ddd4ef6

Please sign in to comment.