Fallback Nodes

翻译自:https://www.behaviortree.dev

Fallback

This family of nodes are known as “Selector” or “Priority” in other frameworks. [这一系列节点在其他框架中称为“选择器”或“优先级”。]

Their purpose is to try different strategies, until we find one that “works”. [他们的目的是尝试不同的策略,直到我们找到一种“有效”的策略。]

Currently the framework provides two kinds of nodes: [目前该框架提供了两种节点:]

  • Fallback [倒退]
  • ReactiveFallback [反应式回退]

They share the following rules: [他们共享以下规则:]

  • Before ticking the first child, the node status becomes RUNNING. [在tick第一个子节点之前,节点状态变为 RUNNING。]

  • If a child returns FAILURE, the fallback ticks the next child. [如果一个孩子返回 FAILURE,则回退会tick下一个孩子。]

  • If the last child returns FAILURE too, all the children are halted and the fallback returns FAILURE. [如果最后一个子节点也返回 FAILURE,则所有子节点都将停止并且回退返回 FAILURE。]

  • If a child returns SUCCESS, it stops and returns SUCCESS. All the children are halted. [如果孩子返回 SUCCESS,它会停止并返回 SUCCESS。所有的孩子都停了下来。]

To understand how the two ControlNodes differ, refer to the following table: [要了解这两个 ControlNode 有何不同,请参阅下表:]

Type of ControlNodeChild returns RUNNING
FallbackTick again
ReactiveFallbackRestart
  • Restart” means that the entire fallback is restarted from the first child of the list. [“重新启动”意味着整个后备从列表的第一个孩子重新开始。]

  • Tick again” means that the next time the fallback is ticked, the same child is ticked again. Previous sibling, which returned FAILURE already, are not ticked again. [“再次tick”表示下一次tick后备,再次tick同一个孩子。已经返回 FAILURE 的前一个兄弟姐妹不再tick。]

Fallback

In this example, we try different strategies to open the door. Check first (and once) if the door is open. [在这个例子中,我们尝试不同的策略来开门。首先(并且一次)检查门是否打开。]
在这里插入图片描述

example “See the pseudocode”

		// index is initialized to 0 in the constructor
		status = RUNNING;

   	while( _index < number_of_children )
   	{
   		child_status = child[index]->tick();
   		
   		if( child_status == RUNNING ) {
   			// Suspend execution and return RUNNING.
   			// At the next tick, _index will be the same.
   			return RUNNING;
   		}
   		else if( child_status == FAILURE ) {
   			// continue the while loop
   			_index++;
   		}
   		else if( child_status == SUCCESS ) {
   			// Suspend execution and return SUCCESS.
   		    HaltAllChildren();
   			_index = 0;
   			return SUCCESS;
   		}
   	}
   	// all the children returned FAILURE. Return FAILURE too.
   	index = 0;
   	HaltAllChildren();
   	return FAILURE;

ReactiveFallback

This ControlNode is used when you want to interrupt an asynchronous child if one of the previous Conditions changes its state from FAILURE to SUCCESS. [如果前面的条件之一将其状态从 FAILURE 更改为 SUCCESS,则当您想要中断异步子节点时使用此 ControlNode。]

In the following example, the character will sleep up to 8 hours. If he/she has fully rested, then the node areYouRested? will return SUCCESS and the asynchronous nodes Timeout (8 hrs) and Sleep will be interrupted. [在下面的示例中,角色最多可以睡 8 个小时。如果他/她已经充分休息,那么节点 areYouRested?将返回 SUCCESS,异步节点超时(8 小时)和睡眠将被中断。]

在这里插入图片描述

example “See the pseudocode”

   	status = RUNNING;

   	for (int index=0; index < number_of_children; index++)
   	{
   		child_status = child[index]->tick();
   		
   		if( child_status == RUNNING ) {
   			// Suspend all subsequent siblings and return RUNNING.
   			HaltSubsequentSiblings();
   			return RUNNING;
   		}
   		
   		// if child_status == FAILURE, continue to tick next sibling
   		
   		if( child_status == SUCCESS ) {
   			// Suspend execution and return SUCCESS.
   			HaltAllChildren();
   			return SUCCESS;
   		}
   	}
   	// all the children returned FAILURE. Return FAILURE too.
   	HaltAllChildren();
   	return FAILURE;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值