行为树注册Action函数

registerSimpleAction

1
2
3
4
5
6
void BT::BehaviorTreeFactory::registerSimpleAction (const std::string&  ID,
const SimpleActionNode::TickFunctor & tick_functor,
PortsList ports = {}
)

typedef std::function<NodeStatus(TreeNode&)> BT::SimpleActionNode::TickFunctor

registerSimpleAction help you register nodes of type SimpleActionNode.

其实就是std::bind的用法,如果在类内的成员函数里注册,应该如下使用

1
2
3
4
5
6
7
8
9
10
BT::NodeStatus TestBT()
{
printf("TestBT\n");
return BT::NodeStatus::SUCCESS;
}

void memberFunc()
{
this->registerSimpleAction("TestBT", std::bind(&BtFactory::TestBT, this) );
}

外部调用时,将类对象本身的地址作为this指针传入

1
2
Class a;
obj.registerSimpleAction(std::bind(&Class::TestBT, &a, placeholders::_1, placeholders::_2));

registerNodeType

行为树注册时,是注册节点的ModelName,而不是InstanceName

报错

  1. 不识别新添加的Action类

factory.registerNodeType<ActionReportError>("ReportError");报了很多错,都是undefine error。解决方法:到CMake里先把对应的cpp文件去掉,编译后报错,再添加回来,成功