Skip to content

Commit 3aec156

Browse files
committed
Upgrades OdometryPublisher system plugin
Allows OdometryPublisher to publish odometry for a non-fixed link of the robot model. Introduces the possibility to publish the odometry of a point after a non-fixed joint. This commit does not change the default behavior of the plugin. Signed-off-by: Carlo Morganti <[email protected]> Signed-off-by: Morgantiz <[email protected]>
1 parent 7eef230 commit 3aec156

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/systems/odometry_publisher/OdometryPublisher.cc

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class gz::sim::systems::OdometryPublisherPrivate
6666
/// \brief Name of the world-fixed coordinate frame for the odometry message.
6767
public: std::string odomFrame;
6868

69+
/// \brief Name of the frame used as child frame id in the odometry message
70+
public: std::string odomChildFrame;
71+
6972
/// \brief Name of the coordinate frame rigidly attached to the mobile
7073
/// robot base.
7174
public: std::string robotBaseFrame;
@@ -180,16 +183,36 @@ void OdometryPublisher::Configure(const Entity &_entity,
180183
this->dataPtr->gaussianNoise = _sdf->Get<double>("gaussian_noise");
181184
}
182185

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();
185187
if (!_sdf->HasElement("robot_base_frame"))
186188
{
187189
gzdbg << "OdometryPublisher system plugin missing <robot_base_frame>, "
188190
<< "defaults to \"" << this->dataPtr->robotBaseFrame << "\"" << std::endl;
189191
}
190192
else
191193
{
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");
193216
}
194217

195218
this->dataPtr->dimensions = 2;
@@ -357,7 +380,7 @@ void OdometryPublisherPrivate::UpdateOdometry(
357380

358381
// Get and set robotBaseFrame to odom transformation.
359382
//! [worldPose]
360-
const math::Pose3d rawPose = worldPose(this->model.Entity(), _ecm);
383+
const math::Pose3d rawPose = worldPose(this->model.LinkByName(_ecm, this->robotBaseFrame), _ecm);
361384
//! [worldPose]
362385
//! [setPoseMsg]
363386
math::Pose3d pose = rawPose * this->offset;
@@ -462,7 +485,7 @@ void OdometryPublisherPrivate::UpdateOdometry(
462485
frame->add_value(odomFrame);
463486
auto childFrame = header.add_data();
464487
childFrame->set_key("child_frame_id");
465-
childFrame->add_value(robotBaseFrame);
488+
childFrame->add_value(odomChildFrame);
466489

467490
msg.mutable_header()->CopyFrom(header);
468491

0 commit comments

Comments
 (0)