Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekPid.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekPid.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-11-21 11:07:53 -0700 (Fri, 21 Nov 2014) $
12  * $Rev: 3814 $
13  *
14  * \brief The Hekateros joint position and velocity PID class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2014-2018. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _HEK_PID_H
50 #define _HEK_PID_H
51 
52 #include <math.h>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/log.h"
56 
57 #include "Dynamixel/Dynamixel.h"
58 #include "Dynamixel/DynaPid.h"
59 
60 #include "Hekateros/hekateros.h"
61 #include "Hekateros/hekTune.h"
62 
63 namespace hekateros
64 {
65  // ---------------------------------------------------------------------------
66  // HekPid Class
67  // ---------------------------------------------------------------------------
68 
69  class HekPid : public DynaPid
70  {
71  public:
72  //
73  // Good default PID values for all Hekateros joints.
74  //
75  static const double WI_DFT; ///< integral sum of errors weight const
76 
77  /*!
78  * \brief Default constructor.
79  *
80  * \param fKp PID proportional constant.
81  * \param fKi PID integral constant.
82  * \param fKd PID derivative constant.
83  * \param fWi PID integral sum of errors weight constant.
84  */
85  HekPid(double fKp=HekTunePidKpDft,
86  double fKi=HekTunePidKiDft,
87  double fKd=HekTunePidKdDft,
88  double fWi=WI_DFT) :
89  DynaPid(fKp, fKi, fKd, fWi)
90  {
92  m_fJointGoalPos = 0.0;
93  m_fJointGoalVel = 0.0;
94  m_fJointCurVel = 0.0;
95  }
96 
97  /*!
98  * \brief Copy constructor.
99  */
100  HekPid(const HekPid &src) : DynaPid(src)
101  {
106  }
107 
108  /*!
109  * \brief Destructor.
110  */
111  virtual ~HekPid() { }
112 
113  /*!
114  * \brief Assignment operator.
115  */
116  HekPid &operator=(const HekPid &rhs)
117  {
118  m_fWi = rhs.m_fWi;
119  SetConstants(rhs.m_fKp, rhs.m_fKi, rhs.m_fKd);
120  InitControl();
121 
126 
127  return *this;
128  }
129 
130  /*!
131  * \brief Get the position and velocity PID K parameters.
132  *
133  * \param [out] fKp Proportional gain parameter.
134  * \param [out] fKi Integral gain parameter.
135  * \param [out] fKd Derivative gain parameter.
136  */
137  void getKParams(double &fKp, double &fKi, double &fKd) const
138  {
139  fKp = m_fKp;
140  fKi = m_fKi;
141  fKd = m_fKd;
142  }
143 
144  /*!
145  * \brief Set the position and velocity PID K parameters.
146  *
147  * \param [in] fKp Proportional gain parameter.
148  * \param [in] fKi Integral gain parameter.
149  * \param [in] fKd Derivative gain parameter.
150  *
151  * \return
152  */
153  void setKParams(const double fKp, const double fKi, const double fKd)
154  {
155  m_fKp = fKp;
156  m_fKi = fKi;
157  m_fKd = fKd;
158  }
159 
160  /*!
161  * \brief Get the maximum delta V (ramp) parameter (radians/second).
162  *
163  * \return Maximum delta velocity.
164  */
165  double getMaxDeltaVParam() const
166  {
167  return m_fMaxDeltaV;
168  }
169 
170  /*!
171  * \brief Set the maximum delta V (ramp) parameter (radians/second).
172  *
173  * \param [in] fMaxDeltaV Maximum delta velocity.
174  */
175  void setMaxDeltaVParam(const double fMaxDeltaV)
176  {
177  m_fMaxDeltaV = fMaxDeltaV;
178  }
179 
180  /*!
181  * \brief Specify the PID set point.
182  *
183  * The PID will control the primary postion Set Point SP through the
184  * velocity Control Variable CV. The PID will strive to reach the goal
185  * velocity (secondary SP) while achieving the primary SP.
186  *
187  * \param fJointGoalPos New goal position set point (radians).
188  * \param fJointGoalVel New goal velocity set point (radians/second).
189  */
190  virtual void specifySetPoint(double fJointGoalPos, double fJointGoalVel);
191 
192  /*!
193  * \brief Apply PID control.
194  *
195  * \param fJointCurPos Current joint position (radians).
196  * The primary Process Variable PV.
197  * \param fJointCurVel Current joint velocity (radians/second).
198  * The secondary PV.
199  * \param dt Delta time step (seconds).
200  *
201  * \return Output.
202  */
203  virtual double control(double fJointCurPos,
204  double fJointCurVel,
205  double fDt)
206  {
207  m_fJointCurVel = fJointCurVel;
208  return Control(fJointCurPos, fDt);
209  }
210 
211  protected:
212  double m_fMaxDeltaV; ///< maximum allowd delta v output
213  double m_fJointGoalPos; ///< goal position (primary SP)
214  double m_fJointGoalVel; ///< goal velocity (secondary SP)
215  double m_fJointCurVel; ///< current velocity (secondary PV)
216 
217  /*!
218  * \brief Convert Control Variable to application-specific output value.
219  *
220  * \param fJointTgtVel Raw joint target velocity (radians/second).
221  * The Control Variable CV from PID.
222  *
223  * \return Target velocity.
224  */
225  virtual double toOutput(double fJointTgtVel);
226  };
227 
228 } // namespace hekateros
229 
230 #endif // _HEK_PID_H
double m_fJointGoalPos
goal position (primary SP)
Definition: hekPid.h:213
HekPid(const HekPid &src)
Copy constructor.
Definition: hekPid.h:100
double m_fJointGoalVel
goal velocity (secondary SP)
Definition: hekPid.h:214
static const double HekTunePidKpDft
Default joint position and velocity PID proportional constant.
Definition: hekTune.h:285
static const double HekTunePidDeltaVNoMax
No maximum PID delta V output special value.
Definition: hekTune.h:319
static const double HekTunePidKdDft
Default joint position and velocity PID derivative constant.
Definition: hekTune.h:301
void setMaxDeltaVParam(const double fMaxDeltaV)
Set the maximum delta V (ramp) parameter (radians/second).
Definition: hekPid.h:175
double m_fJointCurVel
current velocity (secondary PV)
Definition: hekPid.h:215
virtual void specifySetPoint(double fJointGoalPos, double fJointGoalVel)
Specify the PID set point.
Definition: hekPid.cxx:71
double getMaxDeltaVParam() const
Get the maximum delta V (ramp) parameter (radians/second).
Definition: hekPid.h:165
void setKParams(const double fKp, const double fKi, const double fKd)
Set the position and velocity PID K parameters.
Definition: hekPid.h:153
virtual ~HekPid()
Destructor.
Definition: hekPid.h:111
virtual double control(double fJointCurPos, double fJointCurVel, double fDt)
Apply PID control.
Definition: hekPid.h:203
static const double WI_DFT
integral sum of errors weight const
Definition: hekPid.h:75
void getKParams(double &fKp, double &fKi, double &fKd) const
Get the position and velocity PID K parameters.
Definition: hekPid.h:137
virtual double toOutput(double fJointTgtVel)
Convert Control Variable to application-specific output value.
Definition: hekPid.cxx:79
static const double HekTunePidKiDft
Default joint position and velocity PID integral constant.
Definition: hekTune.h:293
Top-level package include file.
HekPid & operator=(const HekPid &rhs)
Assignment operator.
Definition: hekPid.h:116
Hekateros tuning.
HekPid(double fKp=HekTunePidKpDft, double fKi=HekTunePidKiDft, double fKd=HekTunePidKdDft, double fWi=WI_DFT)
Default constructor.
Definition: hekPid.h:85
double m_fMaxDeltaV
maximum allowd delta v output
Definition: hekPid.h:212
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56