Sending a JointTrajectory message

1,280 views
Skip to first unread message

Flavian Hautbois

unread,
Sep 6, 2013, 8:26:12 AM9/6/13
to moveit...@googlegroups.com
Hello everyone,

I have successfully generated a trajectory from a series of cartesian points. The message looks valid (header.stamp is ros::now() + ros::Duration(1), joint_names are in the right order, I resize msg.points[i].positions and velocities. I don't fill acceleration values but they are not used in my controller anyway).

I am publishing it using:

ros::NodeHandle n;
ros::Publisher traj_pub = n.advertise<trajectory_msgs::JointTrajectory>("joint_path_command",100);
trajectory_msgs::JointTrajectory msg;
[Fill the trajectory message]
traj_pub.publish(msg)

In rqt_graph I can see that my node is effectively linked to joint_path_command. However, when I run my node, the "rostopic echo /joint_path_command" shows nothing, and the robot does not move.
What did I do wrong?

Side question: if I only want to send my trajectory to visualize it in RViz, how should I do?

Thanks

Flavian

Ioan Sucan

unread,
Sep 6, 2013, 8:33:01 AM9/6/13
to Flavian Hautbois, moveit-users
Hey Flavian,

I suspect you are not allowing enough time to initialize the ros publisher and destroying the ros publisher right after the publish() call. I consider this to be a bug in ROS, but you can avoid it by increasing the scope of traj_pub.

To display the trajectory, use a DisplayTrajectory message.

Ioan

Flavian Hautbois

unread,
Sep 6, 2013, 8:41:46 AM9/6/13
to Ioan Sucan, moveit-users
"Increasing the scope of traj_pub" <- I don't know what you mean by that...


2013/9/6 Ioan Sucan <isu...@gmail.com>



--
F. Hautbois

Ioan Sucan

unread,
Sep 6, 2013, 8:47:29 AM9/6/13
to Flavian Hautbois, moveit-users
I mean make the variable a member of the class you are using.

Flavian Hautbois

unread,
Sep 6, 2013, 8:54:58 AM9/6/13
to Ioan Sucan, moveit-users
OK. You think my publisher is destroyed too soon?
At the moment my node looks like:

int main(int argc, chat **argv)
{
  ros::init(...);
  ros::AsyncSpinner spinner(1);
  spinner.start();
 
  [The code I posted earlier]
 
  sleep(10)
  ros::waitForShutdown();

  return 0;
}

and I am prototyping so I'm not really using any classes...


2013/9/6 Ioan Sucan <isu...@gmail.com>



--
F. Hautbois

jz...@swri.org

unread,
Sep 6, 2013, 9:29:48 AM9/6/13
to moveit...@googlegroups.com

Flavian,

 The issue is likely not that the publisher is being destroyed too soon, but rather that you’re publishing a message too soon after advertising the publisher.

When a publisher is first created/advertised, ROS notifies the ROS master that a new topic publisher is available.  If there are subscribers listening on that topic (e.g. rostopic echo, robot interface, etc.), then the ROS master passes them the publisher info, and they each create a connection with the publisher node.  All that takes time.  If you publish messages during that process, they will just get “lost”, which is probably what’s happening to your trajectory.

Try adding another sleep call between the n.advertise and traj_pub.publish calls.  Alternatively, you can use a latching publisher or count the number of subscribers before publishing. 

- Jeremy

Flavian Hautbois

unread,
Sep 6, 2013, 9:55:15 AM9/6/13
to jz...@swri.org, moveit-users
Did that-worked. Thanks! Now I've got other problems, but not regarding MoveIt :)


2013/9/6 <jz...@swri.org>



--
F. Hautbois
Reply all
Reply to author
Forward
0 new messages