Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[ROS2] publishing UInt16

Hi, I would like to publish a message without it being of type std_msgs::msg::String.

std_msgs::msg::UInt16 statuswoord;

auto publisher = node->create_publisher<std_msgs::msg::UInt16>("motor_info", rmw_qos_profile_default);  

auto msg =  std::make_shared<std_msgs::msg::UInt16();

msg->data = statuswoord;

But I get following error:

cannot convert ‘std_msgs::msg::UInt16 {aka std_msgs::msg::UInt16_<std::allocator<void> >}’ to std_msgs::msg::UInt16_<std::allocator<void> > >::_data_type {aka short unsigned int}’ in assignment msg->data = test;

In my case I need it to be UInt16, but it might happen that I need another datatype in the future. Is there a guide somewhere on casting all the std_msgs ?