00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2013, Johannes Meyer, TU Darmstadt 00005 * Copyright (c) 2013, Intermodalics BVBA 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of TU Darmstadt and Intermodalics BVBA 00019 * nor the names of its contributors may be 00020 * used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * Copyright (c) 2014, Jonathan Bohren, The Johns Hopkins University 00037 * - Generalized for multiple time sources 00038 * - Integrated with rtt_rosclock package 00039 *********************************************************************/ 00040 00041 #ifndef __RTT_ROSCLOCK_SIM_CLOCK_THREAD_H 00042 #define __RTT_ROSCLOCK_SIM_CLOCK_THREAD_H 00043 00044 #include <rtt/Service.hpp> 00045 #include <rtt/os/Thread.hpp> 00046 #include <rtt/os/TimeService.hpp> 00047 00048 #include <ros/ros.h> 00049 #include <ros/subscriber.h> 00050 #include <ros/callback_queue.h> 00051 00052 #include <rosgraph_msgs/Clock.h> 00053 00054 namespace rtt_rosclock { 00055 00060 class SimClockThread : public RTT::os::Thread 00061 { 00062 public: 00064 static boost::shared_ptr<SimClockThread> Instance(); 00066 static boost::shared_ptr<SimClockThread> GetInstance(); 00068 static void Release(); 00069 00070 virtual ~SimClockThread(); 00071 00073 enum SimClockSource { 00074 SIM_CLOCK_SOURCE_MANUAL = 0, 00075 SIM_CLOCK_SOURCE_ROS_CLOCK_TOPIC = 1 00076 }; 00077 00079 bool setClockSource(SimClockSource clock_source); 00081 bool useROSClockTopic(); 00083 bool useManualClock(); 00084 00086 bool simTimeEnabled() const; 00087 00096 bool updateClock(const ros::Time new_time); 00097 00098 protected: 00099 00101 SimClockThread(); 00102 SimClockThread(SimClockThread const&); 00103 void operator=(SimClockThread const&); 00104 00106 static boost::shared_ptr<SimClockThread> singleton; 00107 00109 void resetTimeService(); 00110 00112 bool updateClockInternal(const ros::Time new_time); 00113 00114 // RTT::os::Thread interface 00115 virtual bool initialize(); 00116 virtual void loop(); 00117 virtual bool breakLoop(); 00118 virtual void finalize(); 00119 00121 RTT::os::TimeService *time_service_; 00122 00124 SimClockSource clock_source_; 00125 00127 bool process_callbacks_; 00128 00130 ros::NodeHandle nh_; 00132 ros::Subscriber clock_subscriber_; 00134 ros::CallbackQueue callback_queue_; 00136 void clockMsgCallback(const rosgraph_msgs::ClockConstPtr& clock); 00137 }; 00138 00139 } 00140 00141 #endif // ifndef __RTT_ROSCLOCK_RTT_ROSCLOCK_ACTIVITY_H 00142 00143 00144