Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 105a476

Browse files
authored
Merge pull request #1 from peroxyacyl/2022.10.05-cache-tf-prefix
2 parents bd2a7c6 + cf91833 commit 105a476

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

include/robot_state_publisher/joint_state_listener.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class JointStateListener {
8787
MimicMap mimic_;
8888
bool use_tf_static_;
8989
bool ignore_timestamp_;
90-
90+
std::string tf_prefix_;
91+
bool tf_prefix_cached_;
9192
};
9293
}
9394

src/joint_state_listener.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ JointStateListener::JointStateListener(const KDL::Tree& tree, const MimicMap& m,
5858
}
5959

6060
JointStateListener::JointStateListener(const std::shared_ptr<RobotStatePublisher>& rsp, const MimicMap& m)
61-
: state_publisher_(rsp), mimic_(m)
61+
: state_publisher_(rsp), mimic_(m), tf_prefix_cached_(false)
6262
{
6363
ros::NodeHandle n_tilde("~");
6464
ros::NodeHandle n;
@@ -92,15 +92,19 @@ JointStateListener::~JointStateListener()
9292

9393
std::string JointStateListener::getTFPrefix()
9494
{
95+
if (tf_prefix_cached_) {
96+
return tf_prefix_;
97+
}
98+
9599
ros::NodeHandle n_tilde("~");
96-
std::string tf_prefix;
97100

98101
// get the tf_prefix parameter from the closest namespace
99102
std::string tf_prefix_key;
100103
n_tilde.searchParam("tf_prefix", tf_prefix_key);
101-
n_tilde.param(tf_prefix_key, tf_prefix, std::string(""));
104+
n_tilde.param(tf_prefix_key, tf_prefix_, std::string(""));
105+
tf_prefix_cached_ = true;
102106

103-
return tf_prefix;
107+
return tf_prefix_;
104108
}
105109

106110
void JointStateListener::callbackFixedJoint(const ros::TimerEvent& e)

0 commit comments

Comments
 (0)