32 #include "entry_publisher.h"
36 #include "sdo_error.h"
38 #include "std_msgs/UInt8.h"
39 #include "std_msgs/UInt16.h"
40 #include "std_msgs/UInt32.h"
41 #include "std_msgs/Int8.h"
42 #include "std_msgs/Int16.h"
43 #include "std_msgs/Int32.h"
44 #include "std_msgs/Bool.h"
45 #include "std_msgs/String.h"
52 : m_device(device), m_entry_name(entry_name), m_access_method(access_method)
56 m_device_prefix =
"device" + std::to_string(node_id) +
"/";
65 std::string topic = m_device_prefix+
"get_"+m_name;
66 DEBUG_LOG(
"Advertising "<<topic);
71 m_publisher = nh.advertise<std_msgs::UInt8>(topic, queue_size);
74 m_publisher = nh.advertise<std_msgs::UInt16>(topic, queue_size);
77 m_publisher = nh.advertise<std_msgs::UInt32>(topic, queue_size);
80 m_publisher = nh.advertise<std_msgs::Int8>(topic, queue_size);
83 m_publisher = nh.advertise<std_msgs::Int16>(topic, queue_size);
86 m_publisher = nh.advertise<std_msgs::Int32>(topic, queue_size);
89 m_publisher = nh.advertise<std_msgs::Bool>(topic, queue_size);
92 m_publisher = nh.advertise<std_msgs::String>(topic, queue_size);
95 ERROR(
"[EntryPublisher::advertise] Invalid entry type.")
110 m_publisher.publish(msg);
114 std_msgs::UInt16 msg;
116 m_publisher.publish(msg);
120 std_msgs::UInt32 msg;
122 m_publisher.publish(msg);
128 m_publisher.publish(msg);
134 m_publisher.publish(msg);
140 m_publisher.publish(msg);
143 case Type::boolean: {
146 m_publisher.publish(msg);
150 std_msgs::String msg;
151 msg.data = (std::string) value;
152 m_publisher.publish(msg);
156 ERROR(
"[EntryPublisher::advertise] Invalid entry type.")
162 ERROR(
"Exception in EntryPublisher::publish(): "<<error.
what());
virtual const char * what() const noexceptoverride
Returns error description.
const Value & get_entry(const std::string &entry_name, const ReadAccessMethod access_method=ReadAccessMethod::use_default)
Gets the value of a dictionary entry by name internally. If there is no cached value or the entry is ...
static std::string escape(const std::string &str)
Converts entry names to lower case and replaces all spaces and '-' by underscores.
This type of exception is thrown when there are problems while accessing devices via SDO...
uint8_t get_node_id() const
Returns the node ID of the device.
This class represents a CanOpen slave device in the network.
void advertise() override
Type get_entry_type(const std::string &entry_name)
Returns the type of a dictionary entry identified by name as it is defined in the local dictionary...
EntryPublisher(Device &device, const std::string &entry_name, const ReadAccessMethod access_method=ReadAccessMethod::use_default)
Constructor.
This class contains a value to be stored in the object dictionary. The value can have one of the type...