Flatland
timekeeper.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name timekeeper.h
11  * @brief Used for simulation time keeping
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifndef FLATLAND_SERVER_TIME_KEEPER_H
48 #define FLATLAND_SERVER_TIME_KEEPER_H
49 
50 #include <ros/ros.h>
51 #include <ros/time.h>
52 
53 namespace flatland_server {
54 
55 class Timekeeper {
56  public:
57  ros::Publisher clock_pub_;
58  ros::NodeHandle nh_;
59  ros::Time time_;
60  double max_step_size_;
61  const std::string clock_topic_;
62 
66  Timekeeper();
67 
71  void StepTime();
72 
76  void UpdateRosClock() const;
77 
82  void SetMaxStepSize(double step_size);
83 
87  const ros::Time& GetSimTime() const;
88 
92  double GetStepSize() const;
93 
97  double GetMaxStepSize() const;
98 };
99 }; // namespace flatland_server
100 #endif // FLATLAND_SERVER_TIME_KEEPER_H
void SetMaxStepSize(double step_size)
Set the maximum step size.
Definition: timekeeper.cpp:69
double max_step_size_
maximum step size
Definition: timekeeper.h:60
double GetStepSize() const
Definition: timekeeper.cpp:75
ros::Publisher clock_pub_
the topic to publish the clock
Definition: timekeeper.h:57
Definition: body.h:55
double GetMaxStepSize() const
Definition: timekeeper.cpp:77
void UpdateRosClock() const
Publish the clock to ROS.
Definition: timekeeper.cpp:63
Timekeeper()
constructor
Definition: timekeeper.cpp:52
const ros::Time & GetSimTime() const
Definition: timekeeper.cpp:73
ros::NodeHandle nh_
ROS Node handle.
Definition: timekeeper.h:58
void StepTime()
Step time once with the current set of parameters.
Definition: timekeeper.cpp:57
const std::string clock_topic_
the name of the clock topic
Definition: timekeeper.h:61
Definition: timekeeper.h:55
ros::Time time_
simulation time
Definition: timekeeper.h:59