clover2_common

Данный пакет содержит общие для всего проекта классы и инструменты: обёртки над стандартными нодами ROS 2, интерфейсы диагностики и наблюдения за параметрами, а также вспомогательные утилиты.

Классы обёртки стандартных C++ нод

Классы-обёртки над стандартными C++ нодами — требуется для унификации функционала который часто используется. node и lifecycle_node имеют одинаковые дополнительные методы.

  • declare_and_watch_parameter<ParameterT>(name, default_value, cb, ...) — повторяет сигнатуру объявления параметра и регистрирует функцию на обновление:

    declare_and_watch_parameter<std::string>(
        "frame_id", "base_link",
        [this](const rclcpp::Parameter& p) { m_frame_id = p.as_string(); },
        "Tracking target");
class node : public rclcpp::Node

Project base node.

Subclassed by clover2_http::server

Public Functions

node(const std::string &node_name, const rclcpp::NodeOptions &options = rclcpp::NodeOptions())

Construct the node.

Параметры:
  • node_name – Node name.

  • options – Node options.

template<typename ParameterT>
inline void declare_and_watch_parameter(const std::string &name, const ParameterT &default_value, clover2_common::util::ParameterFunctorT cb, const std::string &description = "", const std::string &additional_constraints = "", bool read_only = false, bool ignore_override = false)

Declare a parameter and invoke the callback when it changes.

Параметры шаблона:

ParameterT – Type of the parameter.

Параметры:
  • name – Parameter name.

  • default_value – Default value.

  • cb – On change callback.

  • description – Parameter description.

  • additional_constraints – Additional constraints for the descriptor.

  • read_only – Makes parameter readonly.

  • ignore_override – Ignore parameter override.

clover2_common::node_interfaces::NodeDiagnosticsInterface::SharedPtr get_node_diagnostics_interface()

Get the diagnostics interface.

clover2_common::node_interfaces::NodeParametersWatcherInterface::SharedPtr get_node_parameters_watcher_interface()

Get the parameters watcher interface.


clover2_common::node_context

Агрегирует все интерфейсы ноды в одном объекте: стандартные интерфейсы ROS 2, а также специфические для проекта NodeDiagnosticsInterface и NodeParametersWatcherInterface. (Аналог rclcpp::node_interfaces::NodeInterfaces)

class node_context : public NodeInterfaces<NodeBaseInterface, NodeClockInterface, NodeGraphInterface, NodeLoggingInterface, NodeParametersInterface, NodeServicesInterface, NodeTimeSourceInterface, NodeTimersInterface, NodeTopicsInterface, NodeTypeDescriptionsInterface, NodeWaitablesInterface, NodeDiagnosticsInterface, NodeParametersWatcherInterface>

Project node context.

Aggregates standard ROS 2 node interfaces and project custom interfaces.

Public Functions

template<typename NodeT>
inline explicit node_context(NodeT &node)

Construct the node context from a node.

Параметры шаблона:

NodeT – Node type.

Параметры:

node – Node instance.

inline rclcpp::Logger get_logger() const

Get the node logger.


clover2_common::node_runtime

Запускает ноду clover2_common::node в отдельном потоке с собственным SingleThreadedExecutor. Необходим для работы программ с несоколькими циклами выполнения (Boost.Asio или cpptui)

class node_runtime

Project node runtime.

Owns the node, its context, and a dedicated executor thread.

Public Functions

explicit node_runtime(const std::string &node_name, const rclcpp::NodeOptions &options = rclcpp::NodeOptions())

Construct the node runtime.

Параметры:
  • node_name – Node name.

  • options – Node options.

void start()

Start the node runtime.

void stop()

Stop the node runtime.

std::shared_ptr<node> get_node() const

Get the node.

std::shared_ptr<node_context> get_node_context() const

Get the node context.

Собственные интерфейсы ноды


NodeDiagnosticsInterface / NodeDiagnostics

Обёртка над diagnostic_updater, которая хранит диагностические задачи по типу и обеспечивает типизированный доступ.

get_node_diagnostics_interface()->add<diagnostics::lifecycle_state_task>();
...
get_node_diagnostics_interface()
    ->get<diagnostics::lifecycle_state_task>()
    .set_state_getter([this]() { return get_current_state(); });
interface NodeDiagnosticsInterface

Project node diagnostics interface.

Subclassed by clover2_common::node_interfaces::NodeDiagnostics

Public Functions

virtual void add(diagnostic_updater::DiagnosticTask &task) = 0

Add a diagnostic task.

template<typename T, typename ...Args>
inline void add(Args&&... args)

Add a diagnostic task of the given type.

Параметры шаблона:
  • T – Task type. Must inherit from diagnostic_updater::DiagnosticTask.

  • Args – Types of task constructor arguments.

Параметры:

args – Task constructor arguments.

template<typename T>
inline T &get()

Get a diagnostic task by type.

Параметры шаблона:

T – Task type. Must inherit from diagnostic_updater::DiagnosticTask.

Результат:

Reference to the task.

template<typename T>
inline void remove()

Remove a diagnostic task by type.

Параметры шаблона:

T – Task type. Must inherit from diagnostic_updater::DiagnosticTask.

virtual void force_update() = 0

Force update of all diagnostics.


NodeParametersWatcherInterface / NodeParametersWatcher

Наблюдение за параметрами ноды: колбэк вызывается автоматически при изменении значения параметра.

interface NodeParametersWatcherInterface

Project node parameters watcher interface.

Subclassed by clover2_common::node_interfaces::NodeParametersWatcher

Public Functions

virtual void declare_and_watch_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, ParameterFunctorT cb, const rcl_interfaces::msg::ParameterDescriptor &parameter_descriptor = rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override = false) = 0

Declare a parameter and invoke the callback when it changes.

Параметры:
  • name – Parameter name.

  • default_value – Default value.

  • cb – On change callback.

  • parameter_descriptor – Parameter descriptor.

  • ignore_override – Ignore parameter override.

virtual void undeclare_watcher_parameters() = 0

Undeclare all watched parameters.