Public Member Functions | Static Public Member Functions | Friends | List of all members
RVO::RVOSimulator Class Reference

#include <RVOSimulator.h>

Public Member Functions

 ~RVOSimulator ()
 
int addGoal (const Vector2 &position)
 
void setAgentDefaults (int velSampleCountDefault, float neighborDistDefault, int maxNeighborsDefault, float radiusDefault, float goalRadiusDefault, float prefSpeedDefault, float maxSpeedDefault, float safetyFactorDefault, float maxAccelDefault=RVO_INFTY, const Vector2 &velocityDefault=Vector2(0, 0), float orientationDefault=0, int classDefault=0)
 
int addAgent (const Vector2 &startPosition, int goalID)
 
int addAgent (const Vector2 &startPosition, int goalID, int velSampleCount, float neighborDist, int maxNeighbors, float radius, float goalRadius, float prefSpeed, float maxSpeed, float safetyFactor, float maxAccel=RVO_INFTY, const Vector2 &velocity=Vector2(0, 0), float orientation=0, int classID=0)
 
int addObstacle (const Vector2 &point1, const Vector2 &point2)
 
void setRoadmapAutomatic (bool automatic=true)
 
int addRoadmapVertex (const Vector2 &position)
 
int addRoadmapEdge (int vertexID1, int vertexID2)
 
void initSimulation ()
 
int doStep ()
 
bool getReachedGoal () const
 
float getGlobalTime () const
 
float getTimeStep () const
 
void setTimeStep (float stepSize)
 
int getNumAgents () const
 
bool getAgentReachedGoal (int agentID) const
 
const Vector2getAgentPosition (int agentID) const
 
void setAgentPosition (int agentID, const Vector2 &position)
 
const Vector2getAgentVelocity (int agentID) const
 
void setAgentVelocity (int agentID, const Vector2 &velocity)
 
float getAgentRadius (int agentID) const
 
void setAgentRadius (int agentID, float radius)
 
int getAgentVelSampleCount (int agentID) const
 
void setAgentVelSampleCount (int agentID, int samples)
 
float getAgentNeighborDist (int agentID) const
 
void setAgentNeighborDist (int agentID, float distance)
 
int getAgentMaxNeighbors (int agentID) const
 
void setAgentMaxNeighbors (int agentID, int maximum)
 
int getAgentClass (int agentID) const
 
void setAgentClass (int agentID, int classID)
 
float getAgentOrientation (int agentID) const
 
void setAgentOrientation (int agentID, float orientation)
 
int getAgentGoal (int agentID) const
 
void setAgentGoal (int agentID, int goalID)
 
float getAgentGoalRadius (int agentID) const
 
void setAgentGoalRadius (int agentID, float goalRadius)
 
float getAgentPrefSpeed (int agentID) const
 
void setAgentPrefSpeed (int agentID, float prefSpeed)
 
float getAgentMaxSpeed (int agentID) const
 
void setAgentMaxSpeed (int agentID, float maxSpeed)
 
float getAgentMaxAccel (int agentID) const
 
void setAgentMaxAccel (int agentID, float maxAccel)
 
float getAgentSafetyFactor (int agentID) const
 
void setAgentSafetyFactor (int agentID, float safetyFactor)
 
int getNumGoals () const
 
const Vector2getGoalPosition (int goalID) const
 
int getGoalNumNeighbors (int goalID) const
 
int getGoalNeighbor (int goalID, int neighborNr) const
 
int getNumObstacles () const
 
const Vector2getObstaclePoint1 (int obstacleID) const
 
const Vector2getObstaclePoint2 (int obstacleID) const
 
int getNumRoadmapVertices () const
 
const Vector2getRoadmapVertexPosition (int vertexID) const
 
int getRoadmapVertexNumNeighbors (int vertexID) const
 
int getRoadmapVertexNeighbor (int vertexID, int neighborNr) const
 

Static Public Member Functions

static RVOSimulatorInstance ()
 

Friends

class Agent
 
class Roadmap
 
class RoadmapVertex
 
class SweeplineComparator
 
class Obstacle
 
class Goal
 
class KDTree
 

Detailed Description

The main class of the RVO Library.

Constructor & Destructor Documentation

◆ ~RVOSimulator()

RVO::RVOSimulator::~RVOSimulator ( )

Deconstructor of the RVOSimulator instance.

Member Function Documentation

◆ addAgent() [1/2]

int RVO::RVOSimulator::addAgent ( const Vector2 startPosition,
int  goalID 
)

Adds an agent with default parameters to the simulation.

Parameters
startPositionThe start position of the agent
goalIDThe ID of the goal of the agent
Returns
The function returns the ID of the agent that has been added, and an errorcode if the agent defaults have not been set, or when the function is called after the simulation has been initialized.

◆ addAgent() [2/2]

int RVO::RVOSimulator::addAgent ( const Vector2 startPosition,
int  goalID,
int  velSampleCount,
float  neighborDist,
int  maxNeighbors,
float  radius,
float  goalRadius,
float  prefSpeed,
float  maxSpeed,
float  safetyFactor,
float  maxAccel = RVO_INFTY,
const Vector2 velocity = Vector2(0, 0),
float  orientation = 0,
int  classID = 0 
)

Adds an agent with specified parameters to the simulation.

Parameters
startPositionThe start position of the agent
goalIDThe ID of the goal of the agent
velSampleCountThe number of candidate velocities sampled for the agent in each step of the simulation. The running time of the simulation increases linearly with this number.
neighborDistThe distance within which the agent take other agents and obstacles into account in the navigation. The larger this number, the larger the running time of the simulation. If the number is too low, the simulation will not be safe.
maxNeighborsThe maximum number of other agents and obstacles the agent takes into account in the navigation. The larger this number, the larger the running time of the simulation. If the number is too low, the simulation will not be safe.
radiusThe radius of the agent
goalRadiusThe goal radius of the agent; an agent is said to have reached its goal when it is within a distance goalRadius from its goal position.
prefSpeedThe preferred speed of the agent
maxSpeedThe maximum speed of the agent
safetyFactorThe safety factor of the agent. I.e. the weight that is given to the 'time to collision' when penalizing a candidate velocity for the agent (vs. the distance to the preferred velocity). The higher this value, the 'safer' or the 'shyer' the agent is. The lower this value, the more 'aggressive' and 'reckless' the agent is. Its unit is distance.
maxAccelThe maximum acceleration of the agent
velocityThe initial velocity of the agent
orientationThe initial orientation of the agent
classIDThe class of the agent; the class of an agent does not affect the simulation, but can be used in external applications to distinguish among agents
Returns
The function returns the ID of the agent that has been added. It returns an errorcode when the function is called after the simulation has been initialized.

◆ addGoal()

int RVO::RVOSimulator::addGoal ( const Vector2 position)

Adds a goal position to the simulation.

Parameters
positionThe position of the goal
Returns
The function returns the ID of the goal that has been added. It returns an errorcode when the function is called after the simulation has been initialized.

◆ addObstacle()

int RVO::RVOSimulator::addObstacle ( const Vector2 point1,
const Vector2 point2 
)

Adds a line segment obstacle to the simulation. The line segment may not intersect previously added line segments in their interior.

Parameters
point1The position of the first endpoint of the line segment obstacle
point2The position of the second endpoint of the line segment obstacle
Returns
The function returns the ID of the obstacle that has been added. It returns an errorcode when the function is called after the simulation has been initialized.

◆ addRoadmapEdge()

int RVO::RVOSimulator::addRoadmapEdge ( int  vertexID1,
int  vertexID2 
)

Adds an edge between two vertices of the roadmap. The roadmap is undirected.

Parameters
vertexID1The ID of the first vertex of the edge
vertexID2The ID of the second vertex of the edge
Returns
The function returns RVO_SUCCESS when successful, and an errorcode when the function is called after the simulation has been initialized.

◆ addRoadmapVertex()

int RVO::RVOSimulator::addRoadmapVertex ( const Vector2 position)

Adds a vertex to the roadmap of environment. The roadmap is used for global planning for the agents around obstacles.

Parameters
positionThe position of the roadmap vertex
Returns
The function returns the ID of the roadmap vertex that has been added. It returns an errorcode when the function is called after the simulation has been initialized.

◆ doStep()

int RVO::RVOSimulator::doStep ( )

Causes the simulator to take another simulation step. Modifies position, velocity and orientation of agents. Updates the global time of the simulation, and sets a 'reached goal' flag when all of the agents have reached their goal.

Returns
The function returns RVO_SUCCESS on success, and an errorcode when the simulation has not been initialized, or when the global parameters have not been set.

◆ getAgentClass()

int RVO::RVOSimulator::getAgentClass ( int  agentID) const

Retrieving the class of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the class of the specified agent.

◆ getAgentGoal()

int RVO::RVOSimulator::getAgentGoal ( int  agentID) const

Retrieving the goal of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the ID of the goal of the specified agent.

◆ getAgentGoalRadius()

float RVO::RVOSimulator::getAgentGoalRadius ( int  agentID) const

Retrieving the goal radius of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the goal radius of the specified agent.

◆ getAgentMaxAccel()

float RVO::RVOSimulator::getAgentMaxAccel ( int  agentID) const

Retrieving the maximum acceleration of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the acceleration of the specified agent.

◆ getAgentMaxNeighbors()

int RVO::RVOSimulator::getAgentMaxNeighbors ( int  agentID) const

Retrieving the maximum number of neighbors of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the currently set maximum number of neighbors of the specified agent.

◆ getAgentMaxSpeed()

float RVO::RVOSimulator::getAgentMaxSpeed ( int  agentID) const

Retrieving the maximum speed of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the maximum speed of the specified agent.

◆ getAgentNeighborDist()

float RVO::RVOSimulator::getAgentNeighborDist ( int  agentID) const

Retrieving the neighbor distance of an agent

Parameters
agentIDThe agent's ID
Returns
The function returns the currently set neighbor distance of the specified agent.

◆ getAgentOrientation()

float RVO::RVOSimulator::getAgentOrientation ( int  agentID) const

Retrieving the current orientation of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the current orientation of the specified agent.

◆ getAgentPosition()

const Vector2& RVO::RVOSimulator::getAgentPosition ( int  agentID) const

Retrieving the current position of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the current position of the specified agent.

◆ getAgentPrefSpeed()

float RVO::RVOSimulator::getAgentPrefSpeed ( int  agentID) const

Retrieving the preferred speed of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the preferred speed of the specified agent.

◆ getAgentRadius()

float RVO::RVOSimulator::getAgentRadius ( int  agentID) const

Retrieving the radius of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the radius of the specified agent.

◆ getAgentReachedGoal()

bool RVO::RVOSimulator::getAgentReachedGoal ( int  agentID) const

Retrieving whether an agent has reached its goal.

Parameters
agentIDThe agent's ID
Returns
The function returns true when the specified agent has reached its goal. Returns false otherwise.

◆ getAgentSafetyFactor()

float RVO::RVOSimulator::getAgentSafetyFactor ( int  agentID) const

Retrieving the safety factor of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the safety factor of the specified agent.

◆ getAgentVelocity()

const Vector2& RVO::RVOSimulator::getAgentVelocity ( int  agentID) const

Retrieving the current velocity of an agent.

Parameters
agentIDThe agent's ID
Returns
The function returns the current velocity of the specified agent.

◆ getAgentVelSampleCount()

int RVO::RVOSimulator::getAgentVelSampleCount ( int  agentID) const

Retrieving the sample number of an agent

Parameters
agentIDThe agent's ID
Returns
The function returns the currently set number of candidate velocities that is sampled for the specified agent in each step of the simulation.

◆ getGlobalTime()

float RVO::RVOSimulator::getGlobalTime ( ) const
inline
Returns
The function returns the current global time of the simulation. Is initially 0.

◆ getGoalNeighbor()

int RVO::RVOSimulator::getGoalNeighbor ( int  goalID,
int  neighborNr 
) const

Retrieving the ID of a roadmap vertex connected to a goal.

Parameters
goalIDThe goal's ID
neighborNrThe neighbor number
Returns
The ID of the vertex in the roadmap that is the neighborNr'th neighbor of the specified goal.

◆ getGoalNumNeighbors()

int RVO::RVOSimulator::getGoalNumNeighbors ( int  goalID) const

Retrieving the number of roadmap vertices connected to a goal.

Parameters
goalIDThe goal's ID
Returns
The function returns the number of vertices in the roadmap that are neighbors of the specified goal.

◆ getGoalPosition()

const Vector2& RVO::RVOSimulator::getGoalPosition ( int  goalID) const

Retrieving the position of a goal.

Parameters
goalIDThe goal's ID
Returns
The function returns the position of the specified goal.

◆ getNumAgents()

int RVO::RVOSimulator::getNumAgents ( ) const
Returns
The function returns the number of agents in the simulation.

◆ getNumGoals()

int RVO::RVOSimulator::getNumGoals ( ) const
Returns
The function returns the number of goals in the simulation.

◆ getNumObstacles()

int RVO::RVOSimulator::getNumObstacles ( ) const
Returns
The function returns the number of obstacles in the simulation.

◆ getNumRoadmapVertices()

int RVO::RVOSimulator::getNumRoadmapVertices ( ) const
Returns
The function returns the number of vertices in the roadmap of the simulation.

◆ getObstaclePoint1()

const Vector2& RVO::RVOSimulator::getObstaclePoint1 ( int  obstacleID) const

Retrieving the first endpoint of an obstacle.

Parameters
obstacleIDThe obstacle's ID
Returns
The function returns the position of the first endpoint of the specified obstacle.

◆ getObstaclePoint2()

const Vector2& RVO::RVOSimulator::getObstaclePoint2 ( int  obstacleID) const

Retrieving the second endpoint of an obstacle.

Parameters
obstacleIDThe obstacle's ID
Returns
The function returns the position of the second endpoint of the specified obstacle.

◆ getReachedGoal()

bool RVO::RVOSimulator::getReachedGoal ( ) const
inline
Returns
The function returns true when all agents have reached their goal. Returns false otherwise.

◆ getRoadmapVertexNeighbor()

int RVO::RVOSimulator::getRoadmapVertexNeighbor ( int  vertexID,
int  neighborNr 
) const

Retrieving the ID of a roadmap vertex connected to a vertex in the roadmap.

Parameters
vertexIDThe vertex' ID
neighborNrThe neighbor number
Returns
The ID of the vertex in the roadmap that is the neighborNr'th neighbor of the specified roadmap vertex.

◆ getRoadmapVertexNumNeighbors()

int RVO::RVOSimulator::getRoadmapVertexNumNeighbors ( int  vertexID) const

Retrieving the number of roadmap vertices connected to a vertex in the roadmap.

Parameters
vertexIDThe vertex' ID
Returns
The function returns the number of neighbors of the specified vertex in the roadmap.

◆ getRoadmapVertexPosition()

const Vector2& RVO::RVOSimulator::getRoadmapVertexPosition ( int  vertexID) const

Retrieving the position of a vertex in the roadmap.

Parameters
vertexIDThe vertex' ID
Returns
The function returns the position of the specified roadmap vertex.

◆ getTimeStep()

float RVO::RVOSimulator::getTimeStep ( ) const
inline
Returns
The function returns the currently set time step of the simulation.

◆ initSimulation()

void RVO::RVOSimulator::initSimulation ( )

Processes the input (goals, agents, obstacles and roadmap) of the simulation. After initialization, no content can be added anymore to the environment.

◆ Instance()

static RVOSimulator* RVO::RVOSimulator::Instance ( )
static

Instantiates an RVOSimulator.

Returns
The function returns a pointer to the singleton instance.

◆ setAgentClass()

void RVO::RVOSimulator::setAgentClass ( int  agentID,
int  classID 
)

Sets the class of an agent.

Parameters
agentIDThe agent's ID
classIDThe new class of the agent

◆ setAgentDefaults()

void RVO::RVOSimulator::setAgentDefaults ( int  velSampleCountDefault,
float  neighborDistDefault,
int  maxNeighborsDefault,
float  radiusDefault,
float  goalRadiusDefault,
float  prefSpeedDefault,
float  maxSpeedDefault,
float  safetyFactorDefault,
float  maxAccelDefault = RVO_INFTY,
const Vector2 velocityDefault = Vector2(0, 0),
float  orientationDefault = 0,
int  classDefault = 0 
)

Sets the default parameters for agents that are subsequently added.

Parameters
velSampleCountDefaultThe default number of candidate velocities sampled for the agent in each step of the simulation. The running time of the simulation increases linearly with this number.
neighborDistDefaultThe default distance within which the agent take other agents and obstacles into account in the navigation. The larger this number, the larger the running time of the simulation. If the number is too low, the simulation will not be safe.
maxNeighborsDefaultThe default maximum number of other agents and obstacles the agent takes into account in the navigation. The larger this number, the larger the running time of the simulation. If the number is too low, the simulation will not be safe.
radiusDefaultThe default radius of the agents
goalRadiusDefaultThe default goal radius of the agents
prefSpeedDefaultThe default preferred speed of the agents
maxSpeedDefaultThe default maximum speed of the agents
safetyFactorDefaultThe default safety factor of the agents. I.e. the weight that is given to the 'time to collision' when penalizing a candidate velocity for the agent (vs. the distance to the preferred velocity). The higher this value, the 'safer' or the 'shyer' the agent is. The lower this value, the more 'aggressive' and 'reckless' the agent is. Its unit is distance.
maxAccelDefaultThe default maximum acceleration of the agents
velocityDefaultThe default initial velocity of the agents
orientationDefaultThe default initial orientation of the agents
classDefaultThe default class of the agent

◆ setAgentGoal()

void RVO::RVOSimulator::setAgentGoal ( int  agentID,
int  goalID 
)

Sets the goal of an agent.

Parameters
agentIDThe agent's ID
goalIDThe ID of the new goal of the agent

◆ setAgentGoalRadius()

void RVO::RVOSimulator::setAgentGoalRadius ( int  agentID,
float  goalRadius 
)

Sets the goal radius of an agent.

Parameters
agentIDThe agent's ID
goalRadiusThe new goal radius of the agent

◆ setAgentMaxAccel()

void RVO::RVOSimulator::setAgentMaxAccel ( int  agentID,
float  maxAccel 
)

Sets the maximum acceleration of an agent.

Parameters
agentIDThe agent's ID
maxAccelThe new maximum acceleration of the agent

◆ setAgentMaxNeighbors()

void RVO::RVOSimulator::setAgentMaxNeighbors ( int  agentID,
int  maximum 
)

Sets the maximum number of neighbors of the specified agent.

Parameters
agentIDThe agent's ID
maximumThe new maximum number of neighbors.

◆ setAgentMaxSpeed()

void RVO::RVOSimulator::setAgentMaxSpeed ( int  agentID,
float  maxSpeed 
)

Sets the maximum speed of an agent.

Parameters
agentIDThe agent's ID
maxSpeedThe new maximum speed of the agent

◆ setAgentNeighborDist()

void RVO::RVOSimulator::setAgentNeighborDist ( int  agentID,
float  distance 
)

Sets the neighbor distance of the specified agent.

Parameters
agentIDThe agent's ID
distanceThe new neighbor distance.

◆ setAgentOrientation()

void RVO::RVOSimulator::setAgentOrientation ( int  agentID,
float  orientation 
)

Sets the current orientation of an agent.

Parameters
agentIDThe agent's ID
orientationThe new orientation of the agent

◆ setAgentPosition()

void RVO::RVOSimulator::setAgentPosition ( int  agentID,
const Vector2 position 
)

Sets the current position of an agent.

Parameters
agentIDThe agent's ID
positionThe new position of the agent

◆ setAgentPrefSpeed()

void RVO::RVOSimulator::setAgentPrefSpeed ( int  agentID,
float  prefSpeed 
)

Sets the preferred speed of an agent.

Parameters
agentIDThe agent's ID
prefSpeedThe new preferred speed of the agent

◆ setAgentRadius()

void RVO::RVOSimulator::setAgentRadius ( int  agentID,
float  radius 
)

Sets the radius of an agent.

Parameters
agentIDThe agent's ID
radiusThe new radius of the agent

◆ setAgentSafetyFactor()

void RVO::RVOSimulator::setAgentSafetyFactor ( int  agentID,
float  safetyFactor 
)

Sets the safety factor of an agent.

Parameters
agentIDThe agent's ID
safetyFactorThe new safety factor of the agent

◆ setAgentVelocity()

void RVO::RVOSimulator::setAgentVelocity ( int  agentID,
const Vector2 velocity 
)

Sets the current velocity of an agent.

Parameters
agentIDThe agent's ID
velocityThe new velocity of the agent

◆ setAgentVelSampleCount()

void RVO::RVOSimulator::setAgentVelSampleCount ( int  agentID,
int  samples 
)

Sets the number of candidate velocities that is sampled for the specified agent in each step of the simulation.

Parameters
agentIDThe agent's ID
samplesThe new number of samples.

◆ setRoadmapAutomatic()

void RVO::RVOSimulator::setRoadmapAutomatic ( bool  automatic = true)

Sets whether the mutually visible vertices of the roadmap should automatically be connected by edges when the simulation is initialized. Default is false.

Parameters
automaticIf true, the mutually visible vertices will be connected in addition to manually specified edges. If false, no edges will created in addition to the manually specified ones.

◆ setTimeStep()

void RVO::RVOSimulator::setTimeStep ( float  stepSize)
inline

Sets the time step of the simulation.

Parameters
stepSizeThe new time step of the simulation.

The documentation for this class was generated from the following file: