Skip to main content

SetMujocoState Class

Sets MuJoCo simulation state to specified joint positions. More...

Declaration

class moveit_pro::behaviors::SetMujocoState { ... }

Included Headers

#include <set_mujoco_state.hpp>

Base class

classServiceClientBehaviorBase<ServiceT>

A base class for behaviors which need to send a request to a ROS service client and wait for a result. More...

Public Constructors Index

SetMujocoState (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources)

Constructor for SetMujocoState behavior. More...

SetMujocoState (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources, std::unique_ptr< ClientInterfaceBase< moveit_studio_internal_msgs::srv::SetMujocoJointStates > > client_interface)

Private Member Functions Index

tl::expected< std::string, std::string >getServiceName () override

User-provided function to get the name of the service when initializing the service client. More...

tl::expected< moveit_studio_internal_msgs::srv::SetMujocoJointStates::Request, std::string >createRequest () override

User-provided function to create the service request. More...

tl::expected< bool, std::string >processResponse (const moveit_studio_internal_msgs::srv::SetMujocoJointStates::Response &response) override

Optional user-provided function to process the service response after the service has finished. More...

std::shared_future< tl::expected< bool, std::string > > &getFuture () override

Gets the shared future which is used to monitor the progress of the async process. More...

Private Member Attributes Index

std::shared_future< tl::expected< bool, std::string > >response_future_

Holds the result of calling the service asynchronously. More...

Public Static Functions Index

static BT::PortsListprovidedPorts ()

Defines the input/output ports for this behavior. More...

static BT::KeyValueVectormetadata ()

Provides metadata about the behavior for the behavior tree editor. More...

Description

Sets MuJoCo simulation state to specified joint positions.

This behavior reads a RobotState from an input port and calls the configured service (by default, /mujoco_system/set_joint_states) to apply those positions in the simulation. Note: Does NOT handle controller management - use ListControllers and SwitchController to save/restore controller states if needed.

Data Port NamePort TypeObject Type
service_nameInputstd::string
joint_stateInputmoveit_msgs::msg::RobotState

Definition at line 31 of file set_mujoco_state.hpp.

Public Constructors

SetMujocoState()

moveit_pro::behaviors::SetMujocoState::SetMujocoState (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources)

Constructor for SetMujocoState behavior.

Parameters
name

Name of the behavior node.

config

BehaviorTree node configuration.

shared_resources

Shared resources for the behavior (ROS node, planning scene, etc.).

Declaration at line 40 of file set_mujoco_state.hpp, definition at line 29 of file set_mujoco_state.cpp.

SetMujocoState()

moveit_pro::behaviors::SetMujocoState::SetMujocoState (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources, std::unique_ptr< ClientInterfaceBase< moveit_studio_internal_msgs::srv::SetMujocoJointStates > > client_interface)

Declaration at line 44 of file set_mujoco_state.hpp, definition at line 35 of file set_mujoco_state.cpp.

Private Member Functions

createRequest()

tl::expected< moveit_studio_internal_msgs::srv::SetMujocoJointStates::Request, std::string > moveit_pro::behaviors::SetMujocoState::createRequest ()
virtual

User-provided function to create the service request.

Returns

Returns a service request message. If not successful, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.

Declaration at line 66 of file set_mujoco_state.hpp, definition at line 77 of file set_mujoco_state.cpp.

getFuture()

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::SetMujocoState::getFuture ()
inline virtual

Gets the shared future which is used to monitor the progress of the async process.

Classes derived from AsyncBehaviorBase must implement getFuture() so that it returns a shared_future class member.

This exists to prevent destruction of the derived class while the async process is still in-progress. If the derived class is destroyed, the definitions of the functions used within doWork() will be destroyed too, which will result in the virtual functions in the base class being called instead and cause a fault.

This function will force derived classes to add an instance of this type and return a reference to it. The base class can then use this virtual function to access the shared future in functions like onStart.

By adding this virtual function we're properly demonstrating how this future depends on things from the derived class and the natural flow of object lifetimes will do the hard work for us. The std::shared_future destructor will get the value of the future before the derived class is destructed assuming it's the last reference to the shared state. Doing it this way means neither the base nor derived class should need to implement a destructor which is a nice property to have.

Returns

Returns the shared_future, which should be owned by the child class.

Definition at line 73 of file set_mujoco_state.hpp.

getServiceName()

tl::expected< std::string, std::string > moveit_pro::behaviors::SetMujocoState::getServiceName ()
virtual

User-provided function to get the name of the service when initializing the service client.

Returns

Returns the name of the service. If not successful, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.

Declaration at line 63 of file set_mujoco_state.hpp, definition at line 60 of file set_mujoco_state.cpp.

processResponse()

tl::expected< bool, std::string > moveit_pro::behaviors::SetMujocoState::processResponse (const moveit_studio_internal_msgs::srv::SetMujocoJointStates::Response & response)

Optional user-provided function to process the service response after the service has finished.

If no user-defined implementation is provided, then no additional processing will be performed on succeeding service responses and this function will always return void.

Parameters
response

Service response message to process.

Returns

Returns true or false depending on the user's implementation if the service response could be processed successfully. If the service response could not be processed, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.

Declaration at line 70 of file set_mujoco_state.hpp, definition at line 109 of file set_mujoco_state.cpp.

Private Member Attributes

response_future_

std::shared_future<tl::expected<bool, std::string> > moveit_pro::behaviors::SetMujocoState::response_future_

Holds the result of calling the service asynchronously.

Definition at line 79 of file set_mujoco_state.hpp.

Public Static Functions

metadata()

BT::KeyValueVector moveit_pro::behaviors::SetMujocoState::metadata ()
static

Provides metadata about the behavior for the behavior tree editor.

Returns

Key-value pairs describing subcategory and description.

Declaration at line 59 of file set_mujoco_state.hpp, definition at line 55 of file set_mujoco_state.cpp.

providedPorts()

BT::PortsList moveit_pro::behaviors::SetMujocoState::providedPorts ()
static

Defines the input/output ports for this behavior.

Returns

List of ports with their types and descriptions.

Declaration at line 53 of file set_mujoco_state.hpp, definition at line 44 of file set_mujoco_state.cpp.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.