ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@Mike Scheutzow @ravijoshi

Thank you so much for your guidance! nh.loginfo(msg.channels[i]); This doesn't do much for some reason as it output black lines. Serial.print worked with the correct out put.

#include <ros.h>
#include <std_msgs/UInt16MultiArray.h>

#include <mavros_msgs/RCOut.h>
ros::NodeHandle  nh;
uint16_t RC[16];
void messageCb(const mavros_msgs::RCOut& msg){
 for(size_t i = 0; i < msg.channels_length; i++){
   RC[i]=msg.channels[i];}
}

ros::Subscriber<mavros_msgs::RCOut> sub("mavros/rc/out", messageCb );



std_msgs::UInt16MultiArray str_msg;
ros::Publisher chatter("Recieved", &str_msg);


void setup()
{
  nh.getHardware()->setBaud(57600);
  nh.initNode();
  str_msg.data_length=16;
  nh.advertise(chatter);
  nh.subscribe(sub);
}

void loop()
{
  str_msg.data = RC;
  chatter.publish( &str_msg );
  nh.spinOnce();
  delay(50);
}

This code looks to off worked, publishing the correct information, hopefully this might help someone one day too.

thanks again!