tools

Utility Classes and Functions.

This module contains utility classes and functions for various operations commonly used in robotics, engineering, and computational tasks. It includes object-oriented tools for debugging, message logging, and mathematical utilities such as vector and matrix transformations, filtering, interpolation, and optimization techniques. Additionally, several methods for handling rotation, transformations, and load estimation are provided.

This module serves as a foundational toolset for more advanced robotic simulations, optimization tasks, and data analysis processes involving vectors, matrices, and rotations.

robotblockset.tools.get_logger(name: str) Logger[source]

Create and configure a package logger.

Parameters:

name (str) – Logger name.

Returns:

Logger configured with the standard Robotblockset stream handler.

Return type:

logging.Logger

robotblockset.tools.get_rbs_path() str[source]

Return the absolute filesystem path to the installed robotblockset package.

This function imports the robotblockset module and inspects its __file__ attribute to determine the directory in which the package resides. It returns the directory containing the module, not the module file itself.

Returns:

Absolute path to the folder where the robotblockset package is located.

Return type:

str

Raises:

ModuleNotFoundError – If the robotblockset module is not installed or cannot be imported.

class robotblockset.tools.rbs_object[source]

Bases: object

A base class for objects with debugging and messaging capabilities.

Attributes:

Name (str) (The name of the object, used in messages.)

Initialize the base object state.

Returns:

This constructor initializes the object name and verbosity level.

Return type:

None

__init__() None[source]

Initialize the base object state.

Returns:

This constructor initializes the object name and verbosity level.

Return type:

None

Message(msg: str, verb: int = 0, output: TextIO | None = None) None[source]

Logs or prints a message if the verbosity level is sufficient.

Parameters:
  • msg (str) – The message to be logged or printed.

  • verb (int, optional) – The verbosity level required to log or print the message. Defaults to 0.

  • output (io.TextIOBase, optional) – A writable output stream (e.g., a file or StringIO) to write the message to. If None, the message is printed to the standard output. Defaults to None.

Returns:

This method writes the formatted message to the selected output.

Return type:

None

WarningMessage(msg: str) None[source]

Displays a warning message with the name of the object and the provided message.

Parameters:

msg (str) – The warning message to display.

Returns:

This method prints the formatted warning message.

Return type:

None

SetLogLevel(level: int) None[source]

Sets the log verbosity level for the application.

Parameters:

level (int) – Verbosity level to set. Higher values enable more detailed debug output.

Returns:

This method updates the stored verbosity level.

Return type:

None

GetLogLevel() int[source]

Retrieve the current log level.

Returns:

Current verbosity level.

Return type:

int

class robotblockset.tools.load_params(mass: float = 0.0, COM: ~numpy.ndarray = <factory>, inertia: ~numpy.ndarray = <factory>)[source]

Bases: _struct

Load parameters consisting of mass, center of mass (COM), and inertia tensor.

This structure describes the physical properties of a tool or payload attached to the robot. These parameters are typically used by the robot controller (e.g., UR RTDE or MotoROS2) to properly account for dynamics, force estimation, and motion safety.

Parameters:
  • mass (float, optional) – Mass of the tool or payload in kilograms. Default is 0.0.

  • COM (numpy.ndarray, optional) – Center of mass expressed in the tool coordinate system, shape (3,). Default is a zero vector.

  • inertia (numpy.ndarray, optional) – 3×3 inertia matrix about the tool’s coordinate frame origin. Default is a zero matrix.

Attributes:
  • mass (float) – Mass of the attached load.

  • COM (numpy.ndarray) – Center of mass vector.

  • inertia (numpy.ndarray) – Inertia tensor matrix.

mass: float = 0.0
COM: ndarray
inertia: ndarray
class robotblockset.tools.tool_params(name: str, id: int, tcp_position: ~numpy.ndarray = <factory>, tcp_orientation: ~numpy.ndarray = <factory>, load: ~robotblockset.tools.load_params = None, mounted_on: str = 'flange')[source]

Bases: _struct

Represents tool parameters including TCP definition and associated load.

Parameters:
  • name (str) – Name of the tool (human-readable identifier).

  • id (int) – Numeric ID corresponding to the controller’s tool file index.

  • tcp_position (np.ndarray) – 3-element XYZ position of the tool center point (TCP) relative to the flange.

  • tcp_orientation (np.ndarray) – 4-element quaternion (w, x, y, z) describing orientation of the TCP.

  • load (load_params) – Load parameters (mass, COM, inertia) associated with this tool.

  • mounted_on (str) – Identifier of the link or frame this tool is mounted on (e.g., “flange”).

name: str
id: int
tcp_position: ndarray
tcp_orientation: ndarray
load: load_params = None
mounted_on: str = 'flange'
robotblockset.tools.rbs_type(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) ndarray[source]

Convert input data to a squeezed float NumPy array.

Parameters:

x (ArrayLike) – Input data to convert.

Returns:

Squeezed copy of the input data with float dtype.

Return type:

np.ndarray

robotblockset.tools.isscalar(x: Any) bool[source]

Check if the input is a scalar.

A scalar is defined as either an instance of a scalar type or a NumPy array with a single element.

Parameters:

x (Any) – Input value to check.

Returns:

True if the input is a scalar value or a single-element NumPy array.

Return type:

bool

robotblockset.tools.isvector(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], dim: int | None = None) bool[source]

Check if the input is a vector and optionally verify its dimension.

This function determines whether the input x is a vector. A vector is defined as a one-dimensional array with more than one element. If the dim parameter is provided, the function also checks if the vector has the specified dimension.

Parameters:
  • x (ArrayLike) – The input value to check.

  • dim (int, optional) – verify that the vector has this specific dimension.

Returns:

Returns True if x is a vector. If dim is specified, returns True only if x is a vector with the specified dimension. Otherwise, returns False.

Return type:

bool

robotblockset.tools.vector(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | float | int, dim: int | None = None) ndarray[source]

Convert input to a NumPy vector.

Transforms input into a NumPy array vector with optional dimension validation.

Parameters:
  • x (Union[ArrayLike, float, int]) – Input values to transform into a vector.

  • dim (int, optional) – Required vector length. If provided, the result is validated against it.

Returns:

One-dimensional NumPy array representation of the input.

Return type:

np.ndarray

Raises:
  • TypeError – If the input type is unsupported.

  • ValueError – If dim is invalid or does not match the resulting vector length.

robotblockset.tools.ismatrix(x: ndarray, shape: int | Tuple[int, int] | None = None) bool[source]

Check if parameter is a matrix

Tests if the argument is a 2D matrix with a specified shape. If shape is scalar, then only the last dimension of the argument is checked.

Parameters:
  • x (np.ndarray) – value to check

  • shape (Union[int, Tuple[int, int]], optional) – required 2D shape

Returns:

True if x has required dimensions

Return type:

bool

robotblockset.tools.ismatrixarray(x: ndarray, shape: int | Tuple[int, int] | None = None) bool[source]

Check if parameter is a matrix array

Tests if the argument is a array of 2D matrices with a specified shape.

Parameters:
  • x (np.ndarray) – value to check

  • shape (Union[int, Tuple[int, int]], optional) – required 2D shape of submatrix

Returns:

True if x has required dimensions

Return type:

bool

Raises:

ValueError – Wrong shape value

robotblockset.tools.matrix(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | float | int, shape: Tuple[int, int] | None = None) ndarray[source]

Return a matrix

Parameters:
  • x (Union[ArrayLike, float, int]) – values to be transformed to matrix

  • shape (Tuple[int, int], optional) – required 2D shape

Returns:

2D ndarray of specified shape

Return type:

ndarray

Raises:
  • TypeError – Argument type error

  • ValueError – Matrix shape error

robotblockset.tools.check_shape(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], shape: int | Tuple[int, ...]) bool[source]

Check last dimensions of np array

Parameters:
  • x (ArrayLike) – array to be checked

  • shape (Union[int, Tuple[int, ...]]) – required dimension

Returns:

True if parameters is (…, shape)

Return type:

bool

Raises:

TypeError – Parameter type error

robotblockset.tools.isskewsymmetric(S: ndarray, tol: float = 100) bool[source]

Check if matrix is skew-symmetric

Parameters:

S (np.ndarray) – value to check

Returns:

True if S is skew-symmetric

Return type:

bool

robotblockset.tools.isquaternion(Q: Any) bool[source]

Check if parameter is quaternionic array QArray

Parameters:

Q (Any) – input parameter

Returns:

True if parameters is quaternionc array (QArray)

Return type:

bool

robotblockset.tools.getunit(unit: str) float[source]

Calculates unit conversion factor

Parameters:

unit (str) – angular unit, by default ‘rad’

Returns:

unit -> rad conversion factor

Return type:

float

Raises:

ValueError – Invalid unit

robotblockset.tools.check_option(opt: str, val: str) bool[source]

Check if option equals value (case-independent)

Parameters:
  • opt (str) – option to be checked

  • val (str) – value for check

Returns:

Check result

Return type:

bool

Note

For check the shortest string length is used

robotblockset.tools.find_rows(row: ndarray, x: ndarray) List[int][source]

Find indices of rows equal to a reference row.

Parameters:
  • row (np.ndarray) – Reference row to match.

  • x (np.ndarray) – Matrix whose rows are searched.

Returns:

Indices of rows in x that exactly match row.

Return type:

List[int]

robotblockset.tools.grad(fun: Callable[[ndarray], float], x0: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], dx: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] = 1e-06) float | ndarray[source]

Gradient of function at values x

Parameters:
  • fun – function handle

  • x0 (ArrayLike) – function argument values

  • dx (ArrayLike, optional) – deviation to calculate gradient, optional

Returns:

gradient of fun at x

Return type:

float or ndarray

Raises:

ValueError – Wrong arguments size

robotblockset.tools.hessmat(fun: Callable[[ndarray], float], x0: ndarray, delta: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None) ndarray[source]

Hessian matrix of a scalar function with vector argument.

The Hessian matrix of f(x) is the square matrix of the second partial derivatives of f(x).

Parameters:
  • fun (Callable[[np.ndarray], float]) – Scalar function.

  • x0 (np.ndarray) – Function argument of shape (n,).

  • delta (ArrayLike, optional) – Perturbation step used for numerical differentiation.

Returns:

Hessian matrix of fun evaluated at x0.

Return type:

np.ndarray

robotblockset.tools.deadzone(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], width: float = 1, center: float = 0) ndarray[source]

Apply a symmetric dead zone to input values.

Parameters:
  • x (ArrayLike) – Input values.

  • width (float, optional) – Half-width of the zero-output interval around center.

  • center (float, optional) – Center of the dead zone.

Returns:

Input values shifted so values inside the dead zone map to zero.

Return type:

np.ndarray

robotblockset.tools.sigmoid(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], offset: float = 0.0, gain: float = 1.0) ndarray[source]

Sigmoid function

Parameters:
  • x (ArrayLike) – input values

  • offset (float, optional) – function offset, by default 0

  • gain (float, optional) – function gain, by default 1

Returns:

values of sigmoid function

Return type:

array of floats

robotblockset.tools.smoothstep(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], xmin: float, xmax: float) ndarray[source]

Sigmoid-like interpolation and clamping function.

Parameters:
  • x (ArrayLike) – Input values

  • xmin (float) – Minimal x (output=0)

  • xmax (float) – Maximal x (output=1)

Returns:

Output values

Return type:

array of floats

robotblockset.tools.smoothstep3(x: float, x_min: float, x_max: float) float[source]

Performs smooth Hermite interpolation between 0 and 1 when x is in the range [x_min, x_max].

This function interpolates smoothly between 0 and 1 based on the position of x between x_min and x_max. Values of x less than x_min return 0.0, and values greater than x_max return 1.0.

Parameters:
  • x (float) – The input value to interpolate.

  • x_min (float) – The lower edge of the interpolation range.

  • x_max (float) – The upper edge of the interpolation range.

Returns:

The interpolated value between 0.0 and 1.0.

Return type:

float

robotblockset.tools.fit3dcirc(X: ndarray, pl: bool = False) Tuple[ndarray, ndarray, float, ndarray] | Tuple[ndarray, ndarray, float, ndarray, list][source]

Fit a circle to a set of 3D points.

Parameters:
  • X (np.ndarray) – Set of points (n x 3)

  • pl (bool, optional) – Flag for plot (optional, default False).

Returns:

  • pc (array of floats) – Circle center point (3 x 1)

  • n (array of floats) – Normal to circle plane (3 x 1)

  • r (float) – Circle radius.

  • R (array of floats) – Circle frame rotation (3 x 3).

robotblockset.tools.fitplane(points: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Fit a plane to a set of 3D points.

Parameters:

points (np.ndarray) – 3D points (n x 3).

Returns:

  • n (array of floats) – Normal to the plane (3 x 1)

  • R (array of floats) – Orthonormal basis of the plane (3 x 3)

  • p (array of floats) – Point on the plane (3 x 1).

robotblockset.tools.limit_bounds(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], x_min: float, x_max: float, typ: int = 1) ndarray[source]

Calculate gain for a limiter based on given bounds and type.

Parameters:
  • x (ArrayLike) – Input value.

  • x_min (float) – Lower bound.

  • x_max (float) – Upper bound.

  • typ (int, optional) –

    Limiter function type. Supported values are:

    • 1: linear

    • 2 to 4: polynomial x**typ

    • 9: custom reciprocal limiter

    Default is 1.

Returns:

Output values after applying the limiter.

Return type:

np.ndarray

robotblockset.tools.motion_for_load_est(r: Any, q_init: ndarray | None = None, n: int = 50) Tuple[ndarray, ndarray][source]

Generate a set of poses using the last 3 joints and record forces & orientations.

It moves the robot around its home configuration by randomly perturbing the last three joints, then measures the force/torque and sensor orientation.

Parameters:
  • r (Any) – Robot object with an attached force/torque sensor.

  • n (int, optional) – Number of samples to collect. Default is 50.

Returns:

  • Ft (np.ndarray, shape (n, 6)) – Measured forces/torques for each sample.

  • Rt (np.ndarray, shape (3, 3, n)) – Measured sensor orientations as rotation matrices for each sample.

Raises:

ValueError – If r does not appear to be a valid robot object.

robotblockset.tools.load_est(Ft: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], Rt: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) Tuple[float, ndarray, ndarray][source]

Estimates F/T sensor load (mass and COM).

Parameters:
  • Ft (ArrayLike) – Force/torque measurements (n x 6) or (6 x n) numpy array.

  • Rt (ArrayLike) – Sensor orientation matrix (3 x 3 x n) or quaternions (n x 4) numpy array.

Returns:

  • mass (Estimated mass load.)

  • COM (Estimated center of mass (3 x 1 numpy array).)

  • Off (Sensor offset (6 x 1 numpy array).)

robotblockset.tools.load_tools_from_yaml(path: str | Path) tuple[Dict[str, tool_params], str | None][source]

Load tool definitions from a YAML file.

Parameters:

path (Union[str, Path]) – str or Path Path to the YAML file containing tool definitions.

Returns:

  • tools (dict[str, tool_params]) – Dictionary mapping tool names to parsed tool_params objects.

  • default_tool (str or None) – Name of the default tool from the YAML (if defined), otherwise None.

robotblockset.tools.distance2line(p0: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], p: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], dir: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) Tuple[ndarray, float][source]

Find the closest point on line and calculate distance

Parameters:
  • p0 (ArrayLike) – point (3 x 1)

  • p (ArrayLike) – point on line 1 (3 x 1)

  • dir (ArrayLike) – direction of line (3 x 1)

Returns:

  • array of floats – closest point on line (3 x 1)

  • float – normal distance from point to line

robotblockset.tools.dist2lines(p1: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], dir1: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], p2: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], dir2: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], *args: float) Tuple[float, ndarray][source]

Compute the shortest distance between two 3D lines.

Parameters:
  • p1 (ArrayLike) – Point on the first line.

  • dir1 (ArrayLike) – Direction vector of the first line.

  • p2 (ArrayLike) – Point on the second line.

  • dir2 (ArrayLike) – Direction vector of the second line.

  • *args (float) – Optional numerical tolerance used for near-parallel lines.

Returns:

Shortest distance and the corresponding displacement vector.

Return type:

Tuple[float, np.ndarray]

robotblockset.tools.normalize(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], eps: float = np.float64(2.220446049250313e-16)) ndarray[source]

Normalize homogeneous matrix, rotation matrix, or vector.

Parameters:
  • x (ArrayLike) – Homogeneous transformation matrix (4 x 4), rotation matrix (3 x 3), or vector

  • eps (float, optional) – Small threshold to prevent division by zero.

Returns:

Normalized transformation matrix (4 x 4), rotation matrix (3 x 3), or vector

Return type:

array of floats

Raises:
  • TypeError – Wrong argument shape or type

  • ValueError – If any input has zero norm.

robotblockset.tools.vecnormalize(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) ndarray[source]

Normalize vector or rows of a matrix

Parameters:

x (ArrayLike) – matrix (n x m)

Returns:

Normalized vector or matrix with normalized rows

Return type:

array of floats

Raises:

TypeError – Wrong argument shape or type

robotblockset.tools.gradientPath_np(path: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], path_par: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None) ndarray[source]

Calculate gradient along path

Parameters:
  • path (ArrayLike) – path samples (nsamp, n)

  • path_par (ArrayLike, optional) – path parameter (nsamp,) or constant sample distance (scalar)

Returns:

gradient along path (nsamp, n)

Return type:

array of floats

Raises:

TypeError – Wrong parameter shape

robotblockset.tools.gradientPath(path: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], path_par: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None) ndarray[source]

Calculate gradient along path

Parameters:
  • path (ArrayLike) – path samples (nsamp, n)

  • path_par (ArrayLike, optional) – path parameter (nsamp,) or constant sample distance (scalar)

Returns:

gradient along path (nsamp, n)

Return type:

array of floats

Raises:

TypeError – Wrong parameter shape

robotblockset.tools.gradientQuaternionPath(path: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], path_par: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None) ndarray[source]

Calculate velocity along quaternion path

Parameters:
  • path (ArrayLike) – quaternion elements (nsamp, 4)

  • path_par (ArrayLike, optional) – path parameter (nsamp,) or constant sample distance (scalar)

Returns:

gradient along quaternion path (nsamp, 3)

Return type:

array of floats

Raises:

TypeError – Wrong parameter shape

robotblockset.tools.gradientCartesianPath(path: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], path_par: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None) ndarray[source]

Calculate gradient along Cartesian path

Poses are defined by position and quaternion.

Parameters:
  • path (ArrayLike) – Cartesian poses (nsamp, 7)

  • path_par (ArrayLike, optional) – path parameter (nsamp,) or constant sample distance (scalar)

Returns:

gradient along Cartesian path (nsamp, 6)

Return type:

array of floats

robotblockset.tools.wrap_to_pi(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) ndarray[source]

Wrap an angle or array of angles to the range [-π, π].

Parameters:

x (ArrayLike) – Input angle(s) in radians.

Returns:

Wrapped angle(s) in the range [-π, π).

Return type:

float or np.ndarray

robotblockset.tools.limit_rate(value_prev: float, value_target: float, max_delta: float) float[source]

Limits the rate of change from a previous value toward a target value.

Ensures that the change from value_prev to value_target does not exceed max_delta in either direction. Useful for smoothing or clamping rate of change in control systems, animations, or simulations.

Parameters:
  • value_prev (float) – The previous or current value.

  • value_target (float) – The desired target value.

  • max_delta (float) – The maximum allowed change per step.

Returns:

The new value after applying the limited rate of change.

Return type:

float

robotblockset.tools.damped_pinv(A: ndarray, lambda_factor: float = 0.01) ndarray[source]

Compute the damped least squares pseudo-inverse of a matrix.

The function applies Tikhonov regularization to stabilize the computation of the pseudoinverse, particularly for ill-conditioned or singular matrices.

Parameters:
  • A (np.ndarray) – Input matrix for which the damped pseudoinverse is computed.

  • lambda_factor (float, optional) – Regularization parameter controlling the damping effect. A higher value increases numerical stability but may reduce accuracy.

Returns:

Damped pseudoinverse of the input matrix A.

Return type:

array-like, shape (n, m)

robotblockset.tools.filtfilt(signal_data: ndarray, cutoff: float | ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] = 0.1, fs: float = 1.0, order: int = 4, filter_type: str = 'low') ndarray[source]

Applies a zero-phase filter (equivalent to MATLAB’s filtfilt) on multidimensional signals. Each column in signal_data is treated as an independent signal.

Parameters:
  • signal_data (np.ndarray) – The input noisy signals, where each column is a separate signal.

  • cutoff (Union[float, ArrayLike], optional) – The cutoff frequency (normalized: 0 < cutoff < 1, or in Hz if fs is provided).

  • fs (float, optional) – Sampling frequency. If provided, cutoff is interpreted in Hz. Defaults to 1.0.

  • order (int, optional) – The order of the filter. Higher order provides a sharper cutoff. Defaults to 4.

  • filter_type (str, optional) – Type of filter to apply. Options: “low”, “high”, “bandpass”, “bandstop”. Defaults to “low”.

Returns:

The filtered signals with zero-phase distortion.

Return type:

np.ndarray, shape (N, M)

robotblockset.tools.find_closest_row(array_2d: ndarray, array_1d: ndarray) Tuple[int, ndarray][source]

Find the row in a 2D NumPy array that is closest to a given 1D array based on the Euclidean distance.

Parameters:
  • array_2d (np.ndarray) – A 2D NumPy array where each row represents a vector.

  • array_1d (np.ndarray) – A 1D NumPy array (vector) to compare against the rows of array_2d.

Returns:

A tuple containing: - The index of the closest row in array_2d. - The closest row itself from array_2d.

Return type:

tuple

Notes

The distance is calculated using the Euclidean distance formula: d(a, b) = sqrt(sum((a_i - b_i)^2) for each element i in the vectors a and b).

robotblockset.tools.search_valid_range(fun: Callable[[float], Any | None], x_min: float, x_max: float, tolerance: float = 1e-06) Tuple[float, float][source]

Use binary search to find the valid subrange [x_valid_min, x_valid_max].

Parameters:
  • fun (Callable[[float], Optional[Any]]) – The function to check validity of x values.

  • x_min (float) – The minimum value of x.

  • x_max (float) – The maximum value of x.

  • tolerance (float, optional) – The tolerance for checking validity (default is 1e-6).

Returns:

A tuple containing the valid subrange (q7_valid_min, q7_valid_max).

Return type:

tuple

robotblockset.tools.parse_rbs_log(lines: Iterable[str]) List[Tuple[float, str]][source]

Parse ROS2 log lines and extract relative timestamp and event description.

The first timestamp encountered is treated as t = 0.

Parameters:

lines (Iterable[str]) – Iterable of log lines (e.g. list of strings, open file handler).

Returns:

List of tuples: - relative timestamp (seconds since first entry), - event description text.

Return type:

list of (float, str)

robotblockset.tools.print_xml(xml_string: str, is_dark: bool = True) None[source]

Render highlighted XML in a notebook environment.

Parameters:
  • xml_string (str) – XML text to display.

  • is_dark (bool, optional) – Select a dark or light Pygments style.

Returns:

This function displays formatted HTML output.

Return type:

None

robotblockset.tools.print_xml_for_console(xml_string: str) str[source]

Format XML for console output.

Parameters:

xml_string (str) – XML text to pretty-print and colorize.

Returns:

Colorized XML string formatted for terminal output.

Return type:

str

robotblockset.tools.replace_attr_values_in_xml(xml_text: str, old: str, new: str, substring: bool = False) tuple[str, int][source]

Replace attribute values in MJCF XML text.

Parameters:
  • xml_text (str) – XML document text.

  • old (str) – Attribute value to replace.

  • new (str) – Replacement value.

  • substring (bool, optional) – If True, replace matching substrings inside attribute values; otherwise require exact matches.

Returns:

Updated XML text and the number of replacements made.

Return type:

tuple[str, int]

robotblockset.tools.find_attr_values_in_xml(xml_text: str, value: str, substring: bool = False) tuple[str, int][source]

Find XML attributes whose values match a target string.

Parameters:
  • xml_text (str) – XML document text.

  • value (str) – Attribute value to search for.

  • substring (bool, optional) – If True, match attributes containing value; otherwise require an exact match.

Returns:

Matching entries as [parent, element_type, element_name, attribute_name].

Return type:

list[list[str]]

Functions

check_option(opt, val)

Check if option equals value (case-independent)

check_shape(x, shape)

Check last dimensions of np array

damped_pinv(A[, lambda_factor])

Compute the damped least squares pseudo-inverse of a matrix.

deadzone(x[, width, center])

Apply a symmetric dead zone to input values.

dist2lines(p1, dir1, p2, dir2, *args)

Compute the shortest distance between two 3D lines.

distance2line(p0, p, dir)

Find the closest point on line and calculate distance

filtfilt(signal_data[, cutoff, fs, order, ...])

Applies a zero-phase filter (equivalent to MATLAB's filtfilt) on multidimensional signals.

find_attr_values_in_xml(xml_text, value[, ...])

Find XML attributes whose values match a target string.

find_closest_row(array_2d, array_1d)

Find the row in a 2D NumPy array that is closest to a given 1D array based on the Euclidean distance.

find_rows(row, x)

Find indices of rows equal to a reference row.

fit3dcirc(X[, pl])

Fit a circle to a set of 3D points.

fitplane(points)

Fit a plane to a set of 3D points.

get_logger(name)

Create and configure a package logger.

get_rbs_path()

Return the absolute filesystem path to the installed robotblockset package.

getunit(unit)

Calculates unit conversion factor

grad(fun, x0[, dx])

Gradient of function at values x

gradientCartesianPath(path[, path_par])

Calculate gradient along Cartesian path

gradientPath(path[, path_par])

Calculate gradient along path

gradientPath_np(path[, path_par])

Calculate gradient along path

gradientQuaternionPath(path[, path_par])

Calculate velocity along quaternion path

hessmat(fun, x0[, delta])

Hessian matrix of a scalar function with vector argument.

ismatrix(x[, shape])

Check if parameter is a matrix

ismatrixarray(x[, shape])

Check if parameter is a matrix array

isquaternion(Q)

Check if parameter is quaternionic array QArray

isscalar(x)

Check if the input is a scalar.

isskewsymmetric(S[, tol])

Check if matrix is skew-symmetric

isvector(x[, dim])

Check if the input is a vector and optionally verify its dimension.

limit_bounds(x, x_min, x_max[, typ])

Calculate gain for a limiter based on given bounds and type.

limit_rate(value_prev, value_target, max_delta)

Limits the rate of change from a previous value toward a target value.

load_est(Ft, Rt)

Estimates F/T sensor load (mass and COM).

load_tools_from_yaml(path)

Load tool definitions from a YAML file.

matrix(x[, shape])

Return a matrix

motion_for_load_est(r[, q_init, n])

Generate a set of poses using the last 3 joints and record forces & orientations.

normalize(x[, eps])

Normalize homogeneous matrix, rotation matrix, or vector.

parse_rbs_log(lines)

Parse ROS2 log lines and extract relative timestamp and event description.

print_xml(xml_string[, is_dark])

Render highlighted XML in a notebook environment.

print_xml_for_console(xml_string)

Format XML for console output.

rbs_type(x)

Convert input data to a squeezed float NumPy array.

replace_attr_values_in_xml(xml_text, old, new)

Replace attribute values in MJCF XML text.

search_valid_range(fun, x_min, x_max[, ...])

Use binary search to find the valid subrange [x_valid_min, x_valid_max].

sigmoid(x[, offset, gain])

Sigmoid function

smoothstep(x, xmin, xmax)

Sigmoid-like interpolation and clamping function.

smoothstep3(x, x_min, x_max)

Performs smooth Hermite interpolation between 0 and 1 when x is in the range [x_min, x_max].

vecnormalize(x)

Normalize vector or rows of a matrix

vector(x[, dim])

Convert input to a NumPy vector.

wrap_to_pi(x)

Wrap an angle or array of angles to the range [-π, π].

Classes

load_params(mass, COM, inertia)

Load parameters consisting of mass, center of mass (COM), and inertia tensor.

rbs_object()

A base class for objects with debugging and messaging capabilities.

tool_params(name, id, tcp_position, ...)

Represents tool parameters including TCP definition and associated load.