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 "util.hpp" 18 19 #include "ec/pid.hpp" 20 21 #include <cstring> 22 #include <iostream> 23 24 namespace pid_control 25 { 26 27 void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial) 28 { 29 info->checkHysterWithSetpt = initial.checkHysterWithSetpt; 30 info->ts = initial.ts; 31 info->proportionalCoeff = initial.proportionalCoeff; 32 info->integralCoeff = initial.integralCoeff; 33 info->derivativeCoeff = initial.derivativeCoeff; 34 info->feedFwdOffset = initial.feedFwdOffset; 35 info->feedFwdGain = initial.feedFwdGain; 36 info->integralLimit.min = initial.integralLimit.min; 37 info->integralLimit.max = initial.integralLimit.max; 38 info->outLim.min = initial.outLim.min; 39 info->outLim.max = initial.outLim.max; 40 info->slewNeg = initial.slewNeg; 41 info->slewPos = initial.slewPos; 42 info->negativeHysteresis = initial.negativeHysteresis; 43 info->positiveHysteresis = initial.positiveHysteresis; 44 } 45 46 void dumpPIDStruct(ec::pid_info_t* info) 47 { 48 std::cerr << " ts: " << info->ts 49 << " proportionalCoeff: " << info->proportionalCoeff 50 << " integralCoeff: " << info->integralCoeff 51 << " derivativeCoeff: " << info->derivativeCoeff 52 << " feedFwdOffset: " << info->feedFwdOffset 53 << " feedFwdGain: " << info->feedFwdGain 54 << " integralLimit.min: " << info->integralLimit.min 55 << " integralLimit.max: " << info->integralLimit.max 56 << " outLim.min: " << info->outLim.min 57 << " outLim.max: " << info->outLim.max 58 << " slewNeg: " << info->slewNeg << " slewPos: " << info->slewPos 59 << " last_output: " << info->lastOutput 60 << " last_error: " << info->lastError 61 << " integral: " << info->integral << std::endl; 62 63 return; 64 } 65 66 } // namespace pid_control 67