@@ -100,6 +100,79 @@ TEST_F(GazeboRosP3dTest, Publishing)
100
100
EXPECT_NEAR (0.0 , latest_msg->twist .twist .angular .z , tol);
101
101
}
102
102
103
+ TEST_F (GazeboRosP3dTest, DeprecatedOffsetElements)
104
+ {
105
+ // Load test world and start paused
106
+ this ->Load (" worlds/gazebo_ros_p3d.world" , true );
107
+
108
+ // World
109
+ auto world = gazebo::physics::get_world ();
110
+ ASSERT_NE (nullptr , world);
111
+
112
+ // Model
113
+ auto model = world->ModelByName (" the_model" );
114
+ ASSERT_NE (nullptr , model);
115
+
116
+ // Link
117
+ auto link = model->GetLink (" box_link" );
118
+ ASSERT_NE (nullptr , link );
119
+
120
+ // Reference link
121
+ auto ref_link = model->GetLink (" sphere_link" );
122
+ ASSERT_NE (nullptr , ref_link);
123
+
124
+ // Step a bit for model to settle
125
+ world->Step (100 );
126
+
127
+ // Create node and executor
128
+ auto node = std::make_shared<rclcpp::Node>(" gazebo_ros_p3d_test" );
129
+ ASSERT_NE (nullptr , node);
130
+
131
+ rclcpp::executors::SingleThreadedExecutor executor;
132
+ executor.add_node (node);
133
+
134
+ // Create subscriber
135
+ nav_msgs::msg::Odometry::SharedPtr latest_msg{nullptr };
136
+ auto sub = node->create_subscription <nav_msgs::msg::Odometry>(
137
+ " test_deprecated/p3d_test_deprecated" , rclcpp::SensorDataQoS (),
138
+ [&latest_msg](const nav_msgs::msg::Odometry::SharedPtr _msg) {
139
+ latest_msg = _msg;
140
+ });
141
+
142
+ // Wait for a message
143
+ world->Step (1000 );
144
+ unsigned int max_sleep{30u };
145
+ for (auto sleep = 0u ; !latest_msg && sleep < max_sleep; ++sleep ) {
146
+ executor.spin_once (100ms);
147
+ gazebo::common::Time::MSleep (100 );
148
+ }
149
+
150
+ // Check message
151
+ ASSERT_NE (nullptr , latest_msg);
152
+ EXPECT_EQ (" sphere_link" , latest_msg->header .frame_id );
153
+ EXPECT_EQ (" box_link" , latest_msg->child_frame_id );
154
+
155
+ EXPECT_NEAR (
156
+ latest_msg->pose .pose .position .x ,
157
+ -ref_link->WorldPose ().Pos ().X () + link ->WorldPose ().Pos ().X () + 5 , tol);
158
+ EXPECT_NEAR (
159
+ latest_msg->pose .pose .position .y ,
160
+ -ref_link->WorldPose ().Pos ().Y () + link ->WorldPose ().Pos ().Y () + 5 , tol);
161
+ EXPECT_NEAR (
162
+ latest_msg->pose .pose .position .z ,
163
+ -ref_link->WorldPose ().Pos ().Z () + link ->WorldPose ().Pos ().Z () + 5 , tol);
164
+ EXPECT_NEAR (latest_msg->pose .pose .orientation .x , link ->WorldPose ().Rot ().X (), tol);
165
+ EXPECT_NEAR (latest_msg->pose .pose .orientation .y , link ->WorldPose ().Rot ().Y (), tol);
166
+ EXPECT_NEAR (latest_msg->pose .pose .orientation .z , link ->WorldPose ().Rot ().Z (), tol);
167
+
168
+ EXPECT_NEAR (0.0 , latest_msg->twist .twist .linear .x , tol);
169
+ EXPECT_NEAR (0.0 , latest_msg->twist .twist .linear .y , tol);
170
+ EXPECT_NEAR (0.0 , latest_msg->twist .twist .linear .z , tol);
171
+ EXPECT_NEAR (0.0 , latest_msg->twist .twist .angular .x , tol);
172
+ EXPECT_NEAR (0.0 , latest_msg->twist .twist .angular .y , tol);
173
+ EXPECT_NEAR (0.0 , latest_msg->twist .twist .angular .z , tol);
174
+ }
175
+
103
176
int main (int argc, char ** argv)
104
177
{
105
178
rclcpp::init (argc, argv);
0 commit comments