|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
28 mutable std::mutex mutex;
44 using NowFuncPtr = double (*)();
45 using DelayFuncPtr = void (*)(double);
46 const NowFuncPtr nowFunc;
47 const DelayFuncPtr delayFunc;
58 scheduleReset =
false;
66 sleepPeriod(adaptedPeriod),
94 ret = (totalT / estPIt);
107 av = totalT / estPIt;
109 std = sqrt(((1.0 / (estPIt - 1)) * (sumTSq - estPIt * av * av)));
120 unsigned int ret = count;
132 ret = totalUsed / count;
145 av = totalUsed / count;
147 std = sqrt((1.0 / (count - 1)) * (sumUsedSq - count * av * av));
159 currentRun = nowFunc();
166 double dT = (currentRun - previousRun);
171 if (adaptedPeriod < 0) {
178 previousRun = currentRun;
195 double elapsed = nowFunc() - currentRun;
197 totalUsed += elapsed;
198 sumUsedSq += elapsed * elapsed;
201 sleepPeriod = adaptedPeriod - elapsed;
203 delayFunc(sleepPeriod);
208 while (!isClosing()) {
225 adaptedPeriod = period;
231 return adaptedPeriod;
283 return mPriv->setPeriod(period);
288 return mPriv->getPeriod();
293 return mPriv->isSuspended();
313 return mPriv->start();
318 return mPriv->isRunning();
333 return mPriv->getIterations();
338 return mPriv->getEstimatedPeriod();
343 return mPriv->getEstimatedUsed();
348 mPriv->getEstimatedPeriod(av, std);
353 mPriv->getEstimatedUsed(av, std);
381 return mPriv->setPriority(priority, policy);
386 return mPriv->getPriority();
391 return mPriv->getPolicy();
void threadRelease() override
yarp::rosmsg::std_msgs::Time Time
unsigned int getIterations() const
void resume()
Resume the thread if previously suspended.
int getPolicy() const
Query the current scheduling policy of the thread, if the OS supports that.
int getPriority() const
Query the current priority of the thread, if the OS supports that.
void afterStart(bool s) override
bool threadInit() override
double getEstimatedUsed() const
Return the estimated duration of the run() function since last reset.
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No)
Constructor.
double getPeriod() const
Return the current period of the thread.
virtual void beforeStart()
Called just before a new thread starts.
void getEstimatedPeriod(double &av, double &std) const
bool isRunning() const
Returns true when the thread is started, false otherwise.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
double getEstimatedPeriod() const
Return estimated period since last reset.
bool setPeriod(double period)
double getEstimatedPeriod() const
void beforeStart() override
void useSystemClock()
Configure YARP to use system time (this is the default).
virtual void afterStart(bool success)
Called just after a new thread starts (or fails to start), this is executed by the same thread that c...
void resetStat()
Reset thread statistics.
bool start()
Call this to start the thread.
void yield()
The calling thread releases its remaining quantum upon calling this function.
bool setPeriod(double period)
Set the (new) period of the thread.
double getEstimatedUsed() const
void suspend()
Suspend the thread, the thread keeps running by doLoop is never executed.
An abstraction for a periodic thread.
virtual ~PeriodicThread()
int setPriority(int priority, int policy=-1)
Set the priority and scheduling policy of the thread, if the OS supports that.
void getEstimatedUsed(double &av, double &std) const
void askToStop()
Stop the thread.
An abstraction for a thread of execution.
An interface to the operating system, including Port based communication.
virtual bool threadInit()
Initialization method.
The main, catch-all namespace for YARP.
unsigned int getIterations() const
Return the number of iterations performed since last reset.
bool isSuspended() const
Returns true when the thread is suspended, false otherwise.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
virtual void run()=0
Loop function.
void step()
Call this to "step" the thread rather than starting it.
virtual void threadRelease()
Release method.
The components from which ports and connections are built.
Private(PeriodicThread *owner, double p, ShouldUseSystemClock useSystemClock)
void delay(double seconds)
Wait for a certain number of seconds.