MoveIt Pro Behavior Interface  5.2.0
Library for developing custom behaviors for use in MoveIt Pro
moveit_studio::behaviors Namespace Reference

Namespaces

 check_for_error_utils
 

Classes

class  ActionClientBehaviorBase
 A base class for behaviors which need to send a goal to a ROS action client and wait for a result. If the behavior is halted before the action result is received, the action goal will be canceled. More...
 
class  AddToVector
 Pushes an object into a vector and sets the updated vector to the blackboard. More...
 
class  AsyncBehaviorBase
 A base class for behaviors which need to asynchronously run a function that might take a long time to complete. More...
 
struct  BehaviorContext
 The BehaviorContext struct contains shared resources that are common between all instances of Behaviors that inherit from moveit_studio::behaviors::SharedResourcesNode. More...
 
class  ClockInterfaceBase
 A base class which provides an interface for retrieving timepoints from a monotonic clock. More...
 
class  SteadyClockInterface
 Implementation of ClockInterfaceBase for std::chrono::steady_clock. More...
 
class  ForEach
 A class template for creating a behavior tree decorator node to help iterate through a vector of items. More...
 
class  GetMessageFromTopicBehaviorBase
 Base class for Behaviors that get the latest message from a topic specified on an input data port and set that message to an output data port. More...
 
class  LoadMultipleFromYaml
 Loads types from a YAML file, and returns them as a vector in an output port. More...
 
class  LoadFromYaml
 Loads a type from a YAML file, and returns it in an output port. More...
 
class  PublisherInterfaceBase
 Defines an interface to a publisher that sends a message to a topic. More...
 
class  RclcppPublisherInterface
 Implementation of the publisher interface for a rclcpp publisher. More...
 
class  ResetVector
 Create an empty vector and set it to the blackboard. More...
 
class  SaveToYaml
 Save the contents of a ROS 2 message type to a YAML file in a specified namespace. Note: This Behavior template saves the pose into the ~/.config/moveit_pro/robot_config/objectives folder. More...
 
class  SendMessageToTopicBehaviorBase
 Base class for Behaviors that send a message to a topic. The message contents and topic name are specified as input ports. More...
 
class  ServiceClientBehaviorBase
 A base class for behaviors which need to send a request to a ROS service client and wait for a result. More...
 
class  ClientInterfaceBase
 Provides an interface to a service client that can send a single request at a time. WARNING - This class currently does not support calling syncSendRequest function asynchronously from multiple threads. More...
 
class  RclcppClientInterface
 Implements ClientInterfaceBase for the rclcpp service client. More...
 
class  SharedResourcesNode
 The SharedResourcesNode class provides a BehaviorContext object when constructing a BehaviorTree.Cpp node. More...
 
class  SharedResourcesNodeLoaderBase
 The SharedResourcesNodeLoaderBase class is a base class for Behavior loader plugins that register Behaviors inheriting from SharedResourcesNode. More...
 

Functions

bool clientMustBeRecreated (const std::shared_ptr< rclcpp_action::ClientBase > &client, const std::string_view old_action_name, const std::string_view new_action_name)
 Compare an action client's current configuration to the desired new configuration to determine if the client needs to be recreated. More...
 
template<typename... Args>
std::optional< std::string > maybe_error (BT::Expected< Args >... args)
 Check if any of the provided inputs represent error states and, if so, return their error messages. More...
 
template<typename E , typename... Args>
constexpr std::optional< E > maybe_error (tl::expected< Args, E >... args)
 Tests if any of the expected args passed in has an error. More...
 
template<typename MessageT >
bool shouldRecreateSubscriber (const std::shared_ptr< rclcpp::Subscription< MessageT >> &subscriber, const std::string &topic_name, const rclcpp::QoS &publisher_qos)
 Compare a subscriber's current configuration to the desired new configuration to determine if the subscriber needs to be recreated. More...
 
tl::expected< rclcpp::TopicEndpointInfo, std::string > waitForPublisher (const std::shared_ptr< rclcpp::Node > &node, const std::string &topic_name)
 Waits for a publisher to be advertised on the provided topic, and gets the TopicEndpointInfo for the publisher once it appears. More...
 
bool shouldRecreatePublisher (const std::shared_ptr< rclcpp::PublisherBase > &publisher, const std::string_view topic_name, const size_t queue_size, const rclcpp::ReliabilityPolicy reliability_policy)
 Compare a publisher's current configuration to the desired new configuration to determine if the publisher needs to be recreated. More...
 
bool clientMustBeRecreated (const std::shared_ptr< rclcpp::ClientBase > &client, const std::string_view new_service_name)
 Compare a service client's current configuration to the desired new configuration to determine if the client needs to be recreated. More...
 
template<typename T >
BT::NodeBuilder getDefaultNodeBuilder ()
 Helper function to create a BT::NodeBuilder for a behavior tree node with the default constructor signature. More...
 
template<typename T >
BT::NodeBuilder getSharedResourcesNodeBuilder (const std::shared_ptr< moveit_studio::behaviors::BehaviorContext > &shared_resources)
 Helper function to create a BT::NodeBuilder for a behavior tree node which takes shared_ptr<BehaviorContext> as an additional constructor parameter. More...
 
template<typename T >
void registerBehavior (BT::BehaviorTreeFactory &factory, const std::string &name)
 Helper function to register a behavior with the default constructor signature with a BT::BehaviorTreeFactory. More...
 
template<typename T >
void registerBehavior (BT::BehaviorTreeFactory &factory, const std::string &name, const std::shared_ptr< moveit_studio::behaviors::BehaviorContext > &shared_resources)
 Helper function to register a behavior derived from SharedResourcesNode with a BT::BehaviorTreeFactory. More...
 

Variables

constexpr auto kDescriptionLoadFromYaml
 
constexpr auto kDescriptionLoadHeaderFromYaml = "<p>Loads a std::msg Header message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadJointTrajectoryFromYaml
 
constexpr auto kDescriptionLoadObjectSubframeFromYaml
 
constexpr auto kDescriptionLoadPoseFromYaml = "<p>Loads a Pose message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadPoseStampedFromYaml = "<p>Loads a PoseStamped message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadPointStampedFromYaml = "<p>Loads a PointStamped message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadQuaternionFromYaml = "<p>Loads a Quaternion message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadVector3FromYaml = "<p>Loads a Vector3 message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadTransformFromYaml = "<p>Loads a Transform message from a YAML file.</p>"
 
constexpr auto kDescriptionLoadTransformStampedFromYaml
 
constexpr auto kDescriptionLoadHeaderVectorFromYaml
 
constexpr auto kDescriptionLoadPoseVectorFromYaml = "<p>Loads a vector of Pose messages from a YAML file.</p>"
 
constexpr auto kDescriptionLoadPoseStampedVectorFromYaml
 
constexpr auto kDescriptionLoadPointStampedVectorFromYaml
 
constexpr auto kDescriptionLoadObjectSubframeVectorFromYaml
 
constexpr auto kDescriptionSaveToYaml
 
constexpr auto kDescriptionSaveHeaderToYaml
 
constexpr auto kDescriptionSaveJointTrajectoryToYaml
 
constexpr auto kDescriptionSavePoseToYaml
 
constexpr auto kDescriptionSavePoseStampedToYaml
 
constexpr auto kDescriptionSavePointStampedToYaml
 
constexpr auto kDescriptionSaveQuaternionToYaml
 
constexpr auto kDescriptionSaveVector3ToYaml
 
constexpr auto kDescriptionSaveTransformToYaml
 
constexpr auto kDescriptionSaveTransformStampedToYaml
 

Function Documentation

◆ clientMustBeRecreated() [1/2]

bool moveit_studio::behaviors::clientMustBeRecreated ( const std::shared_ptr< rclcpp::ClientBase > &  client,
const std::string_view  new_service_name 
)
inline

Compare a service client's current configuration to the desired new configuration to determine if the client needs to be recreated.

This checks two criteria:

  1. Is the client a nullptr? This will be the case the first time this Behavior is ticked in a new Objective, so the client must be created in that case.
  2. If the client already exists, does it communicate on a topic with the same name as the name provided through the input data port? If not, the client needs to be reinitialized to use the new topic.

This does NOT check if the client's QoS settings match the ones used by the server, because ServiceClientBehaviorBase always creates clients using the rmw_qos_profile_services_default QoS profile. Also, it is unlikely that a ROS 2 service server would use customized QoS settings.

Parameters
clientThe service client to check
new_service_nameThe new service name
Returns
True if the client must be recreated to satisfy the new configuration. False if the client's current configuration already satisfies the new configuration.

◆ clientMustBeRecreated() [2/2]

bool moveit_studio::behaviors::clientMustBeRecreated ( const std::shared_ptr< rclcpp_action::ClientBase > &  client,
const std::string_view  old_action_name,
const std::string_view  new_action_name 
)
inline

Compare an action client's current configuration to the desired new configuration to determine if the client needs to be recreated.

This checks two criteria:

  1. Is the client a nullptr? This will be the case the first time this Behavior is ticked in a new Objective, so the client must be created in that case.
  2. If the client already exists, does it communicate with an action with the same name as the name provided through the input data port? If not, the client needs to be reinitialized to use the new action name.

This does NOT check if the client's QoS settings match the ones used by the server, because ActionClientBehaviorBase always creates clients using the default ROS 2 action client QoS profile. It is also very complex to retrieve the QoS settings for an action server (since it's composed of a collection of services and topics). In any case action clients are almost always created with default QoS settings (or at the very least we've never seen one that used non-default settings).

Parameters
clientThe action client to check
new_action_nameThe new action name
Returns
True if the client must be recreated to satisfy the new configuration. False if the client's current configuration already satisfies the new configuration.

◆ getDefaultNodeBuilder()

template<typename T >
BT::NodeBuilder moveit_studio::behaviors::getDefaultNodeBuilder ( )
inline

Helper function to create a BT::NodeBuilder for a behavior tree node with the default constructor signature.

Template Parameters
TCreate a builder for this type of node. Must be derived from BT::TreeNode.
Returns
A BT::NodeBuilder that creates a node of type T.

◆ getSharedResourcesNodeBuilder()

template<typename T >
BT::NodeBuilder moveit_studio::behaviors::getSharedResourcesNodeBuilder ( const std::shared_ptr< moveit_studio::behaviors::BehaviorContext > &  shared_resources)
inline

Helper function to create a BT::NodeBuilder for a behavior tree node which takes shared_ptr<BehaviorContext> as an additional constructor parameter.

Parameters
shared_resourcesA shared_ptr to an instance of BehaviorContext, which will be provided when creating the behaviors registered by this function.
Template Parameters
TCreate a builder for this type of node. Must be derived from moveit_studio::behaviors::SharedResourcesNode.
Returns
A BT::NodeBuilder that creates a node of type T.

◆ maybe_error() [1/2]

template<typename... Args>
std::optional<std::string> moveit_studio::behaviors::maybe_error ( BT::Expected< Args >...  args)
inline

Check if any of the provided inputs represent error states and, if so, return their error messages.

This was inspired by fp's maybe_error function: https://github.com/tylerjw/fp/blob/b4bf17c2f7a99c07b6ab9b8706357572e960d638/include/fp/result.hpp#L216-L236

Parameters
argsOne or more BT::Expecteds (i.e., results from getInput)
Returns
std::optional wrapping std::string. If all of the inputs in args have values, returns std::nullopt. If one or more of the inputs in args contains an error state instead of a value, return a string that contains the concatenated error messages of all inputs that did not contain a value.

◆ maybe_error() [2/2]

template<typename E , typename... Args>
constexpr std::optional<E> moveit_studio::behaviors::maybe_error ( tl::expected< Args, E >...  args)
constexpr

Tests if any of the expected args passed in has an error.

This was adapted from fp's maybe_error function with a small modification.

Parameters
[in]Thetl::expected<T, E> variables. All have to use the same error type.
Template Parameters
EThe error type
ArgsThe value types for the tl::expected<T, E> args
Returns
The first error found or nothing

◆ registerBehavior() [1/2]

template<typename T >
void moveit_studio::behaviors::registerBehavior ( BT::BehaviorTreeFactory &  factory,
const std::string &  name 
)
inline

Helper function to register a behavior with the default constructor signature with a BT::BehaviorTreeFactory.

Parameters
factoryRegister behaviors with this factory.
nameThe name to use when registering this type of behavior. It is good practice to make this name match the name of the class (e.g., moveit_studio::behaviors::PlanMTCTask is registered as "PlanMTCTask").
Template Parameters
TRegister a behavior of this type.

◆ registerBehavior() [2/2]

template<typename T >
void moveit_studio::behaviors::registerBehavior ( BT::BehaviorTreeFactory &  factory,
const std::string &  name,
const std::shared_ptr< moveit_studio::behaviors::BehaviorContext > &  shared_resources 
)
inline

Helper function to register a behavior derived from SharedResourcesNode with a BT::BehaviorTreeFactory.

Parameters
factoryRegister behaviors with this factory.
nameThe name to use when registering this type of behavior. It is good practice to make this name match the name of the class (e.g., moveit_studio::behaviors::PlanMTCTask is registered as "PlanMTCTask").
shared_resourcesA shared_ptr to an instance of BehaviorContext, which will be provided when creating the behaviors registered by this function.
Template Parameters
TRegister a behavior of this type.

◆ shouldRecreatePublisher()

bool moveit_studio::behaviors::shouldRecreatePublisher ( const std::shared_ptr< rclcpp::PublisherBase > &  publisher,
const std::string_view  topic_name,
const size_t  queue_size,
const rclcpp::ReliabilityPolicy  reliability_policy 
)
inline

Compare a publisher's current configuration to the desired new configuration to determine if the publisher needs to be recreated.

This checks two criteria:

  1. Is the publisher a nullptr? This will be the case the first time this Behavior is ticked in a new Objective, so the publisher must be created in that case.
  2. If the publisher already exists, does it publish to the right topic? If not, the publisher needs to be reinitialized to use the new topic name.
  3. If the publisher already exists, does its queue_size and reliability QoS settings match the new queue_size and reliability? If not, the publisher needs to be reinitialized with these new QoS settings.
Parameters
publisherThe existing publisher to check.
topic_nameThe topic name for the new configuration.
queue_sizeThe queue size for the new configuration.
reliability_policyThe reliability policy for the new configuration
Returns
True if the publisher must be recreated, and false if the publisher's current configuration already satisfies the new configuration.

◆ shouldRecreateSubscriber()

template<typename MessageT >
bool moveit_studio::behaviors::shouldRecreateSubscriber ( const std::shared_ptr< rclcpp::Subscription< MessageT >> &  subscriber,
const std::string &  topic_name,
const rclcpp::QoS &  publisher_qos 
)

Compare a subscriber's current configuration to the desired new configuration to determine if the subscriber needs to be recreated.

This checks three criteria:

  1. Is the subscriber a nullptr? This will be the case the first time this Behavior is ticked in a new Objective, so the subscriber must be created in that case.
  2. If the subscriber already exists, does it listen on the right topic? If not, the client needs to be reinitialized to use the new action name.
  3. If the subscriber already exists, does it use the same reliability QoS setting as the publisher? If not, the subscriber needs to be reinitialized using the same reliability QoS setting as the publisher.
Parameters
subscriberThe existing subscriber to check.
topic_nameThe topic name for the new configuration.
publisher_qosThe publisher's QoS for the new configuration.
Template Parameters
MessageTThe ROS message type used to specialize this function.
Returns
True if the subscriber must be recreated, and false if the subscriber's current configuration already satisfies the new configuration.

◆ waitForPublisher()

tl::expected< rclcpp::TopicEndpointInfo, std::string > moveit_studio::behaviors::waitForPublisher ( const std::shared_ptr< rclcpp::Node > &  node,
const std::string &  topic_name 
)

Waits for a publisher to be advertised on the provided topic, and gets the TopicEndpointInfo for the publisher once it appears.

If multiple publishers are found on the same topic, this function just returns the TopicEndpointInfo for the first one in the order they were reported by the node. If multiple publishers advertise on the same topic with different reliability QoS settings the Behavior will only receive messages from the ones whose settings match the first publisher in the list. This situation will only happen if the publishers have been incorrectly configured, so this is not handled by this Behavior.

Parameters
nodeNode used to retrieve publisher info.
topic_nameName of the topic where we expect the publisher to advertise.
Returns
If one or more publishers were found on the topic, returns the TopicEndpointInfo for the first publisher that was found. If no publishers were found on the topic before the timeout elapsed, return an error result.

Variable Documentation

◆ kDescriptionLoadFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a vector of objects from a file, converts it and their names in the file to a vector of messages, and "
"writes that to an output data port.</p>"

◆ kDescriptionLoadHeaderFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadHeaderFromYaml = "<p>Loads a std::msg Header message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadHeaderVectorFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadHeaderVectorFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a vector of std::msg Header messages from a YAML file.</p>"

◆ kDescriptionLoadJointTrajectoryFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadJointTrajectoryFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a joint trajectory message from a YAML file name and outputs a JointTrajectory ROS message object "
"created from the file contents.</p>"

◆ kDescriptionLoadObjectSubframeFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadObjectSubframeFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a moveit_studio_vision_msgs::msg ObjectSubframe message from a YAML file.</p>"

◆ kDescriptionLoadObjectSubframeVectorFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadObjectSubframeVectorFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a vector of Subframes from a file, converts it and their names in the file to a vector of ROS "
"moveit_studio_vision_msgs::msg::ObjectSubframe messages, and writes that to an output data port.</p>"

◆ kDescriptionLoadPointStampedFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadPointStampedFromYaml = "<p>Loads a PointStamped message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadPointStampedVectorFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadPointStampedVectorFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a vector of PointStamped messages from a YAML file.</p>"

◆ kDescriptionLoadPoseFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadPoseFromYaml = "<p>Loads a Pose message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadPoseStampedFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadPoseStampedFromYaml = "<p>Loads a PoseStamped message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadPoseStampedVectorFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadPoseStampedVectorFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a vector of PoseStamped messages from a YAML file.</p>"

◆ kDescriptionLoadPoseVectorFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadPoseVectorFromYaml = "<p>Loads a vector of Pose messages from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadQuaternionFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadQuaternionFromYaml = "<p>Loads a Quaternion message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadTransformFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadTransformFromYaml = "<p>Loads a Transform message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionLoadTransformStampedFromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadTransformStampedFromYaml
inlineconstexpr
Initial value:
=
"<p>Loads a TransformStamped message from a YAML file.</p>"

◆ kDescriptionLoadVector3FromYaml

constexpr auto moveit_studio::behaviors::kDescriptionLoadVector3FromYaml = "<p>Loads a Vector3 message from a YAML file.</p>"
inlineconstexpr

◆ kDescriptionSaveHeaderToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveHeaderToYaml
inlineconstexpr
Initial value:
=
"<p>Write a Header message given as a `std_msgs::msg::Header` message to a YAML file.</p>"

◆ kDescriptionSaveJointTrajectoryToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveJointTrajectoryToYaml
inlineconstexpr
Initial value:
=
"<p>Accepts a JointTrajectory ROS message object, a namespace, and a file name. Converts and saves the joint "
"trajectory message as a YAML file in the objectives directory at the provided file name and under the provided "
"namespace within the file.</p>"

◆ kDescriptionSavePointStampedToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSavePointStampedToYaml
inlineconstexpr
Initial value:
=
"<p>Write a point stamped given as a `geometry_msgs::msg::PoseStamped` message to a YAML file.</p>"

◆ kDescriptionSavePoseStampedToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSavePoseStampedToYaml
inlineconstexpr
Initial value:
=
"<p>Write a pose given as a `geometry_msgs::msg::PoseStamped` message to a YAML file.</p>"

◆ kDescriptionSavePoseToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSavePoseToYaml
inlineconstexpr
Initial value:
=
"<p>Write a pose given as a `geometry_msgs::msg::Pose` message to a YAML file.</p>"

◆ kDescriptionSaveQuaternionToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveQuaternionToYaml
inlineconstexpr
Initial value:
=
"<p>Write a Quaternion given as a `geometry_msgs::msg::Quaternion` message to a YAML file.</p>"

◆ kDescriptionSaveToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveToYaml
inlineconstexpr
Initial value:
=
"<p>Accepts a ROS message object, a namespace, and a file name. Converts and saves the message as a YAML file in "
"the Objectives directory at the provided file name and under the provided namespace within the file.</p>"

◆ kDescriptionSaveTransformStampedToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveTransformStampedToYaml
inlineconstexpr
Initial value:
=
"<p>Write a Transform given as a `geometry_msgs::msg::TransformStamped` message to a YAML file.</p>"

◆ kDescriptionSaveTransformToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveTransformToYaml
inlineconstexpr
Initial value:
=
"<p>Write a Transform given as a `geometry_msgs::msg::Transform` message to a YAML file.</p>"

◆ kDescriptionSaveVector3ToYaml

constexpr auto moveit_studio::behaviors::kDescriptionSaveVector3ToYaml
inlineconstexpr
Initial value:
=
"<p>Write a Vector3 given as a `geometry_msgs::msg::Vector3` message to a YAML file.</p>"