behavior3行为树
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 line
901 B

  1. -module(wait).
  2. -include("eBhv3.hrl").
  3. -export([open/2, tick/2, close/2]).
  4. %%--------------------------------------------------------------------
  5. %% API functions
  6. %%--------------------------------------------------------------------
  7. -spec open(bt_node(), bt_state()) -> bt_state().
  8. open(#{id := ID}, BTState) ->
  9. blackboard:set(start_time, erlang:system_time(millisecond), ID, BTState).
  10. -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}.
  11. tick(#{id := ID, properties := #{milliseconds := EndTime}} = _BTNode, BTState) ->
  12. StartTime = blackboard:get(start_time, ID, BTState),
  13. case erlang:system_time(millisecond) - StartTime > EndTime of
  14. true ->
  15. {?BT_SUCCESS, BTState};
  16. false ->
  17. {?BT_RUNNING, BTState}
  18. end.
  19. -spec close(bt_node(), bt_state()) -> bt_state().
  20. close(#{id := ID} = _BTNode, BTState) ->
  21. blackboard:remove(start_time, ID, BTState).