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

How to work with std_msgs::Int16MultiArray message type?

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

kump gravatar image

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

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 image gvdhoorn  ( 2019-01-28 11:56:05 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

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

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 image gvdhoorn  ( 2019-01-29 06:32:55 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,368 times

Last updated: Jan 29 '19