ros_sugar.robot.mount#
Where a sensor sits on the robot.
A Mount is a recipe-level statement: this sensor is mounted there on this
robot.
Mounts only describe static transforms. A sensor with moving parts (a pan-tilt head) publishes the dynamic transform from its own base frame to the moving one itself; the recipe then only has to say where that base frame sits, and the two compose in the TF tree.
Module Contents#
Classes#
A static placement of a sensor relative to something else. |
Functions#
Convert roll/pitch/yaw (radians) to a quaternion |
|
Where one mounted thing sits in another’s frame. |
API#
- ros_sugar.robot.mount.quaternion_from_euler(roll: float, pitch: float, yaw: float) Tuple[float, float, float, float]#
Convert roll/pitch/yaw (radians) to a quaternion
(x, y, z, w).ROS transforms carry quaternions while people describe mounts in roll, pitch and yaw, so a recipe states the readable form and this converts. Rotations compose in the ROS convention: yaw about Z, then pitch about Y, then roll about X.
- Parameters:
roll – Rotation about X, in radians
pitch – Rotation about Y, in radians
yaw – Rotation about Z, in radians
- Returns:
Quaternion as
(x, y, z, w)- Return type:
Tuple[float, float, float, float]
- ros_sugar.robot.mount.pose_relative_to(pose: Tuple[Tuple[float, float, float], Tuple[float, float, float]], frame: Tuple[Tuple[float, float, float], Tuple[float, float, float]]) Tuple[Tuple[float, float, float], Tuple[float, float, float]]#
Where one mounted thing sits in another’s frame.
A robot knows where each of its sensors sits on its body, while whatever reads one of them usually wants another in its own frame. Both arguments and the result are
(xyz, rpy)against the same parent.- Parameters:
pose – What is being placed, as
(xyz, rpy)on the parentframe – Whose frame to place it in, as
(xyz, rpy)on the parent
- Returns:
(xyz, rpy)ofposeinframe
- class ros_sugar.robot.mount.Mount#
Bases:
ros_sugar.config.BaseAttrsA static placement of a sensor relative to something else.
Name
Type, Default
Description
parent
str | PluginWhat the sensor is mounted on: the robot plugin, another sensor plugin, or a frame name such as the world frame for a fixed sensor.
xyz
tuple,(0, 0, 0)Translation from the parent frame to the sensor frame, in metres.
rpy
tuple,(0, 0, 0)Rotation from the parent frame to the sensor frame, in radians.
- property parent_frame: str#
Frame this mount is relative to.
- property child_frame: str#
Frame being placed.
- asdict(filter: Optional[Callable] = None) Dict#
Convert class to dict.
- Return type:
dict
- to_dict() Dict#
Convert class to dict.
- Return type:
dict
- asdict_explicit() Dict#
Convert to dict, keeping only what differs from the class defaults.
See
explicit_fields, which this defers to.- Returns:
Fields that differ from the defaults
- Return type:
dict
- from_dict(dict_obj: Dict) None#
Gets attributes values from given dictionary
- Parameters:
dict_obj (Dict) – Dictionary {attribute_name: attribute_value}
- Raises:
ValueError – If attribute_name in dictionary does not exists in class attributes
TypeError – If attribute_value type in dictionary does not correspond to class attribute type
- from_file(file_path: str, nested_root_name: Union[str, None] = None, get_common: bool = False) bool#
Update class attributes from yaml, json, or toml
- Parameters:
file_path – Path to config file (.yaml, .json, .toml)
nested_root_name – Nested root name for the config, defaults to None
get_common – Whether to get extra config root (for merging), defaults to False
- to_json() Union[str, bytes, bytearray]#
Dump to json
- Returns:
description
- Return type:
str | bytes | bytearray
- from_json(json_obj: Union[str, bytes, bytearray]) None#
Gets attributes values from given json
- Parameters:
json_obj (str | bytes | bytearray) – Json object
- has_attribute(attr_name: str) bool#
Checks if class object has attribute with given name
- Parameters:
attr_name (str) – description
- Returns:
If object has attribute with given name
- Return type:
bool
- get_attribute_type(attr_name: str) Optional[type]#
Gets type of given attribute name
- Parameters:
attr_name (str) – description
- Raises:
AttributeError – If class does not have attribute with given name
- Returns:
Attribute type
- Return type:
type
- update_value(attr_name: str, attr_value: Any) bool#
Updates the value of an attribute in the class
- Parameters:
attr_name (str) – Attribute name - can be nested name
attr_value (Any) – Attribute value
- Raises:
AttributeError – If class does not contain attribute with given name
TypeError – If class attribute with given name if of different type
- Returns:
If attribute value is updated
- Return type:
bool
- classmethod get_fields_info(class_object) Dict[str, Dict[str, Any]]#
Returns a dictionary with metadata about each field in the class.
This includes the field’s name, type annotation, and parsed validator info.
- Returns:
A dictionary where keys are field names and values are dicts of metadata.