player.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of Willow Garage, Inc. nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 ********************************************************************/
00034 
00035 #ifndef ROSBAG_PLAYER_H
00036 #define ROSBAG_PLAYER_H
00037 
00038 #include <sys/stat.h>
00039 #if !defined(_MSC_VER)
00040   #include <termios.h>
00041   #include <unistd.h>
00042 #endif
00043 #include <time.h>
00044 
00045 #include <queue>
00046 #include <string>
00047 
00048 #include <ros/ros.h>
00049 #include <ros/time.h>
00050 
00051 #include "rosbag/bag.h"
00052 
00053 #include "rosbag/time_translator.h"
00054 #include "rosbag/macros.h"
00055 
00056 namespace rosbag {
00057 
00059 
00063 ros::AdvertiseOptions createAdvertiseOptions(MessageInstance const& msg, uint32_t queue_size);
00064 
00065 ROSBAG_DECL ros::AdvertiseOptions createAdvertiseOptions(const ConnectionInfo* c, uint32_t queue_size);
00066 
00067 
00068 struct ROSBAG_DECL PlayerOptions
00069 {
00070     PlayerOptions();
00071 
00072     void check();
00073 
00074     std::string prefix;
00075     bool     quiet;
00076     bool     start_paused;
00077     bool     at_once;
00078     bool     bag_time;
00079     double   bag_time_frequency;
00080     double   time_scale;
00081     int      queue_size;
00082     ros::WallDuration advertise_sleep;
00083     bool     try_future;
00084     bool     has_time;
00085     bool     loop;
00086     float    time;
00087     bool     has_duration;
00088     float    duration;
00089     bool     keep_alive;
00090     ros::Duration skip_empty;
00091 
00092     std::vector<std::string> bags;
00093     std::vector<std::string> topics;
00094     std::vector<std::string> pause_topics;
00095 };
00096 
00097 
00099 class ROSBAG_DECL TimePublisher {
00100 public:
00104     TimePublisher();
00105 
00106     void setPublishFrequency(double publish_frequency);
00107     
00108     void setTimeScale(double time_scale);
00109 
00111     void setHorizon(const ros::Time& horizon);
00112 
00114     void setWCHorizon(const ros::WallTime& horizon);
00115 
00117     void setTime(const ros::Time& time);
00118 
00120     ros::Time const& getTime() const;
00121 
00126     void runClock(const ros::WallDuration& duration);
00127 
00129     void runStalledClock(const ros::WallDuration& duration);
00130 
00132     void stepClock();
00133 
00134     bool horizonReached();
00135 
00136 private:
00137     bool do_publish_;
00138     
00139     double publish_frequency_;
00140     double time_scale_;
00141     
00142     ros::NodeHandle node_handle_;
00143     ros::Publisher time_pub_;
00144     
00145     ros::WallDuration wall_step_;
00146     
00147     ros::WallTime next_pub_;
00148 
00149     ros::WallTime wc_horizon_;
00150     ros::Time horizon_;
00151     ros::Time current_;
00152 };
00153 
00154 
00156 
00160 class ROSBAG_DECL Player
00161 {
00162 public:
00163     Player(PlayerOptions const& options);
00164     ~Player();
00165 
00166     void publish();
00167 
00168 private:
00169     int readCharFromStdin();
00170     void setupTerminal();
00171     void restoreTerminal();
00172 
00173     void doPublish(rosbag::MessageInstance const& m);
00174 
00175     void doKeepAlive();
00176 
00177     void printTime();
00178 
00179 
00180 private:
00181 
00182     PlayerOptions options_;
00183 
00184     ros::NodeHandle node_handle_;
00185 
00186     bool paused_;
00187 
00188     bool pause_for_topics_;
00189 
00190     ros::WallTime paused_time_;
00191 
00192     std::vector<boost::shared_ptr<Bag> >  bags_;
00193     std::map<std::string, ros::Publisher> publishers_;
00194 
00195     // Terminal
00196     bool    terminal_modified_;
00197 #if defined(_MSC_VER)
00198     HANDLE input_handle;
00199     DWORD stdin_set;
00200 #else
00201     termios orig_flags_;
00202     fd_set  stdin_fdset_;
00203 #endif
00204     int     maxfd_;
00205 
00206     TimeTranslator time_translator_;
00207     TimePublisher time_publisher_;
00208 
00209     ros::Time start_time_;
00210     ros::Duration bag_length_;
00211 };
00212 
00213 
00214 } // namespace rosbag
00215 
00216 #endif


rosbag
Author(s): Tim Field, Jeremy Leibs, James Bowman
autogenerated on Thu Jun 6 2019 21:11:02