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 24*a076487aSPatrick Venture namespace pid_control 25*a076487aSPatrick Venture { 26*a076487aSPatrick Venture 277af157b1SPatrick Venture void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial) 28d8012181SPatrick Venture { 29d8012181SPatrick Venture std::memset(info, 0x00, sizeof(ec::pid_info_t)); 30d8012181SPatrick Venture 31f77d5a57SPatrick Venture info->ts = initial.ts; 327442c37aSPatrick Venture info->proportionalCoeff = initial.proportionalCoeff; 337442c37aSPatrick Venture info->integralCoeff = initial.integralCoeff; 347442c37aSPatrick Venture info->feedFwdOffset = initial.feedFwdOffset; 357442c37aSPatrick Venture info->feedFwdGain = initial.feedFwdGain; 367442c37aSPatrick Venture info->integralLimit.min = initial.integralLimit.min; 377442c37aSPatrick Venture info->integralLimit.max = initial.integralLimit.max; 387442c37aSPatrick Venture info->outLim.min = initial.outLim.min; 397442c37aSPatrick Venture info->outLim.max = initial.outLim.max; 407442c37aSPatrick Venture info->slewNeg = initial.slewNeg; 417442c37aSPatrick Venture info->slewPos = initial.slewPos; 42572c43daSJames Feist info->negativeHysteresis = initial.negativeHysteresis; 43572c43daSJames Feist info->positiveHysteresis = initial.positiveHysteresis; 44d8012181SPatrick Venture } 45d8012181SPatrick Venture 467af157b1SPatrick Venture void dumpPIDStruct(ec::pid_info_t* info) 47d8012181SPatrick Venture { 487442c37aSPatrick Venture std::cerr << " ts: " << info->ts 497442c37aSPatrick Venture << " proportionalCoeff: " << info->proportionalCoeff 507442c37aSPatrick Venture << " integralCoeff: " << info->integralCoeff 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 59da4a5dd1SPatrick Venture << " integral: " << info->integral << std::endl; 60d8012181SPatrick Venture 61d8012181SPatrick Venture return; 62d8012181SPatrick Venture } 63*a076487aSPatrick Venture 64*a076487aSPatrick Venture } // namespace pid_control 65