@@ -66,6 +66,9 @@ class gz::sim::systems::OdometryPublisherPrivate
66
66
// / \brief Name of the world-fixed coordinate frame for the odometry message.
67
67
public: std::string odomFrame;
68
68
69
+ // / \brief Name of the frame used as child frame id in the odometry message
70
+ public: std::string odomChildFrame;
71
+
69
72
// / \brief Name of the coordinate frame rigidly attached to the mobile
70
73
// / robot base.
71
74
public: std::string robotBaseFrame;
@@ -180,16 +183,36 @@ void OdometryPublisher::Configure(const Entity &_entity,
180
183
this ->dataPtr ->gaussianNoise = _sdf->Get <double >(" gaussian_noise" );
181
184
}
182
185
183
- this ->dataPtr ->robotBaseFrame = this ->dataPtr ->model .Name (_ecm)
184
- + " /" + " base_footprint" ;
186
+ this ->dataPtr ->robotBaseFrame = Link (this ->dataPtr ->model .Links (_ecm).at (0 )).Name (_ecm).value ();
185
187
if (!_sdf->HasElement (" robot_base_frame" ))
186
188
{
187
189
gzdbg << " OdometryPublisher system plugin missing <robot_base_frame>, "
188
190
<< " defaults to \" " << this ->dataPtr ->robotBaseFrame << " \" " << std::endl;
189
191
}
190
192
else
191
193
{
192
- this ->dataPtr ->robotBaseFrame = _sdf->Get <std::string>(" robot_base_frame" );
194
+ const std::string name = _sdf->Get <std::string>(" robot_base_frame" );
195
+ if (this ->dataPtr ->model .LinkByName (_ecm, name) != kNullEntity )
196
+ {
197
+ this ->dataPtr ->robotBaseFrame = name;
198
+ }
199
+ else
200
+ {
201
+ gzerr << " OdometryPublisher system plugin <robot_base_frame> link not found in the model, "
202
+ << " defaults to \" " << this ->dataPtr ->robotBaseFrame << " \" " << std::endl;
203
+ }
204
+ }
205
+
206
+ this ->dataPtr ->odomChildFrame = this ->dataPtr ->model .Name (_ecm)
207
+ + " /" + this ->dataPtr ->robotBaseFrame ;
208
+ if (!_sdf->HasElement (" odom_child_frame" ))
209
+ {
210
+ gzdbg << " OdometryPublisher system plugin missing <odom_child_frame>, "
211
+ << " defaults to \" " << this ->dataPtr ->odomChildFrame << " \" " << std::endl;
212
+ }
213
+ else
214
+ {
215
+ this ->dataPtr ->odomChildFrame = _sdf->Get <std::string>(" odom_child_frame" );
193
216
}
194
217
195
218
this ->dataPtr ->dimensions = 2 ;
@@ -357,7 +380,7 @@ void OdometryPublisherPrivate::UpdateOdometry(
357
380
358
381
// Get and set robotBaseFrame to odom transformation.
359
382
// ! [worldPose]
360
- const math::Pose3d rawPose = worldPose (this ->model .Entity ( ), _ecm);
383
+ const math::Pose3d rawPose = worldPose (this ->model .LinkByName (_ecm, this -> robotBaseFrame ), _ecm);
361
384
// ! [worldPose]
362
385
// ! [setPoseMsg]
363
386
math::Pose3d pose = rawPose * this ->offset ;
@@ -462,7 +485,7 @@ void OdometryPublisherPrivate::UpdateOdometry(
462
485
frame->add_value (odomFrame);
463
486
auto childFrame = header.add_data ();
464
487
childFrame->set_key (" child_frame_id" );
465
- childFrame->add_value (robotBaseFrame );
488
+ childFrame->add_value (odomChildFrame );
466
489
467
490
msg.mutable_header ()->CopyFrom (header);
468
491
0 commit comments