Skip to content

Commit

Permalink
RSDK-2393 Remove Name Parameter from SLAM Functions (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyrhyde authored Apr 7, 2023
1 parent 45f377b commit 5c3e8df
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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.
Expand Down
14 changes: 8 additions & 6 deletions viam-cartographer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func New(

// Cartographer SLAM Service Object
cartoSvc := &cartographerService{
name: config.Name,
primarySensorName: lidar.Name,
executableName: executableName,
subAlgo: subAlgo,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions viam-cartographer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5c3e8df

Please sign in to comment.