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 "../msgs/SimTime.pb.h"
24
25#include <utils/time/clock.h>
26#include <utils/time/timesource.h>
27
28#include <boost/asio.hpp>
29
30#ifndef _GAZEBO_TIMESOURCE_H_
31# define _GAZEBO_TIMESOURCE_H_
32
33typedef const boost::shared_ptr<gazsim_msgs::SimTime const> ConstSimTimePtr;
34
35namespace fawkes {
36/** @class GazsimTimesource
37 * This time-source provides the simulation time from Gazebo in Fawkes
38 * @author Frederik Zwilling
39 */
41{
42public:
43 //Constructor
44 GazsimTimesource(Clock *clock);
45 ///Destructor
47
48 virtual void get_time(timeval *tv) const;
49 virtual timeval conv_to_realtime(const timeval *tv) const;
50 virtual timeval conv_native_to_exttime(const timeval *tv) const;
51
52 /// store data from gazebo time message
53 void on_time_sync_msg(ConstSimTimePtr &msg);
54
55private:
56 timeval get_system_time() const;
57 timeval add(timeval a, timeval b) const;
58 timeval subtract(timeval a, timeval b) const;
59
60private:
61 Clock *clock_;
62
63 //from last msg all in sec
64 timeval last_sim_time_;
65 timeval last_sys_recv_time_;
66 double last_real_time_factor_;
67 timeval last_native_sim_time_;
68};
69
70} // namespace fawkes
71
72#endif
This is supposed to be the central clock in Fawkes.
Definition: clock.h:35
This time-source provides the simulation time from Gazebo in Fawkes.
void on_time_sync_msg(ConstSimTimePtr &msg)
store data from gazebo time message
GazsimTimesource(Clock *clock)
Constructor.
virtual timeval conv_native_to_exttime(const timeval *tv) const
Convert a native time to the external time.
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...
virtual timeval conv_to_realtime(const timeval *tv) const
Convert a time given w.r.t.
TimeSource interface.
Definition: timesource.h:37
Fawkes library namespace.