MoveIt Studio Behavior Interface  2.11.0
Library for developing custom behaviors for use in MoveIt Studio
moveit_studio::behaviors Namespace Reference

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  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  LoadFromYaml
 Loads types from a YAML file, and returns them in an output port. 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  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

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 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...
 
template<class T >
void parseROSMessage (const YAML::Node &node, const InterfaceTypeName &interface_type, T &rhs)
 Templated function to parse any ROS message from a YAML Node. More...
 
template<typename T >
fp::Result< T > parseParameter (const YAML::Node &yaml, const std::string &parameter_name)
 Helper function for parsing a parameter from a YAML::Node. More...
 

Function Documentation

◆ 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()

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.

◆ parseParameter()

template<typename T >
fp::Result<T> moveit_studio::behaviors::parseParameter ( const YAML::Node &  yaml,
const std::string &  parameter_name 
)

Helper function for parsing a parameter from a YAML::Node.

Template Parameters
TType of the parameter.
Parameters
yamlParsed YAML file for an objective containing the parameters for every parameterized behavior in the objective.
parameter_nameParameter name within the YAML file.
Returns
Parsed parameter if parsing it succeeded and it has a valid value. Error otherwise.

◆ parseROSMessage()

template<class T >
void moveit_studio::behaviors::parseROSMessage ( const YAML::Node &  node,
const InterfaceTypeName &  interface_type,
T &  rhs 
)

Templated function to parse any ROS message from a YAML Node.

Template Parameters
theROS message type to load.

This uses the dynamic_message_introspection package to parse any given ROS message from a YAML file. Throws an exception if the message can't be parsed, e.g. if the YAML contains fields not corresponding to the given message type. Example of use: geometry_msgs::msg::Pose pose; parseROSMessage(yaml_node, InterfaceTypeName{"geometry_msgs", "Pose"}, pose);

◆ 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.