blob: 6993fbbcb2ac97ff0cbcc8b8ac099e6ac657d467 [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001/**
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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070017#include "ec/pid.hpp"
18
Patrick Ventured8012182018-03-08 08:21:38 -080019#include <cstring>
20#include <iostream>
21
Patrick Venture7af157b2018-10-30 11:24:40 -070022void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial)
Patrick Ventured8012182018-03-08 08:21:38 -080023{
24 std::memset(info, 0x00, sizeof(ec::pid_info_t));
25
Patrick Venturef77d5a52018-10-23 09:32:52 -070026 info->ts = initial.ts;
Patrick Venture4b0df322019-02-11 09:04:57 -080027 info->proportionalCoeff = initial.p_c;
28 info->integralCoeff = initial.i_c;
29 info->feedFwdOffset = initial.ff_off;
30 info->feedFwdGain = initial.ff_gain;
31 info->integralLimit.min = initial.i_lim.min;
32 info->integralLimit.max = initial.i_lim.max;
33 info->outLim.min = initial.out_lim.min;
34 info->outLim.max = initial.out_lim.max;
35 info->slewNeg = initial.slew_neg;
36 info->slewPos = initial.slew_pos;
James Feist572c43d2019-01-31 15:52:22 -080037 info->negativeHysteresis = initial.negativeHysteresis;
38 info->positiveHysteresis = initial.positiveHysteresis;
Patrick Ventured8012182018-03-08 08:21:38 -080039}
40
Patrick Venture7af157b2018-10-30 11:24:40 -070041void dumpPIDStruct(ec::pid_info_t* info)
Patrick Ventured8012182018-03-08 08:21:38 -080042{
Patrick Venture4b0df322019-02-11 09:04:57 -080043 std::cerr << " ts: " << info->ts << " p_c: " << info->proportionalCoeff
44 << " i_c: " << info->integralCoeff
45 << " ff_off: " << info->feedFwdOffset
46 << " ff_gain: " << info->feedFwdGain
47 << " i_lim.min: " << info->integralLimit.min
48 << " i_lim.max: " << info->integralLimit.max
49 << " out_lim.min: " << info->outLim.min
50 << " out_lim.max: " << info->outLim.max
51 << " slew_neg: " << info->slewNeg
52 << " slew_pos: " << info->slewPos
53 << " last_output: " << info->lastOutput
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 << " integral: " << info->integral << std::endl;
Patrick Ventured8012182018-03-08 08:21:38 -080055
56 return;
57}