std_msgs::UInt8MultiArray发布数组
#include "ros/ros.h" #include "std_msgs/Float32.h" #include <sstream> #include <iostream> #include "std_msgs/UInt8MultiArray.h" #include "std_msgs/MultiArrayDimension.h" using namespace std; int main(int argc, char **argv) { ros::init(argc, argv, "talker"); ros::NodeHandle n; ros::Publisher chatter_pub = n.advertise<std_msgs::UInt8MultiArray>("chatter", 1000); ros::Rate loop_rate(10); while (ros::ok()) { std_msgs::MultiArrayLayout msg; const unsigned int data_sz = 10; std_msgs::UInt8MultiArray m; m.layout.dim.push_back(std_msgs::MultiArrayDimension()); m.layout.dim[0].size = data_sz; m.layout.dim[0].stride = 1; m.layout.dim[0].label = "bla"; cout<<"==========================="<<endl; // only needed if you don't want to use push_back m.data.resize(data_sz); m.data[0] = 2; m.data[1] = 1; chatter_pub.publish(m); ros::spinOnce(); loop_rate.sleep(); } return 0; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。