-
Notifications
You must be signed in to change notification settings - Fork 65
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b449826
Added lua preprocessor for flatland yaml files
josephduchesne f658fdd
Fixed lint
josephduchesne b51924f
Fixed all unit tests
josephduchesne e350570
Added enable/disable support to plugins, models and joints. Fixed bug…
josephduchesne 92a0586
Fixed handling of booleans
josephduchesne fdfac77
added yaml preprocessor documentation
josephduchesne 660154e
tried to fix documentation
josephduchesne f69fc64
tried to fix documentation
josephduchesne aedb8b7
Update yaml_preprocessor.h
josephduchesne df63e0f
Extended model documentation to document the enabled flag
josephduchesne a0640a4
Addressed Luke's code review comments
josephduchesne a17c3e6
Merged in remote
josephduchesne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.. image:: ../_static/flatland_logo2.png | ||
:width: 250px | ||
:align: right | ||
:target: ../_static/flatland_logo2.png | ||
|
||
Yaml Preprocessor | ||
============================== | ||
|
||
Flatland Server has 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. | ||
|
||
body/joint/plugin enabled flag | ||
------------------------------ | ||
Model bodies, plugins and joints now have a new flag `enabled` which can be set to true or false either directly in the yaml, or based on more complex logic from a lua `$eval` string that returns "true" or "false". Disabled bodies, plugins and joints are skipped during yaml loading, and as a result are never instantiated. From Flatland's perspective `enabled: false` causes the affected body/plugin/joint to be deleted. | ||
|
||
bindings for env and param | ||
------------------------------- | ||
|
||
Additional lua function bindings (beyond the normal standard libraries such as string, math, etc.): | ||
|
||
.. code-block:: lua | ||
|
||
env(EnvName) -- blank string + warning if not found | ||
env(EnvName, Default) | ||
param(ParamPath) -- blank string + warning if not found | ||
param(ParamPath, Default) | ||
|
||
Sample expressions | ||
------------------------------ | ||
|
||
.. code-block:: yaml | ||
|
||
foo: $eval "Some arbitrary LUA expression" | ||
bar: | # Multiline string | ||
$eval -- $eval flag required to trigger LUA parsing | ||
if env("FRONT_WHEEL",true) then | ||
return 1.2 | ||
else | ||
return 2.4 | ||
end | ||
|
||
Lua expressions can explicitly `return` their value, but if no `return` is given, one will be prepended to the statement. | ||
|
||
env + param examples | ||
----------------------------- | ||
|
||
.. code-block:: yaml | ||
|
||
# in: (SOME_ENV not set) | ||
foo: $eval env("SOME_ENV") | ||
# out: | ||
foo: "" | ||
|
||
.. code-block:: yaml | ||
|
||
# in: (SOME_ENV not set) | ||
foo: $eval env("SOME_ENV", false) | ||
# out: | ||
foo: false | ||
|
||
.. code-block:: yaml | ||
|
||
# in: (export SOME_ENV=true) | ||
foo: $eval env("SOME_ENV") | ||
# out: | ||
foo: true | ||
|
||
.. code-block:: yaml | ||
|
||
# in: (rosparam /test/param not set) | ||
foo: $eval param("/test/param", 0)/2.0 | ||
# out: | ||
foo: 0 | ||
|
||
.. code-block:: yaml | ||
|
||
# in: (rosparam /test/param set to 5.0) | ||
foo: $eval param("/test/param", 0)/2.0 + 1 | ||
# out: | ||
foo: 2.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
flatland_server/include/flatland_server/yaml_preprocessor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* ______ __ __ __ | ||
* /\ _ \ __ /\ \/\ \ /\ \__ | ||
* \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____ | ||
* \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\ | ||
* \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\ | ||
* \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/ | ||
* \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/ | ||
* @copyright Copyright 2018 Avidbots Corp. | ||
* @name yaml_preprocessor.h | ||
* @brief Yaml preprocessor using Lua | ||
* @author Joseph Duchesne | ||
* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2017, Avidbots Corp. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the Avidbots Corp. nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef FLATLAND_SERVER_YAML_PREPROCESSOR_H | ||
#define FLATLAND_SERVER_YAML_PREPROCESSOR_H | ||
|
||
#include <flatland_server/exceptions.h> | ||
#include <yaml-cpp/yaml.h> | ||
|
||
#include <lauxlib.h> | ||
#include <lua.h> | ||
#include <lualib.h> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace flatland_server { | ||
|
||
/** | ||
*/ | ||
namespace YamlPreprocessor { | ||
/** | ||
* @brief Preprocess with a given node | ||
* @param[in/out] node A Yaml node to parse | ||
* @return The parsed YAML::Node | ||
*/ | ||
void Parse(YAML::Node &node); | ||
|
||
/** | ||
* @brief Constructor with a given path to a yaml file, throws exception on | ||
* failure | ||
* @param[in] path Path to the yaml file | ||
* @return The parsed YAML::Node | ||
*/ | ||
YAML::Node LoadParse(const std::string &path); | ||
|
||
/** | ||
* @brief Find and run any $eval nodes | ||
* @param[in/out] node A Yaml node to recursively parse | ||
*/ | ||
void ProcessNodes(YAML::Node &node); | ||
|
||
/** | ||
* @brief Find and run any $eval expressions | ||
* @param[in/out] node A Yaml string node to parse | ||
*/ | ||
void ProcessScalarNode(YAML::Node &node); | ||
|
||
/** | ||
* @brief Get an environment variable with an optional default value | ||
* @param[in/out] lua_State The lua state/stack to read/write to/from | ||
*/ | ||
int LuaGetEnv(lua_State *L); | ||
|
||
/** | ||
* @brief Get a rosparam with an optional default value | ||
* @param[in/out] lua_State The lua state/stack to read/write to/from | ||
*/ | ||
int LuaGetParam(lua_State *L); | ||
}; | ||
} | ||
|
||
#endif // FLATLAND_SERVER_YAML_PREPROCESSOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,7 +301,11 @@ void Layer::LoadFromBitmap(const cv::Mat &bitmap, double occupied_thresh, | |
} | ||
|
||
void Layer::DebugVisualize() const { | ||
ROS_WARN("======== 3d visualize? ==========="); | ||
// Don't try to visualized uninitalized layers | ||
if (viz_name_.length() == 0) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was an old debugging statement. I removed it. |
||
} | ||
|
||
DebugVisualization::Get().Reset(viz_name_); | ||
DebugVisualization::Get().Reset(viz_name_ + "_3d"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
Are these bindings used for reading the environment variable and rosparam? If so can you explicitly say it?
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.
That's a good point! I'll add that in another pr.