-
Notifications
You must be signed in to change notification settings - Fork 493
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
Use size_t for index variables #946
Conversation
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.
I disagree. The way joints are constructed, the RobotModel
has to specify the joint index from the outside and the value should stay invalid until it is set from there.
So if you insist we can discuss ssize_t
, std::optional
or exceptions from getJointIndex
as alternatives but I'm not convinced refactoring this is any more helpful than annoying. How often do you expect to see robots with 2^31 joints?
About as often as I expect to see a robots with joint indexes of -1. It seems to be that this is a really odd interface. There are a ton of values in these objects that are always used and assumed to be valid. It is a really basic thing to expect objects to only contain valid values after they are constructed. I know that this is a bandaid on a tiny part of the API here. I'll look into refactoring these objects so they can only be constructed in a valid state. |
You never do unless you do not bind the joints to a robot model before use.
More or less agreed. At the same time I thought PickNik is interested in reconfiguring robot models (and thus possibly modifying the joint indices at runtime). I forgot to mention the alternative to assert uses of the index to check whether it was initialized. You can restructure all of this of course, but it is at the core of everything. Let's see what you come up with! 🐈 |
We are but I don't think that means we need index values to be mutable and invalid ever. We know what they are when we construct them.
Do you mind reviewing my latest changes here? I refrained from refactoring everything in these yet, but this PR makes so the index values are never invalid so we can set them to the type that operator[] takes on construction. |
Signed-off-by: Tyler Weaver <tylerjw@gmail.com>
I would like to save |
Codecov Report
@@ Coverage Diff @@
## main #946 +/- ##
==========================================
- Coverage 57.95% 57.72% -0.22%
==========================================
Files 310 310
Lines 26132 26129 -3
==========================================
- Hits 15141 15080 -61
- Misses 10991 11049 +58
Continue to review full report at Codecov.
|
outdated. I can't review again at this moment though.
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.
Overall, the switch to size_t
makes a lot of sense to me. As we change the API, we should probably consider more conceptual changes as well as suggested in the comment.
This pull request is in conflict. Could you fix it @tylerjw? |
@@ -54,8 +56,6 @@ JointModel::JointModel(const std::string& name) | |||
, mimic_offset_(0.0) | |||
, passive_(false) | |||
, distance_factor_(1.0) | |||
, first_variable_index_(-1) |
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.
btw, I very much prefer having explicit indexes enforced with the constructor over allowing constructing stand-alone joints in an invalid state.
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.
I'm fine with these changes, but let's merge #970 first so that this doesn't end up in the docker images for Galactic
Description
This relates to #944
I wasn't able to find anywhere in the code where these values are checked if they are negative before they are used. This was causing an issue with the work I'm doing on bio_ik.
This is an ABI-breaking change but it shouldn't break anyone's code that depends on these values. At best it'll throw some compiler warnings if they were storing the resulting values in signed variables.
Checklist