rtt_rosclock_sim_clock_activity.cpp
Go to the documentation of this file.
1 
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2013, Johannes Meyer, TU Darmstadt
6  * Copyright (c) 2013, Intermodalics BVBA
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of TU Darmstadt and Intermodalics BVBA
20  * nor the names of its contributors may be
21  * used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Copyright (c) 2014, Jonathan Bohren, The Johns Hopkins University
38  * - Generalized for multiple time sources
39  * - Integrated with rtt_rosclock package
40  *********************************************************************/
41 
45 
47 #include <rtt/os/TimeService.hpp>
48 #include <rtt/Logger.hpp>
49 
50 #include <boost/weak_ptr.hpp>
51 
52 using namespace RTT::base;
53 using namespace rtt_rosclock;
54 
55 
56 SimClockActivity::SimClockActivity(RunnableInterface* run, const std::string& name)
57 : ActivityInterface(run)
58  , name_(name)
59  , period_(0.0)
60  , running_(false)
61  , active_(false)
62  , manager_(SimClockActivityManager::Instance())
63 {
64  manager_->add(this);
65 }
66 
68 : ActivityInterface(run)
69  , name_(name)
70  , period_(period)
71  , running_(false)
72  , active_(false)
73  , manager_(SimClockActivityManager::Instance())
74 {
75  manager_->add(this);
76 }
77 
79 {
80  stop();
81  manager_->remove(this);
82 }
83 
85 {
86  if (period_ > 0.0)
87  return period_;
88  else
89  return manager_->getSimulationPeriod();
90 }
91 
93 {
94  return true;
95 }
96 
98 {
99  period_ = s;
100  return true;
101 }
102 
104 {
105  return ~0;
106 }
107 
109 {
110  return false;
111 }
112 
114 {
115  return SimClockThread::GetInstance().get();
116 }
117 
119 {
120  return true;
121 }
122 
124 {
125 }
126 
127 #if defined(RTT_VERSION_GTE)
128 #if RTT_VERSION_GTE(2,9,0)
129 void SimClockActivity::work(RunnableInterface::WorkReason)
130 {
131 }
132 #endif
133 #endif
134 
136 {
137  this->step();
138 }
139 
141 {
142  return false;
143 }
144 
146 {
147 }
148 
150 {
151  if ( active_ == true )
152  {
153  RTT::log(RTT::Error) << "Unable to start slave as it is already started" << RTT::endlog();
154  return false;
155  }
156 
157  active_ = true;
158  last_ = 0;
159 
160  if ( runner ? runner->initialize() : this->initialize() ) {
161  running_ = true;
162  } else {
163  active_ = false;
164  }
165 
166  return active_;
167 }
168 
170 {
171  if ( !active_ )
172  return false;
173 
174  running_ = false;
175  if (runner)
176  runner->finalize();
177  else
178  this->finalize();
179  active_ = false;
180  return true;
181 }
182 
184 {
185  return running_;
186 }
187 
189 {
190  return active_;
191 }
192 
194 {
195  return false;
196 }
197 
199 {
200  return false;
201 }
202 
204 {
205  if (!running_) return false;
206  if (runner) {
207  runner->step();
208 #if defined(RTT_VERSION_GTE)
209 #if RTT_VERSION_GTE(2,9,0)
210  runner->work(RunnableInterface::TimeOut);
211 #endif
212 #endif
213  } else {
214  this->step();
215 #if defined(RTT_VERSION_GTE)
216 #if RTT_VERSION_GTE(2,9,0)
217  this->work(RunnableInterface::TimeOut);
218 #endif
219 #endif
220  }
222  return true;
223 }
224 
226 {
227  return last_;
228 }
virtual void work(WorkReason reason)
double Seconds
bool active_
True if start() has been called.
RTT::Seconds period_
The desired minimum execution period.
bool running_
True after start() has succeeded.
SimClockActivity(RTT::base::RunnableInterface *run=0, const std::string &name="SimClockActivity")
static boost::shared_ptr< SimClockThread > GetInstance()
Get an instance to the singleton SimClockThread or NULL.
static TimeService * Instance()
virtual bool run(RunnableInterface *r)
RunnableInterface * runner
A centralized list of all TaskContexts using SimClockActivity.
virtual RTT::os::TimeService::ticks getLastExecutionTicks() const
virtual bool initialize()=0
boost::shared_ptr< SimClockActivityManager > manager_
Parent activity manager.
RTT::os::TimeService::ticks last_
The last time the activity was executed.
static Logger & log()
virtual RTT::os::ThreadInterface * thread()
static Logger::LogFunction endlog()
ticks getTicks() const


rtt_rosclock
Author(s):
autogenerated on Sat Jun 8 2019 18:06:00