util#
irsim.util#
- irsim.util.util.file_check(file_name, root_path=None)[source]#
Check whether a file exists and return its absolute path.
- Parameters:
file_name (str) – Name of the file to check.
root_path (str, optional) – Root path to use if the file is not found.
- Returns:
Absolute path of the file if found.
- Return type:
str
- Raises:
FileNotFoundError – If the file is not found.
- irsim.util.util.WrapToPi(rad, positive=False)[source]#
The function WrapToPi transforms an angle in radians to the range [-pi, pi].
- Parameters:
rad (float) – Angle in radians. The rad parameter in the WrapToPi function represents an angle in radians that you want to
[-π (transform to the range)
wrapping (π]. The function ensures that the angle is within this range by)
bounds. (it around if it exceeds the)
positive (bool) – Whether to return the positive value of the angle. Useful for angles difference.
- Returns:
The function WrapToPi(rad) returns the angle rad wrapped to the range [-pi, pi].
- irsim.util.util.WrapToRegion(rad, range)[source]#
Transform an angle to a defined range, with length of 2*pi.
- Parameters:
rad (float) – Angle in radians.
range (list) – List defining the range [min, max].
- Returns:
Wrapped angle.
- Return type:
float
- irsim.util.util.convert_list_length(input_data, number=0)[source]#
Convert input to a list with a specific length.
- Parameters:
input_data – Data to convert.
number (int) – Desired length.
- Returns:
Converted list.
- Return type:
list
- irsim.util.util.convert_list_length_dict(input_data, number=0)[source]#
Convert input to a list with a specific length for dictionaries.
- Parameters:
input_data – Data to convert.
number (int) – Desired length.
- Returns:
Converted list.
- Return type:
list
- irsim.util.util.is_list_of_dicts(lst)[source]#
Check if a list contains only dictionaries.
- Parameters:
lst (list) – List to check.
- Returns:
True if all elements are dictionaries, False otherwise.
- Return type:
bool
- irsim.util.util.is_list_of_numbers(lst)[source]#
Check if a list contains only numbers.
- Parameters:
lst (list) – List to check.
- Returns:
True if all elements are numbers, False otherwise.
- Return type:
bool
- irsim.util.util.is_list_of_lists(lst)[source]#
Check if a list contains lists.
- Parameters:
lst (list) – List to check.
- Returns:
True if any element is a list, False otherwise.
- Return type:
bool
- irsim.util.util.is_list_not_list_of_lists(lst)[source]#
Check if a list does not contain lists.
- Parameters:
lst (list) – List to check.
- Returns:
True if no elements are lists, False otherwise.
- Return type:
bool
- irsim.util.util.relative_position(position1, position2, topi=True)[source]#
Calculate the relative position and angle between two points.
- Parameters:
position1 (np.array) – First position [x, y] (2x1).
position2 (np.array) – Second position [x, y] (2x1).
topi (bool) – Whether to wrap angle to [-pi, pi] (default True).
- Returns:
Distance and angle (radians).
- Return type:
tuple
- irsim.util.util.get_transform(state)[source]#
Get rotation and translation matrices from state.
- Parameters:
state (np.array) – State [x, y, theta] (3x1) or [x, y] (2x1).
- Returns:
Translation vector and rotation matrix.
- Return type:
tuple
- irsim.util.util.transform_point_with_state(point, state)[source]#
Transform a point using a state.
- Parameters:
point (np.array) – Point [x, y, theta] (3x1).
state (np.array) – State [x, y, theta] (3x1).
- Returns:
Transformed point (2x1).
- Return type:
np.array
- irsim.util.util.get_affine_transform(state)[source]#
Get affine transform parameters from state.
- Parameters:
state (np.array) – State [x, y, theta] (3x1).
- Returns:
Affine transform parameters.
- Return type:
list
- irsim.util.util.geometry_transform(geometry, state)[source]#
Transform geometry using a state.
- Parameters:
geometry – Shapely geometry to transform.
state (np.array or sequence of 3 floats) – [xoff, yoff, theta]
- Returns:
Transformed geometry.
shapely expects [a, b, d, e, xoff, yoff] for: x’ = a*x + b*y + xoff y’ = d*x + e*y + yoff
- irsim.util.util.vertices_transform(vertices, state)[source]#
Transform vertices using a state.
- Parameters:
vertices (np.array) – Vertices of the object. (2xN)
state (np.array) – State [x, y, theta] (3x1).
- Returns:
Transformed vertices.
- Return type:
np.array
- irsim.util.util.omni_to_diff(state_ori, vel_omni, w_max=1.5, guarantee_time=0.2, tolerance=0.1, mini_speed=0.02)[source]#
Convert omnidirectional velocity to differential velocity.
- Parameters:
state_ori (float) – Orientation angle.
vel_omni (np.array) – Omnidirectional velocity [vx, vy] (2x1).
w_max (float) – Maximum angular velocity.
guarantee_time (float) – Time to guarantee velocity.
tolerance (float) – Angular tolerance.
mini_speed (float) – Minimum speed threshold.
- Returns:
Differential velocity [linear, angular] (2x1).
- Return type:
np.array
- irsim.util.util.diff_to_omni(state_ori, vel_diff)[source]#
Convert differential velocity to omnidirectional velocity.
- Parameters:
state_ori (float) – Orientation angle.
vel_diff (np.array) – Differential velocity [linear, angular] (2x1).
- Returns:
Omnidirectional velocity [vx, vy] (2x1).
- Return type:
np.array
- irsim.util.util.time_it(name='Function')[source]#
Decorator to measure function execution time.
- Parameters:
name (str) – Function name for logging (default “Function”).
print (bool) – Whether to print execution time (default True).
- Returns:
Wrapped function with timing.
- Return type:
function
- irsim.util.util.time_it2(name='Function')[source]#
Decorator to measure function execution time with instance attribute check.
- Parameters:
name (str) – Function name for logging (default “Function”).
- Returns:
Wrapped function with timing.
- Return type:
function
- irsim.util.util.cross_product(o, a, b)[source]#
Compute the cross product of vectors OA and OB.
- Parameters:
o (array-like) – Points representing vectors.
a (array-like) – Points representing vectors.
b (array-like) – Points representing vectors.
- Returns:
Cross product value.
- Return type:
float
- irsim.util.util.is_convex_and_ordered(points)[source]#
Determine if the polygon is convex and return the order (CW or CCW).
- Parameters:
points (np.ndarray) – A 2xN NumPy array representing the vertices of the polygon.
- Returns:
- A tuple where the first element is True if the polygon is convex,
and the second element is ‘CW’ or ‘CCW’ based on the order. If not convex, returns (False, None).
- Return type:
(bool, str)
- irsim.util.util.gen_inequal_from_vertex(vertex: ndarray)[source]#
Generate inequality constraints for a convex polygon.
- Parameters:
vertex (np.array) – Vertices of the polygon (2xN).
- Returns:
G matrix and h vector for the inequality Gx <= h.
- Return type:
tuple
- irsim.util.util.distance(point1, point2)[source]#
Compute the distance between two points.
- Parameters:
point1 (np.array) – First point [x, y] (2x1).
point2 (np.array) – Second point [x, y] (2x1).
- Returns:
Distance between points.
- Return type:
float
- irsim.util.util.random_point_range(range_low=[0, 0, -3.141592653589793], range_high=[10, 10, 3.141592653589793])[source]#
Generate a random point within a range.
- Parameters:
range_low (list) – Lower bound of the range.
range_high (list) – Upper bound of the range.
- Returns:
Random point within the range.
- Return type:
np.array