Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable joint state publisher's topic #1076

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/systems/joint_state_publisher/JointStatePublisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ignition/gazebo/components/JointVelocity.hh"
#include "ignition/gazebo/components/ParentEntity.hh"
#include "ignition/gazebo/components/Pose.hh"
#include "ignition/gazebo/Util.hh"

using namespace ignition;
using namespace gazebo;
Expand Down Expand Up @@ -89,6 +90,14 @@ void JointStatePublisher::Configure(
this->CreateComponents(_ecm, joint);
}
}

// Advertise the state topic
// Sets to provided topic if available
if (_sdf->HasElement("topic"))
{
this->topic = _sdf->Get<std::string>("topic");
}

}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -142,11 +151,26 @@ void JointStatePublisher::PostUpdate(const UpdateInfo &_info,
worldName = _ecm.Component<components::Name>(
parentEntity->Data())->Data();

// Advertise the state topic
std::string topic = std::string("/world/") + worldName + "/model/"
+ this->model.Name(_ecm) + "/joint_state";
// if topic not set it will be empty
std::vector<std::string> topics;
// this helps avoid unecesarry invalid topic error
if (!this->topic.empty())
{
topics.push_back(this->topic);
}
topics.push_back(std::string("/world/") + worldName + "/model/"
+ this->model.Name(_ecm) + "/joint_state");

this->topic = validTopic(topics);
chapulina marked this conversation as resolved.
Show resolved Hide resolved
if (this->topic.empty())
{
ignerr << "No valid topics for JointStatePublisher could be found."
<< "Make sure World/Model name does'nt contain invalid characters.\n";
return;
}

this->modelPub = std::make_unique<transport::Node::Publisher>(
this->node.Advertise<msgs::Model>(topic));
this->node.Advertise<msgs::Model>(this->topic));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/systems/joint_state_publisher/JointStatePublisher.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <memory>
#include <set>
#include <string>
#include <ignition/gazebo/Model.hh>
#include <ignition/transport/Node.hh>
#include <ignition/gazebo/System.hh>
Expand Down Expand Up @@ -82,6 +83,9 @@ namespace systems

/// \brief The joints that will be published.
private: std::set<Entity> joints;

/// \brief The topic
private: std::string topic;
};
}
}
Expand Down