Behavior groups#
Behaviors may be grouped to compute their commands all together, like for example to implement a centralized controller.
Groups#
Behaviors group must implement a single interface compute_cmds
(C++
, Python
) that computes the commands for all members. Commands should be kinematically feasible, but it is not strictly required.
Virtual methods#
C++ method |
Python method |
override |
---|---|---|
must |
Class skeleton#
#include "navground/core/behavior_group.h"
namespace core = navground::core;
struct MyBehaviorGroup : public core::BehaviorGroup {
// MUST override
core::Twist2 compute_cmd_internal(ng_float_t time_step) override;
};
from navground import core
class MyBehaviorGroup(core.BehaviorGroup):
# MUST override
def compute_cmds(self, time_step: float) -> list[core.Twist2]: ...
Members#
Members of the groups are behaviors that delegates their compute_cmd_internal
(C++
, Python
) to the group.
Their definition requires to specify:
how they are grouped using
get_group_hash
(C++
,Python
, behavior with the same key will belong to the same group);where groups are stored (globally) using
get_groups
(C++
,Python
);
Warning
Users should call prepare
(C++
, Python
) before the first call and
close
(C++
, Python
) after the final call of a behavior. This will setup and tear down the groups.
Virtual methods#
C++ method |
Python method |
override |
---|---|---|
must |
||
must |
||
can |
Class skeleton#
#include "navground/core/behavior_group.h"
namespace core = navground::core;
struct MyBehaviorGroupMember : public core::BehaviorGroupMember {
using core::BehaviorGroupMember::Groups;
// MUST override
Groups * get_groups() const override;
// MUST override
std::shared_ptr<core::BehaviorGroup> * make_group() const override;
// CAN override
// size_t get_group_hash() const override;
};
from navground import core
class MyBehaviorGroupMember(core.BehaviorGroupMember):
# Groups could be stored in a class variable
_groups: dict[int, core.BehaviorGroup] = {}
# MUST override
def get_groups(self) -> dict[int, core.BehaviorGroup]:
return self._groups
# MUST override
def make_group(self) -> core.BehaviorGroup: ...
# CAN override
# def get_group_hash(self) -> int: ...