ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I don't believe this has anything to do with casting.
There are two issues with the code you show:
auto msg = std::make_shared<std_msgs::msg::UInt16();
This line is missing the closing >
(after UInt16
), and:
msg->data = statuswoord;
this can't work.
The field data
is of type uint16
in the ROS 2 msg IDL (see here), which gets converted to a std::uint16_t
for C++ (refer to About ROS 2 interfaces: Message description specification - Fields - Field types), which is a short unsigned int
on amd64
and many other architectures.
The statuswoord
variable is of type std_msgs::msg::UInt16
.
You cannot assign a std_msgs::msg::UInt16
to a variable of type std::uint16_t
.
To make this work, you'll have to change the type of statuswoord
to std::uint16_t
.
2 | No.2 Revision |
Is there a guide somewhere on casting all the std_msgs ?
I don't believe this has anything to do with casting.
There are two issues with the code you show:
auto msg = std::make_shared<std_msgs::msg::UInt16();
This line is missing the closing >
(after UInt16
), and:
msg->data = statuswoord;
this can't work.
The field data
is of type uint16
in the ROS 2 msg IDL (see here), which gets converted to a std::uint16_t
for C++ (refer to About ROS 2 interfaces: Message description specification - Fields - Field types), which is a short unsigned int
on amd64
and many other architectures.
The statuswoord
variable is of type std_msgs::msg::UInt16
.
You cannot assign a std_msgs::msg::UInt16
to a variable of type std::uint16_t
.
To make this work, you'll have to change the type of statuswoord
to std::uint16_t
.
3 | No.3 Revision |
Is there a guide somewhere on casting all the std_msgs ?
I don't believe this has anything to do with casting.
There are two issues with the code you show:
auto msg = std::make_shared<std_msgs::msg::UInt16();
This line is missing the closing >
(after UInt16
), and:
std_msgs::msg::UInt16 statuswoord;
msg->data = statuswoord;
this can't work.
The field data
is of type uint16
in the ROS 2 msg IDL (see here), which gets converted to a std::uint16_t
for C++ (refer to About ROS 2 interfaces: Message description specification - Fields - Field types), which is a short unsigned int
on amd64
and many other architectures.
The statuswoord
variable is of type std_msgs::msg::UInt16
.
You cannot assign a std_msgs::msg::UInt16
to a variable of type std::uint16_t
.
To make this work, you'll have to change the type of statuswoord
to std::uint16_t
.