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

Lua preprocessor for yaml #45

Merged
merged 12 commits into from
Jun 4, 2018
Merged

Conversation

josephduchesne
Copy link
Member

@josephduchesne josephduchesne commented Jun 4, 2018

Added a lua preprocessor for YAML with simple bindings for the environment variables and rosparam.
The intent is to be able to build parametric models that are defined by dimensions and flags found in either environment variables or rosparam, in a similar way to xacro+urdf. Because this is parsed at model load time, any roslaunch rosparam loading will have completed and those parameters will be available.

Documentation: https://flatland-simulator.readthedocs.io/en/lua-preprocessor-for-yaml/core_functions/yaml_preprocessor.html

@josephduchesne josephduchesne requested a review from cmperezg June 4, 2018 13:49
@lichunshang
Copy link
Collaborator

cool! So this embeds Lua code into the yaml files?

@josephduchesne
Copy link
Member Author

josephduchesne commented Jun 4, 2018

Yeah. The use case for Avidbots is being able to create one flatland configuration file for each robot, and parametrically load in the cleaning head dimensions, enable/disable sensors based on configuration, etc.

I was originally going to create a domain specific language for conditionally enabling parts of a model, but it was a complexity explosion. Lua is designed for fast, easy integration, and supports way more functionality that we really need. I was mostly interested in arbitrary math equations, nested conditionals, and the ability to integrate with rosparam/environment variables, which this PR achieves in <700 lines of code including documentation and unit test coverage.

The intent is to provide near feature parity with xacro+urdf in terms of being able to parametrically define everything, and conditionally load things.

@josephduchesne josephduchesne requested a review from kubuqi June 4, 2018 15:02

/**
*/
class YamlPreprocessor {
Copy link

Choose a reason for hiding this comment

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

Since all members of this class are public static, why don't just make it a namespace? At this stage it has nothing to do with class.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

ROS_WARN("======== 3d visualize? ===========");
// Don't try to visualized uninitalized layers
if (viz_name_.length() == 0) {
return;
Copy link

Choose a reason for hiding this comment

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

Not sure when will this happen, but do we need a warning here?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was an old debugging statement. I removed it.

<< " disabled");
continue;
} else {
ROS_WARN_STREAM("Body "
Copy link

Choose a reason for hiding this comment

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

Do we really need a warning for enabled bodies? If we don't we can get rid of the entire else clause. Same is true for the other object loadings.

<< body_reader.Get<std::string>("name", "unnamed")
<< " disabled");
continue;
} else {
Copy link

Choose a reason for hiding this comment

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

Just a style preference, we don't really need else here if we have continue above.

ProcessScalarNode(node);
}
break;
}
Copy link

Choose a reason for hiding this comment

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

Add a case default to catch any unexpected types, if any. It also is a clear statement that all cases have been considered.

ROS_INFO_STREAM("Attempting to parse lua " << value);

try {
if (value.find("return ") ==
Copy link

Choose a reason for hiding this comment

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

The scope of this try{} block can be reduced by moving these string manipulations out.

Copy link

@kubuqi kubuqi left a comment

Choose a reason for hiding this comment

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

Looks good other than some minor comments.

@josephduchesne josephduchesne merged commit 5a852d6 into master Jun 4, 2018
bindings for env and param
-------------------------------

Additional lua function bindings (beyond the normal standard libraries such as string, math, etc.):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these bindings used for reading the environment variable and rosparam? If so can you explicitly say it?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point! I'll add that in another pr.

JoaoCostaIFG pushed a commit to JoaoCostaIFG/flatland that referenced this pull request Nov 30, 2022
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.

3 participants