sensors

Sensors module.

This module defines a flexible and extensible framework for integrating sensors into robotic platforms. It includes an abstract sensor base class, a force_torque_sensor interface for handling 6-axis force-torque data, and concrete implementations such as ati_ft_sensor for ATI hardware and dummysensor for simulation or testing.

class robotblockset.sensors.sensor(**kwargs: Any)[source]

Bases: rbs_object

Abstract base class for a sensor attached to a robot.

This class represents a sensor in the context of a robotic system. It includes methods for attaching the sensor to a robot, updating the sensor state, and simulating time. Derived classes must implement the GetState method to retrieve the sensor’s state.

Attributes:
  • Name (str) – The name of the sensor (default is “Sensor”).

  • Robot (robot or None) – The robot to which the sensor is attached. Default is None.

Notes

This is an abstract class, and GetState() must be implemented in subclasses to define the behavior for retrieving the sensor’s state.

Initializes the sensor object.

Parameters:

**kwargs (Any) – Additional parameters to customize the sensor. If robot is provided, the sensor is attached to that robot via AttachTo.

Returns:

This constructor initializes the sensor object in place.

Return type:

None

__init__(**kwargs: Any) None[source]

Initializes the sensor object.

Parameters:

**kwargs (Any) – Additional parameters to customize the sensor. If robot is provided, the sensor is attached to that robot via AttachTo.

Returns:

This constructor initializes the sensor object in place.

Return type:

None

simtime() float[source]

Get the current simulation time.

Returns:

The current simulation time, as returned by perf_counter.

Return type:

float

abstractmethod GetState() None[source]

Abstract method to retrieve the sensor’s state.

Derived classes must implement this method to return the state of the sensor.

Raises:

NotImplementedError – This method must be implemented in subclasses.

SetTsamp(tsamp: float) None[source]

Set the sensor’s sampling time.

Parameters:

tsamp (float) – Sampling period of the sensor in seconds.

Returns:

This method updates the sampling time in place.

Return type:

None

Update() None[source]

Update the sensor’s state by calling the GetState method.

Returns:

This method refreshes the current sensor state in place.

Return type:

None

AttachTo(robot: robot) None[source]

Attach the sensor to a robot.

Parameters:

robot (robot) – Robot instance to which the sensor is attached.

Returns:

This method stores the robot reference in the sensor.

Return type:

None

Detach() None[source]

Detach the sensor from the robot.

Returns:

This method clears the stored robot reference.

Return type:

None

GetAttachedRobot() Tuple[robot | None, str][source]

Get the robot to which the sensor is attached.

Returns:

A tuple containing the robot object and its name, or (None, “None”) if not attached.

Return type:

tuple

class robotblockset.sensors.force_torque_sensor(**kwargs: Any)[source]

Bases: sensor

Class for a force-torque sensor attached to a robot.

This class extends the sensor class to represent a force-torque sensor. The sensor measures forces and torques in six degrees of freedom (3 forces and 3 torques) and provides methods for getting the raw data, updating the sensor state, zeroing the sensor, and setting or updating the load attached to the sensor.

Attributes:
  • SensorData (np.ndarray) – A 1D array containing the sensor’s data (6 values: 3 forces and 3 torques).

  • Load (load_params) – The load object associated with the sensor, containing mass, center of mass, and inertia properties.

Initializes the force-torque sensor with default parameters.

Parameters:

**kwargs (Any) – Additional parameters forwarded to sensor.__init__. If robot is provided, the sensor is attached to that robot via AttachTo.

Returns:

This constructor initializes the force-torque sensor object in place.

Return type:

None

__init__(**kwargs: Any) None[source]

Initializes the force-torque sensor with default parameters.

Parameters:

**kwargs (Any) – Additional parameters forwarded to sensor.__init__. If robot is provided, the sensor is attached to that robot via AttachTo.

Returns:

This constructor initializes the force-torque sensor object in place.

Return type:

None

property FT: ndarray

Returns the 6D force-torque data as a deep copy.

Returns:

A deep copy of the 6D force-torque data (3 forces and 3 torques).

Return type:

np.ndarray

property F: ndarray

Returns the 3D force values as a deep copy.

Returns:

A deep copy of the 3D force values (the first three values of SensorData).

Return type:

np.ndarray

property Trq: ndarray

Returns the 3D torque values as a deep copy.

Returns:

A deep copy of the 3D torque values (the last three values of SensorData).

Return type:

np.ndarray

abstractmethod GetRawFT() ndarray[source]

Abstract method to retrieve the raw force-torque data from the sensor.

This method should be implemented by subclasses to obtain the raw data from the sensor hardware.

Raises:

NotImplementedError – If not implemented in a subclass.

GetState() None[source]

Retrieves the current state of the sensor by calling GetFT().

Returns:

This method updates the cached force-torque data in place.

Return type:

None

GetFT(avg_time: float = 0) ndarray | None[source]

Retrieves the force-torque data, optionally averaging over a period of time.

Parameters:

avg_time (float, optional) – The time period over which to average the data. Default is 0.

Returns:

The 6D force-torque data after averaging and applying the offset, or None if no update.

Return type:

np.ndarray or None

ZeroingFT(time: float = 0) None[source]

Zeroes the force-torque sensor by setting the offset based on the current measurement.

Parameters:

time (float, optional) – Averaging interval in seconds used to estimate the zero offset.

Returns:

This method updates the internal sensor offset.

Return type:

None

SetLoad(load: load_params | None = None, mass: float | None = None, COM: ndarray | None = None, inertia: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None, offset: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None) None[source]

Sets or updates the load properties (mass, COM, inertia, and offset).

Parameters:
  • load (load_params, optional) – Load description object to assign directly.

  • mass (float, optional) – Load mass in kilograms.

  • COM (Vector3DType, optional) – Load center of mass expressed in the sensor frame.

  • inertia (ArrayLike, optional) – Load inertia tensor or inertia parameters.

  • offset (ArrayLike, optional) – Sensor offset to apply to the measured wrench.

Returns:

This method updates the stored load parameters and optional offset.

Return type:

None

GetLoad() load_params[source]

Retrieves the current load associated with the sensor.

Returns:

The current load object attached to the sensor.

Return type:

load_params

SetOffset(offset: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]

Sets the offset for the sensor.

Parameters:

offset (ArrayLike) – Offset wrench applied to subsequent sensor readings.

Returns:

This method replaces the current offset.

Return type:

None

UpdateOffset(offset: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]

Updates the offset for the sensor by subtracting the provided offset.

Parameters:

offset (ArrayLike) – Offset wrench to subtract from the current offset.

Returns:

This method modifies the existing offset in place.

Return type:

None

class robotblockset.sensors.ati_ft_sensor(host: str = '192.168.1.100', **kwargs: Any)[source]

Bases: force_torque_sensor

Force-torque sensor interface for ATI sensors using UDP communication.

This class provides communication with ATI Net F/T sensors over a UDP network connection.

Attributes:
  • host (str) – Resolved IP address of the sensor.

  • port_send (int) – UDP port used to send data to the sensor (default is 49152).

  • port_recv (int) – UDP port used to receive data from the sensor (based on the host IP).

  • sock (socket.socket) – UDP socket object for communication.

  • command (bytes) – Command packet to request force-torque data from the sensor.

Initialize the sensor either by host IP or robot name.

Parameters:
  • host (str, optional) – The IP address of the ATI sensor.

  • **kwargs (Any) – Additional keyword arguments passed to force_torque_sensor.__init__. If robot is provided, the sensor is attached to that robot via the inherited AttachTo logic.

Returns:

This constructor initializes the ATI force-torque sensor object in place.

Return type:

None

__init__(host: str = '192.168.1.100', **kwargs: Any) None[source]

Initialize the sensor either by host IP or robot name.

Parameters:
  • host (str, optional) – The IP address of the ATI sensor.

  • **kwargs (Any) – Additional keyword arguments passed to force_torque_sensor.__init__. If robot is provided, the sensor is attached to that robot via the inherited AttachTo logic.

Returns:

This constructor initializes the ATI force-torque sensor object in place.

Return type:

None

GetRawFT() ndarray[source]

Retrieve raw force-torque data from the ATI sensor.

Returns:

A 6-element numpy array containing the measured forces (Fx, Fy, Fz) and torques (Tx, Ty, Tz) in Newtons and Newton-meters respectively.

Return type:

np.ndarray

Raises:

TimeoutError – If the sensor does not respond within the timeout period.

class robotblockset.sensors.dummysensor(**kwargs: Any)[source]

Bases: sensor

A dummy sensor class for testing or simulation purposes.

This class extends the sensor class and provides a simple implementation of the GetRawFT method. It returns a force-torque data vector of zeros, which is useful for testing or as a placeholder in simulations.

Attributes:
  • Name (str) – The name of the sensor (default is “Dummysensor”).

  • SensorData (np.ndarray) – A 1D array to store the sensor’s force-torque data (6 values: 3 forces and 3 torques).

Initializes the dummy sensor with default parameters.

Parameters:

**kwargs (Any) – Additional keyword arguments passed to sensor.__init__.

Returns:

This constructor initializes the dummy sensor object in place.

Return type:

None

__init__(**kwargs: Any) None[source]

Initializes the dummy sensor with default parameters.

Parameters:

**kwargs (Any) – Additional keyword arguments passed to sensor.__init__.

Returns:

This constructor initializes the dummy sensor object in place.

Return type:

None

GetRawFT() ndarray[source]

Implements the GetRawFT method to return a force-torque data vector of zeros.

This method simulates a dummy sensor by providing a 6D zero vector for force and torque values.

Returns:

A 6D zero vector representing the force and torque data from the sensor.

Return type:

np.ndarray

robotblockset.sensors.issensor(obj: object) bool[source]

Checks if the given object is an instance of the sensor class or its subclasses.

This function uses the isinstance() method to check if the object obj is an instance of the sensor class, which includes instances of any class that inherits from sensor.

Parameters:

obj (object) – The object to check.

Returns:

True if the object is an instance of the sensor class or its subclasses, False otherwise.

Return type:

bool

Functions

issensor(obj)

Checks if the given object is an instance of the sensor class or its subclasses.

Classes

ati_ft_sensor([host])

Force-torque sensor interface for ATI sensors using UDP communication.

dummysensor(**kwargs)

A dummy sensor class for testing or simulation purposes.

force_torque_sensor(**kwargs)

Class for a force-torque sensor attached to a robot.

sensor(**kwargs)

Abstract base class for a sensor attached to a robot.