0

Rosanswers logo

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?


Originally posted by Alsing on ROS Answers with karma: 27 on 2018-01-23

Post score: 0

1 Answers1

0

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2018-01-23

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Alsing on 2018-01-23:
Thanks for the recommendation!

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

Comment by gvdhoorn on 2018-01-24:
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.

Comment by Alsing on 2018-01-24:
@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!

Comment by gvdhoorn on 2018-01-24:
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-rse
  • 39,013
  • 1
  • 1
  • 4