-
Notifications
You must be signed in to change notification settings - Fork 0
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
Loads a monolane YAML file from CLI. #39
Conversation
- Creates a simple library to hold CLI arguments. - Copies a delphyne cmake macro to look for Drake's libraries. - Moves from ignition gui System.hh file to provide visibility to symbols. - Adds test for the CLI library. - Copies double_ring.yaml file from Drake to have a sample at hand.
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.
Thanks @agalbachicar ! Left a couple of minor comments. And as usual, wait of a second pair of eyes from Chris or Carlos.
visualizer/double_ring.yaml
Outdated
@@ -0,0 +1,49 @@ | |||
# -*- yaml -*- |
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.
At least on the delphyne side we can take resources from Drake (in particular the car's mesh) by using drake::AddResourceSearchPath(std::string(std::getenv("DRAKE_INSTALL_PATH")) + "/share/drake");
. Not sure it applies to yaml files too, but if it did we could save from copying them here.
Having said that, if the former is not an option, let's put this in a different dir (road_samples
?)
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.
Done. I had to move it because drake does not export .yaml files when installing.
EXPECT_EQ(global_attributes::GetArgument(0), std::string("abc_123")); | ||
EXPECT_EQ(global_attributes::GetNumberOfArguments(), 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.
Extra new line?
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.
Done.
return RUN_ALL_TESTS(); | ||
} | ||
|
||
} // namespace backend |
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.
AFAIK we are not commenting the namespaces ends (or if we did, you missed them before :))
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.
Done.
visualizer/visualizer.cc
Outdated
std::string configFile = initialConfigFile; | ||
if (argc > 1) { | ||
configFile = argv[1]; | ||
// Loads all the arguments into global attributes so any plugin can access to |
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.
Small suggestion: "Loads all the command line parameters into a set of global attributes, so that any plugin can access them 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.
Done.
EXPECT_EQ(global_attributes::SetArgument("def_456"), 1); | ||
EXPECT_EQ(global_attributes::GetArgument(0), std::string("abc_123")); | ||
EXPECT_EQ(global_attributes::GetArgument(1), std::string("def_456")); | ||
EXPECT_EQ(global_attributes::GetNumberOfArguments(), 2); |
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.
Wouldn't it be better to have using global_attributes::SetArgument
(same with others) at the top to avoid the verbosity in the tests?
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.
Done.
I did it by using the correct namespace.
Thanks @basicNew, it's ready for a second review. |
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.
Thanks @agalbachicar , I don't have further comments. I leave the last word on this to @caguero and/or @clalancette .
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 have two design concerns with this change:
- This is the first instance of delphyne-gui relying on drake itself. In some ways, this sort of breaks the abstraction between the GUI (visualizer) and the backend. While I'm not fundamentally against this, I think it might be a good idea to check with @stonier about this to make sure this is OK.
- One of the things that @stonier hated about the old automotive-demo was its reliance on command-line arguments, which quickly got unwieldy. I'm wondering if we could do this a different way. In particular, what if we somehow attached the monolane YAML to the backend, and then had the visualizer request the data via an ignition service? Would that sort of thing make sense?
Thanks @clalancette, both are valid points. Let me add some comments:
|
@clalancette based on what we discussed in the meeting, do you think this one would be good to go? |
Given the discussions, my design questions are answered, so that's good. I'm going to give the code a quick review now. |
cmake/TestUtils.cmake
Outdated
@@ -29,14 +29,15 @@ macro (delphyne_build_tests) | |||
) | |||
|
|||
target_link_libraries(${BINARY_NAME} | |||
#${IGNITION-COMMON_LIBRARIES} | |||
${IGNITION-COMMON_LIBRARIES} | |||
#${IGNITION-GUI_LIBRARIES} |
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 know you didn't add these, but we should probably just remove all of these commented-out libraries. We can add them as needed.
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.
Done.
EXPECT_EQ(GetArgument(1), std::string("def_456")); | ||
EXPECT_EQ(GetNumberOfArguments(), 2); | ||
} | ||
|
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.
It would probably be a good idea to add a test for the index being out-of-range and throwing an exception.
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.
As the API was changed, a new set of tests were done. I think this one does not apply any more.
visualizer/visualizer.cc
Outdated
configFile = argv[1]; | ||
// Loads all the command line parameters into a set of global attributes, so | ||
// that any plugin can access them later. | ||
for (int i = 0; i < argc; ++i) { |
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 don't think you want to start at 0 here, since that is the name of the program and isn't really a parameter.
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.
Done.
visualizer/GlobalAttributes.hh
Outdated
/// \throws std::runtime_error When index is negative or it is higher or equal | ||
/// to the total number of arguments. | ||
DELPHYNE_GUI_VISIBLE | ||
std::string GetArgument(const int index); |
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.
In general, I really don't like this interface, since it ties an implementation detail of the high-level application (the position of the index in the argv
array) into the lower levels, that have to know that. Also, using indices this way means that you can't launch the visualizer with a monolane YAML file and no config file (for instance), which seems like a valid thing to potentially do. I know we want to stay simple here, but I think I would really prefer to use a simple command-line argument parser, make the passing of the YAML files an option (--load-yaml=filename
, or similar), and then have this interface be a map between a parameter name and the value (e.g. callers would call GetArgument('load-yaml')
and get back filename
.
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 guess the new code is much more aligned now. Let me know if you think something should be changed.
fc450d8
to
a3b54d8
Compare
- Adds a script to easily run the visualizer with MaliputViewer layout.
a3b54d8
to
604554d
Compare
Thanks for your comments @clalancette . I believe the code is much better now. I've also added a script to run the viewer and ommit Maliput layout when running, so it is less verbose now. After building, you should be able to run it like:
PTAL. |
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.
@agalbachicar Thanks a lot! I like this a lot better. There is one backwards-compatibility issue we have to consider here. Prior to this PR, we always passed in the layout as the first, non-option command-line argument. A bunch of scripts in https://github.com/ToyotaResearchInstitute/delphyne rely on that behavior, so if we merge this, those are going to break. I'm fine with making this change (I think this is a big improvement), but could you please do a PR over in delphyne fixing up those users as well? Sorry to keep dragging this out, but I think this will be much better in the end.
@clalancette, PR : maliput/delphyne#223 was created to pair delphyne master branch with this PR. PTAL. |
I see that we're manually parsing all command line arguments. I'm fine with that but if we're going to extend this in the future maybe it's not a terrible idea to add a new gflags dependency or similar to deal with this. |
visualizer/GlobalAttributes.hh
Outdated
|
||
namespace delphyne { | ||
namespace gui { | ||
namespace global_attributes { |
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.
Do we need a new namespace? I think the answer depends if we plan to have multiple files related with global attributes. If the answer is yes, I would leave it, although probably in its own directory. Usually, I've seen a new namespace associated to a new directory in the source file. If we don't plan to have additional files related with global attributes maybe we can live without the namespace.
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.
Given that no further archives are going to be added (at least for the moment) to this namespace I chose to create a class to namespace those methods and removed global_attributes
namespace.
Let me know if you think this is more convenient.
EXPECT_TRUE(HasArgument("foo")); | ||
EXPECT_TRUE(HasArgument("bar")); | ||
EXPECT_TRUE(HasArgument("sample_param")); | ||
EXPECT_EQ(GetArgument("foo"), "bar"); |
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.
Consider to swap the parameters on all EXPECT_EQ
. The expected value should be in the first place. On failure, this macro outputs text that describes the first argument as the expected and the seconds as the thing under test.
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.
Done.
Yeah, same here. I think it's fine to not introduce this dependency now, and instead do a separate PR for that. @agalbachicar , if you don't mind, I'd appreciate it if you could open an issue about switching to something more standard for command-line argument parsing. |
@caguero: thanks for the review! I've addressed your comments. PTAL. @clalancette : issue #50 was created. |
Thank you! |
In this PR you'll find:
It addresses second and third item of issue #35. It closes #28 .