kinecalc.hpp
Go to the documentation of this file.
00001 /*
00002  *  P2OS for ROS
00003  *  Copyright (C) 2009
00004  *     David Feil-Seifer, Brian Gerkey, Kasper Stoy,
00005  *      Richard Vaughan, & Andrew Howard
00006  *  Copyright (C) 2018
00007  *     Hunter L. Allen
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  */
00024 #ifndef P2OS_DRIVER__KINECALC_HPP_
00025 #define P2OS_DRIVER__KINECALC_HPP_
00026 #include <cstdio>
00027 
00028 // Basic vector
00029 typedef struct
00030 {
00031   double x, y, z;
00032 } KineVector;
00033 
00034 // Struct that describes the pose of the end effector
00035 // (result of FK)
00036 typedef struct
00037 {
00038   KineVector p;
00039   KineVector n;
00040   KineVector o;
00041   KineVector a;
00042 } EndEffector;
00043 
00044 class KineCalc
00045 {
00046 public:
00047   KineCalc(void);
00048 
00049   // Kinematics functions
00050   void CalculateFK(const double fromJoints[]);
00051   bool CalculateIK(const EndEffector & fromPosition);
00052 
00053   // Accessor functions
00054   const KineVector & GetP(void) const {return endEffector.p;}
00055   const KineVector & GetN(void) const {return endEffector.n;}
00056   const KineVector & GetO(void) const {return endEffector.o;}
00057   const KineVector & GetA(void) const {return endEffector.a;}
00058   void SetP(const KineVector & newP)
00059   {
00060     endEffector.p.x = newP.x; endEffector.p.y = newP.y; endEffector.p.z = newP.z;
00061   }
00062   void SetN(const KineVector & newN)
00063   {
00064     endEffector.n.x = newN.x; endEffector.n.y = newN.y; endEffector.n.z = newN.z;
00065   }
00066   void SetO(const KineVector & newO)
00067   {
00068     endEffector.o.x = newO.x; endEffector.o.y = newO.y; endEffector.o.z = newO.z;
00069   }
00070   void SetA(const KineVector & newA)
00071   {
00072     endEffector.a.x = newA.x; endEffector.a.y = newA.y; endEffector.a.z = newA.z;
00073   }
00074   void SetP(double newPX, double newPY, double newPZ);
00075   void SetN(double newNX, double newNY, double newNZ);
00076   void SetO(double newOX, double newOY, double newOZ);
00077   void SetA(double newAX, double newAY, double newAZ);
00078 
00079   double GetTheta(unsigned int index);
00080   const double * GetThetas(void) const {return joints;}
00081   void SetTheta(unsigned int index, double newVal);
00082   void SetLinkLengths(
00083     double newLink1, double newLink2, double newLink3, double newLink4,
00084     double newLink5);
00085   void SetOffset(unsigned int joint, double newOffset);
00086   void SetJointRange(unsigned int joint, double min, double max);
00087 
00088   // Use this to calculate N
00089   KineVector CalculateN(const EndEffector & pose);
00090   KineVector Normalise(const KineVector & vector);
00091 
00092 protected:
00093   void CalcTheta4and5(double angles[], const EndEffector & fromPosition);
00094   int ChooseSolution(const EndEffector & fromPosition, const double solutions[][5]);
00095   double CalcSolutionError(const double solution[], const EndEffector & fromPosition);
00096   EndEffector CalcFKForJoints(const double angles[]);
00097   bool SolutionInRange(const double angles[]);
00098 
00099   void PrintEndEffector(const EndEffector & endEffector);
00100 
00101   // The 4 vectors that describe the position and orientation of the
00102   // end effector.
00103   // These should be computed when performing forward kinematics
00104   // and are used to provide data to the client.
00105   EndEffector endEffector;
00106 
00107   // The 5 joint angles.
00108   // These are computed when performing inverse kinematics and
00109   // are used for positioning the arm.
00110   double joints[5];
00111   // Joint offsets, as calibrated and supplied in the config file
00112   double jointOffsets[5];
00113   // Joint ranges
00114   double jointMin[5];
00115   double jointMax[5];
00116 
00117   // The link lengths are required for any of the kinematics to be useful.
00118   // I can't see them changing, but just in case better to have the ability to
00119   // specify them in the config file.
00120   double link1, link2, link3, link4, link5;
00121 };
00122 #endif  // P2OS_DRIVER__KINECALC_HPP_


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 Wed Mar 27 2019 02:34:56