Template Class TfFilter

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

template<class ...Inputs>
class TfFilter : public fkie_message_filters::Filter<IO<Inputs...>, IO<Inputs...>>

Wait for TF transformations for incoming messages.

This filter is intended to be used with a Subscriber as source, and will delay incoming messages until they can be transformed to the specified TF target frames. If the filter input is not unary, only the first argument is examined.

namespace mf = fkie_message_filters;

mf::Subscriber<M> sub;
mf::TfFilter<mf::Subscriber<M>::Output> flt;
ros::NodeHandle nh;

sub.subscribe(nh, "topic", 10);
flt.init(tf2_buffer, "target_frame", 10, nh);
mf::chain(sub, flt);

Public Types

using FilterFailureCB = std::function<void(const Inputs&..., TfFilterResult)>

Callback for failed transform queries.

using Input = IO<Inputs...>

Grouped input types.

This type can be used to define sources with matching types.

using Input = IO<Inputs...>

Grouped input types.

This type can be used to define sources with matching types.

using Output = IO<Outputs...>

Grouped output types.

This type can be used to define sinks with matching types.

using Output = IO<Outputs...>

Grouped output types.

This type can be used to define sinks with matching types.

using V_string = std::vector<std::string>

Type alias for std::vector<std::string>.

Public Functions

inline TfFilter() noexcept

Empty constructor.

Constructs an uninitialized filter object. You need to call init() before you can use the object.

TfFilter(tf2::BufferCore &bc, const std::string &target_frame, uint32_t queue_size) noexcept

Construct and initialize the filter.

The constructor calls init() and set_target_frame() for you.

  • bc a tf2 buffer instance

  • target_frame the TF target frame for the incoming messages

  • queue_size the maximum number of queued messages

Does not throw any exceptions.

TfFilter(tf2::BufferCore &bc, const V_string &target_frames, uint32_t queue_size) noexcept

Construct and initialize the filter.

The constructor calls init() and set_target_frame() for you.

  • bc a tf2 buffer instance

  • target_frames the TF target frames for the incoming messages

  • queue_size the maximum number of queued messages

Does not throw any exceptions.

Connection connect_to_sink(Sink<Outputs...> &dst) noexcept

Connect this source to a sink.

Can be called multiple times to connect multiple sinks; in that case, the sinks receive data in the same order as they have been connected. This function does basically the same thing as Sink::connect_to_source(), only from the opposite point of view.

  • dst the sink that is to be connected

Does not throw any exceptions.

Returns:

a connection object that can be used to monitor or sever the created connection

Connection connect_to_sink(Sink<Outputs...> &dst) noexcept

Connect this source to a sink.

Can be called multiple times to connect multiple sinks; in that case, the sinks receive data in the same order as they have been connected. This function does basically the same thing as Sink::connect_to_source(), only from the opposite point of view.

  • dst the sink that is to be connected

Does not throw any exceptions.

Returns:

a connection object that can be used to monitor or sever the created connection

Connection connect_to_source(Source<Inputs...> &src) noexcept

Connect this sink to a source.

Can be called multiple times to connect multiple sources; in that case, the sink receives data from all connected sources. This function does basically the same thing as Source::connect_to_sink(), only from the opposite point of view.

  • src the source that is to be connected

Does not throw any exceptions.

Returns:

a connection object that can be used to monitor or sever the created connection

Connection connect_to_source(Source<Inputs...> &src) noexcept

Connect this sink to a source.

Can be called multiple times to connect multiple sources; in that case, the sink receives data from all connected sources. This function does basically the same thing as Source::connect_to_sink(), only from the opposite point of view.

  • src the source that is to be connected

Does not throw any exceptions.

Returns:

a connection object that can be used to monitor or sever the created connection

virtual void disconnect() noexcept override

Disconnect from all connected sources and sinks.

Convenience function that calls disconnect_from_all_sources() and disonnect_from_all_sinks().

Does not throw any exceptions.

void disconnect_from_all_sinks() noexcept

Disconnect from all connected sinks.

Severs the connection to all sinks, turning the send() method into a no-op.

Does not throw any exceptions.

void disconnect_from_all_sinks() noexcept

Disconnect from all connected sinks.

Severs the connection to all sinks, turning the send() method into a no-op.

Does not throw any exceptions.

void disconnect_from_all_sources() noexcept

Disconnect from all connected sources.

Severs the connection to all sources. The receive() method will not be called any more.

Does not throw any exceptions.

void disconnect_from_all_sources() noexcept

Disconnect from all connected sources.

Severs the connection to all sources. The receive() method will not be called any more.

Does not throw any exceptions.

void init(tf2::BufferCore &bc, uint32_t queue_size) noexcept

Initialize the filter.

This function allocates internal data structures and makes the filter operational. If the function is called on an already initialized filter, the filter is reinitialized and reset() is called implicitly.

  • bc a TF2 buffer instance

  • queue_size the maximum number of queued messages

Does not throw any exceptions.

virtual void reset() noexcept override

Reset filter state.

Discards all queued messages. Existing connections to sources and sinks are unaffected.

Does not throw any exceptions.

void set_filter_failure_function(FilterFailureCB cb)

Register callback for failed transforms.

Whenever a message is discarded, this callback is called with the message and the reason why the TF transform failed.

  • cb callback function

Throws:

std::logic_error – if the filter is uninitialized

void set_target_frame(const std::string &target_frame)

Choose the TF target frame.

  • target_frame all passed messages will be transformable to this TF frame

Throws:

std::logic_error – if the filter is uninitialized

void set_target_frames(const V_string &target_frames)

Choose the TF target frames.

  • target_frames all passed messages will be transformable to all these TF frames

Throws:

std::logic_error – if the filter is uninitialized

Public Static Attributes

static std::size_t NUM_INPUTS

Number of input arguments.

static std::size_t NUM_INPUTS

Number of input arguments.

static std::size_t NUM_OUTPUTS

Number of output arguments.

static std::size_t NUM_OUTPUTS

Number of output arguments.

Protected Functions

virtual void receive(helpers::argument_t<Inputs>... in) override

Process incoming data.

Derived classes need to override this method to handle all data that is to be consumed by the sink.

Depends on the implementation.

void send(helpers::argument_t<Outputs>... out)

Pass data to all connected sinks.

  • out data

Does not throw any exceptions, but will propagate uncaught exceptions from filter callbacks.

void send(helpers::argument_t<Outputs>... out)

Pass data to all connected sinks.

  • out data

Does not throw any exceptions, but will propagate uncaught exceptions from filter callbacks.

struct Impl

Public Functions

inline Impl(TfFilter<Inputs...> *parent, tf2::BufferCore &bc) noexcept
inline ~Impl()
inline void cancel_all_transformable_requests(std::shared_ptr<MessageInfo> &info) noexcept
inline tf2::TransformableRequestHandle make_transformable_request(std::shared_ptr<MessageInfo> &info, const std::string &target_frame, const std::string &source_frame, const tf2::TimePoint &time) noexcept

Public Members

tf2::BufferCore &bc_
uint32_t cur_queue_size_
FilterFailureCB failure_cb_
uint32_t max_queue_size_
std::list<std::shared_ptr<MessageInfo>> messages_
std::mutex mutex_
TfFilter<Inputs...> *parent_
std::map<tf2::TransformableRequestHandle, std::shared_ptr<MessageInfo>> requests_
V_string target_frames_

Public Static Attributes

static tf2::TransformableRequestHandle NeverTransformable = 0xffffffffffffffffull
static tf2::TransformableRequestHandle TransformAvailable = 0
struct MessageInfo

Public Functions

inline MessageInfo(MessageTuple &&m)

Public Members

std::set<tf2::TransformableRequestHandle> handles
MessageTuple message