|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 Open Source Robotics Foundation |
| 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 | +*/ |
| 17 | +%module pid |
| 18 | +%{ |
| 19 | + #include <ignition/math/PID.hh> |
| 20 | +%} |
| 21 | + |
| 22 | +%include "typemaps.i" |
| 23 | +%apply double *OUTPUT { double &_pe, double &_ie, double &_de }; |
| 24 | + |
| 25 | +namespace ignition |
| 26 | +{ |
| 27 | + namespace math |
| 28 | + { |
| 29 | + class PID |
| 30 | + { |
| 31 | + %rename("%(undercase)s", %$isfunction, %$ismember, %$not %$isconstructor) ""; |
| 32 | + public: PID(const double _p = 0.0, |
| 33 | + const double _i = 0.0, |
| 34 | + const double _d = 0.0, |
| 35 | + const double _imax = -1.0, |
| 36 | + const double _imin = 0.0, |
| 37 | + const double _cmdMax = -1.0, |
| 38 | + const double _cmdMin = 0.0, |
| 39 | + const double _cmdOffset = 0.0); |
| 40 | + public: PID(const PID& pid) = default; |
| 41 | + public: ~PID() = default; |
| 42 | + public: void Init(const double _p = 0.0, |
| 43 | + const double _i = 0.0, |
| 44 | + const double _d = 0.0, |
| 45 | + const double _imax = -1.0, |
| 46 | + const double _imin = 0.0, |
| 47 | + const double _cmdMax = -1.0, |
| 48 | + const double _cmdMin = 0.0, |
| 49 | + const double _cmdOffset = 0.0); |
| 50 | + %rename(set_p_gain) SetPGain; |
| 51 | + public: void SetPGain(const double _p); |
| 52 | + %rename(set_i_gain) SetIGain; |
| 53 | + public: void SetIGain(const double _i); |
| 54 | + %rename(set_d_gain) SetDGain; |
| 55 | + public: void SetDGain(const double _d); |
| 56 | + %rename(set_i_max) SetIMax; |
| 57 | + public: void SetIMax(const double _i); |
| 58 | + %rename(set_i_min) SetIMin; |
| 59 | + public: void SetIMin(const double _i); |
| 60 | + public: void SetCmdMax(const double _c); |
| 61 | + public: void SetCmdMin(const double _c); |
| 62 | + public: void SetCmdOffset(const double _c); |
| 63 | + %rename(p_gain) PGain; |
| 64 | + public: double PGain() const; |
| 65 | + %rename(i_gain) IGain; |
| 66 | + public: double IGain() const; |
| 67 | + %rename(d_gain) DGain; |
| 68 | + public: double DGain() const; |
| 69 | + %rename(i_max) IMax; |
| 70 | + public: double IMax() const; |
| 71 | + %rename(i_min) IMin; |
| 72 | + public: double IMin() const; |
| 73 | + public: double CmdMax() const; |
| 74 | + public: double CmdMin() const; |
| 75 | + public: double CmdOffset() const; |
| 76 | + public: void SetCmd(const double _cmd); |
| 77 | + public: double Cmd() const; |
| 78 | + public: void Errors(double &_pe, double &_ie, double &_de) const; |
| 79 | + public: void Reset(); |
| 80 | + }; |
| 81 | + |
| 82 | + %extend PID { |
| 83 | + double Update(const double error, const double dt) { |
| 84 | + return (*$self).Update(error, std::chrono::duration<double>(dt)); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments