Go to the documentation of this file.00001 #include <rtt/RTT.hpp>
00002 #include <rtt/internal/GlobalService.hpp>
00003
00004 #include <rtt_rosclock/rtt_rosclock.h>
00005 #include <rtt_rosclock/rtt_rosclock_sim_clock_thread.h>
00006
00007 #include <rtt/os/StartStopManager.hpp>
00008
00009 namespace {
00010 boost::shared_ptr<rtt_rosclock::SimClockThread> sim_clock_thread;
00011 }
00012
00013 void unloadROSClockService() {
00014 sim_clock_thread.reset();
00015 }
00016
00017 void loadROSClockService(){
00018 RTT::Service::shared_ptr rosclock = RTT::internal::GlobalService::Instance()->provides("ros")->provides("clock");
00019
00020 rosclock->doc("RTT service for realtime and non-realtime clock measurement.");
00021
00022
00023 sim_clock_thread = rtt_rosclock::SimClockThread::Instance();
00024 RTT::os::StartStopManager::Instance()->stopFunction(&unloadROSClockService);
00025
00026
00027 rosclock->addOperation("host_now", &rtt_rosclock::host_now).doc(
00028 "Get a ros::Time structure based on the NTP-corrected RT time or the ROS simulation time.");
00029 rosclock->addOperation("host_wall_now", &rtt_rosclock::host_now).doc(
00030 "Get a ros::Time structure based on the NTP-corrected RT time or the ROS wall time.");
00031 rosclock->addOperation("rtt_now", &rtt_rosclock::rtt_now).doc(
00032 "Get a ros::Time structure based on the RTT time source.");
00033 rosclock->addOperation("rtt_wall_now", &rtt_rosclock::rtt_wall_now).doc(
00034 "Get a ros::Time structure based on the RTT wall clock time.");
00035
00036
00037 rosclock->addOperation("host_offset_from_rtt", &rtt_rosclock::host_offset_from_rtt).doc(
00038 "Get the difference between the Orocos wall clock and the NTP-corrected wall clock in seconds (host_wall - rtt_wall).");
00039
00040
00041 rosclock->addOperation("useROSClockTopic", &rtt_rosclock::use_ros_clock_topic).doc(
00042 "Use the ROS /clock topic source for updating simulation time.");
00043 rosclock->addOperation("useManualClock", &rtt_rosclock::use_manual_clock).doc(
00044 "Use a manual source for simulation time by calling updateSimClock.");
00045
00046
00047 rosclock->addOperation("enableSimClock", &rtt_rosclock::enable_sim).doc(
00048 "Enable simulation time based on the ROS /clock topic if the /use_sim_time parameter is set. This will override RTT::os::TimeService");
00049 rosclock->addOperation("disableSimClock", &rtt_rosclock::disable_sim).doc(
00050 "Disable simulation time based on the ROS /clock topic.");
00051
00052 rosclock->addOperation("updateSimClock", &rtt_rosclock::update_sim_clock).doc(
00053 "Update the current simulation time and update all SimClockActivities as per their respective frequencies.").arg(
00054 "time","Current simulated time in seconds.");
00055 }
00056
00057 using namespace RTT;
00058 extern "C" {
00059 bool loadRTTPlugin(RTT::TaskContext* c){
00060 if (c != 0) return false;
00061 loadROSClockService();
00062 return true;
00063 }
00064 std::string getRTTPluginName (){
00065 return "rosclock";
00066 }
00067 std::string getRTTTargetName (){
00068 return OROCOS_TARGET_NAME;
00069 }
00070 }