Play a bag with a step
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
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
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
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.
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.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2019-07-10 04:13:48 -0500
Seen: 503 times
Last updated: Jul 10 '19