Base class#
#include "navground/core/behavior.h"
This class describes a generic behavior to reach a target position avoiding collision.
Users should not instantiate this class, which will not make the agent move, but one of its concrete sub-classes equipped with the desired navigation algorithms, which are implemented by overriding any of the (virtual) methods listed in compute_cmd_internal.
The following describes the typical usage of a behavior.
At initialization
select the concrete behavior, the agent’s size (agents are shaped like discs), and Kinematics;
configure the generic parameters: set_optimal_speed, set_horizon, set_safety_margin set_rotation_tau, and set_heading_behavior;
configure the specific parameters of the concrete behavior.
At regular time intervals
update the agent’s state with set_pose and set_twist (or other convenience methods)
update the target with set_target
update the environment state get_environment_state
ask for a control commands by calling compute_cmd
actuate the control commands through user code
Subclassed by navground::core::DummyBehavior, navground::core::HLBehavior, navground::core::HRVOBehavior, navground::core::ORCABehavior
Public Types
Different behavior variants for the angular motion when it is no constrained by the kinematics or already specified by the current target.
They ability to apply them depends on the kinematics and on the current target.
Values:
keep the same orientation
turn towards the target position (if any)
turn towards the target orientation (if any)
follow a target angular speed (if any)
turn towards the velocity direction. This is the only behavior available to constrained kinematics.
Public Functions
Constructs a new instance.
- Parameters:
kinematics – The kinematics of the agent.
radius – The radius of the agent.
Gets the kinematics.
- Returns:
The agent’s kinematics.
Sets the kinematics.
- Parameters:
value – [in] The desired kinematics.
Gets the radius of the agent.
- Returns:
The agent’s radius.
Sets the radius of the agent.
- Parameters:
value – A positive value.
Gets the maximal speed.
- Returns:
The maximal speed returned from Kinematics::get_max_speed
Sets the maximal speed.
- Parameters:
value – [in] The value to pass to Kinematics::set_max_speed
Gets the maximal angular speed speed.
- Returns:
The maximal angular speed from Kinematics::get_max_angular_speed
Sets the maximal angular speed speed.
- Parameters:
value – [in] The value to pass to Kinematics::set_max_angular_speed.
Gets the desired optimal speed.
If not configured through set_optimal_speed, it return get_max_speed.
- Returns:
The desired optimal speed.
Sets the desired optimal speed.
- Parameters:
value – [in] A positive linear speed.
Clamp a speed in the range of feasible values given by the kinematics.
- Parameters:
value – [in] The desired value
- Returns:
the nearest feasible value
Clamp an angular speed in the range of feasible values given by the kinematics.
- Parameters:
value – [in] The desired value
- Returns:
the nearest feasible value
Clamp an twist in the range of feasible values given by the kinematics.
- Parameters:
value – [in] The desired value
- Returns:
the nearest feasible value
Computes the nearest feasible twist given the kinematics and the current twist over a time step.
- Parameters:
value – [in] The desired value
time_step – [in] The time step
- Returns:
the nearest feasible value
Gets the desired optimal angular speed.
If not configured through set_optimal_angular_speed, it will return set to get_max_angular_speed.
- Returns:
The desired optimal angular speed.
Sets the optimal angular speed.
- Parameters:
value – [in] A positive angular speed in radians/time unit.
Gets the relaxation time to rotate towards a desired orientation.
The default behaviors applies a P control to rotations, e.g., \(\omega = \frac{\delta \theta}{\tau_\textrm{rot}}\)
- Returns:
The rotation relaxation time.
Sets the relaxation time to rotate towards a desired orientation. See get_rotation_tau.
- Parameters:
value – [in] The rotation relaxation time. Set it to a zero or negative to rotate as fast as possible.
Gets the minimal safety margin to keep away from obstacles.
- Returns:
The safety margin.
Sets the safety margin to keep away from obstacles.
- Parameters:
value – [in] A positive value.
Gets the horizon: the size of the portion of environment around the agent considered when computing possible collisions. Larger values generally lead to a more computationally expensive compute_cmd but fewer deadlocks and less jamming.
- Returns:
The horizon.
Sets the horizon, see get_horizon.
- Parameters:
value – [in] A positive value.
Gets whether to assume that the compute command will be actuated as it is.
If set, Behavior will assume that the control command computed by compute_cmd be actuated, therefore setting set_actuated_twist to that value. If not set, the user should set Behavior::set_actuated_twist before querying for a new control commands: some behavior use the old actuated control command to compute smoother controls.
- Returns:
True if it assumes that the command will be actuated as it is.
Sets whether to assume that the compute command will be actuated as it is.
See also
- Parameters:
value – [in] The desired value.
Gets the path relaxation time.
- Returns:
The time.
Sets the path relaxation time, see get_path_tau.
- Parameters:
value – [in] A positive value.
Gets the path look-ahead distance.
- Returns:
The distance.
Sets the path look-ahead distance, see get_path_look_ahead.
- Parameters:
value – [in] A positive value.
Gets the current pose in the world-fixed frame.
- Returns:
The current pose.
Sets the current pose in the world-fixed frame.
- Parameters:
value – [in] The desired value
Convenience method to get the current position in the world-fixed frame. See get_pose.
- Returns:
The position.
Convenience method to set the current position in the world-fixed frame. See set_pose.
- Parameters:
value – [in] The desired value
Convenience method to get the current orientation. See get_pose.
- Returns:
The current orientation.
Convenience method to set the current orientation. See set_pose.
- Parameters:
value – [in] The desired value
Gets the current twist.
- Parameters:
frame – [in] The desired frame of reference.
- Returns:
The current twist.
Sets the current twist.
- Parameters:
value – [in] The desired value
Convenience method to get the current velocity. See get_twist.
- Parameters:
frame – [in] The desired frame of reference.
- Returns:
The velocity.
Convenience method to set the current velocity. See set_twist.
- Parameters:
value – [in] The velocity
frame – [in] The desired frame of reference.
Convenience method to get the current speed. See get_twist.
- Returns:
The current speed.
Convenience method to get the current the angular speed.
- Returns:
The current angular speed.
Convenience method to get the current wheel speeds. See get_twist.
- Returns:
The wheel speeds.
Convenience method to set the current wheel speeds. See set_twist.
- Parameters:
value – [in] The wheel speeds
Gets the last actuated twist.
- Parameters:
frame – [in] The desired frame of reference.
- Returns:
The actuated twist.
Sets the last actuated twist.
- Parameters:
value – [in] The desired value
Convenience method to get the last actuated wheel speeds from actuated_twist.
If the agent is not wheeled (Kinematics::is_wheeled), an empty vector is returned.
- Returns:
The actuated wheel speeds.
Actuate a twist command, integrating using Pose2::integrate.
- Parameters:
twist_cmd – [in] The twist
time_step – [in] The time step
enforce_feasibility – [in] Whether to enforce that the command is kinematically feasible
Convenience method to actuate the stored actuated twist command,.
- Parameters:
time_step – [in] The time step
Clone the state of this behavior from another behavior.
- Parameters:
other – [in] The other behavior
Gets the heading behavior:
- Returns:
The heading behavior.
Sets the heading behavior, see get_heading_behavior. When the kinematics has only 2 degrees of freedom (see Kinematics::dof()), the only available behavior is Heading::velocity.
- Parameters:
value – [in] The desired value
Gets the target.
- Returns:
The target.
Gets a reference to the target.
- Returns:
The target.
Sets the target.
- Parameters:
value – [in] The desired value
Query the behavior to get a control command.
Before calling this method, update the state using methods such as set_pose, and set_twist and set the target set_target.
Behaviors may use caching to speed up the next queries if the state does not change.
Modulations are applied as wrappers/context modifiers: right before evaluating the behavior in compute_cmd_internal, it will call BehaviorModulation::pre for any modulation in get_modulations, and right after BehaviorModulation::post but in reverse order.
- Parameters:
time_step – [in] The control time step. Not all behavior use it but some may use it, for example, to limit accelerations.
frame – [in] An optional desired frame of reference for the command.
enforce_feasibility – [in] Whether to enforce that the command is kinematically feasible
- Returns:
The control command as a twist in the specified frame.
Gets the last computed desired velocity.
- Returns:
The desired velocity (only valid if computed) in Frame::absolute
Transform a twist to Frame::absolute.
- Parameters:
value – [in] The original twist
- Returns:
The same twist in Frame::absolute (unchanged if already in Frame::absolute)
Transform a twist to Frame::relative.
- Parameters:
value – [in] The original twist
- Returns:
The same twist in Frame::relative (unchanged if already in Frame::relative)
Transform a vector (e.g., a velocity) from Frame::absolute to Frame::relative.
- Parameters:
value – [in] The vector in Frame::absolute
- Returns:
The vector in Frame::relative
Convert a twist to a reference frame.
- Parameters:
value – [in] The original twist.
frame – [in] The desired frame of reference
- Returns:
The twist in the desired frame of reference.
Convenience method to transform from twist to wheel speeds.
If the agent is not wheeled (Kinematics::is_wheeled), an empty vector is returned.
- Parameters:
value – [in] The twist
- Returns:
The corresponding wheel speeds.
Convenience method to transform from wheel speeds to twist.
If the agent is not wheeled (Kinematics::is_wheeled), an zero twist is returned.
- Parameters:
value – [in] The wheel speeds
- Returns:
The corresponding twist.
Gets the environment state.
- Returns:
The environment state.
Check if the current target has been satisfied.
- Returns:
True if the current target has been satisfied.
Estimate how much time before the target is satisfied.
- Returns:
A positive value if the target is not yet satisfied, else 0.
Determines if the agent is stuck: if should move but it is still.
- Returns:
True if stuck, False otherwise.
Gets the efficacy: the projection of the current velocity on the ideal velocity (ignoring obstacles) towards the target.
A value of 1.0 denotes ideal efficacy, value of 0.0 that the agent is stuck.
- Returns:
The efficacy.
Gets the modulations applied to this behavior.
- Returns:
The modulations.
Gets the modulations applied to this behavior.
- Returns:
The modulations.
Adds a modulation.
- Parameters:
value – [in] The modulation to add
Removes a modulation.
- Parameters:
value – [in] The modulation to remove
Removes all modulations.
Returns the target’s position if not satisfied, else null.
- Parameters:
frame – [in] The desired frame
- Returns:
The position in the desired frame
Returns the target’s orientation if not satisfied, else null.
- Parameters:
frame – [in] The desired frame
- Returns:
The orientation in the desired frame
Returns the direction towards the target’s position if not satisfied, or the target’s direction if defined, else null.
- Parameters:
frame – [in] The desired frame
- Returns:
The normalized direction in the desired frame
Returns the distance to the target point, if valid, else null.
- Parameters:
ignore_tolerance – [in] Whether to ignore the target tolerance
- Returns:
The distance.
Gets the current target velocity.
Multiplication of \ref get_target_direction by \ref get_target_speed. Returns a zero vector if the target direction is undefined.
- Parameters:
frame – [in] The desired frame
- Returns:
The velocity in the desired frame.
Returns the nearest feasible speed to target’s speed, if defined, else to the behavior own optimal speed.
- Returns:
The speed
Returns the nearest feasible angular speed to target’s angular speed, if defined, else to the behavior own optimal angular speed.
- Returns:
The angular speed.
Public Members
The behavior social margin modulation
Public Static Functions
Get a named Heading mode.
Public Static Attributes
Default rotation tau
Default horizon
Default safety margin
Default safety margin
Default safety margin
Protected Functions
Computes the control command.
This is a virtual protected that sub-classes may override to define a behavior and is not part of the public API. Users should call compute_cmd instead.
The base implementation checks for a valid target:
position along a path => calls cmd_twist_along_path
pose => calls cmd_twist_towards_pose
position => calls cmd_twist_towards_point
orientation => calls cmd_twist_towards_orientation
velocity => calls cmd_twist_towards_velocity
angular speed => calls cmd_twist_towards_angular_speed
else => calls cmd_twist_towards_stopping.
To specialize a Behavior, users may override this or any of the methods listed above. They may also override the following internal methods:
The command should be kinematically feasible. The base implementation does not guaranteed it, delegating the check to the methods listed above.
- Parameters:
time_step – [in] The time step
- Returns:
The command in the desired frame.
Compute a command to follow a path.
Users may override it to specialize a Behavior.
The base implementation uses a carrot planner to computes a target velocity, and then calls cmd_twist_towards_velocity.
- Parameters:
path – The desired path in world-fixed frame
speed – [in] The desired speed
time_step – [in] The time step
- Returns:
The command twist.
Computes a command to move towards a desired pose.
Users may override it to specialize a Behavior.
The base implementation ignores the orientation, calling call cmd_twist_towards_point, to first reach the desired position and then rotate in place to reach the desired orientation.
- Parameters:
pose – [in] The desired pose in world-fixed frame
speed – [in] The desired speed
angular_speed – [in] The desired angular speed
time_step – [in] The time step
- Returns:
The command twist.
Computes a command to move towards a desired position.
Users may override it to specialize a Behavior.
The base implementation:
calls desired_velocity_towards_point to compute a desired velocity
calls twist_towards_velocity to compute a desired twist
returns the nearest feasible twist.
- Parameters:
point – [in] The desired position in world-fixed frame
speed – [in] The desired speed
time_step – [in] The time step
- Returns:
The command twist.
Computes a command to turn towards a desired orientation.
Users may override it to specialize a Behavior.
The base implementation:
calls desired_velocity_towards_velocity to compute a desired velocity
calls twist_towards_velocity to compute a desired twist
returns the nearest feasible twist.
- Parameters:
velocity – [in] The velocity in world-fixed frame
time_step – [in] The time step
- Returns:
The command twist.
Computes a command to turn towards a desired orientation.
Users may override it to specialize a Behavior.
The base implementation:
computes a desired angular speed to rotate in get_rotation_tau time towards the desired orientation
- Parameters:
orientation – [in] The desired orientation in world-fixed frame
angular_speed – [in] The desired angular speed
time_step – [in] The time step
- Returns:
The command twist.
Computes a command to turn at a desired angular speed.
Users may override it to specialize a Behavior.
The base implementation returns the nearest feasible twist to a twist with null velocity and desired angular speed.
- Parameters:
angular_speed – [in] The desired angular speed
time_step – [in] The time step
- Returns:
The command twist.
Computes a command to stop.
Users may override it to specialize a Behavior.
The base implementation returns the null twist.
- Parameters:
time_step – [in] The time step
- Returns:
The command twist.
Computes a control velocity towards a desired position.
Users may override it to specialize a Behavior.
The base implementation returns a null vector.
- Parameters:
point – [in] The desired point in world-fixed frame
speed – [in] The desired speed
time_step – [in] The time step
- Returns:
A velocity in world-fixed frame
Computes a control velocity towards a desired velocity.
Users may override it to specialize a Behavior.
The base implementation returns a null vector.
- Parameters:
velocity – [in] The desired velocity in world-fixed frame
time_step – [in] The time step
- Returns:
A velocity in world-fixed frame
Computes a twist to reach a control velocity.
This method assumes that the control velocity is safe. Use it to convert a velocity to a twist once you have computed (using, e.g., desired_velocity_towards_point or desired_velocity_towards_velocity) a safe control velocity.
- Parameters:
velocity – [in] The control velocity in world-fixed frame
- Returns:
A command twist.