13 this->
staticTf = this->remappedTfTopic ==
"tf_static" || this->remappedTfTopic ==
"/tf_static";
16 XmlRpc::XmlRpcValue mappingsParam;
17 const bool hasMappingsParam = this->
privateNodeHandle.getParam(
"mappings", mappingsParam);
18 if (!hasMappingsParam) {
19 mappingsParam.setSize(0);
20 ROS_WARN(
"The 'mappings' parameter to tf_remap is missing");
23 const bool bidirectional = this->
privateNodeHandle.param<
bool>(
"is_bidirectional",
false);
29 if (!tfRemapper.getMappings().empty()) {
30 ROS_INFO_STREAM(
"Applying the following mappings" << (bidirectional ?
" bidirectionally" :
"") <<
31 " to incoming tf frame ids:");
32 for (TfRemapper::MappingsType::const_iterator it = tfRemapper.getMappings().begin();
33 it != tfRemapper.getMappings().end(); ++it) {
34 ROS_INFO_STREAM(
"* " << it->first <<
" " << (bidirectional && !it->second.empty() ?
"<" :
"") <<
"-> " <<
35 (it->second.empty() ?
"DELETE" : it->second));
40 if (it->second.empty())
41 ROS_INFO_STREAM(
"* DELETE <- " << it->first);
45 ROS_WARN(
"No mappings defined.");
48 ROS_INFO_STREAM(
"Old TF topic: " << this->
oldTfTopic);
49 ROS_INFO_STREAM(
"Remapped TF topic: " << this->remappedTfTopic);
51 ROS_INFO(
"Running in static TF mode (caching all TFs, latched publisher)");
68 const std::string& callerid =
event.getPublisherName();
69 if (callerid == ros::this_node::getName())
72 tf2_msgs::TFMessage message = this->tfRemapper.doRemapping(*event.getConstMessage());
77 this->addToStaticTfCache(message, this->staticTfCache);
78 this->remappedTfPublisher.publish(this->staticTfCache);
80 this->remappedTfPublisher.publish(message);
86 const std::string& callerid =
event.getPublisherName();
87 if (callerid == ros::this_node::getName())
90 tf2_msgs::TFMessage message = this->reverseTfRemapper.doRemapping(*event.getConstMessage());
95 this->addToStaticTfCache(message, this->reverseStaticTfCache);
96 this->oldTfPublisher.publish(this->reverseStaticTfCache);
98 this->oldTfPublisher.publish(message);
103 const tf2_msgs::TFMessage& message, tf2_msgs::TFMessage& cache)
const {
105 for (std::vector<geometry_msgs::TransformStamped>::const_iterator it = message.transforms.begin();
106 it != message.transforms.end(); ++it) {
108 for (std::vector<geometry_msgs::TransformStamped>::iterator cacheIt = cache.transforms.begin();
109 cacheIt != cache.transforms.end(); ++cacheIt) {
110 if (it->child_frame_id == cacheIt->child_frame_id) {
117 cache.transforms.push_back(*it);
121 int main(
int argc,
char * argv[])
123 ros::init(argc, argv,
"tf_remapper");
TfRemapper reverseTfRemapper
The remapper that actually changes the TF messages.
TfRemapper tfRemapper
Name of the remapped topic ("/tf").
int main(int argc, char *argv[])
Remap frames in TF messages according to given rules.
ros::Publisher oldTfPublisher
Publisher of /tf.
A node that remaps TF frame names according to the given set of rules.
ros::Subscriber remappedTfSubscriber
Subscriber to /tf_old.
ros::NodeHandle privateNodeHandle
ROS node handle.
const MappingsType & getMappings() const
Get the mappings this remapper uses.
std::string remappedTfTopic
Name of the old topic ("/tf_old").
ros::Publisher remappedTfPublisher
Subscriber to /tf (only in bidirectional mode).
void oldTfCallback(const ros::MessageEvent< tf2_msgs::TFMessage const > &event)
The remapper that actually changes the TF messages in reverse direction.
ros::Subscriber oldTfSubscriber
Private ROS node handle.
void remappedTfCallback(const ros::MessageEvent< tf2_msgs::TFMessage const > &event)
Callback when a TF message arrives on the remapped TF topic.
bool staticTf
Publisher of /tf_old (only in bidirectional mode).
void addToStaticTfCache(const tf2_msgs::TFMessage &message, tf2_msgs::TFMessage &cache) const
Add the given TF message to the static TF cache. Newer TFs overwrite the older ones.
ros::NodeHandle publicNodeHandle
std::string oldTfTopic
Cache of static TF messages in the reverse direction.