ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hy, following a working code tried on an Arduino Mega and ROS Kinetic:
ros::NodeHandle nh;
std_msgs::UInt16MultiArray arr; ros::Publisher pub_arr( "/arr", &arr);
void setup() { nh.getHardware()->setBaud(115200); nh.initNode(); arr.layout.dim = (std_msgs::MultiArrayDimension ) malloc(sizeof(std_msgs::MultiArrayDimension)2); arr.layout.dim[0].label = "height"; arr.layout.dim[0].size = 4; arr.layout.dim[0].stride = 1; arr.layout.data_offset = 0; arr.data = (int )malloc(sizeof(int)8); arr.data_length = 4; nh.advertise(pub_arr);
}
void loop() {
arr.data[0] = 1;
arr.data[1] = 2;
arr.data[2] = 3;
arr.data[3] = 4;
pub_arr.publish(&arr);
nh.spinOnce();
}
2 | No.2 Revision |
Hy, following a working code tried on an Arduino Mega and ROS Kinetic:Kinetic:
Commands in ROS:
$ roscore
ros::NodeHandle nh;//New terminal
$ rosrun rosserial_python serial_node.py /dev/ttyACM0 _baud:=115200
//New terminal
$ rostopic echo /arr
Arduino Code for Publishing an array with 4 words:
#include <ros.h>
#include <std_msgs/UInt16MultiArray.h>
ros::NodeHandle nh;
std_msgs::UInt16MultiArray arr;
ros::Publisher pub_arr( "/arr", &arr);&arr);
void setup() {
nh.getHardware()->setBaud(115200);
nh.initNode();
arr.layout.dim = (std_msgs::MultiArrayDimension )
*)
malloc(sizeof(std_msgs::MultiArrayDimension)2);
malloc(sizeof(std_msgs::MultiArrayDimension)*2);
arr.layout.dim[0].label = "height";
arr.layout.dim[0].size = 4;
arr.layout.dim[0].stride = 1;
arr.layout.data_offset = 0;
arr.data = (int )malloc(sizeof(int)8);
*)malloc(sizeof(int)*8);
arr.data_length = 4;
nh.advertise(pub_arr);nh.advertise(pub_arr);
}
}
void loop() {
arr.data[0] = 1;
arr.data[1] = 2;
arr.data[2] = 3;
arr.data[3] = 4;
pub_arr.publish(&arr);
nh.spinOnce();
}}