Conversation
|
@pakagronglb I think we may go with this implementation instead. If we decide to take this one I want to make sure you know that I really appreciate your contribution. Your PR forced me to think about this a bit more and spurred me to write the code. |
|
@SyZbidi this will be especially useful for simulation and excluding hardware specific behaviors. |
Thank you so much for the opportunity! I really appreciate it. It was a fun and challenging one. |
50b794c to
2a1c7a5
Compare
pakagronglb
left a comment
There was a problem hiding this comment.
I hope my feedback or output will be useful somehow. Thank you again for the opportunity.
Looking at the specific implementation code, I have a few technical observations:
-
Attribute Handling: The code removes the
ifattribute but doesn't appear to have attribute type validation. Consider adding type checking for condition values. -
Function Signature Analysis: The code has good handling of different function signatures (
behaviour,subtrees,tasks). However, for consistency, the conditional processing could be abstracted into its own helper method to keep_create_nodecleaner. -
Error Propagation: When raising BTParseError, it might be helpful to include more context about the failed condition in debug logs to aid troubleshooting.
-
Advanced Pattern: You could consider implementing a lightweight condition parser instead of direct evaluation for better security and flexibility:
def _parse_condition(self, condition_str, args):
# Safer condition parsing with explicit operator support
# This would allow for more controlled evaluation- Performance Enhancement: Since removing dictionary keys is an O(1) operation, you're handling things efficiently, but consider grouping the attribute processing:
# Extract and process special attributes in one block
special_attrs = {}
for attr in ["name", "if", "other_special_attr"]:
if attr in node_attribs:
special_attrs[attr] = node_attribs.pop(attr)This implementation looks solid overall - the approach of handling conditions as attributes is clean and leverages the existing parsing architecture well. Nice work!!!
|
This PR implements the conditional feature using a simple
ifkeyword.Fixes #5
Motivation and Context
To be able to include or exclude elements from a behavior tree in a programmatic way a conditional was necessary.
Changes
ifkeywordType of changes
Checklist
Testing
colcon build --packages-up-to py_trees_parsercolcon test --event-handlers console_cohesion+ --packages-select py_trees_parser