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 170c8223b5SJames Feist #include "util.hpp" 180c8223b5SJames Feist 19da4a5dd1SPatrick Venture #include "ec/pid.hpp" 20da4a5dd1SPatrick Venture 21d8012181SPatrick Venture #include <cstring> 22d8012181SPatrick Venture #include <iostream> 23d8012181SPatrick Venture 24a076487aSPatrick Venture namespace pid_control 25a076487aSPatrick Venture { 26a076487aSPatrick Venture 277af157b1SPatrick Venture void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial) 28d8012181SPatrick Venture { 29f77d5a57SPatrick Venture info->ts = initial.ts; 307442c37aSPatrick Venture info->proportionalCoeff = initial.proportionalCoeff; 317442c37aSPatrick Venture info->integralCoeff = initial.integralCoeff; 32*0e8fc398SBonnie Lo info->derivativeCoeff = initial.derivativeCoeff; 337442c37aSPatrick Venture info->feedFwdOffset = initial.feedFwdOffset; 347442c37aSPatrick Venture info->feedFwdGain = initial.feedFwdGain; 357442c37aSPatrick Venture info->integralLimit.min = initial.integralLimit.min; 367442c37aSPatrick Venture info->integralLimit.max = initial.integralLimit.max; 377442c37aSPatrick Venture info->outLim.min = initial.outLim.min; 387442c37aSPatrick Venture info->outLim.max = initial.outLim.max; 397442c37aSPatrick Venture info->slewNeg = initial.slewNeg; 407442c37aSPatrick Venture info->slewPos = initial.slewPos; 41572c43daSJames Feist info->negativeHysteresis = initial.negativeHysteresis; 42572c43daSJames Feist info->positiveHysteresis = initial.positiveHysteresis; 43d8012181SPatrick Venture } 44d8012181SPatrick Venture 457af157b1SPatrick Venture void dumpPIDStruct(ec::pid_info_t* info) 46d8012181SPatrick Venture { 477442c37aSPatrick Venture std::cerr << " ts: " << info->ts 487442c37aSPatrick Venture << " proportionalCoeff: " << info->proportionalCoeff 497442c37aSPatrick Venture << " integralCoeff: " << info->integralCoeff 50*0e8fc398SBonnie Lo << " derivativeCoeff: " << info->derivativeCoeff 517442c37aSPatrick Venture << " feedFwdOffset: " << info->feedFwdOffset 527442c37aSPatrick Venture << " feedFwdGain: " << info->feedFwdGain 537442c37aSPatrick Venture << " integralLimit.min: " << info->integralLimit.min 547442c37aSPatrick Venture << " integralLimit.max: " << info->integralLimit.max 557442c37aSPatrick Venture << " outLim.min: " << info->outLim.min 567442c37aSPatrick Venture << " outLim.max: " << info->outLim.max 577442c37aSPatrick Venture << " slewNeg: " << info->slewNeg << " slewPos: " << info->slewPos 584b0df320SPatrick Venture << " last_output: " << info->lastOutput 59*0e8fc398SBonnie Lo << " last_error: " << info->lastError 60da4a5dd1SPatrick Venture << " integral: " << info->integral << std::endl; 61d8012181SPatrick Venture 62d8012181SPatrick Venture return; 63d8012181SPatrick Venture } 64a076487aSPatrick Venture 65a076487aSPatrick Venture } // namespace pid_control 66