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

publish multiple data on one topic

asked 2016-02-16 00:19:05 -0600

darshandoria gravatar image

updated 2016-02-16 03:34:25 -0600

gvdhoorn gravatar image

Hello,

Is it possible to publish multiple data i.e angle for servo1 and angle for servo2 on one topic ? If yes, please show me answer how to do it.

Thanks in advance.


Edit: Thank you sir for your answer.

But still getting the error as "Segmentation fault(core dumped)"

Please consider my procedure:

sensor_msgs::JointState joint;
joint.position[1] = 50;
joint.velocity[1] = 100;
joint.effort[1] = 90;

dd.publish(joint);

qDebug() << "position =" << joint.position[1];
qDebug() << "velocity =" << joint.velocity[1];
qDebug() << "effort =" << joint.effort[1];
edit retag flag offensive close merge delete

Comments

@darshandoria: please don't post answers to provide us with more information. Edit your question for that. Use the edit link/button.

gvdhoorn gravatar image gvdhoorn  ( 2016-02-16 03:35:07 -0600 )edit

ok i will take care of it

darshandoria gravatar image darshandoria  ( 2016-02-16 03:41:46 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-02-16 03:42:50 -0600

The vectors containing position, velocity and effort default to a size of zero. You either have to use push_back or resize the vectors before writing to them.

sensor_msgs::JointState joint;
joint.position.push_back(50);
joint.velocity.push_back(100);
joint.effort.push_back(90);

or

sensor_msgs::JointState joint;
joint.position.resize(1);
joint.velocity.resize(1);
joint.effort.resize(1);
joint.position[0] = 50;
joint.velocity[0] = 100;
joint.effort[0] = 90;
edit flag offensive delete link more

Comments

Thank You so much all of you !!!

darshandoria gravatar image darshandoria  ( 2016-02-16 03:57:39 -0600 )edit
1

answered 2016-02-16 00:56:31 -0600

NEngelhard gravatar image

updated 2016-02-16 01:01:16 -0600

You could use a sensor_msgs::JointState http://docs.ros.org/api/sensor_msgs/h... , and fill name and position with your values. Or you create a custom message that contains two floats: http://wiki.ros.org/ROS/Tutorials/Cre...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-16 00:19:05 -0600

Seen: 635 times

Last updated: Feb 16 '16