Skip to content
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-2526 unable to move multiaxis gantry #2168

Conversation

randhid
Copy link
Member

@randhid randhid commented Apr 5, 2023

Fixes an indexing error where an index was out of range in a multiaxis composed of only 3 axes with one length per axis.

  • Add a test for a multiaxis made of multiaxes.

@randhid randhid requested a review from gvaradarajan April 5, 2023 02:14
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 5, 2023
@github-actions

This comment was marked as outdated.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 5, 2023
@randhid randhid requested a review from raybjork April 5, 2023 13:54
jdx += len(subAxNum)

err = subAx.MoveToPosition(ctx, pos, worldState, extra)
if err != nil && !errors.Is(err, context.Canceled) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spieswl @nfranczak @raybjork if you'd like an update. Also, made CurrentInputs and GoToInputs fallthrough functions rather than copy-pastes of the logic to MoveToPosition and Position

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that matches our patterns in arm so I like the consistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually opposite from what we have in arm, where GoToInputs is the function that the basic function that is called by MoveToPosition. Can you switch these to be consistent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's actually more consistent here, the API names are the same, but gantry.MoveToPosition is actually a functional analog to arm.MoveToJointPositions and base.MoveStraight/base.Spin. So this won't change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raybjork pinging you for a response.

@randhid randhid requested a review from penguinland April 5, 2023 13:56
g, err := newMultiAxis(ctx, deps, cfg, logger)
test.That(t, err, test.ShouldBeNil)

err = g.MoveToPosition(ctx, []float64{1, 2, 3, 4, 5, 6}, &referenceframe.WorldState{}, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] Add another test case for trying to call MoveToPosition with too few positions as well

test.That(t, err, test.ShouldBeNil)
test.That(t, pos, test.ShouldResemble, []float64{6, 5, 9, 8, 7})

err = g.MoveToPosition(ctx, []float64{1, 2, 3, 4, 5}, &referenceframe.WorldState{}, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] add a test that MoveToPosition calls MoveToPosition on the subaxis gantries as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More clarification please.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now, it just checks that no error is returned, but a multi-axis gantry should make MoveToPosition calls to its sub-axis gantries with particular arguments based on the order of the gantries and the floats passed to the multi-axis' MoveToPosition call. The test should check that our implementation is making those calls with the correct arguments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is what I added sufficient to what you asked for? I had it as a task on my pr description.

err = g.MoveToPosition(ctx, []float64{1, 2, 3, 4, 5, 6}, &referenceframe.WorldState{}, nil)
test.That(t, err, test.ShouldNotBeNil)

pos, err := g.Position(ctx, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] it would be nice to use t.Run or have a short comment above each test case stating what is tested

Copy link
Member

@penguinland penguinland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Gautham's feedback in addition to my own. but all of that seems easy to fix, and the rest LGTM!

@@ -265,7 +265,7 @@ func (g *oneAxis) homeTwoLimSwitch(ctx context.Context) error {
g.positionLimits = []float64{positionA, positionB}

// Go backwards so limit stops are not hit.
x := g.rotationalToLinear(0.8 * g.lengthMm)
x := g.linearToRotational(0.8 * g.lengthMm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, this looks like a frustrating bug to find! Nice work here.

)
}

jdx := 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did idx get renamed jdx? I'd prefer to go back to the old name, which is obviously short for "index." I don't know what jdx is short for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's common in the non-software world to index using i, j, k, so i actually think in i-index, j-index, k-index.

idx := 0
if len(positions) != len(g.lengthsMm) {
return errors.Errorf(
"number of input positions %v does not match total gantry axes length %v",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change "length" to "count." It's too easy to misread this and think that the position is supposed to be the farthest position out on the gantry (its length). (Other rephrasings are possible, too. Go with whatever you think makes it clearest that the problem is that the input has the wrong dimensionality.)

for _, subAx := range g.subAxes {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer never to start a block of code with a blank line. The change in indentation should be enough to indicate that something new is happening here.

subAxNum, err := subAx.Lengths(ctx, extra)
if err != nil {
return err
}

err = subAx.MoveToPosition(ctx, positions[idx:idx+len(subAxNum)-1], worldState, extra)
if err != nil {
pos := positions[jdx : jdx+len(subAxNum)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Very good catch with the off-by-one error here!

Copy link
Member

@raybjork raybjork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Only comment is this is opposite from how we have arms set up, so I would like to see that change.

Also (and maybe this isn't a part of this scope), I'm wondering if we should be calling motionplan from gantry.MoveToPosition the way we have it set up in arms. It won't matter 99% of the time because it will just reduce to the GoToInputs call, but there is a chance that something weird is set up with geometries that will warrant it having to plan around something in its internal robot geometries

jdx += len(subAxNum)

err = subAx.MoveToPosition(ctx, pos, worldState, extra)
if err != nil && !errors.Is(err, context.Canceled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually opposite from what we have in arm, where GoToInputs is the function that the basic function that is called by MoveToPosition. Can you switch these to be consistent?

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 5, 2023
@randhid randhid requested review from gvaradarajan and raybjork April 5, 2023 22:55
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 5, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 6, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 6, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 6, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2023

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 64% 0.00%
go.viam.com/rdk/components/arm/fake 30% 0.00%
go.viam.com/rdk/components/arm/universalrobots 40% 0.00%
go.viam.com/rdk/components/arm/wrapper 20% 0.00%
go.viam.com/rdk/components/arm/xarm 6% 0.00%
go.viam.com/rdk/components/arm/yahboom 6% 0.00%
go.viam.com/rdk/components/audioinput 53% 0.00%
go.viam.com/rdk/components/base 61% 0.00%
go.viam.com/rdk/components/base/agilex 62% 0.00%
go.viam.com/rdk/components/base/boat 41% 0.00%
go.viam.com/rdk/components/base/wheeled 76% 0.00%
go.viam.com/rdk/components/board 65% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/fake 38% 0.00%
go.viam.com/rdk/components/board/genericlinux 23% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi 50% 0.00%
go.viam.com/rdk/components/camera 64% 0.00%
go.viam.com/rdk/components/camera/align 64% 0.00%
go.viam.com/rdk/components/camera/fake 71% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 77% 0.00%
go.viam.com/rdk/components/camera/rtsp 43% -0.86%
go.viam.com/rdk/components/camera/transformpipeline 78% 0.00%
go.viam.com/rdk/components/camera/videosource 34% 0.00%
go.viam.com/rdk/components/encoder 15% 0.00%
go.viam.com/rdk/components/encoder/fake 76% 0.00%
go.viam.com/rdk/components/gantry 58% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 85% +0.58%
go.viam.com/rdk/components/gantry/oneaxis 86% +0.07%
go.viam.com/rdk/components/generic 82% 0.00%
go.viam.com/rdk/components/gripper 67% 0.00%
go.viam.com/rdk/components/input 86% 0.00%
go.viam.com/rdk/components/input/fake 86% 0.00%
go.viam.com/rdk/components/input/gpio 84% 0.00%
go.viam.com/rdk/components/motor 76% 0.00%
go.viam.com/rdk/components/motor/dimensionengineering 63% 0.00%
go.viam.com/rdk/components/motor/dmc4000 69% 0.00%
go.viam.com/rdk/components/motor/fake 56% 0.00%
go.viam.com/rdk/components/motor/gpio 66% +0.41%
go.viam.com/rdk/components/motor/gpiostepper 54% 0.00%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/motor/ulnstepper 52% 0.00%
go.viam.com/rdk/components/movementsensor 74% 0.00%
go.viam.com/rdk/components/movementsensor/adxl345 66% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 45% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 36% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 29% 0.00%
go.viam.com/rdk/components/movementsensor/mpu6050 83% 0.00%
go.viam.com/rdk/components/posetracker 84% 0.00%
go.viam.com/rdk/components/sensor 66% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 31% 0.00%
go.viam.com/rdk/components/servo 66% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 78% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 81% +3.94%
go.viam.com/rdk/examples/customresources/demos/remoteserver 0% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/ml 67% 0.00%
go.viam.com/rdk/ml/inference 70% 0.00%
go.viam.com/rdk/module 67% 0.00%
go.viam.com/rdk/module/modmanager 80% 0.00%
go.viam.com/rdk/motionplan 71% +0.05%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 69% 0.00%
go.viam.com/rdk/protoutils 49% 0.00%
go.viam.com/rdk/referenceframe 72% 0.00%
go.viam.com/rdk/registry 83% 0.00%
go.viam.com/rdk/resource 84% 0.00%
go.viam.com/rdk/rimage 78% 0.00%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 75% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 86% 0.00%
go.viam.com/rdk/robot/client 82% 0.00%
go.viam.com/rdk/robot/framesystem 65% 0.00%
go.viam.com/rdk/robot/impl 81% 0.00%
go.viam.com/rdk/robot/packages 80% 0.00%
go.viam.com/rdk/robot/server 53% 0.00%
go.viam.com/rdk/robot/web 64% -0.16%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 78% 0.00%
go.viam.com/rdk/services/datamanager 75% 0.00%
go.viam.com/rdk/services/datamanager/builtin 85% +0.44%
go.viam.com/rdk/services/datamanager/datacapture 73% 0.00%
go.viam.com/rdk/services/datamanager/datasync 0% 0.00%
go.viam.com/rdk/services/motion 53% 0.00%
go.viam.com/rdk/services/motion/builtin 86% 0.00%
go.viam.com/rdk/services/navigation 54% 0.00%
go.viam.com/rdk/services/sensors 74% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 25% 0.00%
go.viam.com/rdk/services/slam 84% 0.00%
go.viam.com/rdk/services/slam/builtin 74% 0.00%
go.viam.com/rdk/services/slam/fake 90% 0.00%
go.viam.com/rdk/services/slam/slam_copy/config 97% 0.00%
go.viam.com/rdk/services/slam/slam_copy/dataprocess 71% 0.00%
go.viam.com/rdk/services/slam/slam_copy/utils 100% 0.00%
go.viam.com/rdk/services/vision 79% 0.00%
go.viam.com/rdk/services/vision/builtin 74% 0.00%
go.viam.com/rdk/session 97% 0.00%
go.viam.com/rdk/spatialmath 84% 0.00%
go.viam.com/rdk/subtype 92% 0.00%
go.viam.com/rdk/utils 72% +0.18%
go.viam.com/rdk/vision 26% 0.00%
go.viam.com/rdk/vision/chess 80% 0.00%
go.viam.com/rdk/vision/delaunay 87% 0.00%
go.viam.com/rdk/vision/keypoints 92% 0.00%
go.viam.com/rdk/vision/objectdetection 82% 0.00%
go.viam.com/rdk/vision/odometry 60% 0.00%
go.viam.com/rdk/vision/odometry/cmd 0% 0.00%
go.viam.com/rdk/vision/segmentation 49% 0.00%
go.viam.com/rdk/web/server 26% 0.00%
Summary 65% (22829 / 34871) +0.02%

@randhid randhid merged commit 55bdeae into viamrobotics:main Apr 6, 2023
@randhid randhid deleted the RSDK-2526-unable-to-move-a-multi-axis-gantry branch April 6, 2023 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants