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-251 Add support for capsule geometry types #1766

Conversation

biotinker
Copy link
Member

@biotinker biotinker commented Jan 13, 2023

This adds capsules as a geometry type, supporting efficient collisions with all other geometry types.

Along with this is an initial implementation of meshes- not supported as a geometry type, simply as a backend representation. This is due to a box-capsule collision implementation being taken from here: https://github.com/google/brax/blob/7eaa16b4bf446b117b538dbe9c9401f97cf4afa2/brax/physics/colliders.py

The separating axis theorum is instead used here for the capsules when doing collisions as it is faster. Perhaps we should PR against brax?

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Jan 13, 2023
@biotinker biotinker marked this pull request as ready for review January 13, 2023 22:40
@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 Jan 13, 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 Jan 13, 2023
@biotinker biotinker changed the title Add support for capsule geometry types RSDK-251 Add support for capsule geometry types Jan 13, 2023
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.

Looking good so far. I had a few questions mostly related to the algorithm were using for box-cylinder collisions (and the necessity of meshes in general). I also left a couple comments about what I haven't looked at yet and will get back to in the next pass

spatialmath/mesh.go Show resolved Hide resolved
spatialmath/box.go Outdated Show resolved Hide resolved
spatialmath/box_test.go Outdated Show resolved Hide resolved
spatialmath/capsule.go Outdated Show resolved Hide resolved
spatialmath/capsule.go Show resolved Hide resolved
spatialmath/errors.go Show resolved Hide resolved
spatialmath/geometry.go Show resolved Hide resolved
spatialmath/sphere.go Show resolved Hide resolved
spatialmath/geometry_test.go Show resolved Hide resolved
spatialmath/geometry_utils.go Show resolved Hide resolved
@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 Jan 17, 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 Jan 18, 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 Jan 18, 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 Jan 18, 2023
@biotinker biotinker requested a review from raybjork January 18, 2023 20:27
@viambot viambot removed the safe to test This pull request is marked safe to test from a trusted zone label Jan 18, 2023
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Jan 18, 2023
spatialmath/capsule.go Outdated Show resolved Hide resolved
// box density corresponding to how many points per square mm.
const defaultBoxPointDensity = .5
// Ordered list of box vertices.
var boxVertices = [8]r3.Vector{
Copy link
Member

Choose a reason for hiding this comment

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

[nit] this is the most minor but can we move this section down to where it is used? I'd like the top of this file to stay the most relevant things to a user, and this is only used in mesh creation

Copy link
Member Author

Choose a reason for hiding this comment

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

Globals like this should generally be the first thing (or one of the first things) in a file after the imports.

I don't want to declare these in the function where they're used, because that's a performance-sensitive function and redeclaring these variables on each call will be noticeably expensive.

Perhaps a different file would be appropriate for these? geometry_utils.go if you like

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree that generally you're right. I just feel it hurts readability a bit. You can do whatever you think is right here just wanted to raise this point

spatialmath/capsule.go Show resolved Hide resolved
spatialmath/capsule.go Show resolved Hide resolved
spatialmath/capsule.go Outdated Show resolved Hide resolved
spatialmath/capsule.go Outdated Show resolved Hide resolved
spatialmath/capsule.go Show resolved Hide resolved
spatialmath/capsule.go Outdated Show resolved Hide resolved
spatialmath/capsule.go Show resolved Hide resolved
Copy link
Contributor

@spieswl spieswl left a comment

Choose a reason for hiding this comment

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

The only thing that, in my opinion, needs to be looked at is the capsule ToPoints resolution argument issue when being passed in a 0 value.

// .x| |-------O-------| |x
// ...\___________________/
//
// Length is the distance between the x's, or internal segment length + 2*radius.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I like specifying length as the distance between X marks. If Length were just the internal segment length, we could eliminate some checks for odd values of L versus R, but I haven't yet looked ahead to see if this helps simplify other collision checks. Some idea of why you chose this representation would be appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, this is not a big deal to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I put quite a bit of thought into that choice and went back and forth. This is purely a user experience decision, not something that impacts collision checks at all.

I agree that specifying segment length rather than total length makes for a "cleaner" mathematical representation, for exactly the reasons you mentioned.

However, if we do that, we make it mildly more difficult for a user to actually use. Currently the values are ones that are easy to physically measure. Let's say we go to make a capsule representation of the internal geometries of a UR5 next week. We pull out a tape measure, say "this limb is 175mm long, and 34.3mm diameter, so 17.15mm radius" and we plug that in. We don't have to worry about simple arithmetic to compute the internal segment length, which isn't something that's easily physically measured.

The majority of capsule implementations I found in the wild similarly specify full length, at least at the user-facing interfaces.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW I agree with you on this choice Peter, the most measurable thing should be the thing exposed to the user

Copy link
Contributor

Choose a reason for hiding this comment

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

If you can't measure both aspects I'm not sure what the user is doing.

vecList := s.ToPoints(resolution)
// move points to be correctly located on capsule endcaps
adj := c.length/2 - c.radius
for _, pt := range vecList {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this block mean vecList has some points which are duplicated along the hemisphere of each end of the capsule?

Copy link
Contributor

Choose a reason for hiding this comment

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

Never mind, I see what you're doing. You're splitting a sphere into its two halves and shifting the halves to each end. Nice, I like it.

spatialmath/capsule.go Show resolved Hide resolved
@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 Jan 19, 2023
@biotinker biotinker requested review from spieswl and raybjork January 19, 2023 16:06
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.

Theres just a couple rather minor outstanding comments I left that I think are still unresolved, but after you feel you've resolved them you can merge

@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 Jan 19, 2023
Copy link
Contributor

@spieswl spieswl left a comment

Choose a reason for hiding this comment

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

Cool, LGTM!

@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 56% 0.00%
go.viam.com/rdk/components/arm/universalrobots 41% 0.00%
go.viam.com/rdk/components/arm/xarm 2% 0.00%
go.viam.com/rdk/components/arm/yahboom 7% 0.00%
go.viam.com/rdk/components/audioinput 55% 0.00%
go.viam.com/rdk/components/base 63% 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 66% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/commonsysfs 47% 0.00%
go.viam.com/rdk/components/board/fake 38% 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 63% 0.00%
go.viam.com/rdk/components/camera/fake 67% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 76% 0.00%
go.viam.com/rdk/components/camera/transformpipeline 79% -0.65%
go.viam.com/rdk/components/camera/videosource 45% -0.19%
go.viam.com/rdk/components/encoder 4% 0.00%
go.viam.com/rdk/components/encoder/fake 76% 0.00%
go.viam.com/rdk/components/gantry 60% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 84% 0.00%
go.viam.com/rdk/components/gantry/oneaxis 86% 0.00%
go.viam.com/rdk/components/generic 83% 0.00%
go.viam.com/rdk/components/gripper 68% 0.00%
go.viam.com/rdk/components/input 87% 0.00%
go.viam.com/rdk/components/input/gpio 84% 0.00%
go.viam.com/rdk/components/motor 77% 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 57% 0.00%
go.viam.com/rdk/components/motor/gpio 62% -2.16%
go.viam.com/rdk/components/motor/gpiostepper 57% +0.59%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/movementsensor 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 46% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 36% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 28% 0.00%
go.viam.com/rdk/components/posetracker 86% 0.00%
go.viam.com/rdk/components/sensor 86% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 25% 0.00%
go.viam.com/rdk/components/servo 68% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 76% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 79% 0.00%
go.viam.com/rdk/examples/customresources/demos/complexmodule 0% 0.00%
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 63% 0.00%
go.viam.com/rdk/module/modmanager 79% 0.00%
go.viam.com/rdk/motionplan 59% -0.16%
go.viam.com/rdk/octree 98% 0.00%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 72% 0.00%
go.viam.com/rdk/protoutils 59% 0.00%
go.viam.com/rdk/referenceframe 71% 0.00%
go.viam.com/rdk/registry 89% 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 73% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 85% 0.00%
go.viam.com/rdk/robot/client 81% 0.00%
go.viam.com/rdk/robot/framesystem 65% 0.00%
go.viam.com/rdk/robot/impl 80% 0.00%
go.viam.com/rdk/robot/server 55% 0.00%
go.viam.com/rdk/robot/web 61% 0.00%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/armremotecontrol 71% 0.00%
go.viam.com/rdk/services/armremotecontrol/builtin 52% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 79% 0.00%
go.viam.com/rdk/services/datamanager 79% 0.00%
go.viam.com/rdk/services/datamanager/builtin 78% -0.91%
go.viam.com/rdk/services/datamanager/datacapture 70% 0.00%
go.viam.com/rdk/services/datamanager/datasync 0% 0.00%
go.viam.com/rdk/services/motion 63% 0.00%
go.viam.com/rdk/services/motion/builtin 88% 0.00%
go.viam.com/rdk/services/navigation 53% 0.00%
go.viam.com/rdk/services/sensors 77% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 14% 0.00%
go.viam.com/rdk/services/slam 84% 0.00%
go.viam.com/rdk/services/slam/builtin 70% 0.00%
go.viam.com/rdk/services/vision 80% 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 83% -3.33%
go.viam.com/rdk/subtype 92% 0.00%
go.viam.com/rdk/utils 72% 0.00%
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 25% 0.00%
Summary 65% (21109 / 32650) +0.02%

@biotinker biotinker merged commit 867597f into viamrobotics:main Jan 19, 2023
randhid pushed a commit to randhid/rdk that referenced this pull request Feb 25, 2023
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.

4 participants