1#include "modulo_core/communication/PublisherInterface.hpp"
5#include <rclcpp/publisher.hpp>
6#include <rclcpp_lifecycle/lifecycle_publisher.hpp>
7#include <std_msgs/msg/bool.hpp>
8#include <std_msgs/msg/float64.hpp>
9#include <std_msgs/msg/float64_multi_array.hpp>
10#include <std_msgs/msg/int32.hpp>
11#include <std_msgs/msg/string.hpp>
13#include "modulo_core/communication/PublisherHandler.hpp"
18 : message_pair_(std::move(message_pair)), type_(type) {}
22 "The derived publisher handler is required to override this function to handle activation");
27 "The derived publisher handler is required to override this function to handle deactivation");
36 case MessageType::BOOL:
39 case MessageType::FLOAT64:
42 case MessageType::FLOAT64_MULTI_ARRAY:
43 this->
publish(this->
message_pair_->write<std_msgs::msg::Float64MultiArray, std::vector<double>>());
45 case MessageType::INT32:
48 case MessageType::STRING:
51 case MessageType::ENCODED_STATE:
52 if (!this->
message_pair_->get_message_pair<EncodedState, state_representation::State>()
66template<
typename MsgT>
69 case PublisherType::PUBLISHER:
70 this->
template get_handler<rclcpp::Publisher<MsgT>, MsgT>()->
publish(message);
72 case PublisherType::LIFECYCLE_PUBLISHER:
73 this->
template get_handler<rclcpp_lifecycle::LifecyclePublisher<MsgT>, MsgT>()->
publish(message);
83 if (message_pair ==
nullptr) {
virtual void deactivate()
Deactivate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointe...
PublisherType get_type() const
Get the type of the publisher interface.
virtual void publish()
Publish the data stored in the message pair through the ROS publisher of a derived PublisherHandler i...
std::shared_ptr< MessagePairInterface > get_message_pair() const
Get the pointer to the message pair of the PublisherInterface.
std::shared_ptr< MessagePairInterface > message_pair_
The pointer to the stored MessagePair instance.
PublisherInterface(PublisherType type, std::shared_ptr< MessagePairInterface > message_pair=nullptr)
Constructor with the message type and message pair.
void set_message_pair(const std::shared_ptr< MessagePairInterface > &message_pair)
Set the pointer to the message pair of the PublisherInterface.
virtual void activate()
Activate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer.
A base class for all core exceptions.
An exception class to notify that a certain pointer is null.
Modulo Core communication module for handling messages on publication and subscription interfaces.
PublisherType
Enum of supported ROS publisher types for the PublisherInterface.