Module collision¶
collision_detection¶
- create_collision_checker(obj, params=None, collision_checker_func=None) commonroad_dc.pycrcc.CollisionChecker [source]¶
Function to convert a commonroad-io scenario to a C++ collision checker.
- Parameters
obj – the commonroad-io scenario
params – optional parameters, e.g. adding the minkowski sum with a circle
collision_object_func – specify the converter function (it is usually not necessary to change the default)
- Returns
Returns the C++ collision checker
- create_collision_object(obj, params=None, collision_object_func=None) commonroad_dc.pycrcc.CollisionObject [source]¶
Main function to convert a commonroad-io shape to a C++ collision object.
- Parameters
obj – the object or list of objects (with all the same type) to be converted to C++ collision objects
params – optional parameters, e.g. adding the minkowski sum with a circle
collision_object_func – specify the converter function (it is usually not necessary to change the default)
- Returns
Returns the C++ collision object
trajectory_queries¶
- trajectories_collision_static_obstacles(trajectories: list, static_obstacles: commonroad_dc.pycrcc.ShapeGroup, method='fcl', **kwargs)[source]¶
For each trajectory in the list, returns its time of collision with static obstacles. If the trajectory is not colliding with the static obstacles, the returned timestep of collision is -1.
- Parameters
trajectories – list of input trajectories (each trajectory in the list must be a pycrcc.TimeVariantCollisionObject)
static_obstacles – ShapeGroup with static obstacles (pycrcc.ShapeGroup)
method – broadphase method for the filtering of collision candidates
kwargs – settings of the method
Available methods:
-grid
Use Uniform Grid broadphase algorithm for candidate pair filtering.
Settings:
num_cells - number of cells of the uniform grid broadphase accelerator structure.
auto_orientation - enable automatic choice of uniform grid orientation.
optimize_triangles - use optimized 2D SAT solver for triangles instead of FCL solver.
enable_verification - debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
-fcl
Use a Flexible Collision Library-supported broadphase algorithm for candidate pair filtering.
Settings:
broadphase_type- type of FCL broadphase to be used. 0: Binary Tree, 1: SpatialHashing 2: IntervalTree 3: Simple SAP 4: SAP
num_cells - determines cell size for the SpatialHashing broadphase accelerator structure. Cell size = length of obstacles bounding box along x axis divided by num_cells.
num_buckets - number of hash buckets for the SpatialHashing broadphase accelerator structure.
enable_verification - debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
-box2d
Use 2D AABB Tree broadphase broadphase algorithm from the library Box2D for candidate pair filtering.
Settings:
enable_verification - debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
Additional settings parameters for all broadphase methods:
return_debug_info - True: additionally return debug information.
- Returns
First timestep of collision or -1 is no collision was detected - for each trajectory (as a list of integers). After that, debug information (optional).
Please refer to the tutorial example commonroad_road_compliance_checking for usage example.
- trajectories_enclosure_polygons_static(trajectories: list, sg_polygons: commonroad_dc.pycrcc.ShapeGroup, method='grid', **kwargs)[source]¶
Checks the given trajectories for enclosure within the union of the lane polygons contained in sg_polygons. Uses iterative difference operations and Uniform Grid broadphase for finding the candidate polygons for subtraction. It is necessary to buffer the lane polygons in the preprocessing step before calling this function such that there is no small gap between neighboring lanelets due to numerics.
- Parameters
trajectories – list of input trajectories (each trajectory in the list must be a pycrcc.TimeVariantCollisionObject)
sg_polygons – ShapeGroup with lane polygons of type pycrcc.Polygon for subtraction
method – broadphase method for the finding of candidate polygons
kwargs – settings of the method
Available methods:
-grid
Settings:
num_cells - parameter of the Uniform Grid broadphase (number of vertical grid cells) used to find the candidate Polygons for subtraction. These are not the same as the grid cells into which the lanelet polygons can be cut using boundary.create_road_polygons(scenario, method=’whole_polygon_tiled’).
enable_verification - debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
return_debug_info - True: additionally return debug information.
- Returns
First timestep of incomplete enclosure or -1 if always completely enclosed - for each trajectory. After that, debug information (optional).
Please refer to the tutorial example commonroad_road_compliance_checking for usage example.
- trajectories_collision_dynamic_obstacles(trajectories: list, dynamic_obstacles: list, method='fcl', **kwargs)[source]¶
For each trajectory in the list, returns its time of collision with dynamic obstacles. If the trajectory is not colliding with the dynamic obstacles, the returned timestep of collision is -1.
- Parameters
trajectories – list of input trajectories (each must be a pycrcc.TimeVariantCollisionObject)
dynamic_obstacles – list of dynamic obstacles (each must be a pycrcc.TimeVariantCollisionObject)
method – broadphase method for the filtering of collision candidates
kwargs – settings of the method
Available methods:
-grid
Use Uniform Grid broadphase algorithm for candidate pair filtering.
Settings:
num_cells - number of cells of the uniform grid broadphase accelerator structure.
enable_verification - debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
-fcl
Use a Flexible Collision Library-supported broadphase algorithm for candidate pair filtering.
Settings:
broadphase_type- type of FCL broadphase to be used. 0: Binary Tree, 1: SpatialHashing 2: IntervalTree 3: Simple SAP 4: SAP
num_cells - determines cell size for the SpatialHashing broadphase accelerator structure. Cell size = length of obstacles bounding box along x axis divided by num_cells.
num_buckets - number of hash buckets for the SpatialHashing broadphase accelerator structure.
enable_verification - Debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
-box2d
Use 2D AABB Tree broadphase broadphase algorithm from the library Box2D for candidate pair filtering.
Settings:
enable_verification - debug check if any colliding obstacles were missed by the broadphase (as compared to the bruteforce checker).
Additional settings parameters for all broadphase methods:
return_debug_info - True: additionally return debug information.
- Returns
First timestep of collision or -1 is no collision was detected - for each trajectory (as a list of integers). After that, debug information (optional).
Please refer to the tutorial example commonroad_road_compliance_checking for usage example.
- trajectory_preprocess_obb_sum(trajectory: commonroad_dc.pycrcc.TimeVariantCollisionObject)[source]¶
Preprocess a trajectory using OBB sum hull (for continuous collision detection). The input trajectory must consist of one oriented rectangle per time step. The occupancies of the OBB boxes for two subsequent states are overapproximated with a tightly fitting OBB box.
- Parameters
trajectory – trajectory for preprocessing (pycrcc.TimeVariantCollisionObject)
- Returns
postprocessed trajectory (pycrcc.TimeVariantCollisionObject). Its length is one step smaller compared to the input trajectory.
- filter_trajectories_polygon_enclosure_first_timestep(trajectories, road_polygons)[source]¶
Selects trajectories that have the vehicle fully within the union of the road polygons at their first time step.
- Parameters
trajectories – input list of trajectories for filtering (list of pycrcc.TimeVariantCollisionObject). Only trajectories containing OBB and AABB boxes are supported.
road_polygons – pycrcc.ShapeGroup containing road polygons.
- Returns
List of trajectories fully within the road at their first time step.
- trajectory_collision_static_obstacles(sg_obstacles: commonroad_dc.pycrcc.ShapeGroup, half_box_length, half_box_width, trajectory: list)[source]¶
Returns the time of collision between the input trajectory and the static obstacles. If the trajectory is not colliding with the static obstacles, the returned timestep of collision is -1. The function uses numpy arrays to represent the input trajectory. The trajectory is represented by a moving oriented bounding box.
- Parameters
sg_obstacles – ShapeGroup with obstacles
half_box_length – the half-length (r_x) of the trajectory oriented bounding box
half_box_width – the half-width (r_y) of the trajectory oriented bounding box
trajectory – list of numpy arrays each having 3 elements: x coordinate, y coordinate, OBB box orientation angle in radians
- Returns
First timestep of collision or -1 is no collision was detected.
- trajectory_enclosure_polygons_static(sg_polygons: commonroad_dc.pycrcc.ShapeGroup, half_box_length, half_box_width, trajectory: list)[source]¶
Checks if the given trajectory is enclosed within the lanelet polygons contained in the given ShapeGroup. The function uses numpy arrays to represent the input trajectory. The trajectory is represented by a moving oriented bounding box. The function can be slower than the functions checking a batch of trajectories. But in some cases it can be faster to use this function, for example, when one needs to check for the collision between the first time step of the input trajectory and the static obstacles. In this situation, the creation of the numpy array was considerably faster than the extraction of the occupancy for the first time step.
- Parameters
sg_polygons – ShapeGroup with road polygons
half_box_length – the half-length (r_x) of the trajectory oriented bounding box
half_box_width – the half-width (r_y) of the trajectory oriented bounding box
trajectory – list of numpy arrays each having 3 elements: x coordinate, y coordinate, OBB box orientation angle in radians
- Returns
First timestep of incomplete enclosure or -1 if the trajectory is always completely enclosed within the polygons union.
- obb_enclosure_polygons_static(sg_polygons: commonroad_dc.pycrcc.ShapeGroup, obb: commonroad_dc.pycrcc.RectOBB)[source]¶
Checks if the given obb box is enclosed within the lanelet polygons contained in the given ShapeGroup.
- Parameters
sg_polygons – ShapeGroup with road polygons
obb – the input obb box for enclosure checking
- Returns
First timestep of incomplete enclosure or -1 if the trajectory is always completely enclosed within the polygons union.
visualization¶
- draw_collision_point(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶
- draw_collision_rectaabb(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶
- draw_collision_rectobb(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶
- draw_collision_triangle(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶
- draw_collision_circle(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶
- draw_collision_timevariantcollisionobject(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶
- draw_collision_shapegroup(obj, renderer: commonroad.visualization.renderer.IRenderer, draw_params: Optional[Union[commonroad.visualization.param_server.ParamServer, dict]] = None, call_stack: Optional[Tuple[str, ...]] = ()) None [source]¶