Comments (6)
@peterdavidfagan Thanks for submitting the issue. There are two ways to go about adding this functionality. 1) modify the code generation logic and Python template or 2) try to make use of Python's flexibility to construct the dictionary dynamically. I would prefer option two if possible, that a method can simply be added to the Jinja template. The following implementation should work.
def to_dict(self):
out = {}
def to_dict_internal(instance, base_name):
if isinstance(instance, (str, numbers.Number, list)):
out.update({base_name: instance})
else:
data = [attr for attr in dir(instance) if not callable(getattr(instance, attr)) and not attr.startswith("__") and attr is not "stamp_"]
for attr in data:
to_dict_internal(getattr(instance, attr), ("" if base_name == "" else base_name + ".") + attr)
to_dict_internal(self, "")
return out
Unfortunately, I am not aware of a simpler way to achieve this. Plus, it is unclear if there is a missing edge case in filtering the output of the dir
method. If you or anyone has a suggestion, I'd be interested to get feedback.
from generate_parameter_library.
@peterdavidfagan Awesome, that sounds like a good plan. I think it might be better to add the method to the Params
(below this line ) class instead. That way, the syntax you proposed will work.
param_dict = param_listener.get_params().to_dict()
from generate_parameter_library.
That way, the syntax you proposed will work.
Makes sense, I'll hopefully get to this item before the end of this week.
from generate_parameter_library.
Hey @pac48,
I haven't opened pr yet as I did not finish these changes, but I have been meaning to follow up on this. Currently we are using the policy deployment code in our lab but have been reading yaml files directly via Python. At the moment, I am focused on completing a simulation env for a benchmark, in the new year I have a deadline for policy deployment baselines at which point I plan to update the moveit python library policy deployment code + tutorials. I will look to complete these changes when I am pushing this code.
from generate_parameter_library.
Thanks @pac48, I agree with your suggestion (2), this makes sense and thanks for sharing your code for this. I had started a similar method locally as a util, I'll look to combine this with your code and open a pull request with this method if this works for you?
I'll look to add the method to the ParamListener.
from generate_parameter_library.
@peterdavidfagan I just wanted to ping you about this request. If you were able to make the change feel free to open a PR.
from generate_parameter_library.
Related Issues (20)
- Feature request: Unsigned integers
- Add `# flake8: noqa` tag to generated files HOT 5
- Python cmake example not working HOT 3
- Question: how to handle an array of custom data structures? HOT 7
- Changing Parameter Library Header Installation Location HOT 1
- Issues building mapped data
- How does the installation process work? HOT 2
- Changing parameter declaration HOT 2
- Statically Sized Parameters HOT 3
- Allow nested map definitions HOT 3
- Error when building with different package structure
- Inheritance? HOT 1
- gt<> sets a maximum numeric limit to std::numeric_limits<int>::max() instead of std::numeric_limits<int64_t>::max()
- ROSIDL-compatible Types
- Build hangs in Dockerized Bitbucket CI with coverage flags HOT 1
- Reading External Node Parameters
- How to include the parameters in a dependent package? HOT 4
- Store codegen result for python code in build folder
- Set parameters from YAML dictionary. HOT 3
- Jazzy/Rolling release please? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from generate_parameter_library.