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

More Intuitive CLI for Static Transform Publisher #392

Merged
merged 4 commits into from
Oct 13, 2021

Conversation

allenh1
Copy link
Contributor

@allenh1 allenh1 commented Mar 10, 2021

Opening for visibility. Few TODO's left in line that I'll get to in a bit, but this fixes #295.

Signed-off-by: Hunter L. Allen hunter.allen@ghostrobotics.io

@allenh1 allenh1 added the in progress Actively being worked on (Kanban column) label Mar 10, 2021
@allenh1 allenh1 force-pushed the 295-more-intuitive-command-line-arguments branch from 2b28c36 to df2315b Compare March 11, 2021 14:34
@allenh1 allenh1 added in review Waiting for review (Kanban column) in progress Actively being worked on (Kanban column) and removed in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) labels Mar 11, 2021
@allenh1
Copy link
Contributor Author

allenh1 commented Mar 11, 2021

RPY now supported, but need to add --roll-deg and the like still.

Comment on lines 44 to 254
std::unordered_map<std::string, std::string> ret;
/* collect from [exe] --option1 value --option2 value ... --optionN value */
for (size_t x = 1; x < args.size(); x += 2) {
ret.emplace(std::move(args[x]), std::move(args[x + 1]));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here if the user passes an incorrect command line, like:

--x --y 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that's a good catch. Would likely crash.

Comment on lines 161 to 162
rotation = _get_rotation(arg_map);
translation = _get_translation(arg_map);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the user supplies arguments that we don't understand, like --foo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is actually immune to that. It should set to the identity transform.

That said, it should probably error, since that's not a valid argument.

@tfoote
Copy link
Contributor

tfoote commented Mar 11, 2021

For simplicity I'd suggest that instead of adding a bunch of extra logic to this command line parsing that we consider making a new executable with a new name which can take the new argument styles. This will ensure that we maintain the existing CLI and we can just reuse the existing implementation with a new command line parsing.

One simple alternative that gives a lot of power would be to actually make this into a python tool that has all the bells and whistles turned on, that then executes the less user friendly one under the hood. This would make the command line parsing much less error prone. And users who don't want python on their system can still use the less user friendly C++ version.

@clalancette
Copy link
Contributor

For simplicity I'd suggest that instead of adding a bunch of extra logic to this command line parsing that we consider making a new executable with a new name which can take the new argument styles. This will ensure that we maintain the existing CLI and we can just reuse the existing implementation with a new command line parsing.

The thing is, we still need most of the logic to parse the command-line anyway. Adding a second executable only removes the backwards compatibility logic, and I don't expect that to be a whole lot of code anyway. To me, the benefit of keeping the current executable name, and being able to (eventually) remove the old arguments outweighs the downside of carrying a bit of extra logic around.

I guess the command-line parsing becomes much easier if we switch the whole thing to Python. But the thing is that we've gone a long way towards separating C++ and Python packages in geometry2, and I'd like to not go back on that. So we'd have to move the new executable to tf2_ros_py, and then it is harder for users to migrate and discover, etc. I just don't think that parsing the command-line arguments in C++ is going to be that hard, and so I don't think it warrants a big hammer here.

TLDR: my opinion is that we should continue down the path of parsing the command-line arguments in the current executable, and add (just a small bit more) logic to deal with the backwards-compatible arguments.

@tfoote
Copy link
Contributor

tfoote commented Mar 12, 2021

Ok, If we were to switch it to be python based it would likely move to tf2_tools or the like to avoid the dependency.

@clalancette
Copy link
Contributor

Ok, If we were to switch it to be python based it would likely move to tf2_tools or the like to avoid the dependency.

Yes, that's a good point.

It seems to me that we have 3 options here:

  1. Rewrite this utility to be in Python. This has some obvious code maintenance benefits. The downside is that it is disruptive to users on two axes: they need to change the package that the utility comes from, and they need to change the command-line arguments to the new syntax.
  2. Create a new executable in C++ that only takes the new arguments. This gets rid of some back-compat logic, but still requires that we write the command-line parsing ourselves. This is disruptive to users on two axes: they need to change the executable they are running, and they need to change the command-line arguments to the new syntax.
  3. Put all of the command-line parsing and back-compat right into the existing executable. This is disruptive to users on one axis: they need to change the command-line arguments to the new syntax.

Option 3 is the least disruptive to users; option 1 is easier long-term maintenance (2 seems to be the worst of both worlds, so I won't consider it further). Hard to choose :).

@allenh1 You are the one actually working on this, so any thoughts from you on this?

@allenh1
Copy link
Contributor Author

allenh1 commented Mar 12, 2021

@allenh1 You are the one actually working on this, so any thoughts from you on this?

Hm. I think @tfoote makes a really good point here. I am not opposed to option 1 here at all.

I'm really not a fan of option 2. I can see that being a real maintenance headache in the future where we have the component version, the standalone executable, and the other standalone executable for the same thing. That's probably overkill, imo.

As for option 3, it's definitely a lot of code for setting arguments, but I'm much faster with my C++ than my Python to be honest. And I feel like after printing the deprecation warning for the old style in Galactic, it can be removed completely in H-turtle.

So my preference is definitely 3, but probably just because it's all C++. I am fine with 1 if that's what we want instead.

@clalancette
Copy link
Contributor

clalancette commented Mar 12, 2021

@allenh1 I'll leave the final decision to you. I'm slightly more in favor of 3 than 1, just because of the relative ease of transition. Tully seems to be more in favor of 1 than 3, because of the maintenance. You are doing the work, so you can do what you feel is best and be the tie-breaker :).

If you do decide to go with 1, remember that in addition to the new Python executable we'll want a small update to the existing static_transform_broadcaster_program to say This utility is deprecated, use <new_executable> now.

@allenh1
Copy link
Contributor Author

allenh1 commented Mar 12, 2021

If you do decide to go with 3, remember that in addition to the new Python executable

Do you mean 1? Just to be clear...

@clalancette
Copy link
Contributor

Do you mean 1? Just to be clear...

Yes! Sorry. Will update the comment.

@clalancette clalancette self-assigned this Apr 1, 2021
@clalancette clalancette added the more-information-needed Further information is required label Apr 1, 2021
@clalancette clalancette force-pushed the 295-more-intuitive-command-line-arguments branch from df2315b to d45244f Compare September 16, 2021 17:22
@clalancette
Copy link
Contributor

@allenh1 I spent a bit of time here and reimplemented this to take care of all of the issues earlier identified, as well as adding support for both new-style and old-style arguments (the latter print a warning). I think this now fulfills all of the requirements we were looking for; can you take a look at the code and let me know what you think about it?

@clalancette clalancette removed in progress Actively being worked on (Kanban column) more-information-needed Further information is required labels Sep 24, 2021
@allenh1
Copy link
Contributor Author

allenh1 commented Sep 26, 2021

I think this now fulfills all of the requirements we were looking for; can you take a look at the code and let me know what you think about it?

@clalancette looks good to me. Thanks for finishing this up for me.

@clalancette
Copy link
Contributor

@ahcorde When you get a chance, can you do a review of this? Thanks.

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

This looks good to me, but since I rewrote substantial portions of it I'll wait on @ahcorde before merging it. I'll run CI on it in the meantime.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

clalancette commented Oct 5, 2021

Fixed some warnings on Windows and rebased. Here's another try at CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette clalancette force-pushed the 295-more-intuitive-command-line-arguments branch 2 times, most recently from 9cf4e53 to c38fab3 Compare October 11, 2021 13:26
@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette clalancette force-pushed the 295-more-intuitive-command-line-arguments branch from c38fab3 to eca4cf4 Compare October 11, 2021 18:31
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

just a mirnor style comment, otherwise LGTM

tf2_ros/src/static_transform_broadcaster_program.cpp Outdated Show resolved Hide resolved
allenh1 and others added 3 commits October 12, 2021 19:05
Signed-off-by: Hunter L. Allen <hunter.allen@ghostrobotics.io>
In this approach, we still allow the old command-line style,
but it prints a warning and is deprecated.  The new style is
to use flags (like --x, --qx, etc), so that it is clear to
the user which axes they are overriding.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette clalancette force-pushed the 295-more-intuitive-command-line-arguments branch from eca4cf4 to e2d83c2 Compare October 12, 2021 19:05
@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor

clalancette commented Oct 13, 2021

One more CI to take the test warnings into account:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
  • Windows Debug Build Status

@clalancette
Copy link
Contributor

CI is green, approved, so merging. Thanks for the initial code @allenh1 , and thanks for the review @ahcorde .

@clalancette clalancette merged commit 254748f into ros2 Oct 13, 2021
@delete-merged-branch delete-merged-branch bot deleted the 295-more-intuitive-command-line-arguments branch October 13, 2021 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

static_transform_publisher more intuitive command-line arguments
4 participants