Fawkes API  Fawkes Development Version
gazsim_timesource_source.h
1 /***************************************************************************
2  * gazsim_timesource_source.h - Plugin sets the fawkes time
3  * to the simulation time
4  *
5  * Created: Wed Sep 25 16:02:54 2013
6  * Copyright 2013 Frederik Zwilling
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <boost/asio.hpp>
24 #include <utils/time/timesource.h>
25 #include <utils/time/clock.h>
26 
27 #include "../msgs/SimTime.pb.h"
28 
29 #ifndef __GAZEBO_TIMESOURCE_H_
30 #define __GAZEBO_TIMESOURCE_H_
31 
32 
33 typedef const boost::shared_ptr<gazsim_msgs::SimTime const> ConstSimTimePtr;
34 
35 namespace fawkes
36 {
37  /** @class GazsimTimesource
38  * This time-source provides the simulation time from Gazebo in Fawkes
39  * @author Frederik Zwilling
40  */
42  {
43  public:
44  //Constructor
45  GazsimTimesource(Clock* clock);
46  ///Destructor
48 
49  virtual void get_time(timeval* tv) const;
50  virtual timeval conv_to_realtime(const timeval* tv) const;
51  virtual timeval conv_native_to_exttime(const timeval* tv) const;
52 
53  /// store data from gazebo time message
54  void on_time_sync_msg(ConstSimTimePtr &msg);
55 
56  private:
57  timeval get_system_time() const;
58  timeval add(timeval a, timeval b) const;
59  timeval subtract(timeval a, timeval b) const;
60 
61  private:
62  Clock* clock_;
63 
64  //from last msg all in sec
65  timeval last_sim_time_;
66  timeval last_sys_recv_time_;
67  double last_real_time_factor_;
68  timeval last_native_sim_time_;
69 
70  };
71 
72 }
73 
74 #endif
virtual timeval conv_to_realtime(const timeval *tv) const
Convert a time given w.r.t.
GazsimTimesource(Clock *clock)
Constructor.
Fawkes library namespace.
This is supposed to be the central clock in Fawkes.
Definition: clock.h:34
TimeSource interface.
Definition: timesource.h:36
virtual void get_time(timeval *tv) const
The Simulation time is estimated by looking at the timeinterval to the last received msg and the last...
void on_time_sync_msg(ConstSimTimePtr &msg)
store data from gazebo time message
This time-source provides the simulation time from Gazebo in Fawkes.
virtual timeval conv_native_to_exttime(const timeval *tv) const
Convert a native time to the external time.