BT14:自定义的用于枚举类型的SwitchNode

大家好,欢迎大家关注我的知乎专栏慢慢悠悠小马车


内建SwitchNode的局限 

BT6:ControlNodes源码解析 - 知乎icon-default.png?t=M276https://zhuanlan.zhihu.com/p/472996050

BehaviorTree.CPP中有内建的SwitchNode,定义在 BehaviorTree.CPP/include/behaviortree_cpp_v3/controls/switch_node.h。但是其只能接收string类型的值,因为定义的input port就是string类型。

static PortsList providedPorts() {
  PortsList ports;
  ports.insert(BT::InputPort<std::string>("variable"));
  for (unsigned i = 0; i < NUM_CASES; i++) {
    char case_str[20];
    sprintf(case_str, "case_%d", i + 1);
    ports.insert(BT::InputPort<std::string>(case_str));
  }
  return ports;
}

这样用起来很不方便,大多数switch-case的逻辑都是和枚举值一起用的。因此我实现了一个自定义的control node,用来接收枚举类型的值,称为EnumSwitchNode。改动很简单,只需将input port的类型改为模板,并检查输入类是枚举类型。

Talk is cheap, let's see the code.

自定义的EnumSwitchNode

#ifndef BTNODES_CONTROL_NODES_ENUM_SWITCH_NODE_H
#define BTNODES_CONTROL_NODES_ENUM_SWITCH_NODE_H

#includ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值