xref: /openbmc/phosphor-pid-control/pid/util.cpp (revision 7442c37a)
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*7442c37aSPatrick Venture     info->proportionalCoeff = initial.proportionalCoeff;
28*7442c37aSPatrick Venture     info->integralCoeff = initial.integralCoeff;
29*7442c37aSPatrick Venture     info->feedFwdOffset = initial.feedFwdOffset;
30*7442c37aSPatrick Venture     info->feedFwdGain = initial.feedFwdGain;
31*7442c37aSPatrick Venture     info->integralLimit.min = initial.integralLimit.min;
32*7442c37aSPatrick Venture     info->integralLimit.max = initial.integralLimit.max;
33*7442c37aSPatrick Venture     info->outLim.min = initial.outLim.min;
34*7442c37aSPatrick Venture     info->outLim.max = initial.outLim.max;
35*7442c37aSPatrick Venture     info->slewNeg = initial.slewNeg;
36*7442c37aSPatrick Venture     info->slewPos = initial.slewPos;
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*7442c37aSPatrick Venture     std::cerr << " ts: " << info->ts
44*7442c37aSPatrick Venture               << " proportionalCoeff: " << info->proportionalCoeff
45*7442c37aSPatrick Venture               << " integralCoeff: " << info->integralCoeff
46*7442c37aSPatrick Venture               << " feedFwdOffset: " << info->feedFwdOffset
47*7442c37aSPatrick Venture               << " feedFwdGain: " << info->feedFwdGain
48*7442c37aSPatrick Venture               << " integralLimit.min: " << info->integralLimit.min
49*7442c37aSPatrick Venture               << " integralLimit.max: " << info->integralLimit.max
50*7442c37aSPatrick Venture               << " outLim.min: " << info->outLim.min
51*7442c37aSPatrick Venture               << " outLim.max: " << info->outLim.max
52*7442c37aSPatrick Venture               << " slewNeg: " << info->slewNeg << " slewPos: " << info->slewPos
534b0df320SPatrick Venture               << " last_output: " << info->lastOutput
54da4a5dd1SPatrick Venture               << " integral: " << info->integral << std::endl;
55d8012181SPatrick Venture 
56d8012181SPatrick Venture     return;
57d8012181SPatrick Venture }
58