kompass.components.drive_manager#

Module Contents#

Classes#

DriveManagerConfig

DriveManager component configuration parameters

DriveManager

DriveManager component used for direct communication with the robot.

API#

class kompass.components.drive_manager.DriveManagerConfig#

Bases: kompass.config.ComponentConfig

DriveManager component configuration parameters

Name

Type, Default

Description

closed_loop

bool, True

Publish commands in closed loop by checking the robot velocity from the odometry topic

closed_loop_span

int, 3

Max number of commands to send in a closed loop execution

smooth_commands

bool, False

Filter (smooth) incoming velocity commands to limit the acceleration

cmd_tolerance

float, 0.05

Tolerance value when checking for reaching the command in closed loop

critical_zone_angle

float, 45deg

Angle range for the emergency stop critical zone (deg)

critical_zone_distance

float, 0.05

Distance for the emergency stop critical zone (meters)

slowdown_zone_distance

float, 0.2

Distance for the slowdown zone (meters)

disable_safety_stop

bool, False

Set to True to disable the safety stop functionality

use_without_scan_sensor

bool, False

Set to True to allow running the drive manager with no spatial sensor at all. Range sensors (e.g. front and back ultrasounds) count as safety sensors and do not need this flag

use_gpu

bool, True

Use GPU implementation for the critical zone checking if available, otherwise use CPU implementation

sensor_data_timeout

float, 0.2

Maximum age (seconds) of a safety sensor’s last message before it is considered stale

stale_sensor_policy

str, "stop"

What to do when a safety sensor goes stale: "stop" triggers an emergency stop until data returns, "skip" runs the check on the remaining sensors only

class kompass.components.drive_manager.DriveManager(component_name: str, config_file: Optional[str] = None, config: Optional[kompass.components.drive_manager.DriveManagerConfig] = None, inputs: Optional[Dict[str, kompass.components.ros.Topic]] = None, outputs: Optional[Dict[str, kompass.components.ros.Topic]] = None, **kwargs)#

Bases: kompass.components.component.Component

DriveManager component used for direct communication with the robot.

Inputs:

Key Name

Allowed Types

Number

Default

intermediate_cmd

geometry_msgs.msg.Twist

1

Topic(name="/control", msg_type="Twist")

intermediate_cmd_list

kompass_interfaces.msg.TwistArray

1

Topic(name="/control_list", msg_type="TwistArray")

spatial_sensor

sensor_msgs.msg.LaserScan, sensor_msgs.msg.PointCloud2, sensor_msgs.msg.Range

1 to 10

Topic(name="/scan", msg_type="LaserScan")

robot_location

nav_msgs.msg.Odometry, geometry_msgs.msg.PoseStamped, geometry_msgs.msg.Pose

1

Topic(name="/odom", msg_type="Odometry")

Outputs:

Key Name

Allowed Types

Number

Default

final_command

geometry_msgs.msg.Twist, geometry_msgs.msg.TwistStamped

1

Topic(name="/cmd_vel", msg_type="Twist")

emergency

std_msgs.msg.Bool

1

Topic(name="/emergency_stop", msg_type="Bool")


init_variables()#

Overwrites the init variables method called at Node init

execute_cmd_closed_loop(output: geometry_msgs.msg.Twist, max_time: float)#

Execute a control command in closed loop

Parameters:
  • cmd (Twist) – Velocity Twist message

  • max_time (float) – Maximum time for the closed loop execution (s)

stop_robot(stop_timeout: float = 5.0, **_) → kompass.components.ros.ActionReturnType#

Stops the robot in closed loop: drops queued commands and publishes zero velocity until the robot moves slower than its minimum velocity

Parameters:

stop_timeout (float) – Maximum time to wait for the robot to stop (s)

Returns:

If the robot stopped, with a reason when it did not

Return type:

ActionReturnType

move_forward(max_distance: float, **_) → kompass.components.ros.ActionReturnType#

Moves the robot forward if the forward direction is clear of obstacles

Parameters:

max_distance (float) – Maximum distance (m)

Returns:

If the movement action is performed, with the distance traveled

Return type:

ActionReturnType

move_backward(max_distance: float, **_) → kompass.components.ros.ActionReturnType#

Moves the robot backwards if the backward direction is clear of obstacles

Parameters:

max_distance (float) – Maximum distance (m)

Returns:

If the movement action is performed, with the distance traveled

Return type:

ActionReturnType

rotate_in_place(max_rotation: float, safety_margin: Optional[float] = None, **_) → kompass.components.ros.ActionReturnType#

Rotates the robot in place if the space around it is clear.

Turns the way the angle asks for: a negative max_rotation is a clockwise rotation of that size

Parameters:
  • max_rotation (float) – Angle to turn (rad), signed

  • safety_margin (Optional[float], optional) – Clearance to keep beyond the critical zone while turning (m), None for 5% of the robot’s radius. The checker sees out to the slowdown zone, so a margin wider than the band between the two zones asks for the most it can tell: nothing inside the slowdown zone at all

Returns:

If the movement action is performed, with the angle rotated

Return type:

ActionReturnType

move_to_unblock(max_distance_forward: Optional[float] = None, max_distance_backwards: Optional[float] = None, max_rotation: float = np.pi / 2, rotation_safety_margin: Optional[float] = None, **_) → kompass.components.ros.ActionReturnType#

Moves the robot forward/backward or rotate in place to get out of blocking spots

Parameters:
  • max_distance_forward (Optional[float], optional) – Maximum distance to move forward (meters), if None defaults to 2 * robot_radius

  • max_distance_backwards (Optional[float], optional) – Maximum distance to move backwards (meters), if None defaults to 2 * robot_radius

  • max_rotation (float, optional) – Maximum rotation angle (radians), defaults to np.pi/4

  • rotation_safety_margin (Optional[float], optional) – Safety margin to perform rotation in place (meters), if None defaults to 5% of robot_radius

Returns:

If one of the movement actions is performed, with the one that was

Return type:

ActionReturnType

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:

RobotConfig

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_type for 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_id of 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_id of the data itself. This is the counterpart of transform_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.frames

  • static_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_output to 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

Parameters:

key (str) – Input key name

Returns:

Topic(s)

Return type:

Union[Topic, List[Topic], None]

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

Parameters:

key (str) – Output key name

Returns:

Topic(s)

Return type:

Union[Topic, List[Topic], None]

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:

GenericCallback

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:

Publisher

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