Ask Your Question

How to work with std_msgs::Int16MultiArray message type?

asked 2019-01-28 11:40:42 -0500

kump gravatar image

updated 2019-01-28 11:44:01 -0500

What is needed to publish a How to work with std_msgs::Int16MultiArray message?

I tried

std_msgs::Int16MultiArray msg;
int16_t *velocities; = velocities;

but just those few lines gives me errors while compiling

error: no match for ‘operator=’ (operand types are ‘std_msgs::Int16MultiArray_<std::allocator<void> >::_data_type {aka std::vector<short int, std::allocator<short int> >}’ and ‘int16_t* {aka short int*}’) = velocities;
edit retag flag offensive close merge delete


I believe this is a duplicate of #q37185.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-28 11:56:05 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-01-29 06:05:46 -0500

kump gravatar image

This works:

# definition in header
std::vector<physics::JointPtr> joints;
ros::Publisher rosPub;
std::unique_ptr<ros::NodeHandle> rosNode;

# initialization
this->rosNode.reset(new ros::NodeHandle( node_name ));
this->rosPub = this->rosNode->advertise<std_msgs::Float32MultiArray>("/velocity",1);

# callback function
std_msgs::Float32MultiArray msg; this->joints[0]->GetVelocity(0) ); this->joints[1]->GetVelocity(0) ); this->joints[2]->GetVelocity(0) );

edit flag offensive delete link more


Please note that you're not initialising the layout field here. Subscribers that expect that field to describe the size, dimensionality and shape of the data you're publishing will not work correctly.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-29 06:32:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-01-28 11:40:42 -0500

Seen: 815 times

Last updated: Jan 29 '19