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

Loads a monolane YAML file from CLI. #39

Merged
merged 4 commits into from
Feb 7, 2018

Conversation

agalbachicar
Copy link
Collaborator

In this PR you'll find:

  • GlobalAttirbutes: a super simple library to hold CLI arguments.
  • A copy of a delphyne cmake macro to look for Drake's libraries.
  • A copy of ignition gui System.hh file to provide visibility to symbols.
  • Some basic tests for GlobalAttributes library.
  • A copy of double_ring.yaml file from Drake to have a sample at hand.
  • Monolane load in the plugin.

It addresses second and third item of issue #35. It closes #28 .

- 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.
Copy link

@basicNew basicNew left a 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.

@@ -0,0 +1,49 @@
# -*- yaml -*-

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?)

Copy link
Collaborator Author

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);


Choose a reason for hiding this comment

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

Extra new line?

Copy link
Collaborator Author

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

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 :))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

std::string configFile = initialConfigFile;
if (argc > 1) {
configFile = argv[1];
// Loads all the arguments into global attributes so any plugin can access to

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"

Copy link
Collaborator Author

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);

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?

Copy link
Collaborator Author

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.

@agalbachicar
Copy link
Collaborator Author

Thanks @basicNew, it's ready for a second review.

Copy link

@basicNew basicNew left a 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 .

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.

I have two design concerns with this change:

  1. 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.
  2. 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?

@basicNew
Copy link

Thanks @clalancette, both are valid points. Let me add some comments:

  1. The visualizer needs to be able to parse a file (or, later on, a ign transport message) and create a road network in memory. To do this we agreed on using maliput as a library, so there is indeed a dependency
    between the road network visualizer and drake (and I think it is ok). However, I agree that we shouldn't depend on the whole libdrake.so but instead find a way to export (or bazel install) only maliput as a library.
  2. Loading the yaml from the command line was a specific requirement for this first iteration. The idea is that someone working on a road network can quickly launch a visualizer from the command line and load a file. However that is just the first version. Further iterations will bring a UI file open prompt and a better integration with the backend to retrieve the model from an ign message. So you are on the right track, but we are just doing a first prototype now :).

@basicNew
Copy link

basicNew commented Feb 1, 2018

@clalancette based on what we discussed in the meeting, do you think this one would be good to go?

@clalancette
Copy link
Contributor

@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.

@@ -29,14 +29,15 @@ macro (delphyne_build_tests)
)

target_link_libraries(${BINARY_NAME}
#${IGNITION-COMMON_LIBRARIES}
${IGNITION-COMMON_LIBRARIES}
#${IGNITION-GUI_LIBRARIES}
Copy link
Contributor

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.

Copy link
Collaborator Author

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);
}

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

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) {
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 you want to start at 0 here, since that is the name of the program and isn't really a parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

/// \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);
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@agalbachicar agalbachicar force-pushed the Issue/#28_Load_Maliput_File branch from fc450d8 to a3b54d8 Compare February 2, 2018 20:28
- Adds a script to easily run the visualizer with MaliputViewer layout.
@agalbachicar agalbachicar force-pushed the Issue/#28_Load_Maliput_File branch from a3b54d8 to 604554d Compare February 2, 2018 20:33
@agalbachicar
Copy link
Collaborator Author

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:

 maliput_viewer.sh --yaml_file=${PATH_TO_DELPHYNE_WS}/install/share/delphyne/road_samples/double_ring.yaml

PTAL.

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.

@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.

@agalbachicar
Copy link
Collaborator Author

@clalancette, PR : maliput/delphyne#223 was created to pair delphyne master branch with this PR. PTAL.

@caguero
Copy link
Contributor

caguero commented Feb 7, 2018

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.


namespace delphyne {
namespace gui {
namespace global_attributes {
Copy link
Contributor

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.

Copy link
Collaborator Author

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");
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@clalancette
Copy link
Contributor

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.

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.

@agalbachicar
Copy link
Collaborator Author

@caguero: thanks for the review! I've addressed your comments. PTAL.

@clalancette : issue #50 was created.

@agalbachicar agalbachicar merged commit 805a6c4 into master Feb 7, 2018
@agalbachicar agalbachicar deleted the Issue/#28_Load_Maliput_File branch February 7, 2018 18:24
@clalancette
Copy link
Contributor

@clalancette : issue #50 was created.

Thank you!

@stonier stonier mentioned this pull request Feb 8, 2018
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actually load a maliput file
4 participants