ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Let's look at the message definition of mavros_msgs/RCOut:
# RAW Servo out state
std_msgs/Header header
uint16[] channels
It means that the mavros_msgs/RCOut
Therefore, inside the subscriber function, the safest option is to iterate over channels array as shown below:
void messageCb(const mavros_msgs::RCOut& msg){
for(size_t i = 0; i < msg.channels.size(); i++);
ROS_INFO_STREAM("index: " << i << " value: " << msg.channels[i]);
}
2 | No.2 Revision |
Let's look at the message definition of mavros_msgs/RCOut:
# RAW Servo out state
std_msgs/Header header
uint16[] channels
It means that the mavros_msgs/RCOut
Therefore, inside the subscriber function, the safest option is to iterate over channels array the channels
array. However, as shown below:@Mike Scheutzow mentioned in the comment below, we can not call size()
on an array. Instead, we have to use the generated variable channels_length
. Please read Section 2.4 Arrays for information on arrays. Below is a sample code to iterate over channels
array:
nh.loginfo("Printing channels");
void messageCb(const mavros_msgs::RCOut& msg){
for(size_t i = 0; i < msg.channels.size(); msg.channels_length; i++);
ROS_INFO_STREAM("index: " << i << " value: " << msg.channels[i]);
nh.loginfo(msg.channels[i]);
}
Please use the above snippet only for debugging purposes. Once you have confirmed the values and corresponding indices, please disable/remove it, as the page Logging in rosserial suggests that this kind of logging is very expensive.