GCC Code Coverage Report


Directory: src/
File: src/TimeIntegrator.cpp
Date: 2026-09-03 17:04:53
Exec Total Coverage
Lines: 0 39 0.0%
Branches: 0 46 0.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2021 Jonathan Grahl <jonathan.grahl@igh.de>
4 * 2021 Florian Pose <florian.pose@igh.de>
5 *
6 * This file is part of the reta library (realtime-automation).
7 *
8 * The reta library is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation, either version 3 of the License, or (at
11 * your option) any later version.
12 *
13 * The reta library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with the reta library. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
23 #include "reta/TimeIntegrator.h"
24
25 #include "Base.h"
26 #include "reta/UserParameter.h"
27
28 using std::function;
29 using std::make_unique;
30 using std::shared_ptr;
31 using std::string;
32 using std::vector;
33
34 using namespace Reta;
35
36 /****************************************************************************/
37
38 struct RETA_LOCAL TimeIntegrator::Impl : public Base
39 {
40 Impl(shared_ptr<Task>, const string &, unsigned int);
41
42 shared_ptr<Task> task;
43
44 vector<double> time;
45 vector<double> offset;
46
47 UserParameter addOffset;
48 UserParameter reset;
49 };
50
51 /****************************************************************************/
52
53 TimeIntegrator::Impl::Impl(
54 shared_ptr<Task> task,
55 const string &prefix,
56 unsigned int width) :
57 Base {prefix},
58 task {task},
59 time(width, 0.0),
60 offset(width, 0.0),
61 addOffset(task, prefix + "/AddOffset", width),
62 reset(task, prefix + "/Reset", width)
63 {
64 checkZeroWidth(width);
65
66 pdserv *pdserv {task->getPdServ()};
67 pdtask *pdtask {task->getPdTask()};
68
69 pdserv_signal(
70 pdtask, 1, (prefix + "/Time").c_str(), pd_double_T, time.data(),
71 time.size(), NULL);
72 pdserv_parameter(
73 pdserv, (prefix + "/Offset").c_str(), 0666, pd_double_T,
74 offset.data(), offset.size(), NULL, NULL, NULL);
75 }
76
77 /****************************************************************************/
78
79 TimeIntegrator::TimeIntegrator(
80 shared_ptr<Task> task,
81 const string &prefix,
82 unsigned int width) :
83 impl {make_unique<Impl>(task, prefix, width)}
84 {}
85
86 /****************************************************************************/
87
88 TimeIntegrator::~TimeIntegrator()
89 {}
90
91 /****************************************************************************/
92
93 void TimeIntegrator::update(bool integrate)
94 {
95 update(vector<uint8_t> {integrate});
96 }
97
98 /****************************************************************************/
99
100 void TimeIntegrator::update(function<bool(unsigned int)> integrate)
101 {
102 vector<uint8_t> integrateVector(impl->time.size());
103 for (unsigned int i = 0; i < impl->time.size(); i++) {
104 integrateVector[i] = integrate(i);
105 }
106
107 update(integrateVector);
108 }
109
110 /****************************************************************************/
111
112 void TimeIntegrator::update(const vector<uint8_t> &integrate)
113 {
114 impl->checkSize(integrate, impl->time);
115
116 impl->addOffset.update();
117 impl->reset.update();
118
119 for (unsigned int i = 0; i < impl->time.size(); i++) {
120 if (integrate[i]) {
121 impl->time[i] += impl->task->getPeriod();
122 }
123
124 if (impl->addOffset.getChanged(i)) {
125 impl->time[i] += impl->offset[i];
126 }
127
128 if (impl->reset.getChanged(i)) {
129 impl->time[i] = 0.0;
130 }
131 }
132 }
133
134 /****************************************************************************/
135
136 double TimeIntegrator::getTime(unsigned int i) const
137 {
138 return impl->time.at(i);
139 }
140
141 /****************************************************************************/
142
143 vector<double> TimeIntegrator::getTimeVector() const
144 {
145 return impl->time;
146 }
147
148 /****************************************************************************/
149