Skip to content

Commit 6609f88

Browse files
mergify[bot]andreas-loefflerahcorde
authored
Added WorldStatistics message support for the ros_gz_bridge (backport #841) (#847)
Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com> Co-authored-by: Andreas Loeffler <73336148+andreas-loeffler@users.noreply.github.com> Co-authored-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
1 parent 7e90ae1 commit 6609f88

File tree

12 files changed

+334
-0
lines changed

12 files changed

+334
-0
lines changed

ros_gz_bridge/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ The following message types can be bridged for topics:
4646
| ros_gz_interfaces/msg/GuiCamera | ignition::msgs::GUICamera |
4747
| ros_gz_interfaces/msg/JointWrench | ignition::msgs::JointWrench |
4848
| ros_gz_interfaces/msg/Light | ignition::msgs::Light |
49+
| ros_gz_interfaces/msg/LogPlaybackStatistics | ignition.msgs.LogPlaybackStatistics |
4950
| ros_gz_interfaces/msg/SensorNoise | ignition::msgs::SensorNoise |
5051
| ros_gz_interfaces/msg/StringVec | ignition::msgs::StringMsg_V |
5152
| ros_gz_interfaces/msg/TrackVisual | ignition::msgs::TrackVisual |
5253
| ros_gz_interfaces/msg/VideoRecord | ignition::msgs::VideoRecord |
5354
| ros_gz_interfaces/msg/WorldControl | ignition::msgs::WorldControl |
55+
| ros_gz_interfaces/msg/WorldStatistics | ignition.msgs.WorldStatistics |
5456
| rosgraph_msgs/msg/Clock | ignition::msgs::Clock |
5557
| sensor_msgs/msg/BatteryState | ignition::msgs::BatteryState |
5658
| sensor_msgs/msg/CameraInfo | ignition::msgs::CameraInfo |

ros_gz_bridge/include/ros_gz_bridge/convert/ros_gz_interfaces.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
#include <gz/msgs/float_v.pb.h>
2727
#include <gz/msgs/gui_camera.pb.h>
2828
#include <gz/msgs/light.pb.h>
29+
#include <gz/msgs/log_playback_stats.pb.h>
2930
#include <gz/msgs/param.pb.h>
3031
#include <gz/msgs/param_v.pb.h>
3132
#include <gz/msgs/sensor_noise.pb.h>
3233
#include <gz/msgs/stringmsg_v.pb.h>
3334
#include <gz/msgs/track_visual.pb.h>
3435
#include <gz/msgs/video_record.pb.h>
3536
#include <gz/msgs/world_control.pb.h>
37+
#include <gz/msgs/world_stats.pb.h>
3638

3739
// ROS 2 messages
3840
#include <ros_gz_interfaces/msg/altimeter.hpp>
@@ -45,12 +47,14 @@
4547
#include <ros_gz_interfaces/msg/float32_array.hpp>
4648
#include <ros_gz_interfaces/msg/gui_camera.hpp>
4749
#include <ros_gz_interfaces/msg/light.hpp>
50+
#include <ros_gz_interfaces/msg/log_playback_statistics.hpp>
4851
#include <ros_gz_interfaces/msg/param_vec.hpp>
4952
#include <ros_gz_interfaces/msg/sensor_noise.hpp>
5053
#include <ros_gz_interfaces/msg/string_vec.hpp>
5154
#include <ros_gz_interfaces/msg/track_visual.hpp>
5255
#include <ros_gz_interfaces/msg/video_record.hpp>
5356
#include <ros_gz_interfaces/msg/world_control.hpp>
57+
#include <ros_gz_interfaces/msg/world_statistics.hpp>
5458

5559
// Required for HAVE_DATAFRAME definition
5660
#include <ros_gz_bridge/ros_gz_bridge.hpp>
@@ -309,6 +313,18 @@ convert_gz_to_ros(
309313
const gz::msgs::WorldReset & gz_msg,
310314
ros_gz_interfaces::msg::WorldReset & ros_msg);
311315

316+
template<>
317+
void
318+
convert_gz_to_ros(
319+
const gz::msgs::WorldStatistics & gz_msg,
320+
ros_gz_interfaces::msg::WorldStatistics & ros_msg);
321+
322+
template<>
323+
void
324+
convert_ros_to_gz(
325+
const ros_gz_interfaces::msg::WorldStatistics & ros_msg,
326+
gz::msgs::WorldStatistics & gz_msg);
327+
312328
template<>
313329
void
314330
convert_ros_to_gz(
@@ -320,6 +336,19 @@ void
320336
convert_gz_to_ros(
321337
const gz::msgs::Float_V & gz_msg,
322338
ros_gz_interfaces::msg::Float32Array & ros_msg);
339+
340+
template<>
341+
void
342+
convert_ros_to_gz(
343+
const ros_gz_interfaces::msg::LogPlaybackStatistics & ros_msg,
344+
gz::msgs::LogPlaybackStatistics & gz_msg);
345+
346+
template<>
347+
void
348+
convert_gz_to_ros(
349+
const gz::msgs::LogPlaybackStatistics & gz_msg,
350+
ros_gz_interfaces::msg::LogPlaybackStatistics & ros_msg);
351+
323352
} // namespace ros_gz_bridge
324353

325354
#endif // ROS_GZ_BRIDGE__CONVERT__ROS_GZ_INTERFACES_HPP_

ros_gz_bridge/ros_gz_bridge/mappings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@
6868
Mapping('GuiCamera', 'GUICamera'),
6969
Mapping('JointWrench', 'JointWrench'),
7070
Mapping('Light', 'Light'),
71+
Mapping('LogPlaybackStatistics', 'LogPlaybackStatistics'),
7172
Mapping('ParamVec', 'Param'),
7273
Mapping('ParamVec', 'Param_V'),
7374
Mapping('SensorNoise', 'SensorNoise'),
7475
Mapping('StringVec', 'StringMsg_V'),
7576
Mapping('TrackVisual', 'TrackVisual'),
7677
Mapping('VideoRecord', 'VideoRecord'),
78+
Mapping('WorldStatistics', 'WorldStatistics'),
7779
],
7880
'rosgraph_msgs': [
7981
Mapping('Clock', 'Clock'),

ros_gz_bridge/src/convert/ros_gz_interfaces.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,43 @@ convert_gz_to_ros(
796796
ros_msg.model_only = gz_msg.model_only();
797797
}
798798

799+
template<>
800+
void
801+
convert_ros_to_gz(
802+
const ros_gz_interfaces::msg::WorldStatistics & ros_msg,
803+
gz::msgs::WorldStatistics & gz_msg)
804+
{
805+
convert_ros_to_gz(ros_msg.header, *gz_msg.mutable_header());
806+
convert_ros_to_gz(ros_msg.sim_time, *gz_msg.mutable_sim_time());
807+
convert_ros_to_gz(ros_msg.pause_time, *gz_msg.mutable_pause_time());
808+
convert_ros_to_gz(ros_msg.real_time, *gz_msg.mutable_real_time());
809+
gz_msg.set_paused(ros_msg.paused);
810+
gz_msg.set_iterations(ros_msg.iterations);
811+
gz_msg.set_model_count(ros_msg.model_count);
812+
convert_ros_to_gz(ros_msg.log_playback_statistics, *gz_msg.mutable_log_playback_stats());
813+
gz_msg.set_real_time_factor(ros_msg.real_time_factor);
814+
convert_ros_to_gz(ros_msg.step_size, *gz_msg.mutable_step_size());
815+
}
816+
817+
template<>
818+
void
819+
convert_gz_to_ros(
820+
const gz::msgs::WorldStatistics & gz_msg,
821+
ros_gz_interfaces::msg::WorldStatistics & ros_msg)
822+
{
823+
convert_gz_to_ros(gz_msg.header(), ros_msg.header);
824+
convert_gz_to_ros(gz_msg.sim_time(), ros_msg.sim_time);
825+
convert_gz_to_ros(gz_msg.pause_time(), ros_msg.pause_time);
826+
convert_gz_to_ros(gz_msg.real_time(), ros_msg.real_time);
827+
ros_msg.paused = gz_msg.paused();
828+
ros_msg.iterations = gz_msg.iterations();
829+
ros_msg.model_count = gz_msg.model_count();
830+
convert_gz_to_ros(gz_msg.log_playback_stats(), ros_msg.log_playback_statistics);
831+
ros_msg.real_time_factor = gz_msg.real_time_factor();
832+
convert_gz_to_ros(gz_msg.step_size(), ros_msg.step_size);
833+
}
834+
835+
799836
template<>
800837
void
801838
convert_ros_to_gz(
@@ -819,4 +856,27 @@ convert_gz_to_ros(
819856
ros_msg.data.push_back(p);
820857
}
821858
}
859+
860+
template<>
861+
void
862+
convert_ros_to_gz(
863+
const ros_gz_interfaces::msg::LogPlaybackStatistics & ros_msg,
864+
gz::msgs::LogPlaybackStatistics & gz_msg)
865+
{
866+
convert_ros_to_gz(ros_msg.header, *gz_msg.mutable_header());
867+
convert_ros_to_gz(ros_msg.start_time, *gz_msg.mutable_start_time());
868+
convert_ros_to_gz(ros_msg.end_time, *gz_msg.mutable_end_time());
869+
}
870+
871+
template<>
872+
void
873+
convert_gz_to_ros(
874+
const gz::msgs::LogPlaybackStatistics & gz_msg,
875+
ros_gz_interfaces::msg::LogPlaybackStatistics & ros_msg)
876+
{
877+
convert_gz_to_ros(gz_msg.header(), ros_msg.header);
878+
convert_gz_to_ros(gz_msg.start_time(), ros_msg.start_time);
879+
convert_gz_to_ros(gz_msg.end_time(), ros_msg.end_time);
880+
}
881+
822882
} // namespace ros_gz_bridge

ros_gz_bridge/test/utils/gz_test_msg.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,5 +1746,82 @@ void compareTestMsg(const std::shared_ptr<gz::msgs::AnnotatedOriented3DBox_V> &
17461746
}
17471747
}
17481748

1749+
void createTestMsg(gz::msgs::LogPlaybackStatistics & _msg)
1750+
{
1751+
createTestMsg(*_msg.mutable_header());
1752+
1753+
gz::msgs::Time start_time;
1754+
createTestMsg(start_time);
1755+
_msg.mutable_start_time()->CopyFrom(start_time);
1756+
1757+
gz::msgs::Time end_time;
1758+
createTestMsg(end_time);
1759+
_msg.mutable_end_time()->CopyFrom(end_time);
1760+
}
1761+
1762+
void compareTestMsg(const std::shared_ptr<gz::msgs::LogPlaybackStatistics> & _msg)
1763+
{
1764+
gz::msgs::LogPlaybackStatistics expected_msg;
1765+
createTestMsg(expected_msg);
1766+
1767+
compareTestMsg(std::make_shared<gz::msgs::Header>(_msg->header()));
1768+
compareTestMsg(std::make_shared<gz::msgs::Time>(_msg->start_time()));
1769+
compareTestMsg(std::make_shared<gz::msgs::Time>(_msg->end_time()));
1770+
}
1771+
1772+
void createTestMsg(gz::msgs::WorldStatistics & _msg)
1773+
{
1774+
createTestMsg(*_msg.mutable_header());
1775+
1776+
gz::msgs::Time sim_time;
1777+
createTestMsg(sim_time);
1778+
_msg.mutable_sim_time()->CopyFrom(sim_time);
1779+
1780+
gz::msgs::Time pause_time;
1781+
createTestMsg(pause_time);
1782+
_msg.mutable_pause_time()->CopyFrom(pause_time);
1783+
1784+
gz::msgs::Time real_time;
1785+
createTestMsg(real_time);
1786+
_msg.mutable_real_time()->CopyFrom(real_time);
1787+
1788+
_msg.set_paused(false);
1789+
_msg.set_iterations(123);
1790+
_msg.set_model_count(10);
1791+
1792+
gz::msgs::LogPlaybackStatistics log_playback_stats_msg;
1793+
createTestMsg(log_playback_stats_msg);
1794+
_msg.mutable_log_playback_stats()->CopyFrom(log_playback_stats_msg);
1795+
1796+
_msg.set_real_time_factor(0.75);
1797+
1798+
gz::msgs::Time step_size;
1799+
createTestMsg(step_size);
1800+
_msg.mutable_step_size()->CopyFrom(step_size);
1801+
}
1802+
1803+
void compareTestMsg(const std::shared_ptr<gz::msgs::WorldStatistics> & _msg)
1804+
{
1805+
gz::msgs::WorldStatistics expected_msg;
1806+
createTestMsg(expected_msg);
1807+
1808+
compareTestMsg(std::make_shared<gz::msgs::Header>(_msg->header()));
1809+
compareTestMsg(std::make_shared<gz::msgs::Time>(_msg->sim_time()));
1810+
compareTestMsg(std::make_shared<gz::msgs::Time>(_msg->pause_time()));
1811+
compareTestMsg(std::make_shared<gz::msgs::Time>(_msg->real_time()));
1812+
1813+
EXPECT_EQ(expected_msg.paused(), _msg->paused());
1814+
EXPECT_EQ(expected_msg.iterations(), _msg->iterations());
1815+
EXPECT_EQ(expected_msg.model_count(), _msg->model_count());
1816+
1817+
compareTestMsg(
1818+
std::make_shared<gz::msgs::LogPlaybackStatistics>(_msg->log_playback_stats()));
1819+
1820+
EXPECT_FLOAT_EQ(expected_msg.real_time_factor(), _msg->real_time_factor());
1821+
1822+
compareTestMsg(
1823+
std::make_shared<gz::msgs::Time>(_msg->step_size()));
1824+
}
1825+
17491826
} // namespace testing
17501827
} // namespace ros_gz_bridge

ros_gz_bridge/test/utils/gz_test_msg.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <gz/msgs/joy.pb.h>
4545
#include <gz/msgs/laserscan.pb.h>
4646
#include <gz/msgs/light.pb.h>
47+
#include <gz/msgs/log_playback_stats.pb.h>
4748
#include <gz/msgs/magnetometer.pb.h>
4849
#include <gz/msgs/model.pb.h>
4950
#include <gz/msgs/navsat.pb.h>
@@ -68,6 +69,7 @@
6869
#include <gz/msgs/wrench.pb.h>
6970
#include <gz/msgs/annotated_axis_aligned_2d_box_v.pb.h>
7071
#include <gz/msgs/annotated_oriented_3d_box_v.pb.h>
72+
#include <gz/msgs/world_stats.pb.h>
7173

7274
#include <memory>
7375

@@ -560,6 +562,22 @@ void createTestMsg(gz::msgs::AnnotatedOriented3DBox_V & _msg);
560562
/// \param[in] _msg The message to compare.
561563
void compareTestMsg(const std::shared_ptr<gz::msgs::AnnotatedOriented3DBox_V> & _msg);
562564

565+
/// \brief Create a message used for testing.
566+
/// \param[out] _msg The message populated.
567+
void createTestMsg(gz::msgs::LogPlaybackStatistics & _msg);
568+
569+
/// \brief Compare a message with the populated for testing.
570+
/// \param[in] _msg The message to compare.
571+
void compareTestMsg(const std::shared_ptr<gz::msgs::LogPlaybackStatistics> & _msg);
572+
573+
/// \brief Create a message used for testing.
574+
/// \param[out] _msg The message populated.
575+
void createTestMsg(gz::msgs::WorldStatistics & _msg);
576+
577+
/// \brief Compare a message with the populated for testing.
578+
/// \param[in] _msg The message to compare.
579+
void compareTestMsg(const std::shared_ptr<gz::msgs::WorldStatistics> & _msg);
580+
563581
} // namespace testing
564582
} // namespace ros_gz_bridge
565583

ros_gz_bridge/test/utils/ros_test_msg.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,5 +1636,91 @@ void compareTestMsg(const std::shared_ptr<vision_msgs::msg::Detection3DArray> &
16361636
}
16371637
}
16381638

1639+
void createTestMsg(ros_gz_interfaces::msg::LogPlaybackStatistics & _msg)
1640+
{
1641+
std_msgs::msg::Header header_msg;
1642+
createTestMsg(header_msg);
1643+
_msg.header = header_msg;
1644+
1645+
builtin_interfaces::msg::Time start_time;
1646+
createTestMsg(start_time);
1647+
_msg.start_time = start_time;
1648+
1649+
builtin_interfaces::msg::Time end_time;
1650+
createTestMsg(end_time);
1651+
_msg.end_time = end_time;
1652+
}
1653+
1654+
void compareTestMsg(const std::shared_ptr<ros_gz_interfaces::msg::LogPlaybackStatistics> & _msg)
1655+
{
1656+
ros_gz_interfaces::msg::LogPlaybackStatistics expected_msg;
1657+
createTestMsg(expected_msg);
1658+
1659+
compareTestMsg(std::make_shared<std_msgs::msg::Header>(_msg->header));
1660+
compareTestMsg(std::make_shared<builtin_interfaces::msg::Time>(_msg->start_time));
1661+
compareTestMsg(std::make_shared<builtin_interfaces::msg::Time>(_msg->end_time));
1662+
}
1663+
1664+
void createTestMsg(ros_gz_interfaces::msg::WorldStatistics & _msg)
1665+
{
1666+
std_msgs::msg::Header header_msg;
1667+
createTestMsg(header_msg);
1668+
_msg.header = header_msg;
1669+
1670+
builtin_interfaces::msg::Time sim_time;
1671+
createTestMsg(sim_time);
1672+
_msg.sim_time = sim_time;
1673+
1674+
builtin_interfaces::msg::Time pause_time;
1675+
createTestMsg(pause_time);
1676+
_msg.pause_time = pause_time;
1677+
1678+
builtin_interfaces::msg::Time real_time;
1679+
createTestMsg(real_time);
1680+
_msg.real_time = real_time;
1681+
1682+
_msg.paused = false;
1683+
1684+
_msg.iterations = 123;
1685+
1686+
_msg.model_count = 10;
1687+
1688+
ros_gz_interfaces::msg::LogPlaybackStatistics log_playback_statistics;
1689+
createTestMsg(log_playback_statistics);
1690+
_msg.log_playback_statistics = log_playback_statistics;
1691+
1692+
_msg.real_time_factor = 0.75;
1693+
1694+
builtin_interfaces::msg::Time step_size;
1695+
createTestMsg(step_size);
1696+
_msg.step_size = step_size;
1697+
}
1698+
1699+
void compareTestMsg(const std::shared_ptr<ros_gz_interfaces::msg::WorldStatistics> & _msg)
1700+
{
1701+
ros_gz_interfaces::msg::WorldStatistics expected_msg;
1702+
createTestMsg(expected_msg);
1703+
1704+
compareTestMsg(std::make_shared<std_msgs::msg::Header>(_msg->header));
1705+
1706+
compareTestMsg(std::make_shared<builtin_interfaces::msg::Time>(_msg->sim_time));
1707+
compareTestMsg(std::make_shared<builtin_interfaces::msg::Time>(_msg->pause_time));
1708+
compareTestMsg(std::make_shared<builtin_interfaces::msg::Time>(_msg->real_time));
1709+
1710+
EXPECT_EQ(expected_msg.paused, _msg->paused);
1711+
1712+
EXPECT_EQ(expected_msg.iterations, _msg->iterations);
1713+
1714+
EXPECT_EQ(expected_msg.model_count, _msg->model_count);
1715+
1716+
compareTestMsg(
1717+
std::make_shared<ros_gz_interfaces::msg::LogPlaybackStatistics>(
1718+
_msg->log_playback_statistics));
1719+
1720+
EXPECT_FLOAT_EQ(expected_msg.real_time_factor, _msg->real_time_factor);
1721+
1722+
compareTestMsg(std::make_shared<builtin_interfaces::msg::Time>(_msg->step_size));
1723+
}
1724+
16391725
} // namespace testing
16401726
} // namespace ros_gz_bridge

0 commit comments

Comments
 (0)