Skip to content

Commit

Permalink
add frame_id and child_frame_id attribute support for DiffDrive
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume <[email protected]>
  • Loading branch information
Guillaume committed Sep 20, 2020
1 parent f6b4b0a commit 472ec3f
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/systems/diff_drive/DiffDrive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ class ignition::gazebo::systems::DiffDrivePrivate

/// \brief A mutex to protect the target velocity command.
public: std::mutex mutex;

/// \brief frame_id from sdf.
public: std::string sdf_frame_id;

/// \brief frame_id from sdf.
public: std::string sdf_child_frame_id;
};

//////////////////////////////////////////////////
Expand Down Expand Up @@ -260,6 +266,12 @@ void DiffDrive::Configure(const Entity &_entity,
this->dataPtr->odomPub = this->dataPtr->node.Advertise<msgs::Odometry>(
odomTopic);

if (_sdf->HasElement("frame_id"))
this->dataPtr->sdf_frame_id=_sdf->Get<std::string>("frame_id");

if (_sdf->HasElement("child_frame_id"))
this->dataPtr->sdf_child_frame_id=_sdf->Get<std::string>("child_frame_id");

ignmsg << "DiffDrive subscribing to twist messages on [" << topic << "]"
<< std::endl;
}
Expand Down Expand Up @@ -422,16 +434,27 @@ void DiffDrivePrivate::UpdateOdometry(const ignition::gazebo::UpdateInfo &_info,
// Set the frame id.
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->model.Name(_ecm) + "/odom");
if (this->sdf_frame_id.empty()){
frame->add_value(this->model.Name(_ecm) + "/odom");
}else{
frame->add_value(this->sdf_frame_id);
}

std::optional<std::string> linkName = this->canonicalLink.Name(_ecm);
if (linkName)
{
if (this->sdf_child_frame_id.empty()){
if (linkName)
{
auto childFrame = msg.mutable_header()->add_data();
childFrame->set_key("child_frame_id");
childFrame->add_value(this->model.Name(_ecm) + "/" + *linkName);
}
}else {
auto childFrame = msg.mutable_header()->add_data();
childFrame->set_key("child_frame_id");
childFrame->add_value(this->model.Name(_ecm) + "/" + *linkName);
childFrame->add_value(this->sdf_child_frame_id);
}


// Publish the message
this->odomPub.Publish(msg);
}
Expand Down

0 comments on commit 472ec3f

Please sign in to comment.