ros_sugar.config.base_config¶
Config Classes for Components and Topics
Module Contents¶
Classes¶
Class for quality of service (QoS) configuration in ROS2 |
|
Node General Parameters |
|
Component run type: |
|
External processor type: |
|
Component configuration parameters |
API¶
- class ros_sugar.config.base_config.QoSConfig¶
Bases:
ros_sugar.config.base_attrs.BaseAttrsClass for quality of service (QoS) configuration in ROS2
Name
Type, Default
Description
history
int,[qos](https://docs.ros2.org/foxy/api/rclpy/api/qos.html).HistoryPolicy.KEEP_LASTSample store type: ALL or LAST (up to N samples, configurable via the queue depth option)
queue_size
int,10Used only if the “history” policy was set to “keep last”
reliability
int,qos.ReliabilityPolicy.RELIABLELevel of reliability in delivering samples
durability
int,qos.DurabilityPolicy.VOLATILEDetermines if the publisher will be persisting samples for “late-joining” subscriptions (Transit Local) or not (Volatile)
- to_ros() rclpy.qos.QoSProfile¶
Converts the config class to ROS2 QoS Profile
- Returns:
ROS2 QoS Profile
- Return type:
qos.QoSProfile
- asdict(filter: Optional[Callable] = None) Dict¶
Convert class to dict.
- Return type:
dict
- to_dict() Dict¶
Convert class to dict.
- 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.
- class ros_sugar.config.base_config.BaseConfig¶
Bases:
ros_sugar.config.base_attrs.BaseAttrsNode General Parameters
- Parameters:
loop_rate (float) – Rate (Hz) in which the node executes
visualization (bool) – To publish additional topics for visualization
- asdict(filter: Optional[Callable] = None) Dict¶
Convert class to dict.
- Return type:
dict
- to_dict() Dict¶
Convert class to dict.
- 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.
- class ros_sugar.config.base_config.ComponentRunType(*args, **kwds)¶
Bases:
enum.EnumComponent run type:
Timed: Executes main in a timed loop
Event: Executes based on a trigger topic/event
Server: Executes based on a ROS service request from a client
ActionServer: Executes based on a ROS action server request from a client
- classmethod to_str(enum_value) str¶
Return string value corresponding to enum value if exists
- Parameters:
enum_value (ComponentRunType | str) – description
- Raises:
ValueError – If the enum value is not from this class
- Returns:
String value
- Return type:
str
- name()¶
The name of the Enum member.
- value()¶
The value of the Enum member.
- class ros_sugar.config.base_config.ExternalProcessorType(*args, **kwds)¶
Bases:
enum.EnumExternal processor type:
MSG_PRE_PROCESSOR: Executes before publishing a ros msg
MSG_POST_PROCESSOR: Executes after receiving a ros msg in a callback
- classmethod to_str(enum_value) str¶
Return string value corresponding to enum value if exists
- Parameters:
enum_value (ExternalProcessorType | str) – description
- Raises:
ValueError – If the enum value is not from this class
- Returns:
String value
- Return type:
str
- name()¶
The name of the Enum member.
- value()¶
The value of the Enum member.
- class ros_sugar.config.base_config.BaseComponentConfig¶
Bases:
ros_sugar.config.base_config.BaseConfigComponent configuration parameters
- Parameters:
fallback_rate (float) – Rate (Hz) at which the component checks for fallbacks and executes actions if a failure is detected.
log_level (Union[str, LoggingSeverity]) – Logging level for the component’s internal logs. Can be a string or
LoggingSeverityenum.rclpy_log_level (Union[str, LoggingSeverity]) – Logging level for rclpy (ROS client library) logs. Can be a string or
LoggingSeverityenum.wait_for_restart_time (float) – Time (in seconds) the component waits for a node to come back online after restart. Used to avoid infinite restart loops. Recommended to use a high value.
- asdict(filter: Optional[Callable] = None) Dict¶
Convert class to dict.
- Return type:
dict
- to_dict() Dict¶
Convert class to dict.
- 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.