rosbag: added --loop / -l for looping playback #2706

This commit is contained in:
Tim Field 2010-05-24 19:42:42 +00:00
parent 0a6e10a669
commit 44e5c3a1c2
4 changed files with 39 additions and 24 deletions

View File

@ -68,6 +68,7 @@ struct PlayerOptions
ros::WallDuration advertise_sleep;
bool try_future;
bool has_time;
bool loop;
float time;
std::vector<std::string> bags;

View File

@ -45,6 +45,7 @@ void printUsage() {
fprintf(stderr, " -s sec\tsleep <sec> sleep duration after every advertise call (to allow subscribers to connect)\n");
fprintf(stderr, " -t sec\tstart <sec> seconds into the files\n");
fprintf(stderr, " -q sz\tUse an outgoing queue of size <sz> (defaults to 0)\n");
fprintf(stderr, " -l\tloop playback\n");
fprintf(stderr, " -h\tdisplay this help message\n");
}
@ -52,10 +53,11 @@ rosbag::PlayerOptions parseOptions(int argc, char** argv) {
rosbag::PlayerOptions opts;
int option_char;
while ((option_char = getopt(argc, argv, "nahpb:r:s:t:q:T")) != -1) {
while ((option_char = getopt(argc, argv, "nahlpb:r:s:t:q:T")) != -1) {
switch (option_char) {
case 'n': opts.quiet = true; break;
case 'a': opts.at_once = true; break;
case 'l': opts.loop = true; break;
case 'p': opts.start_paused = true; break;
case 'T': opts.try_future = true; break;
case 'q': opts.queue_size = atoi(optarg); break;

View File

@ -67,6 +67,7 @@ PlayerOptions::PlayerOptions() :
advertise_sleep(200000),
try_future(false),
has_time(false),
loop(false),
time(0.0f)
{
}
@ -150,39 +151,48 @@ void Player::publish() {
std::cout << std::endl << "Hit space to toggle paused, or 's' to step." << std::endl;
// Set up our time_translator and publishers
while (true) {
// Set up our time_translator and publishers
time_translator_.setTimeScale(options_.time_scale);
time_translator_.setTimeScale(options_.time_scale);
start_time_ = view.begin()->getTime();
time_translator_.setRealStartTime(start_time_);
bag_length_ = view.getEndTime() - view.getBeginTime();
start_time_ = view.begin()->getTime();
time_translator_.setRealStartTime(start_time_);
bag_length_ = view.getEndTime() - view.getBeginTime();
time_publisher_.setTime(start_time_);
time_publisher_.setTime(start_time_);
ros::WallTime now_wt = ros::WallTime::now();
time_translator_.setTranslatedStartTime(ros::Time(now_wt.sec, now_wt.nsec));
ros::WallTime now_wt = ros::WallTime::now();
time_translator_.setTranslatedStartTime(ros::Time(now_wt.sec, now_wt.nsec));
time_publisher_.setTimeScale(options_.time_scale);
if (options_.bag_time)
time_publisher_.setPublishFrequency(options_.bag_time_frequency);
else
time_publisher_.setPublishFrequency(-1.0);
time_publisher_.setTimeScale(options_.time_scale);
if (options_.bag_time)
time_publisher_.setPublishFrequency(options_.bag_time_frequency);
else
time_publisher_.setPublishFrequency(-1.0);
paused_ = options_.start_paused;
paused_time_ = now_wt;
paused_ = options_.start_paused;
paused_time_ = now_wt;
// Call do-publish for each message
foreach(MessageInstance m, view) {
if (!node_handle_.ok())
// Call do-publish for each message
foreach(MessageInstance m, view) {
if (!node_handle_.ok())
break;
doPublish(m);
}
if (!node_handle_.ok()) {
std::cout << std::endl;
break;
doPublish(m);
}
if (!options_.loop) {
std::cout << std::endl << "Done." << std::endl;
break;
}
}
std::cout << std::endl << "Done." << std::endl;
ros::shutdown();
}

View File

@ -149,6 +149,7 @@ def play_cmd(argv):
parser.add_option("-d", "--delay", dest="delay", default=0.2, type='float', action="store", help="sleep SEC seconds after every advertise call (to allow subscribers to connect)", metavar="SEC")
parser.add_option("-r", "--rate", dest="rate", default=1.0, type='float', action="store", help="multiply the publish rate by FACTOR", metavar="FACTOR")
parser.add_option("-s", "--start", dest="sleep", default=0.0, type='float', action="store", help="start SEC seconds into the bag files", metavar="SEC")
parser.add_option("-l", "--loop", dest="loop", default=False, action="store_true", help="loop playback")
parser.add_option("--try-future-version", dest="try_future", default=False, action="store_true", help="still try to open a bag file, even if the version number is not known to the player")
(options, args) = parser.parse_args(argv)
@ -161,6 +162,7 @@ def play_cmd(argv):
if options.quiet: cmd.extend(["-n"])
if options.pause: cmd.extend(["-p"])
if options.immediate: cmd.extend(["-a"])
if options.loop: cmd.extend(["-l"])
if options.try_future: cmd.extend(["-T"])
if options.clock: