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

Minimising jerk by publishing faster than subscribing

asked 2018-01-23 09:07:32 -0600

Alsing gravatar image

Is there a way I could publish a node at a different rate of subscribing?

I do intend to have a python script instercept /cmd_vel and publish it 5 times faster in incrementally.

For eg:

pub = rospy.Publisher("/cmd_vel", Twist)
rospy.SUbscriber("/pre_cmd_vel")
i = 1
rate = rospy.Rate(10)
while linear.change < 5:
    rate = rospy.Rate(50)    
    p.linear.x = i
    pub.publish(p)
    i = i + 1
    rate.sleep()
rate = rospy.Rate(10)`

Would something like that work? SInce jerking is caused by acceleration, breaking a command for a sudden jump in velocity into smaller blocks would give less jerk?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-23 09:34:05 -0600

gvdhoorn gravatar image

Would wiki/yocs_velocity_smoother not do what you want?

As to your question: of course you can 'publish faster than you subscribe' (more accurate would be: publish faster than the rate at which messages are incoming). Just use a timer to control the publication rate.

edit flag offensive delete link more

Comments

Thanks for the recommendation!

I'll take a look at it. HOwever, is my implementation correct?

Alsing gravatar image Alsing  ( 2018-01-23 22:31:05 -0600 )edit

Well, no:

  • Rate inside while
  • no callback for your subscriber

and some other things.

I would really recommend using the velocity smoother. If you must create something yourself: use a timer, not a while loop.

And I don't understand the p.linear.x = i line.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-24 02:52:18 -0600 )edit

@gvdhoorn The crux of the code would be having rate inside while. So while [condition], rate is different. But I looked at the timer and probably will go with that route. Or yocs_velocity_smoother. Thanks alot!

Alsing gravatar image Alsing  ( 2018-01-24 04:29:21 -0600 )edit

I don't think Rate works like you think it does: it's a convenience object, that keeps track of time for you between calls to sleep(). It doesn't affect scheduling of your while loop or something. Creating multiple Rate instances at different lines will not do anything special.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-24 04:31:03 -0600 )edit

Question Tools

Stats

Asked: 2018-01-23 09:07:32 -0600

Seen: 151 times

Last updated: Jan 23 '18