kompass.components.controller#
Module Contents#
Classes#
Controller component configuration parameters |
|
Controller component used for path tracking and control around dynamic obstacles during navigation. |
API#
- class kompass.components.controller.ControllerConfig#
Bases:
kompass.config.ComponentConfigController component configuration parameters
Name
Type, Default
Description
algorithm
ControllersID| str,DWAAlgorithm used to compute the control command
control_time_step
float,0.1Time step in MPC-like controllers (s)
debug
bool,FalseTurn on debug mode to published additional data for visualization
use_direct_sensor
bool,FalseTo used direct sensor information, otherwise the node subscriber to a local map
ctrl_publish_type
CmdPublishType | str,TWIST_ARRAYHow to publish the control commands
vision_depth_max_age
float,0.2Largest stamp difference (s) between the vision detections and the separate depth input (
vision_depth) for the two to be paired; older depth is not used
- class kompass.components.controller.Controller(*, component_name: str, config_file: Optional[str] = None, config: Optional[kompass.components.controller.ControllerConfig] = None, inputs: Optional[Dict[kompass.components.defaults.TopicsKeys, kompass.components.ros.Topic]] = None, outputs: Optional[Dict[kompass.components.defaults.TopicsKeys, kompass.components.ros.Topic]] = None, **kwargs)#
Bases:
kompass.components.component.ComponentController component used for path tracking and control around dynamic obstacles during navigation.
Inputs:
Key Name
Allowed Types
Number
Default
plan
1
Topic(name="/plan", msg_type="Path")location
nav_msgs.msg.Odometry,geometry_msgs.msg.PoseStamped,geometry_msgs.msg.Pose1
Topic(name="/odom", msg_type="Odometry")sensor_data
1
Topic(name="/scan", msg_type="LaserScan")local_map
1
Topic(name="/local_map/occupancy_layer", msg_type="OccupancyGrid")vision_detections
automatika_embodied_agents.msg.Trackings,automatika_embodied_agents.msg.Detections2D1
None(required for the vision tracking action)depth_camera_info
1
None(required for the vision tracking action)vision_depth
sensor_msgs.msg.Image(depth image aligned with the detection camera),sensor_msgs.msg.PointCloud21
None(optional: lifts the detections to 3D instead of the depth embedded in the detections message)Outputs:
Key Name
Allowed Types
Number
Default
command
1
Topic(name="/control", msg_type="Twist")multi_command
1
Topic(name="/control_list", msg_type="TwistArray")interpolation
1
Topic(name="/interpolated_path", msg_type="Path")local_plan
1
Topic(name="/local_path", msg_type="Path")tracked_point
nav_msgs.msg.Odometry,geometry_msgs.msg.PoseStamped,geometry_msgs.msg.Poseautomatika_embodied_agents.msg.Detection2D1
Topic(name="/tracked_point", msg_type="PoseStamped")Available Run Types:
Set directly from Controller ‘run_type’ property.
TIMED: Compute a new control command periodically if all inputs are available.
ACTIONSERVER: Offers a ControlPath ROS action and continuously computes a new control once an action request is received until goal point is reached
Usage Example:
from kompass.components import ControllerConfig, Controller from kompass.topic import Topic # Setup custom configuration my_config = ControllerConfig(loop_rate=10.0) # Init a controller object my_controller = Controller(component_name="controller", config=my_config) # Change an input my_controller.inputs(plan=Topic(name='/global_path', msg_type='Path')) # Change run type (default "Timed") my_controller.run_type = "ActionServer" # Change plugin my_controller.plugin = 'DWA'
- custom_on_activate()#
Component custom activation method to add activation based on the control mode
- custom_create_all_subscribers()#
Overrides BaseComponent create_all_subscribers to implement controller mode change
- create_all_timers()#
Overrides create_all_timers from BaseComponent to add timers for commands execution and tracking publishing
- destroy_all_timers()#
Overrides destroy_all_timers from BaseComponent to destroy the timers for commands execution and tracking publishing
- create_all_services()#
Creates all node services
- destroy_all_services()#
Destroys all node services
- inspect_component() str#
Method to return a string representation of the component configuration, used for inspection and LLM-based reasoning about the component
- Returns:
String representation of the component configuration
- Return type:
str
- get_ros_entrypoints() Dict[str, Dict[str, Any]]#
Get the component ROS entry points (additional services and actions) as a dictionary.
- property tracked_point: Optional[numpy.ndarray]#
Getter of tracked pose on the reference path if a path is set to the controller
- Returns:
description
- Return type:
- property local_plan: Optional[nav_msgs.msg.Path]#
Getter of controller local plan
- Returns:
description
- Return type:
- property local_plan_debug: Optional[nav_msgs.msg.Path]#
Getter of controller local plan debug (collected samples)
- Returns:
description
- Return type:
- property interpolated_path: Optional[nav_msgs.msg.Path]#
Getter of interpolated global path
- Returns:
Path Interpolation
- Return type:
Optional[Path]
- property direct_sensor: bool#
Getter of flag to use direct sensor data in the controller, if False the controller uses the local map
- Returns:
Use direct sensor data flag
- Return type:
bool
- property algorithm: kompass_core.control.ControllersID#
Getter of controller algorithm
- Returns:
description
- Return type:
- property mode: kompass.components._modes.ControllerMode#
Get the current control mode
- Returns:
control mode ControllerMode.PATH_FOLLOWER or ControllerMode.VISION_FOLLOWER
- Return type:
ControllerMode
- set_algorithm(algorithm_value: Union[str, kompass_core.control.ControllersID], **_) kompass.utils.ActionReturnType#
Component action - Set controller algorithm action
- Parameters:
algorithm_value (Union[str, ControllersID]) – algorithm value
- Returns:
Success, with the reason when the algorithm could not be set
- Return type:
ActionReturnType
- init_variables()#
Overwrites the init variables method called at Node init
- stop_path_tracking(**_) kompass.utils.ActionReturnType#
Ends tracking of the current path, as if its end was reached, and stops the robot. A new plan resumes tracking
- Returns:
Always succeeds
- Return type:
ActionReturnType
- main_action_callback(goal_handle) Union[kompass_interfaces.action.ControlPath.Result, kompass_interfaces.action.TrackVisionTarget.Result]#
Executes the selected control action
- Parameters:
goal_handle (ControlPath | TrackVisionTarget) – Action request
- Returns:
Action result
- Return type:
Union[ControlPath.Result, TrackVisionTarget.Result]
- reached_point(goal_point: Optional[kompass_core.models.RobotState]) bool#
Checks if the current robot state is close to a given goal point
- Parameters:
goal_point (RobotState | None) – Goal point
tolerance (PathTrackingError) – Tolerance to goal
- Returns:
If the distance to the goal is less than the given tolerance
- Return type:
bool
- custom_on_configure()#
Component custom configuration method to set the core debug level
- property robot: kompass.config.RobotConfig#
Getter of robot config
Every Kompass component reasons about the robot’s body – its size for collision checking, its velocity envelope for control – so a missing robot config is an error rather than something to default around.
- Returns:
Robot configuration
- Return type:
- Raises:
ValueError – If no robot configuration has been set
- property robot_geometry_type: kompass_core.models.RobotGeometry.Type#
Getter of the robot geometry as the type the algorithms take
The description carries the geometry as a plain name, since Sugarcoat does no geometry math. The algorithms take the type the C++ library defines, so convert on the way in.
- Returns:
Robot geometry type
- Return type:
RobotGeometry.Type
- property robot_ctrl_limits: kompass_core.models.RobotCtrlLimits#
Getter of the robot velocity envelope as the type the algorithms take
Counterpart of
robot_geometry_typefor the control limits: the description declares them, the C++ library enforces them, and this is the one place the two are matched up.- Returns:
Robot control limits
- Return type:
RobotCtrlLimits
- property run_type: kompass.config.ComponentRunType#
Component run type: Timed, ActionServer or Event
- Returns:
Timed, ActionServer or Server
- Return type:
str
- property inputs_keys: List[kompass.components.defaults.TopicsKeys]#
Getter of component inputs key names that should be used in the inputs dictionary
- property outputs_keys: List[kompass.components.defaults.TopicsKeys]#
Getter of component outputs key names that should be used in the inputs dictionary
- inputs(**kwargs)#
Set component input streams (topics) : kwargs[topic_keyword]=Topic()
- outputs(**kwargs)#
Set component output streams (topics)
- set_input(**kwargs) bool#
Set value of an input(s) topic
- Returns:
If input(s) successfully updated
- Return type:
bool
- set_output(**kwargs) bool#
Set value of an output(s) topic
- Returns:
If output is successfully updates
- Return type:
bool
- config_from_file(config_file: str)#
Configure component from file
- Parameters:
config_file (str) – Path to file (yaml, json, toml)
- property odom_tf_listener: Optional[ros_sugar.tf.TFListener]#
Gets a transform listener from the robot location frame to the world.
The localization frame is not configured: it is read from the
header.frame_idof the location messages, so this is None until the first one arrives. When the robot is already localized in the world frame the lookup resolves to the identity transform, so “no odometry” needs no special case.- Returns:
TF listener from the location frame to the world frame
- Return type:
Optional[TFListener]
- transform_inputs_to(topic_key: kompass.components.defaults.TopicsKeys, goal_frame: str, static_tf: bool = False) None#
Ask for every input under a key to be delivered in a given frame.
Handles keys bound to several topics (such as multiple proximity sensors), each of which carries its own source frame in its messages.
- Parameters:
topic_key (TopicsKeys) – Key of the component input topic(s)
goal_frame (str) – Frame the data should be expressed in
static_tf (bool) – Whether the sensors are rigidly mounted
- input_tf_listener(topic_key: kompass.components.defaults.TopicsKeys, goal_frame: str, static_tf: bool = False, idx: int = 0) Optional[ros_sugar.tf.TFListener]#
Gets a transform listener from an input’s own frame to a given frame.
The source frame is not configured anywhere: it is read from the
header.frame_idof the data itself. This is the counterpart oftransform_input_to, for algorithms that need the transform (its translation and rotation) rather than transformed data.- Parameters:
topic_key (TopicsKeys) – Key of the component input topic
goal_frame (str) – Frame to transform into, usually one of
config.framesstatic_tf (bool) – Whether the sensor is rigidly mounted
idx (int) – Index of the input, for keys bound to several topics
- Returns:
TF listener, or None until the first message on that input arrives. Data already in the goal frame yields a listener that resolves to the identity transform.
- Return type:
Optional[TFListener]
- resolve_input_tf(topic_key: kompass.components.defaults.TopicsKeys, goal_frame: Optional[str] = None, idx: int = 0) Tuple[bool, Optional[tf2_ros.TransformStamped]]#
Resolve, at call time, the transform taking an input into a given frame.
Unlike the transform cached on a callback (refreshed only on message arrival), this looks the TF up live, so a TF that came up late is still picked up. Pass the returned transform to the callback’s
get_outputto deliver the data in the goal frame.- Parameters:
topic_key (TopicsKeys) – Key of the component input topic
goal_frame (Optional[str]) – Frame to deliver the data in, defaults to the configured world frame
idx (int) – Index of the input, for keys bound to several topics
- Returns:
Whether the input can be delivered in the goal frame, and the transform to ask for it with (None when none is needed)
- Return type:
Tuple[bool, Optional[TransformStamped]]
- wait_input_tf(topic_key: kompass.components.defaults.TopicsKeys, idx: int = 0, timeout: Optional[float] = None, static_tf: bool = True) Optional[ros_sugar.tf.TFListener]#
Block until an input has delivered its first message and the transform from the input’s own frame to the robot base is available. The first message is names the input’s frame.
- Parameters:
topic_key (TopicsKeys) – Key of the component input topic
idx (int) – Index of the input, for keys bound to several topics
static_tf (bool) – Whether the input’s frame is rigidly mounted
- Returns:
The listener holding the transform, or None when the timeout passed
- Return type:
Optional[TFListener]
- wait_sensor_config(topic_key: kompass.components.defaults.TopicsKeys, idx: int = 0, timeout: Optional[float] = None) Optional[kompass_cpp.types.SensorConfig]#
Describe a spatial sensor input (LaserScan or PointCloud2) as the core’s
SensorConfig. Its mount pose from the transform of its own frame to the robot base and, for a point cloud, the encoding of its x/y/z fields read from the first message.- Parameters:
topic_key (TopicsKeys) – Key of the sensor input topic
idx (int) – Index of the input, for keys bound to several topics
timeout (Optional[float]) – Seconds to wait before giving up, None waits indefinitely
- Returns:
The sensor description, or None when the timeout passed or the first message could not be decoded
- Return type:
Optional[SensorConfig]
- in_topic_name(key: Union[str, kompass.components.defaults.TopicsKeys]) Union[str, List[str], None]#
Get the topic(s) name(s) corresponding to an input key name
- Parameters:
key (str) – Input key name
- Returns:
Topic(s) name(s)
- Return type:
Union[str, List[str], None]
- out_topic_name(key: Union[str, kompass.components.defaults.TopicsKeys]) Union[str, List[str], None]#
Get the topic(s) name(s) corresponding to an output key name
- Parameters:
key (str) – Output key name
- Returns:
Topic(s) name(s)
- Return type:
Union[str, List[str], None]
- get_in_topic(key: Union[str, kompass.components.defaults.TopicsKeys]) Union[kompass.components.ros.Topic, List[kompass.components.ros.Topic], None]#
Get the topic(s) corresponding to an input key name
- get_out_topic(key: Union[str, kompass.components.defaults.TopicsKeys]) Union[kompass.components.ros.Topic, List[kompass.components.ros.Topic], None]#
Get the topic(s) corresponding to an output key name
- get_callback(key: Union[str, kompass.components.defaults.TopicsKeys], idx: int = 0) Optional[kompass.callbacks.GenericCallback]#
Get callback with given input key name
- Parameters:
key (str) – Input key name
idx (int, optional) – Index of the input of multiple inputs correspond to the same key, defaults to 0
- Raises:
KeyError – If key is not found in component inputs
- Returns:
Callback object
- Return type:
- get_publisher(key: Union[str, kompass.components.defaults.TopicsKeys], idx: int = 0) ros_sugar.io.Publisher#
Get publisher with given output key name
- Parameters:
key (str) – Output topic key name
idx (int, optional) – Index of the output of multiple inputs correspond to the same key, defaults to 0
- Raises:
KeyError – If key is not found in component outputs
- Returns:
Publisher object
- Return type:
- callbacks_inputs_check(inputs_to_check: Optional[List[str]] = None, inputs_to_exclude: Optional[List[str]] = None) bool#
Check that all node inputs are provided before executing callback