Behaviors#
Environment state#
Behaviors must expose their local environment state through get_environment_state
to let other user update it. The returned type should be a sub-class of EnvironmentState
(C++
, Python
), which is an empty base class.
Therefore, if your behavior needs a new type of environment state, start by defining the new class
#include "navground/core/state.h"
struct MyEnvironmentState : public EnvironmentState {
using EnvironmentState::EnvironmentState;
// ...
};
from navground import core
class MyEnvironmentState(core.EnvironmentState):
def __init__(self):
super().__init()
Compute a command#
Behaviors are complex objects that can be specialized in different ways.
The public method compute_cmd
(C++
, Python
) calls the virtual method compute_cmd_internal
(C++
, Python
), which in turn calls forwards the request to different methods depending on which targets are currently in use:
position along a path:
cmd_twist_along_path
pose:
cmd_twist_towards_pose
position:
cmd_twist_towards_point
orientation:
cmd_twist_towards_orientation
velocity:
cmd_twist_towards_velocity
angular speed:
cmd_twist_towards_angular_speed
none:
cmd_twist_towards_stopping
.
To specialize a behavior, users may override compute_cmd_internal
or
any of the methods listed above.
They may also override the following internal methods:
desired_velocity_towards_point
, used by the basecmd_twist_towards_point
desired_velocity_towards_velocity
, used by the basecmd_twist_towards_velocity
twist_towards_velocity
, use by by the basecmd_twist_towards_point
andcmd_twist_towards_velocity
.
The command produced by compute_cmd_internal
should be kinematically feasible, but it is not strictly required.
Virtual methods#
C++ method |
Python method |
override |
---|---|---|
must |
||
can |
||
can |
||
can |
||
can |
||
can |
||
can |
||
can |
||
can |
||
can |
||
can |
Class skelethon#
#include "navground/core/behavior.h"
namespace core = navground::core;
struct MyBehavior : public core::Behavior {
MyEnvironmentState _env_state;
// MUST override ... the base returns an null pointer.
EnvironmentState *get_environment_state() const {return &_env_state; }
// CAN override
// core::Twist2 compute_cmd_internal(ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_along_path(Path &path, ng_float_t speed, ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_towards_pose(const Pose2 &pose, ng_float_t speed, Radians angular_speed, ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_towards_point(const core::Vector2 &point, ng_float_t speed, ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_towards_velocity(const core::Vector2 &velocity, ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_towards_orientation(Radians orientation, ng_float_t angular_speed, ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_towards_angular_speed(ng_float_t angular_speed, ng_float_t time_step) override;
// CAN override
// core::Twist2 cmd_twist_towards_stopping(ng_float_t time_step) override;
// CAN override
// core::Vector2 desired_velocity_towards_point(const core::Vector2 &point, ng_float_t speed, ng_float_t time_step) override;
// CAN override
// core::Vector2
// desired_velocity_towards_velocity(const core::Vector2 &velocity, ng_float_t time_step) override;
// CAN override
// core::Twist2 twist_towards_velocity(const core::Vector2 &velocity) override;
};
from navground import core
class MyBehavior(core.PyBehavior):
def __init__(self, kinematics: core.Kinematics | None = None, radius: float = 0):
super().__init__(kinematics, radius)
self._env_state = MyEnvironmentState()
def get_environment_state(self) -> core.EnvironmentState:
return self._env_state
# CAN override
# def compute_cmd_internal(time_step: float) -> core.Twist2: ...
# CAN override
# def cmd_twist_along_path(path: core.Path, speed: float , time_step: float) -> core.Twist2: ...
# CAN override
# def cmd_twist_towards_pose(pose: core.Pose2, speed: float , angular_speed: float, time_step: float , frame: core.Frame ) -> core.Twist2: ...
# CAN override
# def cmd_twist_towards_point(point: core.Vector2, speed: float , time_step: float) -> core.Twist2: ...
# CAN override
# def cmd_twist_towards_velocity(velocity: core.Vector2, time_step: float) -> core.Twist2: ...
# CAN override
# def cmd_twist_towards_orientation(orientation: float, angular_speed: float, time_step: float ) -> core.Twist2: ...
# CAN override
# def cmd_twist_towards_angular_speed(angular_speed: float, time_step: float) -> core.Twist2: ...
# CAN override
# def cmd_twist_towards_stopping(time_step: float) -> core.Twist2: ...
# CAN override
# def desired_velocity_towards_point(point: core.Vector2, speed: float , time_step: float) -> core.Vector2: ...
# CAN override
# def desired_velocity_towards_velocity(velocity: core.Vector2, time_step: float) -> core.Vector2: ...
# CAN override
# def twist_towards_velocity(velocity: core.Vector2) -> core.Twist2: ...