Agent#

#include "navground/sim/agent.h"
class Agent : public navground::sim::Entity#

This class describes an agent.

The agent navigates in the environment using a task, a state estimation, a kinematic and a behavior, and a controller.

Agents have a circular shape which should match the shape of their navigation navground::core::Behavior.

The role of task and state estimation is to provide goals and environment state (perception) to the behavior.

Agents have a public identifies id that is accessible by the other agents’ state estimation and may be passed to their behavior as navground::core::Neighbor::id. This identifier may not be unique (e.g., may be used to identifies groups of agents).

Agents runs their update at the rate set by control_period even if the world is updated at a faster rate.

Public Functions

inline Agent(ng_float_t radius = 0, std::shared_ptr<Behavior> behavior = nullptr, std::shared_ptr<Kinematics> kinematics = nullptr, std::shared_ptr<Task> task = nullptr, std::shared_ptr<StateEstimation> estimation = nullptr, ng_float_t control_period = 0, unsigned id = 0)#

Constructs a new instance.

Parameters:
  • radius[in] The radius of the agent

  • behavior[in] The behavior

  • kinematics[in] The kinematics

  • task[in] The task

  • estimation[in] The estimation

  • control_period[in] The control period

  • id[in] The public identifier

inline Neighbor as_neighbor() const#

Returns a neighbor representation of the agent with the same shape, position and id.

Returns:

The neighbor representation

inline Neighbor as_translated_neighbor(const Vector2 &delta) const#

Returns a neighbor representation of the agent with the same shape and id but with position translated by delta.

Parameters:

delta[in] The delta

Returns:

The neighbor representation

inline void set_state_estimation(const std::shared_ptr<StateEstimation> &value)#

Sets the state estimation.

Parameters:

value[in] The desired value

inline StateEstimation *get_state_estimation() const#

Gets the state estimation.

Returns:

The state estimation.

void set_behavior(const std::shared_ptr<Behavior> &value)#

Sets the navigation behavior.

Automatically set the behavior radius and kinematics to match the agent.

Parameters:

value[in] The desired value

inline Behavior *get_behavior() const#

Gets the navigation behavior.

Returns:

The navigation behavior.

inline void set_kinematics(const std::shared_ptr<Kinematics> &value)#

Sets the kinematics.

Parameters:

value[in] The desired value

inline Kinematics *get_kinematics() const#

Gets the kinematics.

Returns:

The kinematics.

inline void set_task(const std::shared_ptr<Task> &value)#

Sets the task.

Parameters:

value[in] The desired value

inline Task *get_task() const#

Gets the task.

Returns:

The task.

inline Controller *get_controller()#

Gets the navigation controller.

Returns:

The controller.

inline const Controller *get_controller() const#

Gets the navigation controller.

Returns:

The controller.

bool idle() const#

Returns whether the task is done and the control is idle.

Returns:

False if it has an active task or if the control is running

Twist2 get_last_cmd(core::Frame frame) const#

Gets the last command.

Returns:

The controller.

inline Twist2 get_last_cmd() const#

Gets the last command.

Returns:

The command.

inline void set_last_cmd(const Twist2 &value)#

Sets the last command.

Parameters:

value[in] The value

inline Twist2 get_actuated_cmd() const#

Gets the last actuated command.

        The actuated command is always kinematically feasible
Returns:

The command.

inline Pose2 get_pose() const#

Gets the current pose.

Returns:

The current pose.

inline void set_pose(const Pose2 &value)#

Sets the current pose.

Parameters:

value[in] The pose

inline Twist2 get_twist() const#

Gets the current twist.

Returns:

The current twist.

inline void set_twist(const Twist2 &value)#

Sets the current twist.

Parameters:

value[in] The value

inline void add_tag(const std::string &tag)#

Adds a tag.

Parameters:

tag[in] The tag

inline void remove_tag(const std::string &tag)#

Removes a tag.

Parameters:

tag[in] The tag

void actuate(const Twist2 &cmd, ng_float_t dt)#

Actuate the current agent control command.

Parameters:
  • dt[in] The time step

  • cmd[in] The desired command

inline bool has_been_stuck_since(ng_float_t time) const#

Determines if the agent has been stuck since a given time.

Parameters:

time[in] The time

Returns:

True if been stuck since, False otherwise.

inline ng_float_t get_time_since_stuck() const#

Gets the time since the agents has been stuck.

Returns:

The time since stuck.

inline bool get_enabled() const#

Gets whether the agent is enabled.

        Disabled agents are ignored in the simulation.
Returns:

True if enabled.

inline void set_enabled(bool value)#

Sets whether the agent is enabled.

        Disabled agents are ignored in the simulation.
Parameters:

value[in] The desired value

Public Members

unsigned id#

The agent public identifier

ng_float_t radius#

The agent radius

ng_float_t control_period#

The control period

Pose2 pose#

The current pose

Twist2 twist#

The current twist

Twist2 last_cmd#

The last control command

std::string type#

The type of the agent.

The agent type should not used by the neighbors state estimation. It is mainly used internally to draw the agents in the UI.

std::string color#

The color of the agent.

A valid CSS color to fill the agent in the UI or empty to use the default color.

std::set<std::string> tags#

A set of tags used to label the agent.

Tags are used to add meta-information about an agent, for instance when it gets generated by a scenario.

bool external#

Whether the agent is controlled externally.

External agents are not controlled by this simulation but are part of the state estimation used by the agents controlled in this simulation.

Public Static Functions

static inline std::shared_ptr<Agent> make(ng_float_t radius = 0, std::shared_ptr<Behavior> behavior = nullptr, std::shared_ptr<Kinematics> kinematics = nullptr, std::shared_ptr<Task> task = nullptr, std::shared_ptr<StateEstimation> estimation = nullptr, ng_float_t control_period = 0, unsigned id = 0)#

Factory method to build an agent.

Parameters:
  • radius[in] The radius of the agent

  • behavior[in] The behavior

  • kinematics[in] The kinematics

  • task[in] The task

  • estimation[in] The estimation

  • control_period[in] The control period

  • id[in] The public identifier

Returns:

A new agent