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