Ask Your Question
0

JointTrajectory time_from_start resets to all zeros after publish()

asked 2014-06-26 17:37:56 -0500

Rick C NIST gravatar image

Ubuntu 12.04 ROS Hydro

I am publishing a JointTrajectory to Gazebo and monitoring the topic using rostopic echo. The data that I publish is different from what gets captured by rostopic echo. Somehow the "time_from_start" portion of the data gets zeroed out.

A snippet of my code is as follows

  # this is where I create and populate the JointTrajectory
  jt = make_trajectory_msg(plan=plan, secs=0.5, dt=0.2, frame_id='base_link' )
  rospy.loginfo("Publishing joint trajectory")
  while not rospy.is_shutdown():
    print jt
    gazebo_command_publisher.publish(jt)
    r.sleep()

As you can see, right before I call publish() I print the trajectory. Here is what the trajectory looks like before the publish()

header: 
  seq: 5
  stamp: 
    secs: 0
    nsecs: 0
  frame_id: base_link
joint_names: ['arm_joint_1', 'arm_joint_2', 'arm_joint_3', 'arm_joint_4', 'arm_joint_5']
points: 
  - 
    positions: [0.2792831707677692, 0.4627657000396006, -0.8622084888670658, 0.8533643604717218, 0.1568816032950613]
    velocities: [0.0, 0.0, 0.0, 0.0, 0.0]
    accelerations: [0.0, 0.0, 0.0, 0.0, 0.0]
    effort: []
    time_from_start: 
      secs: 0.7
      nsecs: 0

And here is the trajectory after it is captured by rostopic echo:

header: 
  seq: 5
  stamp: 
    secs: 0
    nsecs: 0
  frame_id: base_link
joint_names: ['arm_joint_1', 'arm_joint_2', 'arm_joint_3', 'arm_joint_4', 'arm_joint_5']
points: 
  - 
    positions: [0.2792831707677692, 0.4627657000396006, -0.8622084888670658, 0.8533643604717218, 0.1568816032950613]
    velocities: [0.0, 0.0, 0.0, 0.0, 0.0]
    accelerations: [0.0, 0.0, 0.0, 0.0, 0.0]
    effort: []
    time_from_start: 
      secs: 0
      nsecs: 0
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-06-27 04:41:56 -0500

Adolfo Rodriguez T gravatar image

The secs and nsecs fields of a timestamp are integer values, so secs: 0.7 is getting truncated to zero.

To represent 0.7s, you can either do time_from_start = rospy.Duration.from_sec(0.7), or explicitly set the fields to secs = 0 and nsecs = 700000000

More here http://wiki.ros.org/rospy/Overview/Time

edit flag offensive delete link more

Comments

Thank you. That was what I was looking for. I will use the rospy.Duration method from now on.

Rick C NIST gravatar image Rick C NIST  ( 2014-06-27 08:22:31 -0500 )edit

You're welcome. I'd appreciate it if you check the answer as valid to so the question shows up as resolved.

Adolfo Rodriguez T gravatar image Adolfo Rodriguez T  ( 2014-06-27 09:57:57 -0500 )edit
0

answered 2016-03-09 19:55:07 -0500

Benjamin Blumer gravatar image

Were you using the gazebo_ros_joint_pose_trajectory plugin?

I found a bug in it today and it looks like it's been that way for years. The upshot is that all the time_from_starts were getting zerod regardless of the message sent to Gazebo.

If you're interested in seeing the cause, check out this pull request.

edit flag offensive delete link more

Comments

Hi Benjamin, Yes, I was using the plugin that you mentioned.

Rick C NIST gravatar image Rick C NIST  ( 2016-03-10 08:59:24 -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

2 followers

Stats

Asked: 2014-06-26 17:37:56 -0500

Seen: 272 times

Last updated: Mar 09 '16