Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the bridge aware of both gz and ignition msgs #349

Merged
merged 3 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ros_gz_bridge/resource/get_mappings.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ get_gz_to_ros_mapping(const std::string & gz_type_name, std::string & ros_type_n
@[end if]@

@[for m in mappings]@
if (gz_type_name == "@(m.gz_string())")
if (gz_type_name == "@(m.gz_string())" || gz_type_name == "@(m.ign_string())")
{
ros_type_name = "@(m.ros2_string())";
return true;
Expand Down Expand Up @@ -68,7 +68,11 @@ get_all_message_mappings_ros_to_gz()
@[for m in mappings]@
{
"@(m.ros2_string())", // ROS 2
"@(m.gz_string())", // Gazebo
"@(m.gz_string())", // Gazebo
},
{
"@(m.ros2_string())", // ROS 2
"@(m.ign_string())", // Gazebo
},
@[end for]@
};
Expand Down
12 changes: 6 additions & 6 deletions ros_gz_bridge/resource/pkg_factories.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ get_factory__@(ros2_package_name)(
{
@[for m in mappings]@
if ((ros_type_name == "@(m.ros2_string())" || ros_type_name.empty()) &&
gz_type_name == "@(m.gz_string())")
(gz_type_name == "@(m.gz_string())" || gz_type_name == "@(m.ign_string())"))
{
return std::make_shared<
Factory<
@(m.ros2_type()),
@(m.gz_type())
@(m.ign_type())
>
>("@(m.ros2_string())", "@(m.gz_string())");
}
Expand All @@ -52,10 +52,10 @@ template<>
void
Factory<
@(m.ros2_type()),
@(m.gz_type())
@(m.ign_type())
>::convert_ros_to_gz(
const @(m.ros2_type()) & ros_msg,
@(m.gz_type()) & gz_msg)
@(m.ign_type()) & gz_msg)
{
ros_gz_bridge::convert_ros_to_gz(ros_msg, gz_msg);
}
Expand All @@ -64,9 +64,9 @@ template<>
void
Factory<
@(m.ros2_type()),
@(m.gz_type())
@(m.ign_type())
>::convert_gz_to_ros(
const @(m.gz_type()) & gz_msg,
const @(m.ign_type()) & gz_msg,
@(m.ros2_type()) & ros_msg)
{
ros_gz_bridge::convert_gz_to_ros(gz_msg, ros_msg);
Expand Down
2 changes: 1 addition & 1 deletion ros_gz_bridge/resource/pkg_factories.hpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace ros_gz_bridge

std::shared_ptr<FactoryInterface>
get_factory__@(ros2_package_name)(
const std::string & ros_type_name,
const std::string & ros_type_name,
const std::string & gz_type_name);

} // namespace ros_gz_bridge
Expand Down
12 changes: 10 additions & 2 deletions ros_gz_bridge/ros_gz_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ def ros2_type(self):
# Return ROS2 type of a message (eg std_msgs::msg::Bool)
return f'{self.ros2_package_name}::msg::{self.ros2_message_name}'

def gz_string(self):
def ign_string(self):
# Return GZ string version of a message (eg ignition.msgs.Bool)
return f'ignition.msgs.{self.gz_message_name}'

def gz_type(self):
def ign_type(self):
# Return GZ type of a message (eg ignition::msgs::Bool)
return f'ignition::msgs::{self.gz_message_name}'

def gz_string(self):
# Return GZ string version of a message (eg ignition.msgs.Bool)
return f'gz.msgs.{self.gz_message_name}'

def gz_type(self):
# Return GZ type of a message (eg ignition::msgs::Bool)
return f'gz::msgs::{self.gz_message_name}'

def unique(self):
return f'{self.gz_message_name.lower()}_{self.ros2_message_name.lower()}'

Expand Down
4 changes: 2 additions & 2 deletions ros_gz_bridge/test/resource/gz_publisher.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ int main(int /*argc*/, char **/*argv*/)
@[for m in mappings]@
// @(m.gz_string()).
auto @(m.unique())_pub =
node.Advertise<@(m.gz_type())>("@(m.unique())");
@(m.gz_type()) @(m.unique())_msg;
node.Advertise<@(m.ign_type())>("@(m.unique())");
@(m.ign_type()) @(m.unique())_msg;
ros_gz_bridge::testing::createTestMsg(@(m.unique())_msg);

@[end for]@
Expand Down
2 changes: 1 addition & 1 deletion ros_gz_bridge/test/resource/gz_subscriber.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private: ignition::transport::Node node;
/////////////////////////////////////////////////
TEST(GzSubscriberTest, @(m.unique()))
{
MyTestClass<@(m.gz_type())> client("@(m.unique())");
MyTestClass<@(m.ign_type())> client("@(m.unique())");

using namespace std::chrono_literals;
ros_gz_bridge::testing::waitUntilBoolVar(
Expand Down