|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
24 # include <mmsystem.h>
35 bool clock_owned =
false;
36 bool network_clock_ok =
false;
37 Clock* pclock =
nullptr;
40 std::mutex& getTimeMutex()
42 static std::mutex mutex;
46 void printNoClock_ErrorMessage()
48 yCError(TIME,
"Warning an issue has been found, please update the code.");
49 yCError(TIME,
" Clock is not initialized.");
50 yCError(TIME,
" This means YARP framework has not been properly initialized.");
51 yCError(TIME,
" The clock can be initialized with one of the following methods:");
52 yCError(TIME,
" - Create yarp::os::Network object or call yarp::os::Network::init()");
53 yCError(TIME,
" - Call useSystemClock()");
54 yCError(TIME,
" otherwise use yarp::os::SystemClock::nowSystem() and yarp::os::SystemClock::delaySystem() instead of Time::now() and Time::delay()");
59 if (pclock ==
nullptr) {
77 printNoClock_ErrorMessage();
87 if (pclock !=
nullptr) {
99 timeGetDevCaps(&tm,
sizeof(TIMECAPS));
100 timeBeginPeriod(tm.wPeriodMin);
109 timeGetDevCaps(&tm,
sizeof(TIMECAPS));
110 timeEndPeriod(tm.wPeriodMin);
120 Clock* clk = getClock();
130 Clock* clk = getClock();
134 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
139 #endif // YARP_NO_DEPRECATED
150 getTimeMutex().lock();
152 Clock* old_pclock = pclock;
153 bool old_clock_owned = clock_owned;
160 if (old_clock_owned && (old_pclock !=
nullptr)) {
164 getTimeMutex().unlock();
192 getTimeMutex().lock();
194 Clock* old_pclock = pclock;
195 bool old_clock_owned = clock_owned;
197 if (_networkClock ==
nullptr) {
198 yCFatal(TIME,
"failed creating NetworkClock client");
201 if (_networkClock->open(clock, localPortName)) {
202 network_clock_ok =
true;
205 pclock = _networkClock;
209 yCFatal(TIME,
"failed creating NetworkClock client, cannot open input port");
213 if (old_clock_owned && (old_pclock !=
nullptr)) {
217 getTimeMutex().unlock();
220 while ((pclock !=
nullptr) && !pclock->
isValid()) {
223 yCInfo(TIME,
"Waiting for clock server to start broadcasting data ...");
232 if (clock ==
nullptr) {
233 yCFatal(TIME,
"failed configuring CustomClock client");
238 yCFatal(TIME,
"Error: CustomClock is not valid");
242 getTimeMutex().lock();
245 Clock* old_pclock = pclock;
246 bool old_clock_owned = clock_owned;
253 if (old_clock_owned && (old_pclock !=
nullptr)) {
257 getTimeMutex().unlock();
282 return yarp_clock_type;
287 std::string clockTypeString;
289 type = yarp_clock_type;
294 clockTypeString =
"System clock";
298 clockTypeString =
"Network clock";
302 clockTypeString =
"Custom clock";
306 clockTypeString =
"Clock has not been initialized yet: This should never happen. Is the object yarp::os::Network been initialized?";
310 clockTypeString =
"Unknown clock: This should never happen. Is the object yarp::os::Network been initialized?";
313 return clockTypeString;
320 return getClock()->isValid();
@ YARP_CLOCK_UNINITIALIZED
static void yield()
Reschedule the execution of current thread, allowing other threads to run.
bool isValid()
Check if time is valid (non-zero).
virtual void delay(double seconds)=0
Wait for a certain number of seconds.
bool isCustomClock()
Check if YARP is using a user-defined custom time.
void startTurboBoost()
For OS where it makes sense sets the scheduler to be called more often.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
static double nowSystem()
void useSystemClock()
Configure YARP to use system time (this is the default).
static void delaySystem(double seconds)
yarpClockType getClockType()
void yield()
The calling thread releases its remaining quantum upon calling this function.
void turboBoost()
For OS where it makes sense sets the scheduler to be called more often.
virtual double now()=0
Return the current time in seconds, relative to an arbitrary starting point.
void useNetworkClock(const std::string &clock, const std::string &localPortName="")
Configure YARP to read time from a specified topic.
#define yCAssert(component, x)
#define yCError(component,...)
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
bool isSystemClock()
Check if YARP is providing system time.
std::string clockTypeToString(yarpClockType type)
Converts clock type enum into string.
bool isClockInitialized()
Check if YARP clock is initialized.
void useCustomClock(Clock *clock)
Configure YARP clients to use a custom clock source provided by the user.
#define YARP_OS_LOG_COMPONENT(name, name_string)
virtual bool isValid() const =0
Check if time is valid (non-zero).
void delay(double seconds)
Wait for a certain number of seconds.
bool isNetworkClock()
Check if YARP is providing network time.
#define yCFatal(component,...)