首页 > 代码库 > std_msgs::UInt8MultiArray发布数组
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; }
std_msgs::UInt8MultiArray发布数组
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。