diff --git a/go.mod b/go.mod index 35a3d6dc..21d92f40 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/rhysd/actionlint v1.6.23 go.opencensus.io v0.24.0 go.viam.com/api v0.1.106 - go.viam.com/rdk v0.2.34-0.20230406203657-55bdeae9ff52 + go.viam.com/rdk v0.2.34-0.20230407220031-b6a992c7135b go.viam.com/slam v0.1.34-0.20230404174630-f82fcc184401 go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 go.viam.com/utils v0.1.18-0.20230327140716-bfeb34d89117 diff --git a/go.sum b/go.sum index a1bf95ac..8ff65a14 100644 --- a/go.sum +++ b/go.sum @@ -1384,6 +1384,8 @@ go.viam.com/api v0.1.106 h1:H//FPoU/KHRtyZI5wBJzQmf5hJUronqnfAVv4Q9fk28= go.viam.com/api v0.1.106/go.mod h1:NQC9FZnerAfIPJLJ42vgzQMoe1WAQRuVoQEf1JauxtQ= go.viam.com/rdk v0.2.34-0.20230406203657-55bdeae9ff52 h1:E7iW0X/d2lJWh4U53ZDHoLaR/dUDFYGFmy/f1VqnJKc= go.viam.com/rdk v0.2.34-0.20230406203657-55bdeae9ff52/go.mod h1:DZlQvkrFergpm6430h7aoKavSPQxSWNmcTj1rLbySmA= +go.viam.com/rdk v0.2.34-0.20230407220031-b6a992c7135b h1:tdYHjFQ0pVTs4qpqAGl0ImViRtmDTdyw4nrjs48c6Wo= +go.viam.com/rdk v0.2.34-0.20230407220031-b6a992c7135b/go.mod h1:DZlQvkrFergpm6430h7aoKavSPQxSWNmcTj1rLbySmA= go.viam.com/slam v0.1.34-0.20230404174630-f82fcc184401 h1:BEOffh7pXjC6bpJfE3LD9Mqzhj1RSJD8SkNzT2edoBk= go.viam.com/slam v0.1.34-0.20230404174630-f82fcc184401/go.mod h1:4oJw66kSTlro9tuaxjiFaDJPQjd546CHl1Y77qCx3cI= go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 h1:oBiK580EnEIzgFLU4lHOXmGAE3MxnVbeR7s1wp/F3Ps= diff --git a/integration_test.go b/integration_test.go index 2d55a654..83347e6f 100644 --- a/integration_test.go +++ b/integration_test.go @@ -37,7 +37,7 @@ const ( // Checks the cartographer map and confirms there at least 100 map points. func testCartographerMap(t *testing.T, svc slam.Service) { - pcd, err := slam.GetPointCloudMapFull(context.Background(), svc, "test") + pcd, err := slam.GetPointCloudMapFull(context.Background(), svc) test.That(t, err, test.ShouldBeNil) test.That(t, pcd, test.ShouldNotBeNil) @@ -53,7 +53,7 @@ func testCartographerPosition(t *testing.T, svc slam.Service, expectedComponentR expectedOri := &spatialmath.R4AA{Theta: 0, RX: 0, RY: 1, RZ: 0} toleranceOri := 0.5 - position, componentRef, err := svc.GetPosition(context.Background(), "test") + position, componentRef, err := svc.GetPosition(context.Background()) test.That(t, err, test.ShouldBeNil) test.That(t, componentRef, test.ShouldEqual, expectedComponentRef) @@ -73,7 +73,7 @@ func testCartographerPosition(t *testing.T, svc slam.Service, expectedComponentR // Checks the cartographer internal state. func testCartographerInternalState(t *testing.T, svc slam.Service, dataDir string) { - internalState, err := slam.GetInternalStateFull(context.Background(), svc, "test") + internalState, err := slam.GetInternalStateFull(context.Background(), svc) test.That(t, err, test.ShouldBeNil) // Save the data from the call to GetInternalState for use in next test. diff --git a/viam-cartographer.go b/viam-cartographer.go index 7db66d44..b70753a1 100644 --- a/viam-cartographer.go +++ b/viam-cartographer.go @@ -133,6 +133,7 @@ func New( // Cartographer SLAM Service Object cartoSvc := &cartographerService{ + name: config.Name, primarySensorName: lidar.Name, executableName: executableName, subAlgo: subAlgo, @@ -187,6 +188,7 @@ func New( // cartographerService is the structure of the slam service. type cartographerService struct { generic.Unimplemented + name string primarySensorName string executableName string subAlgo SubAlgo @@ -215,11 +217,11 @@ type cartographerService struct { // GetPosition forwards the request for positional data to the slam library's gRPC service. Once a response is received, // it is unpacked into a Pose and a component reference string. -func (cartoSvc *cartographerService) GetPosition(ctx context.Context, name string) (spatialmath.Pose, string, error) { +func (cartoSvc *cartographerService) GetPosition(ctx context.Context) (spatialmath.Pose, string, error) { ctx, span := trace.StartSpan(ctx, "viamcartographer::cartographerService::GetPosition") defer span.End() - req := &pb.GetPositionRequest{Name: name} + req := &pb.GetPositionRequest{Name: cartoSvc.name} resp, err := cartoSvc.clientAlgo.GetPosition(ctx, req) if err != nil { @@ -234,20 +236,20 @@ func (cartoSvc *cartographerService) GetPosition(ctx context.Context, name strin // GetPointCloudMap creates a request, calls the slam algorithms GetPointCloudMap endpoint and returns a callback // function which will return the next chunk of the current pointcloud map. -func (cartoSvc *cartographerService) GetPointCloudMap(ctx context.Context, name string) (func() ([]byte, error), error) { +func (cartoSvc *cartographerService) GetPointCloudMap(ctx context.Context) (func() ([]byte, error), error) { ctx, span := trace.StartSpan(ctx, "viamcartographer::cartographerService::GetPointCloudMap") defer span.End() - return grpchelper.GetPointCloudMapCallback(ctx, name, cartoSvc.clientAlgo) + return grpchelper.GetPointCloudMapCallback(ctx, cartoSvc.name, cartoSvc.clientAlgo) } // GetInternalState creates a request, calls the slam algorithms GetInternalState endpoint and returns a callback // function which will return the next chunk of the current internal state of the slam algo. -func (cartoSvc *cartographerService) GetInternalState(ctx context.Context, name string) (func() ([]byte, error), error) { +func (cartoSvc *cartographerService) GetInternalState(ctx context.Context) (func() ([]byte, error), error) { ctx, span := trace.StartSpan(ctx, "viamcartographer::cartographerService::GetInternalState") defer span.End() - return grpchelper.GetInternalStateCallback(ctx, name, cartoSvc.clientAlgo) + return grpchelper.GetInternalStateCallback(ctx, cartoSvc.name, cartoSvc.clientAlgo) } // StartDataProcess starts a go routine that saves data from the lidar to the user-defined data directory. diff --git a/viam-cartographer_test.go b/viam-cartographer_test.go index c289becd..026c46bd 100644 --- a/viam-cartographer_test.go +++ b/viam-cartographer_test.go @@ -210,19 +210,19 @@ func TestEndpointFailures(t *testing.T) { svc, err := testhelper.CreateSLAMService(t, attrCfg, logger, false, testExecutableName) test.That(t, err, test.ShouldBeNil) - pNew, frame, err := svc.GetPosition(context.Background(), "slam service name") + pNew, frame, err := svc.GetPosition(context.Background()) test.That(t, pNew, test.ShouldBeNil) test.That(t, frame, test.ShouldBeEmpty) test.That(t, fmt.Sprint(err), test.ShouldContainSubstring, "error getting SLAM position") - callbackPointCloud, err := svc.GetPointCloudMap(context.Background(), "slam service name") + callbackPointCloud, err := svc.GetPointCloudMap(context.Background()) test.That(t, err, test.ShouldBeNil) test.That(t, callbackPointCloud, test.ShouldNotBeNil) chunkPCD, err := callbackPointCloud() test.That(t, err.Error(), test.ShouldContainSubstring, "error receiving pointcloud chunk") test.That(t, chunkPCD, test.ShouldBeNil) - callbackInternalState, err := svc.GetInternalState(context.Background(), "hi") + callbackInternalState, err := svc.GetInternalState(context.Background()) test.That(t, err, test.ShouldBeNil) test.That(t, callbackInternalState, test.ShouldNotBeNil) chunkInternalState, err := callbackInternalState()