World#
#include "navground/sim/world.h"
A rectangulare region
Super-class that adds a unique ID to world entities.
This unique ID should not be fed to navigation behaviors, but only used internally by the simulation, for instance, to identify entities in a UI.
Subclassed by navground::sim::Agent, navground::sim::Obstacle, navground::sim::Wall
Public Functions
Constructs a new instance.
Constructs a new instance.
- Parameters:
id – [in] The identifier
Determines if the entity has been in collision at least once since the given time.
- Parameters:
time – [in] The time
- Returns:
True if been in collision since, False otherwise.
Returns the last collision time.
- Returns:
The time
Resets the entity.
Public Members
Unique identifier
Public Static Functions
Reset the UID counter to zero.
A static obstacle with circular shape.
Public Functions
Constructs a new instance.
- Parameters:
position – [in] The position of the circle
radius – [in] The radius of the circle
Constructs a new instance.
Constructs a new instance.
- Parameters:
disc – [in] A disc
Disc conversion operator.
Public Members
The disc.
A static wall.
Currently, only line segment are valid shapes of walls.
Public Functions
Constructs a new instance.
- Parameters:
p1 – [in] The line segment start vertex
p2 – [in] The line segment end vertex
Constructs a new instance.
Constructs a new instance.
- Parameters:
ls – [in] A line segment
LineSegment conversion operator.
Public Members
The line segment.
Ghost agents used in worlds that have a lattice.
This class describes a world.
A world implements the core part of the simulation. It holds a collection of entities as walls, obstacles, and agents.
After setting up the world entities, users call update or run to perform one or more simulation steps, where
each agent updates its control
each agent perform actuate its control command
collisions are checked and resolved
time is advanced
World simulation uses a simple collision model that does not attempt to be realistic but should be computationally efficient.
first runs a broad-phase using
libgeos STR Trees <>
_ where potential collisions are found using rectangular bounding boxes.then it runs a narrow-phase using the simple exact geometric shape of the obstacles and record pairs of entities that are in collision.
finally it resolves collisions by colliding moving minimally entities away from each other, setting to zero the component of their velocities that would attract them together.
Public Types
An (optional) one dimensional lattice defined by the initial point and the size of the cell.
A callback to be executed at each simulation step
A condition for the simulation to terminate
Public Functions
Constructs a new instance.
Updates world for a single time step.
- Parameters:
time_step – [in] The time step
Updates world for a single time step without actuation and collisions resolution.
- Parameters:
time_step – [in] The time step
advance_time – [in] Whenever to advance time too.
Actuate then controllers and perform collisions resolutions.
- Parameters:
time_step – [in] The duration of each time step
Updates the world for one or more time steps.
- Parameters:
steps – [in] The number of steps
time_step – [in] The duration of each time step
Updates the world until a condition is satisfied.
- Parameters:
condition – [in] The condition
time_step – [in] The duration of each time step
Gets the simulation time.
- Returns:
The simulation time.
Gets the simulation step.
- Returns:
The simulation step.
Adds an agent to the world.
- Parameters:
agent – [in] The agent
Remove an agent from the world.
- Parameters:
agent – [in] The agent
Remove an agent from the world.
- Parameters:
uid – [in] The uid of the agent
Adds a line to the world as a wall.
- Parameters:
line – [in] The line
Adds a wall to the world.
- Parameters:
wall – [in] The wall
Adds a disc the world as a static obstacle.
- Parameters:
disc – [in] The disc
Adds a static obstacle the world.
- Parameters:
obstacle – [in] The obstacle
Adds a random obstacles in the world bounding box.
It iteratively try to sample a disc that is far enough of any other item. If the sampling fails, it counts as a try and the process stop after either enough obstacles have been added or enough tries performed.
- Parameters:
number – [in] The number of obstacles
min_radius – [in] The minimum radius of obstacles
max_radius – [in] The maximum radius of obstacles
margin – [in] The minimal distance to other obstacles or agents. For agents, it’s additional to their safety margin.
max_tries – [in] The maximum tries before terminating.
Gets all agents in this world.
- Returns:
All agents.
Gets all neighbor of an agent.
- Parameters:
agent – [in] The agent
distance – [in] The radius of the neighborhood
ignore_lattice – [in] Whether to ignore the lattice when computing neighbors
- Returns:
All neighbor within a circle of radius
radius
centered around the agent.
Split a bounding box by the lattice-induced grid.
- Parameters:
bounding_box – [in] The bounding box
ignore_lattice – [in] Indicates if the lattice is to be ignored
- Returns:
A vector of pairs of translation (along the lattice) and subset of the bounding box that fit in that lattice cell.
Gets all agents in a bounding box.
- Parameters:
bb – [in] The bounding box specified in world-fixed coordinates
- Returns:
All agents that lie in a bounding box.
Gets all obstacles in a bounding box.
- Parameters:
bb – [in] The bounding box specified in world-fixed coordinates
- Returns:
All obstacles that lie in a bounding box.
Gets all obstacles in this world.
- Returns:
All obstacles.
Gets all disc shaped static obstacles in this world.
- Parameters:
ignore_lattice – [in] Whether to ignore the lattice
- Returns:
All obstacles.
Gets all agents in a bounding box.
- Parameters:
bb – [in] The bounding box specified in world-fixed
ignore_lattice – [in] Whether to ignore the lattice when computing neighbors
- Returns:
All obstacles that lie in a bounding box
Gets all walls in this world.
- Returns:
All walls.
Gets all line obstacles in this world.
- Returns:
All ine obstacles.
Gets all walls in a bounding box.
- Parameters:
bb – [in] The bounding box specified in world-fixed
- Returns:
All walls that lie in a bounding box
Replaces all obstacles.
- Parameters:
obstacles – [in] The new obstacles
Replaces all walls.
- Parameters:
walls – [in] The new walls
Gets the colliding pairs computed during the last simulation step.
- Returns:
The colliding pair of entities.
Calculates the safety violation, i.e. the maximal penetration of a neighbor or obstacle in the safety margin of the agent.
- Parameters:
agent – [in] The agent
safety_margin – [in] The safety margin. If not set, it will default to the agent’s behavior safety margin.
- Returns:
The safety violation or 0 if no violation.
The random generator shared by all distribution used to generate and simulate this world.
- Returns:
The random generator
Sets the random generator shared by all distribution used to generate and simulate this world.
- Parameters:
value – [in] The desired random generator
Copy the random generator from another world.
- Parameters:
world – [in] The world
Gets the random seed.
- Returns:
The random seed.
Sets the random seed.
- Parameters:
seed – [in] The random seed
Check if all agents are idle (i.e., their tasks are done and their controller are idle).
- Returns:
True if all agents are idle
Check if all agents are idle or stuck (i.e., they are no moving because they task is done or they are deadlocked)
- Returns:
True if all agents are idle or stuck
Move agents so that they do not overlap anymore with themselves or with any obstacle.
- Parameters:
minimal_distance – [in] The minimal distance
with_safety_margin – [in] Whether the safety margin should be added to the minimal distance
max_iterations – [in] The maximal number of iterations to perform.
Determines if this world uses a lattice.
- Returns:
True if it uses a lattice, False otherwise.
Gets the periodic lattice.
- Parameters:
axis – [in] The axis (0 for x, 1 for y)
- Returns:
An optional tuple of points that define a periodic lattice that wraps the selected axis.
Sets the periodic lattice.
- Parameters:
axis – [in] The axis (0 for x, 1 for y)
value – [in] An optional tuple of points that define a periodic lattice that wraps the selected axis. Pass none to unset the lattice and remove wrapping.
The N=0, 1, or 2 vectors that define the lattice, e.g.,
{delta_x, -delta_x}
if only the axis=0 lattice is set.- Parameters:
include_zero – [in] Whether to include the zero vector
c8 – [in] Whether to use 8-connectivity instead of 4-connectivity
- Returns:
A vector of 2D vectors
Gets the lattice cell.
- Returns:
The lattice cell.
Check if two entities are currently in collision.
- Parameters:
e1 – [in] The first entity
e2 – [in] The second entity
- Returns:
True if they are in collision.
Find an entity by identifier.
- Parameters:
uid – [in] The entity uid
- Returns:
The entity or nullptr if not found.
Find an agent by identifier.
- Parameters:
uid – [in] The agent uid
- Returns:
The agent or nullptr if not found.
Adds a callback to be executed after each simulation step.
- Parameters:
value – [in] The callback
Clear all the callbacks.
Sets a condition to terminate simulations.
- Parameters:
value – [in] The desired condition.
Returns whether there is a termination condition set.
- Returns:
True if a termination condition has been set.
Checks whether the simulation should terminate.
- Returns:
True if a termination condition is set and evaluates to true.
Gets the agents that had a collision after
now - duration
.- Parameters:
duration – [in] The duration
- Returns:
The agents in collision.
Gets the agents that are in stuck since
now - duration
.- Parameters:
duration – [in] The duration
- Returns:
The agents in deadlock.
Snap agents’ twists smaller than epsilon to zero.
- Parameters:
epsilon – [in] The tolerance
Searches for the index of an agent.
- Parameters:
agent – [in] The agent
- Returns:
The index of this agent in the world agents list or null if not found.
Gets the bounding box that contains all agents, obstacles and walls.
- Returns:
The computed bounding box.
Sets the bounding box.
- Parameters:
value – [in] The desired value. Pass none to unset the bounding box.
Gets the bounding box.
- Returns:
The bounding box that has been set with set_bounding_box or get_minimal_bounding_box in case none is set.
Determines if a bounding box is set.
- Returns:
True if bounding box is set, False otherwise.
Notify that some agents have moved, therefore the str tree need to be updated.
Record the collision between two entities.
- Parameters:
e1 – The first entity
e2 – The second entity
Clear collisions.