Wrench3D
SUMMARY
Force and torque in 3D space.
python
from telekinesis import datatypes
wrench = datatypes.Wrench3D([1.0, 0.0, 0.0, 0.0, 0.0, 0.5])Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | np.ndarray | list | tuple | Required | Force and torque [fx, fy, fz, tx, ty, tz] with shape (6,). |
Raises
| Exception | Condition |
|---|---|
TypeError | data can't be converted to float32 (e.g. non-numeric elements) |
ValueError | data is not rank-1, or its shape isn't (6,) |
ValueError | data contains a non-finite value (NaN/Inf) |
Attributes
| Attribute | Type | Description |
|---|---|---|
data | np.ndarray | Defensive copy of the underlying (6,) float32 array. Assigning a new value re-validates it the same way as construction. |
shape | tuple[int, ...] | Always (6,). |
ndim | int | Always 1. |
dtype | np.dtype | Always float32. |
size | int | Always 6. |
Methods
| Method | Type | Description |
|---|---|---|
Wrench3D.coerce(value) | Wrench3D | Converts array-like data into a Wrench3D. If value is already a Wrench3D, it is returned unchanged; otherwise it goes through the same checks as constructing one directly. |
to_numpy(copy=True) | np.ndarray | Returns the wrench as a plain array. With the default copy=True you get an independent copy; pass copy=False to get a direct reference to the internal array instead, so mutating it also mutates the Wrench3D. |
copy() | Wrench3D | Returns a new, independent Wrench3D with the same data. |
Operators
| Operation | Behavior |
|---|---|
w == other | True only if other is also a Wrench3D with element-equal data. False for anything else. |
len(w) | Always 6. |
np.asarray(w) | Returns a copy of data as an np.ndarray; NumPy functions accept a Wrench3D directly. |
Visualization
python
import rerun as rr
# Your code block
# ....
rr.init("wrench3d_example", spawn=True)
datatypes.visualize(wrench, entity_path="/wrench", label="Wrench3D")Example
python
"""Demonstrates the Telekinesis Wrench3D datatype."""
import time
import numpy as np
import rerun as rr
from loguru import logger
from telekinesis import datatypes
def wrench3d_example():
"""Demonstrate creation, inspection, operations, visualization, and serialization."""
# ======================= Create ============================================
values = np.array([1.0, 0.0, 0.0, 0.0, 0.0, 0.5], dtype=np.float32)
wrench3d = datatypes.Wrench3D(values)
logger.info(f"Created Wrench3D: {wrench3d}")
wrench3d_from_coerce = datatypes.Wrench3D.coerce(values)
logger.info(f"Wrench3D created via coerce: {wrench3d_from_coerce}")
# ======================= Inspect ===========================================
logger.info(f"data={wrench3d.data}")
logger.info(f"shape={wrench3d.shape}")
logger.info(f"ndim={wrench3d.ndim}")
logger.info(f"dtype={wrench3d.dtype}")
logger.info(f"size={wrench3d.size}")
# ======================= Operations =========================================
wrench3d.data = np.array([0.0, 2.0, 0.0, 0.0, 0.0, 1.5], dtype=np.float32)
logger.info(f"Updated Wrench3D: {wrench3d}")
wrench3d_copy = wrench3d.copy()
logger.info(f"Copied Wrench3D: {wrench3d_copy}")
wrench3d_numpy = wrench3d.to_numpy(copy=True)
logger.info(f"NumPy Wrench3D: {wrench3d_numpy}")
numpy_array = np.asarray(wrench3d)
logger.info(f"NumPy array: {numpy_array}")
logger.info(f"Sum: {np.sum(wrench3d)}")
logger.info(f"length={len(wrench3d)}")
# ======================= Visualize =========================================
rr.init("wrench3d_example", spawn=True)
datatypes.visualize(
wrench3d_from_coerce, entity_path="/wrench3d/coerced", label="Coerced Wrench3D"
)
datatypes.visualize(wrench3d, entity_path="/wrench3d/updated", label="Updated Wrench3D")
# ======================= Serialize / Deserialize ===========================
start = time.perf_counter()
serialized = datatypes.serialize(wrench3d)
serialization_ms = (time.perf_counter() - start) * 1000
start = time.perf_counter()
deserialized = datatypes.deserialize(serialized)["param_0"]
deserialization_ms = (time.perf_counter() - start) * 1000
logger.info(f"Deserialized Wrench3D: {deserialized}")
logger.info(f"Round-trip successful: {wrench3d == deserialized}")
logger.info(f"Serialization time: {serialization_ms:.3f} ms")
logger.info(f"Deserialization time: {deserialization_ms:.3f} ms")
if __name__ == "__main__":
wrench3d_example()
