xref: /openbmc/phosphor-pid-control/pid/util.cpp (revision 4b0df320)
1d8012181SPatrick Venture /**
2d8012181SPatrick Venture  * Copyright 2017 Google Inc.
3d8012181SPatrick Venture  *
4d8012181SPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5d8012181SPatrick Venture  * you may not use this file except in compliance with the License.
6d8012181SPatrick Venture  * You may obtain a copy of the License at
7d8012181SPatrick Venture  *
8d8012181SPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9d8012181SPatrick Venture  *
10d8012181SPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11d8012181SPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12d8012181SPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d8012181SPatrick Venture  * See the License for the specific language governing permissions and
14d8012181SPatrick Venture  * limitations under the License.
15d8012181SPatrick Venture  */
16d8012181SPatrick Venture 
17da4a5dd1SPatrick Venture #include "ec/pid.hpp"
18da4a5dd1SPatrick Venture 
19d8012181SPatrick Venture #include <cstring>
20d8012181SPatrick Venture #include <iostream>
21d8012181SPatrick Venture 
227af157b1SPatrick Venture void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial)
23d8012181SPatrick Venture {
24d8012181SPatrick Venture     std::memset(info, 0x00, sizeof(ec::pid_info_t));
25d8012181SPatrick Venture 
26f77d5a57SPatrick Venture     info->ts = initial.ts;
27*4b0df320SPatrick Venture     info->proportionalCoeff = initial.p_c;
28*4b0df320SPatrick Venture     info->integralCoeff = initial.i_c;
29*4b0df320SPatrick Venture     info->feedFwdOffset = initial.ff_off;
30*4b0df320SPatrick Venture     info->feedFwdGain = initial.ff_gain;
31*4b0df320SPatrick Venture     info->integralLimit.min = initial.i_lim.min;
32*4b0df320SPatrick Venture     info->integralLimit.max = initial.i_lim.max;
33*4b0df320SPatrick Venture     info->outLim.min = initial.out_lim.min;
34*4b0df320SPatrick Venture     info->outLim.max = initial.out_lim.max;
35*4b0df320SPatrick Venture     info->slewNeg = initial.slew_neg;
36*4b0df320SPatrick Venture     info->slewPos = initial.slew_pos;
37572c43daSJames Feist     info->negativeHysteresis = initial.negativeHysteresis;
38572c43daSJames Feist     info->positiveHysteresis = initial.positiveHysteresis;
39d8012181SPatrick Venture }
40d8012181SPatrick Venture 
417af157b1SPatrick Venture void dumpPIDStruct(ec::pid_info_t* info)
42d8012181SPatrick Venture {
43*4b0df320SPatrick Venture     std::cerr << " ts: " << info->ts << " p_c: " << info->proportionalCoeff
44*4b0df320SPatrick Venture               << " i_c: " << info->integralCoeff
45*4b0df320SPatrick Venture               << " ff_off: " << info->feedFwdOffset
46*4b0df320SPatrick Venture               << " ff_gain: " << info->feedFwdGain
47*4b0df320SPatrick Venture               << " i_lim.min: " << info->integralLimit.min
48*4b0df320SPatrick Venture               << " i_lim.max: " << info->integralLimit.max
49*4b0df320SPatrick Venture               << " out_lim.min: " << info->outLim.min
50*4b0df320SPatrick Venture               << " out_lim.max: " << info->outLim.max
51*4b0df320SPatrick Venture               << " slew_neg: " << info->slewNeg
52*4b0df320SPatrick Venture               << " slew_pos: " << info->slewPos
53*4b0df320SPatrick Venture               << " last_output: " << info->lastOutput
54da4a5dd1SPatrick Venture               << " integral: " << info->integral << std::endl;
55d8012181SPatrick Venture 
56d8012181SPatrick Venture     return;
57d8012181SPatrick Venture }
58