blob: ac6edb1dde0d31190ae005bd6d8c04aaef5553eb [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
James Feist0c8223b2019-05-08 15:33:33 -070017#include "util.hpp"
18
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019#include "ec/pid.hpp"
20
Patrick Ventured8012182018-03-08 08:21:38 -080021#include <cstring>
22#include <iostream>
23
Patrick Venturea0764872020-08-08 07:48:43 -070024namespace pid_control
25{
26
Patrick Venture7af157b2018-10-30 11:24:40 -070027void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial)
Patrick Ventured8012182018-03-08 08:21:38 -080028{
Patrick Venturef77d5a52018-10-23 09:32:52 -070029 info->ts = initial.ts;
Patrick Venture7442c372019-02-11 10:21:05 -080030 info->proportionalCoeff = initial.proportionalCoeff;
31 info->integralCoeff = initial.integralCoeff;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080032 info->derivativeCoeff = initial.derivativeCoeff;
Patrick Venture7442c372019-02-11 10:21:05 -080033 info->feedFwdOffset = initial.feedFwdOffset;
34 info->feedFwdGain = initial.feedFwdGain;
35 info->integralLimit.min = initial.integralLimit.min;
36 info->integralLimit.max = initial.integralLimit.max;
37 info->outLim.min = initial.outLim.min;
38 info->outLim.max = initial.outLim.max;
39 info->slewNeg = initial.slewNeg;
40 info->slewPos = initial.slewPos;
James Feist572c43d2019-01-31 15:52:22 -080041 info->negativeHysteresis = initial.negativeHysteresis;
42 info->positiveHysteresis = initial.positiveHysteresis;
Patrick Ventured8012182018-03-08 08:21:38 -080043}
44
Patrick Venture7af157b2018-10-30 11:24:40 -070045void dumpPIDStruct(ec::pid_info_t* info)
Patrick Ventured8012182018-03-08 08:21:38 -080046{
Patrick Venture7442c372019-02-11 10:21:05 -080047 std::cerr << " ts: " << info->ts
48 << " proportionalCoeff: " << info->proportionalCoeff
49 << " integralCoeff: " << info->integralCoeff
Bonnie Lo0e8fc392022-10-05 10:20:55 +080050 << " derivativeCoeff: " << info->derivativeCoeff
Patrick Venture7442c372019-02-11 10:21:05 -080051 << " 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 Venture4b0df322019-02-11 09:04:57 -080058 << " last_output: " << info->lastOutput
Bonnie Lo0e8fc392022-10-05 10:20:55 +080059 << " last_error: " << info->lastError
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 << " integral: " << info->integral << std::endl;
Patrick Ventured8012182018-03-08 08:21:38 -080061
62 return;
63}
Patrick Venturea0764872020-08-08 07:48:43 -070064
65} // namespace pid_control