Skip to content

Commit

Permalink
RSDK-2393 Remove Name Parameter from SLAM Functions (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyrhyde authored Apr 7, 2023
1 parent fef5266 commit 3726e0f
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.33
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.33 h1:5YrkYYWAyqCs5yPRwzhjQRD5gn6dxsy4y3Kl/PRnHB8=
go.viam.com/slam v0.1.33/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 @@ -76,7 +76,7 @@ func releaseImages(t *testing.T, subAlgo viamorbslam3.SubAlgo) {

// testOrbslamMap checks the orbslam map and confirms there are more than zero map points.
func testOrbslamMap(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 Down Expand Up @@ -105,7 +105,7 @@ func testOrbslamPosition(t *testing.T, svc slam.Service, subAlgo viamorbslam3.Su
expectedOri = &spatialmath.R4AA{Theta: 0.002, RX: 0.602, RY: -0.772, RZ: -0.202}
}

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 @@ -125,7 +125,7 @@ func testOrbslamPosition(t *testing.T, svc slam.Service, subAlgo viamorbslam3.Su

// testOrbslamInternalState checks the orbslam internal state.
func testOrbslamInternalState(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-orb-slam3.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func runtimeServiceValidation(
// orbslamService is the structure of the ORB_SLAM3 slam service.
type orbslamService struct {
generic.Unimplemented
name string
primarySensorName string
subAlgo SubAlgo
executableName string // by default: DefaultExecutableName
Expand Down Expand Up @@ -244,11 +245,11 @@ func configureCameras(ctx context.Context,

// 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 (orbSvc *orbslamService) GetPosition(ctx context.Context, name string) (spatialmath.Pose, string, error) {
func (orbSvc *orbslamService) GetPosition(ctx context.Context) (spatialmath.Pose, string, error) {
ctx, span := trace.StartSpan(ctx, "viamorbslam3::orbslamService::GetPosition")
defer span.End()

req := &pb.GetPositionRequest{Name: name}
req := &pb.GetPositionRequest{Name: orbSvc.name}

resp, err := orbSvc.clientAlgo.GetPosition(ctx, req)
if err != nil {
Expand All @@ -263,20 +264,20 @@ func (orbSvc *orbslamService) GetPosition(ctx context.Context, name string) (spa

// 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 (orbSvc *orbslamService) GetPointCloudMap(ctx context.Context, name string) (func() ([]byte, error), error) {
func (orbSvc *orbslamService) GetPointCloudMap(ctx context.Context) (func() ([]byte, error), error) {
ctx, span := trace.StartSpan(ctx, "viamorbslam3::orbslamService::GetPointCloudMap")
defer span.End()

return grpchelper.GetPointCloudMapCallback(ctx, name, orbSvc.clientAlgo)
return grpchelper.GetPointCloudMapCallback(ctx, orbSvc.name, orbSvc.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 (orbSvc *orbslamService) GetInternalState(ctx context.Context, name string) (func() ([]byte, error), error) {
func (orbSvc *orbslamService) GetInternalState(ctx context.Context) (func() ([]byte, error), error) {
ctx, span := trace.StartSpan(ctx, "viamorbslam3::orbslamService::GetInternalState")
defer span.End()

return grpchelper.GetInternalStateCallback(ctx, name, orbSvc.clientAlgo)
return grpchelper.GetInternalStateCallback(ctx, orbSvc.name, orbSvc.clientAlgo)
}

// New returns a new slam service for the given robot.
Expand Down Expand Up @@ -342,6 +343,7 @@ func New(ctx context.Context,

// SLAM Service Object
orbSvc := &orbslamService{
name: config.Name,
primarySensorName: primarySensorName,
subAlgo: subAlgo,
executableName: executableName,
Expand Down
6 changes: 3 additions & 3 deletions viam-orb-slam3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,19 @@ func TestEndpointFailures(t *testing.T) {
svc, err := createSLAMService(t, attrCfg, logger, false, true, testExecutableName)
test.That(t, err, test.ShouldBeNil)

pNew, frame, err := svc.GetPosition(context.Background(), "slam_test_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_test_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(), "slam_test_name")
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 3726e0f

Please sign in to comment.