kinecalc.hpp
Go to the documentation of this file.
1 /*
2  * P2OS for ROS
3  * Copyright (C) 2009
4  * David Feil-Seifer, Brian Gerkey, Kasper Stoy,
5  * Richard Vaughan, & Andrew Howard
6  * Copyright (C) 2018
7  * Hunter L. Allen
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *
23  */
24 #ifndef P2OS_DRIVER__KINECALC_HPP_
25 #define P2OS_DRIVER__KINECALC_HPP_
26 #include <cstdio>
27 
28 // Basic vector
29 typedef struct
30 {
31  double x, y, z;
32 } KineVector;
33 
34 // Struct that describes the pose of the end effector
35 // (result of FK)
36 typedef struct
37 {
42 } EndEffector;
43 
44 class KineCalc
45 {
46 public:
47  KineCalc(void);
48 
49  // Kinematics functions
50  void CalculateFK(const double fromJoints[]);
51  bool CalculateIK(const EndEffector & fromPosition);
52 
53  // Accessor functions
54  const KineVector & GetP(void) const {return endEffector.p;}
55  const KineVector & GetN(void) const {return endEffector.n;}
56  const KineVector & GetO(void) const {return endEffector.o;}
57  const KineVector & GetA(void) const {return endEffector.a;}
58  void SetP(const KineVector & newP)
59  {
60  endEffector.p.x = newP.x; endEffector.p.y = newP.y; endEffector.p.z = newP.z;
61  }
62  void SetN(const KineVector & newN)
63  {
64  endEffector.n.x = newN.x; endEffector.n.y = newN.y; endEffector.n.z = newN.z;
65  }
66  void SetO(const KineVector & newO)
67  {
68  endEffector.o.x = newO.x; endEffector.o.y = newO.y; endEffector.o.z = newO.z;
69  }
70  void SetA(const KineVector & newA)
71  {
72  endEffector.a.x = newA.x; endEffector.a.y = newA.y; endEffector.a.z = newA.z;
73  }
74  void SetP(double newPX, double newPY, double newPZ);
75  void SetN(double newNX, double newNY, double newNZ);
76  void SetO(double newOX, double newOY, double newOZ);
77  void SetA(double newAX, double newAY, double newAZ);
78 
79  double GetTheta(unsigned int index);
80  const double * GetThetas(void) const {return joints;}
81  void SetTheta(unsigned int index, double newVal);
82  void SetLinkLengths(
83  double newLink1, double newLink2, double newLink3, double newLink4,
84  double newLink5);
85  void SetOffset(unsigned int joint, double newOffset);
86  void SetJointRange(unsigned int joint, double min, double max);
87 
88  // Use this to calculate N
89  KineVector CalculateN(const EndEffector & pose);
90  KineVector Normalise(const KineVector & vector);
91 
92 protected:
93  void CalcTheta4and5(double angles[], const EndEffector & fromPosition);
94  int ChooseSolution(const EndEffector & fromPosition, const double solutions[][5]);
95  double CalcSolutionError(const double solution[], const EndEffector & fromPosition);
96  EndEffector CalcFKForJoints(const double angles[]);
97  bool SolutionInRange(const double angles[]);
98 
100 
101  // The 4 vectors that describe the position and orientation of the
102  // end effector.
103  // These should be computed when performing forward kinematics
104  // and are used to provide data to the client.
106 
107  // The 5 joint angles.
108  // These are computed when performing inverse kinematics and
109  // are used for positioning the arm.
110  double joints[5];
111  // Joint offsets, as calibrated and supplied in the config file
112  double jointOffsets[5];
113  // Joint ranges
114  double jointMin[5];
115  double jointMax[5];
116 
117  // The link lengths are required for any of the kinematics to be useful.
118  // I can't see them changing, but just in case better to have the ability to
119  // specify them in the config file.
121 };
122 #endif // P2OS_DRIVER__KINECALC_HPP_
double jointOffsets[5]
Definition: kinecalc.hpp:112
const KineVector & GetO(void) const
Definition: kinecalc.hpp:56
double CalcSolutionError(const double solution[], const EndEffector &fromPosition)
Definition: kinecalc.cpp:404
void CalculateFK(const double fromJoints[])
Definition: kinecalc.cpp:180
double x
Definition: kinecalc.hpp:31
double joints[5]
Definition: kinecalc.hpp:110
const KineVector & GetP(void) const
Definition: kinecalc.hpp:54
bool CalculateIK(const EndEffector &fromPosition)
Definition: kinecalc.cpp:199
const double * GetThetas(void) const
Definition: kinecalc.hpp:80
TFSIMD_FORCE_INLINE const tfScalar & y() const
void SetO(const KineVector &newO)
Definition: kinecalc.hpp:66
bool SolutionInRange(const double angles[])
Definition: kinecalc.cpp:466
double link1
Definition: kinecalc.hpp:120
void SetJointRange(unsigned int joint, double min, double max)
Definition: kinecalc.cpp:107
void SetOffset(unsigned int joint, double newOffset)
Definition: kinecalc.cpp:102
double link4
Definition: kinecalc.hpp:120
void SetLinkLengths(double newLink1, double newLink2, double newLink3, double newLink4, double newLink5)
Definition: kinecalc.cpp:91
double link2
Definition: kinecalc.hpp:120
void SetTheta(unsigned int index, double newVal)
Definition: kinecalc.cpp:86
double jointMax[5]
Definition: kinecalc.hpp:115
KineVector p
Definition: kinecalc.hpp:38
void SetN(const KineVector &newN)
Definition: kinecalc.hpp:62
double GetTheta(unsigned int index)
Definition: kinecalc.cpp:81
KineVector n
Definition: kinecalc.hpp:39
KineVector o
Definition: kinecalc.hpp:40
KineVector CalculateN(const EndEffector &pose)
Definition: kinecalc.cpp:135
TFSIMD_FORCE_INLINE const tfScalar & x() const
double link5
Definition: kinecalc.hpp:120
double min(double a, double b)
const KineVector & GetA(void) const
Definition: kinecalc.hpp:57
void SetP(const KineVector &newP)
Definition: kinecalc.hpp:58
double y
Definition: kinecalc.hpp:31
void PrintEndEffector(const EndEffector &endEffector)
Definition: kinecalc.cpp:163
EndEffector endEffector
Definition: kinecalc.hpp:105
double jointMin[5]
Definition: kinecalc.hpp:114
EndEffector CalcFKForJoints(const double angles[])
Definition: kinecalc.cpp:426
double z
Definition: kinecalc.hpp:31
void CalcTheta4and5(double angles[], const EndEffector &fromPosition)
Definition: kinecalc.cpp:332
int ChooseSolution(const EndEffector &fromPosition, const double solutions[][5])
Definition: kinecalc.cpp:373
const KineVector & GetN(void) const
Definition: kinecalc.hpp:55
KineVector a
Definition: kinecalc.hpp:41
void SetA(const KineVector &newA)
Definition: kinecalc.hpp:70
double max(double a, double b)
double link3
Definition: kinecalc.hpp:120
KineCalc(void)
Definition: kinecalc.cpp:27
KineVector Normalise(const KineVector &vector)
Definition: kinecalc.cpp:118


p2os_driver
Author(s): Hunter L. Allen , David Feil-Seifer , Aris Synodinos , Brian Gerkey, Kasper Stoy, Richard Vaughan, Andrew Howard, Tucker Hermans, ActivMedia Robotics LLC, MobileRobots Inc.
autogenerated on Sat Jun 20 2020 03:29:42