Ask Your Question
0

Play a bag with a step

asked 2019-07-10 04:13:48 -0600

hachbani gravatar image

updated 2019-07-10 04:14:52 -0600

Hello,

I want to play a Bagfile, but only advertise one message and skip the 2 following.. and there we go.. anyway to do this ?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-07-10 05:03:00 -0600

gvdhoorn gravatar image

updated 2019-07-10 05:58:17 -0600

You're describing subsampling a topic, correct?

If so: I don't believe that is supported right now.

You could post-process your back yourself using the rosbag API. Only keeping 1 out of 3 messages shouldn't be too hard to implement.


Edit:

Yes, i want to record on an other bag, only 1 out of 3 messages that are published from the original bag. can you tell me more about how can I do it ?

write a Python script that does something like the following:

import rosbag

# opening hard-coded filenames here, but you could obviously make this
# a command line option

count = 0
with rosbag.Bag('output.bag', 'w') as outbag:
    for topic, msg, t in rosbag.Bag('input.bag').read_messages():

        # drop only messages on 'your_topic'
        if topic == "/your_topic":
            # here we drop every 2 out of 3 messages
            if (count % 3 == 0):
                outbag.write(topic, msg, t)

        else:
            outbag.write(topic, msg, t)

        count += 1

This is essentially example 1 combined with example 5.

I haven't checked this, so it could be that you'd need to tweak this a bit or make some corrections.

edit flag offensive delete link more

Comments

Yes, i want to record on an other bag, only 1 out of 3 messages that are published from the original bag. can you tell me more about how can I do it ? I don't really understand the utility of the rosbag API you gave me. Thanks

hachbani gravatar imagehachbani ( 2019-07-10 05:41:54 -0600 )edit

Thanks for the help, I know how to code in Python, but never used a python code with ROS, how do I run the code after editing it ?

hachbani gravatar imagehachbani ( 2019-07-10 06:20:15 -0600 )edit

It's just Python. There is nothing special about it.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-10 06:30:29 -0600 )edit

You appear to have removed the comment you posted, but:

I want to subsample all the topics, so I removed the first If syntax

the code you showed counted all messages from all topics. So it wasn't skipping 2 msgs from a single topic, but it just counted all msgs and skipped 2 messages from all topics. That leads to many more skipped messages. You'll want to have counters per topic.

'm getting an error 'No module named 'yaml' ' when It tries to import rosbag. Any idea ?

Perhaps something like #q327808.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-10 08:55:54 -0600 )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

1 follower

Stats

Asked: 2019-07-10 04:13:48 -0600

Seen: 47 times

Last updated: Jul 10 '19