time_server.cpp
Go to the documentation of this file.
00001 /*
00002  * time_server.cpp
00003  * Copyright 2013 University of Massachusetts Lowell
00004  * Author: Jonathan Hasenzahl
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     // To start the clock, we wait for the first service call. The difference
00037     // between the actual start of dish generation in a receiver node and the
00038     // start of the clock here is only a few milliseconds.
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     // Calculate the responses
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 }


time_server
Author(s): Jonathan Hasenzahl
autogenerated on Sun Jan 5 2014 11:12:28