Skip to content

Commit 0ce6d44

Browse files
committed
Allowed ignoring extrapolation TF warnings.
1 parent 70966c3 commit 0ce6d44

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

include/robot_model_renderer/c_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ int robot_model_renderer_sensorMsgsEncodingToOgrePixelFormat(const char* encodin
219219
* \param[in] model The robot model to render (string version of the URDF file).
220220
* \param[out] errorMessagesAllocator Allocator for the errors encountered during construction of this class.
221221
* \param[in] config Configuration of this class.
222+
* \param[in] warnExtrapolation Whether to warn on TF extrapolation errors.
222223
* \return A handle to the constructed class instance. Nullptr if the construction failed.
223224
* \note Delete this instance by calling robot_model_renderer_deleteRobotModelRenderer() when no longer needed.
224225
*/
225226
robot_model_renderer_RobotModelRendererHandle robot_model_renderer_createRobotModelRenderer(
226227
cras_allocator_t logMessagesAllocator,
227228
const char* model,
228229
cras_allocator_t errorMessagesAllocator,
229-
robot_model_renderer_RobotModelRendererConfig config);
230+
robot_model_renderer_RobotModelRendererConfig config,
231+
bool warnExtrapolation);
230232

231233
/**
232234
* \brief Delete the instance created by robot_model_renderer_createRobotModelRenderer().

include/robot_model_renderer/robot/tf_link_updater.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TFLinkUpdater : public LinkUpdater, public cras::HasLogger
2525
{
2626
public:
2727
explicit TFLinkUpdater(const cras::LogHelperPtr& log, tf2::BufferCore* tf,
28-
const std::string& fixed_frame = {}, const std::string& tf_prefix = {});
28+
const std::string& fixed_frame = {}, const std::string& tf_prefix = {}, bool warn_extrapolation = true);
2929

3030
void setFixedFrame(const std::string& fixedFrame);
3131

@@ -37,14 +37,15 @@ class TFLinkUpdater : public LinkUpdater, public cras::HasLogger
3737
tf2::BufferCore* tf_;
3838
std::string fixed_frame_;
3939
std::string tf_prefix_;
40+
bool warn_extrapolation_;
4041
};
4142

4243
class TFROSLinkUpdater : public TFLinkUpdater
4344
{
4445
public:
4546
explicit TFROSLinkUpdater(const cras::LogHelperPtr& log, const std::shared_ptr<cras::InterruptibleTFBuffer>& tf,
4647
const std::string& fixed_frame = {}, const std::string& tf_prefix = {},
47-
const ros::Duration& timeout = ros::Duration(0.01));
48+
const ros::Duration& timeout = ros::Duration(0.01), bool warn_extrapolation = true);
4849

4950
virtual void setTimeoutStart(const ros::Time& time);
5051

src/c_api.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class LogGuard
185185

186186
robot_model_renderer_RobotModelRendererHandle robot_model_renderer_createRobotModelRenderer(
187187
cras_allocator_t logMessagesAllocator, const char* model, cras_allocator_t errorMessagesAllocator,
188-
robot_model_renderer_RobotModelRendererConfig config)
188+
robot_model_renderer_RobotModelRendererConfig config, const bool warnExtrapolation)
189189
{
190190
urdf::Model robotModel;
191191
try
@@ -213,7 +213,8 @@ robot_model_renderer_RobotModelRendererHandle robot_model_renderer_createRobotMo
213213
{
214214
LogGuard logGuard(handle);
215215

216-
handle->linkUpdater = std::make_shared<robot_model_renderer::TFLinkUpdater>(handle->log, &handle->tf);
216+
handle->linkUpdater = std::make_shared<robot_model_renderer::TFLinkUpdater>(
217+
handle->log, &handle->tf, "", "", warnExtrapolation);
217218

218219
handle->renderer = std::make_unique<robot_model_renderer::RobotModelRenderer>(
219220
handle->log, robotModel, handle->linkUpdater.get(), errors, config_cpp);

src/robot/tf_link_updater.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ std::string concat(const std::string& prefix, const std::string& frame)
3030
}
3131

3232
TFLinkUpdater::TFLinkUpdater(const cras::LogHelperPtr& log, tf2::BufferCore* tf,
33-
const std::string& fixed_frame, const std::string& tf_prefix)
34-
: cras::HasLogger(log), tf_(tf), fixed_frame_(fixed_frame), tf_prefix_(tf_prefix)
33+
const std::string& fixed_frame, const std::string& tf_prefix, const bool warn_extrapolation)
34+
: cras::HasLogger(log), tf_(tf), fixed_frame_(fixed_frame), tf_prefix_(tf_prefix),
35+
warn_extrapolation_(warn_extrapolation)
3536
{
3637
}
3738

3839
TFROSLinkUpdater::TFROSLinkUpdater(const cras::LogHelperPtr& log,
3940
const std::shared_ptr<cras::InterruptibleTFBuffer>& tf, const std::string& fixed_frame, const std::string& tf_prefix,
40-
const ros::Duration& timeout)
41-
: TFLinkUpdater(log, &tf->getRawBuffer(), fixed_frame, tf_prefix), timeout_(timeout), tf_ros_(tf)
41+
const ros::Duration& timeout, const bool warn_extrapolation)
42+
: TFLinkUpdater(log, &tf->getRawBuffer(), fixed_frame, tf_prefix, warn_extrapolation), tf_ros_(tf), timeout_(timeout)
4243
{
4344
}
4445

@@ -71,8 +72,11 @@ cras::expected<void, LinkUpdateError> TFLinkUpdater::getLinkTransforms(
7172
}
7273
catch (const tf2::ExtrapolationException& e)
7374
{
74-
CRAS_WARN_STREAM_THROTTLE_NAMED(1.0, "link_updater",
75-
"No transform from [" << link_name_prefixed << "] to [" << fixed_frame_ << "]: " << e.what());
75+
if (warn_extrapolation_)
76+
{
77+
CRAS_WARN_STREAM_THROTTLE_NAMED(1.0, "link_updater",
78+
"No transform from [" << link_name_prefixed << "] to [" << fixed_frame_ << "]: " << e.what());
79+
}
7680
error.error = e.what();
7781
error.name = link_name_prefixed;
7882
error.maySucceedLater = true;

src/robot_model_renderer/cras_bag_tools_plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def set_bag(self, bag):
113113
if model is None:
114114
raise RuntimeError("RenderCameraMask requires robot URDF either as a file or ROS parameter.")
115115

116-
self.renderer = RobotModelRenderer(model, self._config, self._encoding)
116+
self.renderer = RobotModelRenderer(model, self._config, self._encoding, warnExtrapolation=False)
117117

118118
def filter(self, topic, msg, stamp, header):
119119
if self.renderer is None:
@@ -124,8 +124,8 @@ def filter(self, topic, msg, stamp, header):
124124
if stamp - s < self.tf_timeout:
125125
to_try.append((m, s, h))
126126
else:
127-
print("Failed transforming robot for mask rendering at time %s: %r" % (m.header.stamp, e),
128-
file=sys.stderr)
127+
print("Failed transforming robot for mask rendering at time %i.%09i: %r" % (
128+
m.header.stamp.secs, m.header.stamp.nsecs, e), file=sys.stderr)
129129
self._failed_msgs = []
130130

131131
if topic.lstrip('/') == 'tf':
@@ -148,7 +148,8 @@ def filter(self, topic, msg, stamp, header):
148148
header = fix_connection_header(copy.copy(header), self.mask_topic, Image._type, Image._md5sum, Image)
149149
result.append((self.mask_topic, img, stamp, header))
150150
else:
151-
print("Failed rendering robot mask for time %s: %r" % (msg.header.stamp, err), file=sys.stderr)
151+
print("Failed rendering robot mask for time %i.%09i: %r" % (
152+
msg.header.stamp.secs, msg.header.stamp.nsecs, err), file=sys.stderr)
152153

153154
return result
154155

src/robot_model_renderer/renderer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _get_library():
3333

3434
__lib.robot_model_renderer_createRobotModelRenderer.restype = robot_model_renderer_RobotModelRendererHandle
3535
__lib.robot_model_renderer_createRobotModelRenderer.argtypes = [
36-
Allocator.ALLOCATOR, c_char_p, Allocator.ALLOCATOR, RobotModelRendererConfig,
36+
Allocator.ALLOCATOR, c_char_p, Allocator.ALLOCATOR, RobotModelRendererConfig, c_bool,
3737
]
3838

3939
__lib.robot_model_renderer_deleteRobotModelRenderer.restype = None
@@ -85,13 +85,14 @@ def sensorMsgsEncodingToOgrePixelFormat(encoding):
8585
class RobotModelRenderer(object):
8686
"""Renderer of robot model from URDF."""
8787

88-
def __init__(self, model, config, imageEncoding=None):
88+
def __init__(self, model, config, imageEncoding=None, warnExtrapolation=True):
8989
"""Construct the renderer.
9090
9191
:param str model: The URDF model to load.
9292
:param RobotModelRendererConfig config: Configuration of this class.
9393
:param imageEncoding: Encoding of the rendered image (one of sensor_msgs/image_encodings.h).
9494
:type imageEncoding: str or none
95+
:param bool warnExtrapolation: If true, warn on TF extrapolation errors.
9596
:throws RuntimeError: If construction failed.
9697
"""
9798
self._log_alloc = LogMessagesAllocator()
@@ -104,7 +105,7 @@ def __init__(self, model, config, imageEncoding=None):
104105

105106
error_alloc = StringAllocator()
106107
self._handle = _get_library().robot_model_renderer_createRobotModelRenderer(
107-
self._log_alloc_func, model.encode("utf-8"), error_alloc.get_cfunc(), config)
108+
self._log_alloc_func, model.encode("utf-8"), error_alloc.get_cfunc(), config, warnExtrapolation)
108109

109110
self._camera_info = None
110111
self._flush_log_messages()

0 commit comments

Comments
 (0)