Libbarrett
1.2.4
|
00001 /* 00002 Copyright 2009, 2010 Barrett Technology <support@barrett.com> 00003 00004 This file is part of libbarrett. 00005 00006 This version of libbarrett is free software: you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License as 00008 published by the Free Software Foundation, either version 3 of the 00009 License, or (at your option) any later version. 00010 00011 This version of libbarrett is distributed in the hope that it will be 00012 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License along 00017 with this version of libbarrett. If not, see 00018 <http://www.gnu.org/licenses/>. 00019 00020 Further, non-binding information about licensing is available at: 00021 <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes> 00022 */ 00023 00024 /* 00025 * pid_controller.h 00026 * 00027 * Created on: Oct 20, 2009 00028 * Author: dc 00029 */ 00030 00031 #ifndef BARRETT_SYSTEMS_PID_CONTROLLER_H_ 00032 #define BARRETT_SYSTEMS_PID_CONTROLLER_H_ 00033 00034 00035 #include <Eigen/Core> 00036 #include <libconfig.h++> 00037 00038 #include <barrett/detail/ca_macro.h> 00039 #include <barrett/math/traits.h> 00040 #include <barrett/systems/abstract/execution_manager.h> 00041 #include <barrett/systems/abstract/controller.h> 00042 00043 00044 namespace barrett { 00045 namespace systems { 00046 00047 00048 // TODO(dc): rewrite as a PIDFilter + Controller<SingleIO> 00049 00050 template<typename InputType, 00051 typename OutputType = typename InputType::actuator_type, 00052 typename MathTraits = math::Traits<InputType> > 00053 class PIDController : public Controller<InputType, OutputType> { 00054 public: 00055 typedef typename MathTraits::unitless_type unitless_type; 00056 00057 explicit PIDController(const std::string& sysName = "PIDController"); 00058 explicit PIDController(const libconfig::Setting& setting, const std::string& sysName = "PIDController"); 00059 virtual ~PIDController() { this->mandatoryCleanUp(); } 00060 00061 void setFromConfig(const libconfig::Setting& setting); 00062 void setKp(const unitless_type& proportionalGains); 00063 void setKi(const unitless_type& integralGains); 00064 void setKd(const unitless_type& derivitiveGains); 00065 void setIntegratorState(const unitless_type& integratorState); 00066 void setIntegratorLimit(const unitless_type& intSaturations); 00067 void setControlSignalLimit(const unitless_type& csSaturations); 00068 00069 void resetIntegrator(); 00070 00071 unitless_type& getKp() { return kp; } 00072 const unitless_type& getKp() const { return kp; } 00073 unitless_type& getKi() { return ki; } 00074 const unitless_type& getKi() const { return ki; } 00075 unitless_type& getKd() { return kd; } 00076 const unitless_type& getKd() const { return kd; } 00077 const unitless_type& getIntegratorState() const { return intError; } 00078 unitless_type& getIntegratorLimit() { return intErrorLimit; } 00079 const unitless_type& getIntegratorLimit() const { return intErrorLimit; } 00080 OutputType& getControlSignalLimit() { return controlSignalLimit; } 00081 const OutputType& getControlSignalLimit() const { return controlSignalLimit; } 00082 00083 protected: 00084 void setSamplePeriod(double timeStep); 00085 00086 virtual void operate(); 00087 virtual void onExecutionManagerChanged() { 00088 Controller<InputType, OutputType>::onExecutionManagerChanged(); // First, call super 00089 getSamplePeriodFromEM(); 00090 } 00091 00092 double T_s; 00093 InputType error, error_1; 00094 unitless_type intError, intErrorLimit; 00095 unitless_type kp, ki, kd; 00096 OutputType controlSignal, controlSignalLimit; 00097 // unitless_type controlSignal, controlSignalLimit; 00098 00099 void getSamplePeriodFromEM(); 00100 00101 private: 00102 DISALLOW_COPY_AND_ASSIGN(PIDController); 00103 00104 public: 00105 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(MathTraits::RequiresAlignment) 00106 }; 00107 00108 00109 } 00110 } 00111 00112 00113 // include template definitions 00114 #include <barrett/systems/detail/pid_controller-inl.h> 00115 00116 00117 #endif /* BARRETT_SYSTEMS_PID_CONTROLLER_H_ */