Skip to content

Commit

Permalink
Added convenience methods to create empty action goals with BabelFish.
Browse files Browse the repository at this point in the history
(cherry picked from commit dcf7930)
  • Loading branch information
StefanFabian committed Oct 23, 2024
1 parent 3cbbb71 commit 5d472cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ros_babel_fish/include/ros_babel_fish/babel_fish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class BabelFish : public std::enable_shared_from_this<BabelFish>

/*!
* Creates an empty message of the given type.
* @param type The message type, e.g.: "std_msgs/Header"
* @param type The message type, e.g.: "std_msgs/msg/Header"
* @return An empty message of the given type
*
* @throws BabelFishException If the message description was not found
Expand All @@ -155,7 +155,7 @@ class BabelFish : public std::enable_shared_from_this<BabelFish>

/*!
* Creates a service request message for the given service type.
* @param type The type of the service, e.g., rosapi/GetParam
* @param type The type of the service, e.g., rcl_interfaces/srv/GetParameters
* @return An empty service request message that can be used to call a service of the given type
*
* @throws BabelFishException If the service description was not found
Expand All @@ -165,6 +165,16 @@ class BabelFish : public std::enable_shared_from_this<BabelFish>
//! @copydoc create_service_request
CompoundMessage::SharedPtr create_service_request_shared( const std::string &type ) const;

/*!
* Creates an empty action goal for the given action type.
* @param type The type of the action, e.g., example_interfaces/action/Fibonacci
* @return An empty action goal message that can be used to send a goal to an action server.
*/
CompoundMessage create_action_goal( const std::string &type ) const;

//! @copydoc create_action_goal_request
CompoundMessage::SharedPtr create_action_goal_shared( const std::string &type ) const;

MessageTypeSupport::ConstSharedPtr get_message_type_support( const std::string &type ) const;

ServiceTypeSupport::ConstSharedPtr get_service_type_support( const std::string &type ) const;
Expand Down
19 changes: 19 additions & 0 deletions ros_babel_fish/src/babel_fish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ CompoundMessage::SharedPtr BabelFish::create_service_request_shared( const std::
return CompoundMessage::make_shared( type_support->request() );
}

CompoundMessage BabelFish::create_action_goal( const std::string &type ) const
{
const ActionTypeSupport::ConstSharedPtr &type_support = get_action_type_support( type );
if ( type_support == nullptr ) {
throw BabelFishException( "BabelFish doesn't know an action of type: " + type );
}
MessageMembersIntrospection introspection = type_support->goal_service_type_support->request();
size_t index =
std::find_if( introspection->members_, introspection->members_ + introspection->member_count_,
[]( const auto &a ) { return std::strcmp( a.name_, "goal" ) == 0; } ) -
introspection->members_;
return CompoundMessage( type_support->goal_service_type_support->request().getMember( index ) );
}

CompoundMessage::SharedPtr BabelFish::create_action_goal_shared( const std::string &type ) const
{
return CompoundMessage::make_shared( create_action_goal( type ) );
}

MessageTypeSupport::ConstSharedPtr BabelFish::get_message_type_support( const std::string &type ) const
{
for ( const auto &provider : type_support_providers_ ) {
Expand Down

0 comments on commit 5d472cc

Please sign in to comment.