Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 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 | |
James Feist | 0c8223b | 2019-05-08 15:33:33 -0700 | [diff] [blame] | 17 | #include "util.hpp" |
| 18 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 19 | #include "ec/pid.hpp" |
| 20 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 21 | #include <cstring> |
| 22 | #include <iostream> |
| 23 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 24 | namespace pid_control |
| 25 | { |
| 26 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 27 | void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 28 | { |
| 29 | std::memset(info, 0x00, sizeof(ec::pid_info_t)); |
| 30 | |
Patrick Venture | f77d5a5 | 2018-10-23 09:32:52 -0700 | [diff] [blame] | 31 | info->ts = initial.ts; |
Patrick Venture | 7442c37 | 2019-02-11 10:21:05 -0800 | [diff] [blame] | 32 | info->proportionalCoeff = initial.proportionalCoeff; |
| 33 | info->integralCoeff = initial.integralCoeff; |
| 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; |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 42 | info->negativeHysteresis = initial.negativeHysteresis; |
| 43 | info->positiveHysteresis = initial.positiveHysteresis; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 46 | void dumpPIDStruct(ec::pid_info_t* info) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 47 | { |
Patrick Venture | 7442c37 | 2019-02-11 10:21:05 -0800 | [diff] [blame] | 48 | std::cerr << " ts: " << info->ts |
| 49 | << " proportionalCoeff: " << info->proportionalCoeff |
| 50 | << " integralCoeff: " << info->integralCoeff |
| 51 | << " feedFwdOffset: " << info->feedFwdOffset |
| 52 | << " feedFwdGain: " << info->feedFwdGain |
| 53 | << " integralLimit.min: " << info->integralLimit.min |
| 54 | << " integralLimit.max: " << info->integralLimit.max |
| 55 | << " outLim.min: " << info->outLim.min |
| 56 | << " outLim.max: " << info->outLim.max |
| 57 | << " slewNeg: " << info->slewNeg << " slewPos: " << info->slewPos |
Patrick Venture | 4b0df32 | 2019-02-11 09:04:57 -0800 | [diff] [blame] | 58 | << " last_output: " << info->lastOutput |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 59 | << " integral: " << info->integral << std::endl; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 60 | |
| 61 | return; |
| 62 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 63 | |
| 64 | } // namespace pid_control |