irsim.lib#

Submodules#

Attributes#

Classes#

Behavior

Represents the behavior of an agent in the simulation.

reciprocal_vel_obs

A class to implement the Reciprocal Velocity Obstacle (RVO) algorithm for multi-robot collision avoidance.

KinematicsFactory

Factory class to create kinematics handlers.

GeometryFactory

Factory class to create geometry handlers.

Functions#

differential_kinematics(state, velocity, step_time[, ...])

Calculate the next state for a differential wheel robot.

ackermann_kinematics(state, velocity, step_time[, ...])

Calculate the next state for an Ackermann steering vehicle.

omni_kinematics(state, velocity, step_time[, noise, alpha])

Calculate the next position for an omnidirectional robot.

register_behavior(kinematics, action)

decorator to register a method in the behavior registry

random_generate_polygon([number, center_range, ...])

reference: https://stackoverflow.com/questions/8997099/algorithm-to-generate-random-2d-polygon

generate_polygon(center, avg_radius, irregularity, ...)

Generate a random polygon around a center point.

Package Contents#

irsim.lib.differential_kinematics(state, velocity, step_time, noise=False, alpha=[0.03, 0, 0, 0.03])[source]#

Calculate the next state for a differential wheel robot.

Parameters:
  • state – A 3x1 vector [x, y, theta] representing the current position and orientation.

  • velocity – A 2x1 vector [linear, angular] representing the current velocities.

  • step_time – The time step for the simulation.

  • noise – Boolean indicating whether to add noise to the velocity (default False).

  • alpha – List of noise parameters for the velocity model (default [0.03, 0, 0, 0.03]). alpha[0] and alpha[1] are for linear velocity, alpha[2] and alpha[3] are for angular velocity.

Returns:

A 3x1 vector [x, y, theta] representing the next state.

Return type:

next_state

irsim.lib.ackermann_kinematics(state, velocity, step_time, noise=False, alpha=[0.03, 0, 0, 0.03], mode='steer', wheelbase=1)[source]#

Calculate the next state for an Ackermann steering vehicle.

Parameters:
  • state – A 4x1 vector [x, y, theta, steer_angle] representing the current state.

  • velocity – A 2x1 vector representing the current velocities, format depends on mode. For “steer” mode, [linear, steer_angle] is expected. For “angular” mode, [linear, angular] is expected.

  • step_time – The time step for the simulation.

  • noise – Boolean indicating whether to add noise to the velocity (default False).

  • alpha – List of noise parameters for the velocity model (default [0.03, 0, 0, 0.03]). alpha[0] and alpha[1] are for linear velocity, alpha[2] and alpha[3] are for angular velocity.

  • mode – The kinematic mode, either “steer” or “angular” (default “steer”).

  • wheelbase – The distance between the front and rear axles (default 1).

Returns:

A 4x1 vector representing the next state.

Return type:

new_state

irsim.lib.omni_kinematics(state, velocity, step_time, noise=False, alpha=[0.03, 0, 0, 0.03])[source]#

Calculate the next position for an omnidirectional robot.

Parameters:
  • state – A 2x1 vector [x, y] representing the current position.

  • velocity – A 2x1 vector [vx, vy] representing the current velocities.

  • step_time – The time step for the simulation.

  • noise – Boolean indicating whether to add noise to the velocity (default False).

  • alpha – List of noise parameters for the velocity model (default [0.03, 0.03]). alpha[0] is for x velocity, alpha[1] is for y velocity.

Returns:

A 2x1 vector [x, y] representing the next position.

Return type:

new_position

irsim.lib.kinematics_factory#
irsim.lib.register_behavior(kinematics: str, action: str)[source]#

decorator to register a method in the behavior registry

Parameters:
  • kinematics – only support diff, omni, or acker

  • action – defined action for the kinematics

class irsim.lib.Behavior(object_info=None, behavior_dict=None)[source]#

Represents the behavior of an agent in the simulation.

Parameters:
  • object_info (object) – Object information from the object_base class ObjectInfo.

  • behavior_dict (dict) –

    Dictionary containing behavior parameters for different behaviors. Name Options include: ‘dash’, ‘rvo’. target_roles:

    • ’all’: all objects in the environment will be considered within this behavior.

    • ’obstacle’: only obstacles will be considered within this behavior.

    • ’robot’: only robots will be considered within this behavior.

Initializes the Behavior class with object information and behavior parameters.

Parameters:
  • object_info (object) – Information about the agent.

  • behavior_dict (dict) – Behavior parameters.

object_info = None#
behavior_dict#
gen_vel(ego_object, external_objects=[])[source]#

Generate velocity for the agent based on the behavior dictionary.

Parameters:
  • ego_object – the object itself

  • external_objects – all the other objects in the environment

Returns:

Generated velocity for the agent.

Return type:

np.array (2, 1)

load_behavior(behaviors: str = '.behavior_methods')[source]#

Load behavior parameters from the script.

Parameters:

behaviors (str) – name of the bevavior script.

invoke_behavior(kinematics: str, action: str, **kwargs: Any) Any[source]#

Invoke a specific behavior method based on kinematics model and action type.

This method looks up and executes the appropriate behavior function from the behavior registry based on the combination of kinematics model and action name.

Parameters:
  • kinematics (str) –

    Kinematics model identifier. Supported values:

    • ’diff’: Differential drive kinematics

    • ’omni’: Omnidirectional kinematics

    • ’acker’: Ackermann steering kinematics

  • action (str) –

    Behavior action name. Examples:

    • ’dash’: Direct movement toward goal

    • ’rvo’: Reciprocal Velocity Obstacles for collision avoidance

  • **kwargs – Additional keyword arguments passed to the behavior function. Common parameters include ego_object, external_objects, goal, etc.

Returns:

Generated velocity vector (2x1) in the format appropriate for the specified kinematics model.

Return type:

np.ndarray

Raises:

ValueError – If no behavior method is found for the given kinematics and action combination.

Example

>>> # Invoke differential drive dash behavior
>>> vel = behavior.invoke_behavior('diff', 'dash',
...                               ego_object=robot,
...                               external_objects=obstacles)
property logger#
irsim.lib.random_generate_polygon(number=1, center_range=[0, 0, 0, 0], avg_radius_range=[0.1, 1], irregularity_range=[0, 1], spikeyness_range=[0, 1], num_vertices_range=[4, 10], **kwargs)[source]#

reference: https://stackoverflow.com/questions/8997099/algorithm-to-generate-random-2d-polygon

Generate random polygons with specified properties.

Parameters:
  • number (int) – Number of polygons to generate (default 1).

  • center_range (List[float]) – Range for the polygon center [min_x, min_y, max_x, max_y].

  • avg_radius_range (List[float]) – Range for the average radius of the polygons.

  • irregularity_range (List[float]) – Range for the irregularity of the polygons.

  • spikeyness_range (List[float]) – Range for the spikeyness of the polygons.

  • num_vertices_range (List[int]) – Range for the number of vertices of the polygons.

Returns:

List of vertices for each polygon or a single polygon’s vertices if number=1.

irsim.lib.generate_polygon(center, avg_radius, irregularity, spikeyness, num_vertices)[source]#

Generate a random polygon around a center point.

Parameters:
  • center (Tuple[float, float]) – Center of the polygon.

  • avg_radius (float) – Average radius from the center to vertices.

  • irregularity (float) – Variance of angle spacing between vertices. Range [0, 1]

  • spikeyness (float) – Variance of radius from the center. Range [0, 1]

  • num_vertices (int) – Number of vertices for the polygon.

Returns:

Vertices of the polygon in CCW order.

Return type:

numpy.ndarray

class irsim.lib.reciprocal_vel_obs(state: list, obs_state_list=[], vxmax=1.5, vymax=1.5, acce=0.5, factor=1.0)[source]#

A class to implement the Reciprocal Velocity Obstacle (RVO) algorithm for multi-robot collision avoidance.

Parameters:
  • state (list) – The rvo state of the agent [x, y, vx, vy, radius, vx_des, vy_des].

  • obs_state_list (list) – List of states of static obstacles [[x, y, vx, vy, radius]].

  • vxmax (float) – Maximum velocity in the x direction.

  • vymax (float) – Maximum velocity in the y direction.

  • acce (float) – Acceleration limit.

state#
obs_state_list = []#
vxmax = 1.5#
vymax = 1.5#
acce = 0.5#
factor = 1.0#
update(state, obs_state_list)[source]#
cal_vel(mode='rvo')[source]#

Calculate the velocity of the agent based on the Reciprocal Velocity Obstacle (RVO) algorithm.

Parameters:

mode (str) – The vo configure to calculate the velocity. It can be “rvo”, “hrvo”, or “vo”. - rvo: Reciprocal Velocity Obstacle (RVO) algorithm, for multi-robot collision avoidance. - hrvo: Hybrid Reciprocal Velocity Obstacle (HRVO) algorithm, for multi-robot collision avoidance. - vo: Velocity Obstacle (VO) algorithm, for obstacle-robot collision avoidance.

config_rvo()[source]#
config_rvo_mode(obstacle)[source]#
config_hrvo()[source]#
config_hrvo_mode(obstacle)[source]#
config_vo()[source]#
config_vo_mode(obstacle)[source]#
vel_candidate(rvo_list)[source]#
vo_out(vx, vy, rvo_list)[source]#
vel_select(vo_outside, vo_inside)[source]#
penalty(vel, vel_des, factor)[source]#
static between_vector(line_left_vector, line_right_vector, line_vector)[source]#
static cross_product(vector1, vector2)[source]#
class irsim.lib.KinematicsFactory[source]#

Factory class to create kinematics handlers.

static create_kinematics(name: str = None, noise: bool = False, alpha: list = None, mode: str = 'steer', wheelbase: float = None, role: str = 'robot') KinematicsHandler[source]#
class irsim.lib.GeometryFactory[source]#

Factory class to create geometry handlers.

static create_geometry(name: str = 'circle', **kwargs) geometry_handler[source]#