Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "time_server/time_server.h"
00008
00014 void TimeServer::init()
00015 {
00016 service_ = n_.advertiseService("time_service", &TimeServer::service, this);
00017 ros::spin();
00018 }
00019
00033 bool TimeServer::service(time_server::time_srv::Request& req,
00034 time_server::time_srv::Response& res)
00035 {
00036
00037
00038
00039 static bool run_once = true;
00040 if (run_once)
00041 {
00042 offset_ = ros::Time::now() - ros::Time(0);
00043 ROS_INFO("Time server seeded successfully");
00044 run_once = false;
00045 }
00046
00047
00048 res.actual = ros::Time::now() - offset_;
00049 res.delta = req.target - res.actual;
00050
00051 printf("Query: %.6fs Actual %.6fs Delta %.6fs\n", req.target.toSec(),
00052 res.actual.toSec(), res.delta.toSec());
00053
00054 return true;
00055 }
00056
00060 int main(int argc, char** argv)
00061 {
00062 ros::init(argc, argv, "time_server");
00063 TimeServer time_server;
00064 return 0;
00065 }