Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jayscoder committed Apr 21, 2024
1 parent 7edbba7 commit 63bacf0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
23 changes: 9 additions & 14 deletions pybts/composites/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ def stop(self, new_status: Status = Status.INVALID) -> None:
Args:
new_status: behaviour will transition to this new status
"""
self.logger.debug(
"%s.stop(%s)"
% (
self.__class__.__name__,
"%s->%s" % (self.status, new_status)
)
)
super().stop(new_status)
# Priority interrupt handling
if new_status == Status.INVALID:
self.current_child = None
Expand All @@ -53,12 +47,6 @@ def stop(self, new_status: Status = Status.INVALID) -> None:
): # redundant if INVALID->INVALID
child.stop(new_status)

# Regular Behaviour.stop() handling
# could call directly, but replicating here to avoid repeating the logger
self.terminate(new_status)
self.status = new_status
self.iterator = self.tick()

def tip(self) -> typing.Optional[behaviour.Behaviour]:
"""
Recursive function to extract the last running node of the tree.
Expand Down Expand Up @@ -266,6 +254,9 @@ def seq_sel_tick(

def switch_tick(self, index: int | typing.Callable[['Composite'], int], tick_again_status: list[Status]) -> \
typing.Iterator[py_trees.behaviour.Behaviour]:
self.debug_info['tick_count'] += 1
self.logger.debug("%s.tick()" % (self.__class__.__name__))

if self.status in tick_again_status:
# 重新执行上次执行的子节点
assert self.current_child is not None
Expand All @@ -280,7 +271,11 @@ def switch_tick(self, index: int | typing.Callable[['Composite'], int], tick_aga
# 清除子节点的状态(停止正在执行的子节点)
child.stop(Status.INVALID)

self.status = self.current_child.status
new_status = self.current_child.status
if new_status != Status.RUNNING:
self.stop(new_status)

self.status = new_status
yield self

def gen_index(self):
Expand Down
4 changes: 2 additions & 2 deletions pybts/composites/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def tick(self) -> typing.Iterator[py_trees.behaviour.Behaviour]:
# 否则就认为执行失败
new_status = Status.FAILURE

# if new_status != Status.RUNNING:
# self.stop(new_status)
if new_status != Status.RUNNING:
self.stop(new_status)

self.status = new_status
yield self
Expand Down
2 changes: 1 addition & 1 deletion pybts/composites/switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Switcher(Composite):
- jinja2模版: 从context中获取
- random: 随机数
"""

def __init__(self, index: typing.Union[int, str] = 'random', **kwargs):
super().__init__(**kwargs)
self.index = index
Expand Down

0 comments on commit 63bacf0

Please sign in to comment.