9 #include <sys/timerfd.h> 16 : _period(period), _name(name) {
22 printf(
"[PeriodicTask] Tried to start %s but it was already running!\n",
33 printf(
"[PeriodicTask] Tried to stop %s but it wasn't running!\n",
38 printf(
"[PeriodicTask] Waiting for %s to stop...\n",
_name.c_str());
40 printf(
"[PeriodicTask] Done!\n");
60 printf(
"|%-20s|%6.4f|%6.4f|%6.4f|%6.4f|%6.4f\n",
_name.c_str(),
66 auto timerFd = timerfd_create(CLOCK_MONOTONIC, 0);
68 int nanoseconds = (int)(1e9 * std::fmod(
_period, 1.
f));
73 timerSpec.it_interval.tv_sec = seconds;
74 timerSpec.it_value.tv_sec = seconds;
75 timerSpec.it_value.tv_nsec = nanoseconds;
76 timerSpec.it_interval.tv_nsec = nanoseconds;
78 timerfd_settime(timerFd, 0, &timerSpec,
nullptr);
79 unsigned long long missed = 0;
81 printf(
"[PeriodicTask] Start %s (%d s, %d ns)\n",
_name.c_str(), seconds,
88 int m = read(timerFd, &missed,
sizeof(missed));
93 printf(
"[PeriodicTask] %s has stopped!\n",
_name.c_str());
99 _tasks.push_back(task);
103 printf(
"\n----------------------------TASKS----------------------------\n");
104 printf(
"|%-20s|%-6s|%-6s|%-6s|%-6s|%-6s\n",
"name",
"rt",
"rt-max",
"T-des",
106 printf(
"-----------------------------------------------------------\n");
107 for (
auto& task : _tasks) {
111 printf(
"-------------------------------------------------------------\n\n");
115 for (
auto& task : _tasks) {
116 if (task->isSlow()) {
124 for (
auto& task : _tasks) {
Implementation of a periodic function running in a separate thread. Periodic tasks have a task manage...
PeriodicTask(PeriodicTaskManager *taskManager, float period, std::string name)
Timer for measuring how long things take.
void printStatusOfSlowTasks()
void printf_color(PrintColor color, const char *fmt,...)
void addTask(PeriodicTask *task)
MX f(const MX &x, const MX &u)