diff --git a/include/behaviortree_cpp/decorators/timeout_node.h b/include/behaviortree_cpp/decorators/timeout_node.h index 717efb76b307e4..393353d45d733b 100644 --- a/include/behaviortree_cpp/decorators/timeout_node.h +++ b/include/behaviortree_cpp/decorators/timeout_node.h @@ -33,6 +33,7 @@ class TimeoutNode : public DecoratorNode uint64_t timer_id_; unsigned msec_; + bool refresh_parameter_; }; } diff --git a/src/controls/parallel_node.cpp b/src/controls/parallel_node.cpp index 35360a481bce4a..33446b2976b194 100644 --- a/src/controls/parallel_node.cpp +++ b/src/controls/parallel_node.cpp @@ -28,14 +28,17 @@ ParallelNode::ParallelNode(const std::string& name, int threshold) ParallelNode::ParallelNode(const std::string &name, const NodeParameters ¶ms) : ControlNode::ControlNode(name, params), - refresh_parameter_(false) - { - if( !getParam(THRESHOLD_KEY, threshold_) ) + refresh_parameter_(false) +{ + refresh_parameter_ = isBlackboardPattern( params.at(THRESHOLD_KEY) ); + if(!refresh_parameter_) { - throw std::runtime_error("Missing parameter [threshold] in ParallelNode"); + if( !getParam(THRESHOLD_KEY, threshold_) ) + { + throw std::runtime_error("Missing parameter [threshold] in ParallelNode"); + } } - refresh_parameter_ = isBlackboardPattern( params.at(THRESHOLD_KEY) ); - } +} NodeStatus ParallelNode::tick() { diff --git a/src/controls/sequence_star_node.cpp b/src/controls/sequence_star_node.cpp index 65e30c3cd25acc..96f3a5d778844a 100644 --- a/src/controls/sequence_star_node.cpp +++ b/src/controls/sequence_star_node.cpp @@ -30,11 +30,14 @@ SequenceStarNode::SequenceStarNode(const std::string& name, const NodeParameters : ControlNode::ControlNode(name, params), current_child_idx_(0), refresh_parameter_(false) { - if( !getParam(RESET_PARAM, reset_on_failure_) ) + refresh_parameter_ = isBlackboardPattern( params.at(RESET_PARAM) ); + if(!refresh_parameter_) { - throw std::runtime_error("Missing parameter [reset_on_failure] in SequenceStarNode"); + if( !getParam(RESET_PARAM, reset_on_failure_) ) + { + throw std::runtime_error("Missing parameter [reset_on_failure] in SequenceStarNode"); + } } - refresh_parameter_ = isBlackboardPattern( params.at(RESET_PARAM) ); } NodeStatus SequenceStarNode::tick() diff --git a/src/decorators/repeat_node.cpp b/src/decorators/repeat_node.cpp index 6b6dca29681da1..8cad7c853dc6f3 100644 --- a/src/decorators/repeat_node.cpp +++ b/src/decorators/repeat_node.cpp @@ -30,11 +30,14 @@ RepeatNode::RepeatNode(const std::string& name, const NodeParameters& params) try_index_(0), refresh_parameter_(false) { - if( !getParam(NUM_CYCLES, num_cycles_) ) + refresh_parameter_ = isBlackboardPattern( params.at(NUM_CYCLES) ); + if(!refresh_parameter_) { - throw std::runtime_error("Missing parameter [num_cycles] in RepeatNode"); + if( !getParam(NUM_CYCLES, num_cycles_) ) + { + throw std::runtime_error("Missing parameter [num_cycles] in RepeatNode"); + } } - refresh_parameter_ = isBlackboardPattern( params.at(NUM_CYCLES) ); } NodeStatus RepeatNode::tick() diff --git a/src/decorators/retry_node.cpp b/src/decorators/retry_node.cpp index 68ccb500bb6ad5..15c68009c0eebb 100644 --- a/src/decorators/retry_node.cpp +++ b/src/decorators/retry_node.cpp @@ -30,11 +30,14 @@ RetryNode::RetryNode(const std::string& name, const NodeParameters& params) try_index_(0), refresh_parameter_(false) { - if( !getParam(NUM_ATTEMPTS, max_attempts_) ) + refresh_parameter_ = isBlackboardPattern( params.at(NUM_ATTEMPTS) ); + if(!refresh_parameter_) { - throw std::runtime_error("Missing parameter [num_attempts] in RetryNode"); + if( !getParam(NUM_ATTEMPTS, max_attempts_) ) + { + throw std::runtime_error("Missing parameter [num_attempts] in RetryNode"); + } } - refresh_parameter_ = isBlackboardPattern( params.at(NUM_ATTEMPTS) ); } NodeStatus RetryNode::tick() diff --git a/src/decorators/timeout_node.cpp b/src/decorators/timeout_node.cpp index 02a8a43ef57a62..352f4818e25031 100644 --- a/src/decorators/timeout_node.cpp +++ b/src/decorators/timeout_node.cpp @@ -21,15 +21,23 @@ TimeoutNode::TimeoutNode(const std::string& name, unsigned milliseconds) TimeoutNode::TimeoutNode(const std::string& name, const BT::NodeParameters& params) : DecoratorNode(name, params), child_halted_(false), msec_(0) { - auto param = getParam("msec"); - if (param) + refresh_parameter_ = isBlackboardPattern( params.at("msec") ); + if(!refresh_parameter_) { - msec_ = param.value(); + if( !getParam("msec", msec_) ) + { + throw std::runtime_error("Missing parameter [msec] in TimeoutNode"); + } } } NodeStatus TimeoutNode::tick() { + if( refresh_parameter_ ) + { + getParam("msec", msec_); + } + if (status() == NodeStatus::IDLE) { setStatus(NodeStatus::RUNNING);