Ask Your Question
0

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;
msg.data = 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*}’)
         msg.data = velocities;
edit retag flag offensive close merge delete

Comments

I believe this is a duplicate of #q37185.

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

1 Answer

Sort by » oldest newest most voted
0

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;
msg.data.push_back( this->joints[0]->GetVelocity(0) );
msg.data.push_back( this->joints[1]->GetVelocity(0) );
msg.data.push_back( this->joints[2]->GetVelocity(0) );

this->rosPub.publish(msg);
edit flag offensive delete link more

Comments

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 imagegvdhoorn ( 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

Stats

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

Seen: 113 times

Last updated: Jan 29