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;
  // ...
};

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 base cmd_twist_towards_point

  • desired_velocity_towards_velocity, used by the base cmd_twist_towards_velocity

  • twist_towards_velocity, use by by the base cmd_twist_towards_point and cmd_twist_towards_velocity.

The command produced by compute_cmd_internal should be kinematically feasible, but it is not strictly required.

Virtual methods#

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;
};