Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekPid.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekPid.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-11-30 19:56:45 -0700 (Sun, 30 Nov 2014) $
12  * $Rev: 3817 $
13  *
14  * The Hekateros joint position and velocity PID class implementation.
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 #include <math.h>
50 
51 #include "rnr/rnrconfig.h"
52 #include "rnr/log.h"
53 
54 #include "Dynamixel/Dynamixel.h"
55 #include "Dynamixel/DynaPid.h"
56 
57 #include "Hekateros/hekateros.h"
58 #include "Hekateros/hekPid.h"
59 #include "Hekateros/hekUtils.h"
60 
61 using namespace std;
62 using namespace hekateros;
63 
64 
65 // -----------------------------------------------------------------------------
66 // HekPid Class
67 // -----------------------------------------------------------------------------
68 
69 const double HekPid::WI_DFT = 0.25; ///< integral sum of errors weight const
70 
71 void HekPid::specifySetPoint(double fJointGoalPos, double fJointGoalVel)
72 {
73  DynaPid::SpecifySetPoint(fJointGoalPos, true);
74 
75  m_fJointGoalPos = fJointGoalPos;
76  m_fJointGoalVel = fJointGoalVel;
77 }
78 
79 double HekPid::toOutput(double fCVJointTgtVel)
80 {
81  double fMax = fabs(m_fJointGoalVel);
82 
83  // limit delta velocity
84  if( m_fMaxDeltaV != HekTunePidDeltaVNoMax )
85  {
86  fCVJointTgtVel = fcap(fCVJointTgtVel, m_fJointCurVel-m_fMaxDeltaV,
87  m_fJointCurVel+m_fMaxDeltaV);
88  }
89 
90  return fcap(fCVJointTgtVel, -fMax, fMax);
91 }
double fcap(double a, double min, double max)
Cap value within limits [min, max].
Definition: hekUtils.h:163
The Hekateros joint position and velocity PID class interface.
Top-level package include file.
Hekateros common utilities.
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56