-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSDK-3950 - call into cgo for getPosition #188
Merged
kim-mishra
merged 8 commits into
viam-modules:main
from
kim-mishra:RSDK-3950-call-into-cgo-for-getPosition
Jul 11, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
05d6255
getPosition and tests
kim-mishra d28e78e
lint
kim-mishra 38d50f4
newZeroPose instead of empty vec and ori into new pose
kim-mishra fe9bca9
newZeroPose -> nil
kim-mishra 42bbde4
remove successful client t.Run
kim-mishra a23a0ab
test for error case
kim-mishra c03c8e2
added back tests for component reference
kim-mishra f90093d
make a test helper
kim-mishra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/edaniels/golog" | ||
"github.com/golang/geo/r3" | ||
|
@@ -243,6 +244,112 @@ func TestGetPositionEndpoint(t *testing.T) { | |
}) | ||
} | ||
|
||
func setMockGetPositionFunc( | ||
mockCartoFacade *cartofacade.Mock, | ||
pos cartofacade.GetPosition, | ||
) { | ||
mockCartoFacade.GetPositionFunc = func( | ||
ctx context.Context, | ||
timeout time.Duration, | ||
) (cartofacade.GetPosition, error) { | ||
return pos, | ||
nil | ||
} | ||
} | ||
|
||
func checkGetPositionModularizationV2Outputs( | ||
t *testing.T, | ||
mockCartoFacade *cartofacade.Mock, | ||
inputPose commonv1.Pose, | ||
inputQuat map[string]interface{}, | ||
inputComponentRef string, | ||
svc *cartographerService, | ||
pos cartofacade.GetPosition, | ||
) { | ||
setMockGetPositionFunc(mockCartoFacade, pos) | ||
|
||
pose, componentReference, err := svc.GetPosition(context.Background()) | ||
test.That(t, err, test.ShouldBeNil) | ||
expectedPose := spatialmath.NewPose( | ||
r3.Vector{X: inputPose.X, Y: inputPose.Y, Z: inputPose.Z}, | ||
makeQuaternionFromGenericMap(inputQuat), | ||
) | ||
test.That(t, pose, test.ShouldResemble, expectedPose) | ||
test.That(t, componentReference, test.ShouldEqual, inputComponentRef) | ||
} | ||
|
||
func TestGetPositionModularizationV2Endpoint(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a test for |
||
svc := &cartographerService{Named: resource.NewName(slam.API, "test").AsNamed()} | ||
mockCartoFacade := &cartofacade.Mock{} | ||
svc.cartofacade = mockCartoFacade | ||
svc.modularizationV2Enabled = true | ||
|
||
originPos := cartofacade.GetPosition{ | ||
X: 0, | ||
Y: 0, | ||
Z: 0, | ||
Real: 1.0, | ||
Imag: 0.0, | ||
Jmag: 0.0, | ||
Kmag: 0.0, | ||
} | ||
|
||
nonOriginPos := cartofacade.GetPosition{ | ||
X: 5, | ||
Y: 5, | ||
Z: 5, | ||
Real: 1.0, | ||
Imag: 1.0, | ||
Jmag: 0.0, | ||
Kmag: 0.0, | ||
} | ||
|
||
var inputPose commonv1.Pose | ||
var inputQuat map[string]interface{} | ||
|
||
t.Run("empty component reference success", func(t *testing.T) { | ||
svc.primarySensorName = "" | ||
inputPose = commonv1.Pose{X: 0, Y: 0, Z: 0, OX: 0, OY: 0, OZ: 1, Theta: 0} | ||
inputQuat = map[string]interface{}{"real": 1.0, "imag": 0.0, "jmag": 0.0, "kmag": 0.0} | ||
|
||
checkGetPositionModularizationV2Outputs(t, mockCartoFacade, inputPose, inputQuat, "", svc, originPos) | ||
}) | ||
|
||
t.Run("origin pose success", func(t *testing.T) { | ||
svc.primarySensorName = "primarySensor1" | ||
inputPose = commonv1.Pose{X: 0, Y: 0, Z: 0, OX: 0, OY: 0, OZ: 1, Theta: 0} | ||
inputQuat = map[string]interface{}{"real": 1.0, "imag": 0.0, "jmag": 0.0, "kmag": 0.0} | ||
|
||
checkGetPositionModularizationV2Outputs(t, mockCartoFacade, inputPose, inputQuat, "primarySensor1", svc, originPos) | ||
}) | ||
|
||
t.Run("non origin pose success", func(t *testing.T) { | ||
svc.primarySensorName = "primarySensor2" | ||
inputPose = commonv1.Pose{X: 5, Y: 5, Z: 5, OX: 0, OY: 0, OZ: 1, Theta: 0} | ||
inputQuat = map[string]interface{}{"real": 1.0, "imag": 1.0, "jmag": 0.0, "kmag": 0.0} | ||
|
||
checkGetPositionModularizationV2Outputs(t, mockCartoFacade, inputPose, inputQuat, "primarySensor2", svc, nonOriginPos) | ||
}) | ||
|
||
t.Run("error case", func(t *testing.T) { | ||
svc.primarySensorName = "primarySensor3" | ||
mockCartoFacade.GetPositionFunc = func( | ||
ctx context.Context, | ||
timeout time.Duration, | ||
) (cartofacade.GetPosition, error) { | ||
return cartofacade.GetPosition{}, errors.New("testError") | ||
} | ||
|
||
inputPose = commonv1.Pose{X: 0, Y: 0, Z: 0, OX: 0, OY: 0, OZ: 1, Theta: 0} | ||
inputQuat = map[string]interface{}{"real": 1.0, "imag": 0.0, "jmag": 0.0, "kmag": 0.0} | ||
pose, componentReference, err := svc.GetPosition(context.Background()) | ||
|
||
test.That(t, err, test.ShouldBeError, errors.New("testError")) | ||
test.That(t, pose, test.ShouldBeNil) | ||
test.That(t, componentReference, test.ShouldEqual, "") | ||
}) | ||
} | ||
|
||
//nolint:dupl | ||
func TestGetPointCloudMapEndpoint(t *testing.T) { | ||
svc := &cartographerService{Named: resource.NewName(slam.API, "test").AsNamed()} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please test this error case?