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

rosh topics.foo[0] not working as expected in a loop

asked 2012-05-10 10:10:48 -0600

updated 2012-05-10 10:13:22 -0600

I've noticed a little oddity with how topics work in rosh. To be specific, I would expect the following two snippets to yield the same results:

for topics.foo[:]:
    print foo

while ok():
    print topics.foo[0]

The first one does a good job printing all messages received on /foo, but the second only seems to get every other, even if the messages are being published very slowly.

For what I'm doing, using the first one would be awkward - I have a for loop which loops over some data, and at each iteration, I need the latest message on some topic, and that message won't show up until after some of my loop body has finished.

Does anyone have ideas on what's going on? (also, now that @kwc isn't at WG anymore, is anyone maintaining rosh?)

edit retag flag offensive close merge delete

Comments

Unfortunately it sounds like rosh is more or less orphaned now: https://code.ros.org/trac/ros/ticket/3954

Patrick Bouffard gravatar image Patrick Bouffard  ( 2012-05-10 14:12:27 -0600 )edit

That's too bad. If you're up for working together, I would be open to becoming a maintainer for rosh and making sure it gets the care it deserves.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2012-05-10 15:54:27 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-05-13 07:56:10 -0600

kwc gravatar image

There are probably some bugs in there, as rosh never advanced beyond the experimental phase, but it's also the case that the "while ok()" formulation will never be equivalent. The first formulation specifies you wish to iterate directly over the messages in the topic, so it gets its own consistent message buffer. The latter formulation attempts to poll messages out at an unspecified rate.

You might instead try:

topics.foo[-1]

which pulls out the 'last buffered message'. This will often give you the same message if you are polling too fast, but is less likely to skip messages.

BTW: the topics code was probably the earliest written in terms of rosh experimentation, so its the most in need of an overhaul. Part of the issue with the indexing calls is that they are very inefficient as they can trigger (un)subscribes quite easily, which could lead to the skipped message behavior that you are seeing.

I'm happy to move the hosting of rosh elsewhere if it will make it easier to contribute to. Github seems to be the popular place now with pull requests.

edit flag offensive delete link more

Comments

Thanks Ken - I played around with topics.foo[-1], and it didn't seem to do what I wanted, but I don't recall in exactly what way. If you want to move it over to github, I'd be happy to commit fixes as things come up.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2012-05-14 04:43:15 -0600 )edit

Cool! I'll try and carve out some time later this week to do the migration (still pretty swamped right now)

kwc gravatar image kwc  ( 2012-05-15 06:34:38 -0600 )edit

Just wondering if there was any update on this. It would be great to be able to use rosh in fuerte.

bhaskara gravatar image bhaskara  ( 2012-06-04 07:56:25 -0600 )edit
0

answered 2012-06-12 12:39:30 -0600

bhaskara gravatar image

updated 2012-06-12 12:46:19 -0600

OK, so I got most of rosh (minus roslaunch) working in Fuerte. The main problem was that roslib doesn't really exist in fuerte, and I fixed this with an ugly hack: copy roslib from electric into a new package roslib_electric, and replace references to it within rosh. I verified that publication and subscription of messages works; nothing else is tested. It's at https://github.com/bhaskara/rosh_fuerte .

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-05-10 10:10:48 -0600

Seen: 245 times

Last updated: Jun 12 '12