Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds python interface to PID and SemanticVersion. #229

Merged
merged 3 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ if (SWIG_FOUND)
set(swig_files
Angle
GaussMarkovProcess
PID
Rand
SemanticVersion
Vector2
Vector3
Vector4)
Expand Down Expand Up @@ -70,8 +72,10 @@ if (PYTHONLIBS_FOUND)
set(python_tests
Angle_TEST
GaussMarkovProcess_TEST
PID_TEST
python_TEST
Rand_TEST
SemanticVersion_TEST
Vector2_TEST
Vector3_TEST
Vector4_TEST
Expand Down
88 changes: 88 additions & 0 deletions src/python/PID.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
%module pid
%{
#include <ignition/math/PID.hh>
%}

%include "typemaps.i"
%apply double *OUTPUT { double &_pe, double &_ie, double &_de };

namespace ignition
{
namespace math
{
class PID
{
%rename("%(undercase)s", %$isfunction, %$ismember, %$not %$isconstructor) "";
public: PID(const double _p = 0.0,
const double _i = 0.0,
const double _d = 0.0,
const double _imax = -1.0,
const double _imin = 0.0,
const double _cmdMax = -1.0,
const double _cmdMin = 0.0,
const double _cmdOffset = 0.0);
public: PID(const PID& pid) = default;
public: ~PID() = default;
public: void Init(const double _p = 0.0,
const double _i = 0.0,
const double _d = 0.0,
const double _imax = -1.0,
const double _imin = 0.0,
const double _cmdMax = -1.0,
const double _cmdMin = 0.0,
const double _cmdOffset = 0.0);
%rename(set_p_gain) SetPGain;
public: void SetPGain(const double _p);
%rename(set_i_gain) SetIGain;
public: void SetIGain(const double _i);
%rename(set_d_gain) SetDGain;
public: void SetDGain(const double _d);
%rename(set_i_max) SetIMax;
public: void SetIMax(const double _i);
%rename(set_i_min) SetIMin;
public: void SetIMin(const double _i);
public: void SetCmdMax(const double _c);
public: void SetCmdMin(const double _c);
public: void SetCmdOffset(const double _c);
%rename(p_gain) PGain;
public: double PGain() const;
%rename(i_gain) IGain;
public: double IGain() const;
%rename(d_gain) DGain;
public: double DGain() const;
%rename(i_max) IMax;
public: double IMax() const;
%rename(i_min) IMin;
public: double IMin() const;
public: double CmdMax() const;
public: double CmdMin() const;
public: double CmdOffset() const;
public: void SetCmd(const double _cmd);
public: double Cmd() const;
public: void Errors(double &_pe, double &_ie, double &_de) const;
public: void Reset();
};

%extend PID {
double Update(const double error, const double dt) {
return (*$self).Update(error, std::chrono::duration<double>(dt));
}
}
}
}
Loading