Skip to content

Commit

Permalink
fixing issue microsoft#22
Browse files Browse the repository at this point in the history
getParam refering to a blackboard would always fail in the constructor,
because the blackboard pointer is still null.
  • Loading branch information
Davide Faconti committed Nov 29, 2018
1 parent df7f81d commit 7bf053d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/behaviortree_cpp/decorators/timeout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TimeoutNode : public DecoratorNode
uint64_t timer_id_;

unsigned msec_;
bool refresh_parameter_;
};
}

Expand Down
15 changes: 9 additions & 6 deletions src/controls/parallel_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ ParallelNode::ParallelNode(const std::string& name, int threshold)
ParallelNode::ParallelNode(const std::string &name,
const NodeParameters &params)
: 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()
{
Expand Down
9 changes: 6 additions & 3 deletions src/controls/sequence_star_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions src/decorators/repeat_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions src/decorators/retry_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 11 additions & 3 deletions src/decorators/timeout_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>("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);
Expand Down

0 comments on commit 7bf053d

Please sign in to comment.