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

Rosserial Multiarray Problem

asked 2021-04-23 01:06:34 -0500

mat46ias gravatar image

Hi! Iḿ using my arduino to publish a simple array. This is the code I'm using.

#include <ros.h>
#include <std_msgs/Int16MultiArray.h>
ros::NodeHandle  nh;
int value[2]={1,6};
std_msgs::Int16MultiArray str_msg;
ros::Publisher chatter("uno", &str_msg);
void setup()
{
nh.initNode();
nh.advertise(chatter);
}
void loop()
{
str_msg.data = value[2];
str_msg.data_length = 2;
chatter.publish( &str_msg );
nh.spinOnce();
delay(1000);
}

This code compiles on the Arduino but returns the following message:

warning: invalid conversion from 'int' to 'std_msgs::Int16MultiArray::_data_type* {aka int*}' [-fpermissive] str_msg.data = value[2];

Also, when I run echo on my Terminal I receive the wrong array. Something like this:

layout: 
dim: []
data_offset: 0
data: [30, 0]

How can I fix this? Thanks a lot!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-04-24 16:20:33 -0500

mat46ias gravatar image

I managed to made it work by changing the line str_msg.data = value[2]; to str_msg.data = value;

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-04-23 01:06:34 -0500

Seen: 279 times

Last updated: Apr 24 '21