Skip to content
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

Understanding the Nodes #134

Open
NatkaB opened this issue Sep 8, 2021 · 1 comment
Open

Understanding the Nodes #134

NatkaB opened this issue Sep 8, 2021 · 1 comment

Comments

@NatkaB
Copy link

NatkaB commented Sep 8, 2021

I am trying to understand what each node in Groot does. I couldn't find information about some of them in the documentation. For example I do not understand what "BlackboardCheckString", "BlackboardCheckDouble" or "BlackboardCheckInt" do. Could someone explain this to me or show me the website with info about this?

@DoMissHome
Copy link

#ifndef DECORATOR_BLACKBOARD_PRECONDITION_NODE_H
#define DECORATOR_BLACKBOARD_PRECONDITION_NODE_H

#include "behaviortree_cpp_v3/decorator_node.h"

namespace BT
{
/**

  • This node excute its child only if the value of a given input port
  • is equal to the expected one.
  • If this precondition is met, this node will return the same status of the
  • child, otherwise it will return the value specified in "return_on_mismatch".
  • Example:
  • <BlackboardCheckInt value_A="{the_answer}"
  •                 value_B="42"
    
  •                 return_on_mismatch="FAILURE" />
    

*/
template
class BlackboardPreconditionNode : public DecoratorNode
{
public:
BlackboardPreconditionNode(const std::string& name, const NodeConfiguration& config)
: DecoratorNode(name, config)
{
if( std::is_same<T,int>::value)
setRegistrationID("BlackboardCheckInt");
else if( std::is_same<T,double>::value)
setRegistrationID("BlackboardCheckDouble");
else if( std::is_same<T,std::string>::value)
setRegistrationID("BlackboardCheckString");
}

virtual ~BlackboardPreconditionNode() override = default;

static PortsList providedPorts()
{
    return {InputPort("value_A"),
            InputPort("value_B"),
            InputPort<NodeStatus>("return_on_mismatch") };
}

private:
virtual BT::NodeStatus tick() override;
};

//----------------------------------------------------

template inline
NodeStatus BlackboardPreconditionNode::tick()
{
T value_A;
T value_B;
NodeStatus default_return_status = NodeStatus::FAILURE;

setStatus(NodeStatus::RUNNING);

if( getInput("value_A", value_A) &&
    getInput("value_B", value_B) &&
    value_B == value_A )
{
    return child_node_->executeTick();
}

if( child()->status() == NodeStatus::RUNNING )
{
    haltChild();
}
getInput("return_on_mismatch", default_return_status);
return default_return_status;

}

} // end namespace

#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants