Publish sealed evaluation sources, batch 22
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolver.hpp +141 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolverpos_recursive.cpp +101 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolverpos_recursive.hpp +53 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolvervel_recursive.cpp +111 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolvervel_recursive.hpp +51 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainhdsolver_vereshchagin.cpp +521 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainhdsolver_vereshchagin.hpp +535 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver.hpp +62 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_recursive_newton_euler.cpp +100 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_recursive_newton_euler.hpp +78 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_vereshchagin.cpp +36 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_vereshchagin.hpp +40 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolver.hpp +169 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_lma.cpp +324 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_lma.hpp +256 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr.cpp +81 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr.hpp +97 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr_jl.cpp +122 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr_jl.hpp +129 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv.cpp +137 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv.hpp +118 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_givens.cpp +122 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_givens.hpp +57 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_nso.cpp +189 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_nso.hpp +160 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_wdls.cpp +224 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_wdls.hpp +244 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacdotsolver.cpp +252 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacdotsolver.hpp +183 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacsolver.cpp +101 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacsolver.hpp +74 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/config.h.in +37 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc.cpp +26 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc.hpp +315 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc.inl +598 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc_io.hpp +58 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames.cpp +445 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames.hpp +1354 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames.inl +1343 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames_io.cpp +310 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames_io.hpp +114 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/framevel.cpp +27 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/framevel.hpp +470 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/framevel.inl +661 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/framevel_io.hpp +55 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/jacobian.cpp +153 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/jacobian.hpp +88 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/jntarray.cpp +123 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/jntarray.hpp +227 -0
- third_party/orocos_kinematics_dynamics/orocos_kdl/src/jntarrayacc.cpp +177 -0
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolver.hpp
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_FKSOLVER_HPP
|
| 23 |
+
#define KDL_CHAIN_FKSOLVER_HPP
|
| 24 |
+
|
| 25 |
+
#include "chain.hpp"
|
| 26 |
+
#include "framevel.hpp"
|
| 27 |
+
#include "frameacc.hpp"
|
| 28 |
+
#include "jntarray.hpp"
|
| 29 |
+
#include "jntarrayvel.hpp"
|
| 30 |
+
#include "jntarrayacc.hpp"
|
| 31 |
+
#include "solveri.hpp"
|
| 32 |
+
|
| 33 |
+
namespace KDL {
|
| 34 |
+
/**
|
| 35 |
+
* \brief This <strong>abstract</strong> class encapsulates a
|
| 36 |
+
* solver for the forward position kinematics for a KDL::Chain.
|
| 37 |
+
*
|
| 38 |
+
* @ingroup KinematicFamily
|
| 39 |
+
*/
|
| 40 |
+
//Forward definition
|
| 41 |
+
class ChainFkSolverPos : public KDL::SolverI {
|
| 42 |
+
public:
|
| 43 |
+
/**
|
| 44 |
+
* Calculate forward position kinematics for a KDL::Chain,
|
| 45 |
+
* from joint coordinates to cartesian pose.
|
| 46 |
+
*
|
| 47 |
+
* @param q_in input joint coordinates
|
| 48 |
+
* @param p_out reference to output cartesian pose
|
| 49 |
+
*
|
| 50 |
+
* @return if < 0 something went wrong
|
| 51 |
+
*/
|
| 52 |
+
virtual int JntToCart(const JntArray& q_in, Frame& p_out,int segmentNr=-1)=0;
|
| 53 |
+
/**
|
| 54 |
+
* Calculate forward position kinematics for a KDL::Chain,
|
| 55 |
+
* from joint coordinates to cartesian pose.
|
| 56 |
+
*
|
| 57 |
+
* @param q_in input joint coordinates
|
| 58 |
+
* @param p_out reference to a vector of output cartesian poses for all segments
|
| 59 |
+
*
|
| 60 |
+
* @return if < 0 something went wrong
|
| 61 |
+
*/
|
| 62 |
+
virtual int JntToCart(const JntArray& q_in, std::vector<KDL::Frame>& p_out,int segmentNr=-1)=0;
|
| 63 |
+
|
| 64 |
+
virtual void updateInternalDataStructures()=0;
|
| 65 |
+
virtual ~ChainFkSolverPos(){};
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* \brief This <strong>abstract</strong> class encapsulates a solver
|
| 70 |
+
* for the forward velocity kinematics for a KDL::Chain.
|
| 71 |
+
*
|
| 72 |
+
* @ingroup KinematicFamily
|
| 73 |
+
*/
|
| 74 |
+
class ChainFkSolverVel : public KDL::SolverI {
|
| 75 |
+
public:
|
| 76 |
+
/**
|
| 77 |
+
* Calculate forward position and velocity kinematics, from
|
| 78 |
+
* joint coordinates to cartesian coordinates.
|
| 79 |
+
*
|
| 80 |
+
* @param q_in input joint coordinates (position and velocity)
|
| 81 |
+
* @param out output cartesian coordinates (position and velocity)
|
| 82 |
+
*
|
| 83 |
+
* @return if < 0 something went wrong
|
| 84 |
+
*/
|
| 85 |
+
virtual int JntToCart(const JntArrayVel& q_in, FrameVel& out,int segmentNr=-1)=0;
|
| 86 |
+
/**
|
| 87 |
+
* Calculate forward position and velocity kinematics, from
|
| 88 |
+
* joint coordinates to cartesian coordinates.
|
| 89 |
+
*
|
| 90 |
+
* @param q_in input joint coordinates (position and velocity)
|
| 91 |
+
* @param out output cartesian coordinates for all segments (position and velocity)
|
| 92 |
+
*
|
| 93 |
+
* @return if < 0 something went wrong
|
| 94 |
+
*/
|
| 95 |
+
virtual int JntToCart(const JntArrayVel& q_in, std::vector<KDL::FrameVel>& out,int segmentNr=-1)=0;
|
| 96 |
+
|
| 97 |
+
virtual void updateInternalDataStructures()=0;
|
| 98 |
+
virtual ~ChainFkSolverVel(){};
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* \brief This <strong>abstract</strong> class encapsulates a solver
|
| 103 |
+
* for the forward acceleration kinematics for a KDL::Chain.
|
| 104 |
+
*
|
| 105 |
+
* @ingroup KinematicFamily
|
| 106 |
+
*/
|
| 107 |
+
class ChainFkSolverAcc : public KDL::SolverI {
|
| 108 |
+
public:
|
| 109 |
+
/**
|
| 110 |
+
* Calculate forward position, velocity and acceleration
|
| 111 |
+
* kinematics, from joint coordinates to cartesian coordinates
|
| 112 |
+
*
|
| 113 |
+
* @param q_in input joint coordinates (position, velocity and
|
| 114 |
+
* acceleration
|
| 115 |
+
@param out output cartesian coordinates (position, velocity
|
| 116 |
+
* and acceleration
|
| 117 |
+
*
|
| 118 |
+
* @return if < 0 something went wrong
|
| 119 |
+
*/
|
| 120 |
+
virtual int JntToCart(const JntArrayAcc& q_in, FrameAcc& out,int segmentNr=-1)=0;
|
| 121 |
+
/**
|
| 122 |
+
* Calculate forward position, velocity and acceleration
|
| 123 |
+
* kinematics, from joint coordinates to cartesian coordinates
|
| 124 |
+
*
|
| 125 |
+
* @param q_in input joint coordinates (position, velocity and
|
| 126 |
+
* acceleration
|
| 127 |
+
* @param out output cartesian coordinates (position, velocity
|
| 128 |
+
* and acceleration for all segments
|
| 129 |
+
*
|
| 130 |
+
* @return if < 0 something went wrong
|
| 131 |
+
*/
|
| 132 |
+
virtual int JntToCart(const JntArrayAcc& q_in, std::vector<FrameAcc>& out,int segmentNr=-1)=0;
|
| 133 |
+
|
| 134 |
+
virtual void updateInternalDataStructures()=0;
|
| 135 |
+
virtual ~ChainFkSolverAcc()=0;
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
}//end of namespace KDL
|
| 140 |
+
|
| 141 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolverpos_recursive.cpp
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Francois Cauwe <francois at cauwe dot org>
|
| 2 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 3 |
+
|
| 4 |
+
// Version: 1.0
|
| 5 |
+
// Author: Francois Cauwe <francois at cauwe dot org>
|
| 6 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#include "chainfksolverpos_recursive.hpp"
|
| 25 |
+
#include <iostream>
|
| 26 |
+
|
| 27 |
+
namespace KDL {
|
| 28 |
+
|
| 29 |
+
ChainFkSolverPos_recursive::ChainFkSolverPos_recursive(const Chain& _chain):
|
| 30 |
+
chain(_chain)
|
| 31 |
+
{
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
int ChainFkSolverPos_recursive::JntToCart(const JntArray& q_in, Frame& p_out, int seg_nr) {
|
| 35 |
+
unsigned int segmentNr;
|
| 36 |
+
if(seg_nr<0)
|
| 37 |
+
segmentNr=chain.getNrOfSegments();
|
| 38 |
+
else
|
| 39 |
+
segmentNr = seg_nr;
|
| 40 |
+
|
| 41 |
+
p_out = Frame::Identity();
|
| 42 |
+
|
| 43 |
+
if(q_in.rows()!=chain.getNrOfJoints())
|
| 44 |
+
return (error = E_SIZE_MISMATCH);
|
| 45 |
+
else if(segmentNr>chain.getNrOfSegments())
|
| 46 |
+
return (error = E_OUT_OF_RANGE);
|
| 47 |
+
else{
|
| 48 |
+
int j=0;
|
| 49 |
+
for(unsigned int i=0;i<segmentNr;i++){
|
| 50 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 51 |
+
p_out = p_out*chain.getSegment(i).pose(q_in(j));
|
| 52 |
+
j++;
|
| 53 |
+
}else{
|
| 54 |
+
p_out = p_out*chain.getSegment(i).pose(0.0);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
return (error = E_NOERROR);
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
int ChainFkSolverPos_recursive::JntToCart(const JntArray& q_in, std::vector<Frame>& p_out, int seg_nr) {
|
| 61 |
+
unsigned int segmentNr;
|
| 62 |
+
if(seg_nr<0)
|
| 63 |
+
segmentNr=chain.getNrOfSegments();
|
| 64 |
+
else
|
| 65 |
+
segmentNr = seg_nr;
|
| 66 |
+
|
| 67 |
+
if(q_in.rows()!=chain.getNrOfJoints())
|
| 68 |
+
return -1;
|
| 69 |
+
else if(segmentNr>chain.getNrOfSegments())
|
| 70 |
+
return -1;
|
| 71 |
+
else if(p_out.size() != segmentNr)
|
| 72 |
+
return -1;
|
| 73 |
+
else if(segmentNr == 0)
|
| 74 |
+
return -1;
|
| 75 |
+
else{
|
| 76 |
+
int j=0;
|
| 77 |
+
// Initialization
|
| 78 |
+
if(chain.getSegment(0).getJoint().getType()!=Joint::Fixed) {
|
| 79 |
+
p_out[0] = chain.getSegment(0).pose(q_in(j));
|
| 80 |
+
j++;
|
| 81 |
+
}else
|
| 82 |
+
p_out[0] = chain.getSegment(0).pose(0.0);
|
| 83 |
+
|
| 84 |
+
for(unsigned int i=1;i<segmentNr;i++){
|
| 85 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 86 |
+
p_out[i] = p_out[i-1]*chain.getSegment(i).pose(q_in(j));
|
| 87 |
+
j++;
|
| 88 |
+
}else{
|
| 89 |
+
p_out[i] = p_out[i-1]*chain.getSegment(i).pose(0.0);
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
return 0;
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
ChainFkSolverPos_recursive::~ChainFkSolverPos_recursive()
|
| 97 |
+
{
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolverpos_recursive.hpp
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDLCHAINFKSOLVERPOS_RECURSIVE_HPP
|
| 23 |
+
#define KDLCHAINFKSOLVERPOS_RECURSIVE_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainfksolver.hpp"
|
| 26 |
+
|
| 27 |
+
namespace KDL {
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Implementation of a recursive forward position kinematics
|
| 31 |
+
* algorithm to calculate the position transformation from joint
|
| 32 |
+
* space to Cartesian space of a general kinematic chain (KDL::Chain).
|
| 33 |
+
*
|
| 34 |
+
* @ingroup KinematicFamily
|
| 35 |
+
*/
|
| 36 |
+
class ChainFkSolverPos_recursive : public ChainFkSolverPos
|
| 37 |
+
{
|
| 38 |
+
public:
|
| 39 |
+
ChainFkSolverPos_recursive(const Chain& chain);
|
| 40 |
+
~ChainFkSolverPos_recursive();
|
| 41 |
+
|
| 42 |
+
virtual int JntToCart(const JntArray& q_in, Frame& p_out, int segmentNr=-1);
|
| 43 |
+
virtual int JntToCart(const JntArray& q_in, std::vector<Frame>& p_out, int segmentNr=-1);
|
| 44 |
+
|
| 45 |
+
virtual void updateInternalDataStructures() {};
|
| 46 |
+
|
| 47 |
+
private:
|
| 48 |
+
const Chain& chain;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolvervel_recursive.cpp
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Francois Cauwe <francois at cauwe dot org>
|
| 2 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 3 |
+
|
| 4 |
+
// Version: 1.0
|
| 5 |
+
// Author: Francois Cauwe <francois at cauwe dot org>
|
| 6 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#include "chainfksolvervel_recursive.hpp"
|
| 25 |
+
|
| 26 |
+
namespace KDL
|
| 27 |
+
{
|
| 28 |
+
ChainFkSolverVel_recursive::ChainFkSolverVel_recursive(const Chain& _chain):
|
| 29 |
+
chain(_chain)
|
| 30 |
+
{
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
ChainFkSolverVel_recursive::~ChainFkSolverVel_recursive()
|
| 34 |
+
{
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
int ChainFkSolverVel_recursive::JntToCart(const JntArrayVel& in,FrameVel& out,int seg_nr)
|
| 38 |
+
{
|
| 39 |
+
unsigned int segmentNr;
|
| 40 |
+
if(seg_nr<0)
|
| 41 |
+
segmentNr=chain.getNrOfSegments();
|
| 42 |
+
else
|
| 43 |
+
segmentNr = seg_nr;
|
| 44 |
+
|
| 45 |
+
out=FrameVel::Identity();
|
| 46 |
+
|
| 47 |
+
if(!(in.q.rows()==chain.getNrOfJoints()&&in.qdot.rows()==chain.getNrOfJoints()))
|
| 48 |
+
return (error = E_SIZE_MISMATCH);
|
| 49 |
+
else if(segmentNr>chain.getNrOfSegments())
|
| 50 |
+
return (error = E_OUT_OF_RANGE);
|
| 51 |
+
else{
|
| 52 |
+
int j=0;
|
| 53 |
+
for (unsigned int i=0;i<segmentNr;i++) {
|
| 54 |
+
//Calculate new Frame_base_ee
|
| 55 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 56 |
+
out=out*FrameVel(chain.getSegment(i).pose(in.q(j)),
|
| 57 |
+
chain.getSegment(i).twist(in.q(j),in.qdot(j)));
|
| 58 |
+
j++;//Only increase jointnr if the segment has a joint
|
| 59 |
+
}else{
|
| 60 |
+
out=out*FrameVel(chain.getSegment(i).pose(0.0),
|
| 61 |
+
chain.getSegment(i).twist(0.0,0.0));
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
return (error = E_NOERROR);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
int ChainFkSolverVel_recursive::JntToCart(const JntArrayVel& in,std::vector<FrameVel>& out,int seg_nr)
|
| 69 |
+
{
|
| 70 |
+
unsigned int segmentNr;
|
| 71 |
+
if(seg_nr<0)
|
| 72 |
+
segmentNr=chain.getNrOfSegments();
|
| 73 |
+
else
|
| 74 |
+
segmentNr = seg_nr;
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
if(!(in.q.rows()==chain.getNrOfJoints()&&in.qdot.rows()==chain.getNrOfJoints()))
|
| 79 |
+
return -1;
|
| 80 |
+
else if(segmentNr>chain.getNrOfSegments())
|
| 81 |
+
return -1;
|
| 82 |
+
else if(out.size()!=segmentNr)
|
| 83 |
+
return -1;
|
| 84 |
+
else if(segmentNr == 0)
|
| 85 |
+
return -1;
|
| 86 |
+
else{
|
| 87 |
+
int j=0;
|
| 88 |
+
// Initialization
|
| 89 |
+
if(chain.getSegment(0).getJoint().getType()!=Joint::Fixed) {
|
| 90 |
+
out[0] = FrameVel(chain.getSegment(0).pose(in.q(0)),
|
| 91 |
+
chain.getSegment(0).twist(in.q(0),in.qdot(0)));
|
| 92 |
+
j++;
|
| 93 |
+
}else
|
| 94 |
+
out[0] = FrameVel(chain.getSegment(0).pose(0.0),
|
| 95 |
+
chain.getSegment(0).twist(0.0,0.0));
|
| 96 |
+
|
| 97 |
+
for (unsigned int i=1;i<segmentNr;i++) {
|
| 98 |
+
//Calculate new Frame_base_ee
|
| 99 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 100 |
+
out[i]=out[i-1]*FrameVel(chain.getSegment(i).pose(in.q(j)),
|
| 101 |
+
chain.getSegment(i).twist(in.q(j),in.qdot(j)));
|
| 102 |
+
j++;//Only increase jointnr if the segment has a joint
|
| 103 |
+
}else{
|
| 104 |
+
out[i]=out[i-1]*FrameVel(chain.getSegment(i).pose(0.0),
|
| 105 |
+
chain.getSegment(i).twist(0.0,0.0));
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
return 0;
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainfksolvervel_recursive.hpp
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_FKSOLVERVEL_RECURSIVE_HPP
|
| 23 |
+
#define KDL_CHAIN_FKSOLVERVEL_RECURSIVE_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainfksolver.hpp"
|
| 26 |
+
|
| 27 |
+
namespace KDL
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Implementation of a recursive forward position and velocity
|
| 31 |
+
* kinematics algorithm to calculate the position and velocity
|
| 32 |
+
* transformation from joint space to Cartesian space of a general
|
| 33 |
+
* kinematic chain (KDL::Chain).
|
| 34 |
+
*
|
| 35 |
+
* @ingroup KinematicFamily
|
| 36 |
+
*/
|
| 37 |
+
class ChainFkSolverVel_recursive : public ChainFkSolverVel
|
| 38 |
+
{
|
| 39 |
+
public:
|
| 40 |
+
ChainFkSolverVel_recursive(const Chain& chain);
|
| 41 |
+
~ChainFkSolverVel_recursive();
|
| 42 |
+
|
| 43 |
+
virtual int JntToCart(const JntArrayVel& q_in,FrameVel& out,int segmentNr=-1);
|
| 44 |
+
virtual int JntToCart(const JntArrayVel& q_in,std::vector<FrameVel>& out,int segmentNr=-1);
|
| 45 |
+
virtual void updateInternalDataStructures() {};
|
| 46 |
+
private:
|
| 47 |
+
const Chain& chain;
|
| 48 |
+
};
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainhdsolver_vereshchagin.cpp
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2009 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Author: Herman Bruyninckx
|
| 6 |
+
// Author: Azamat Shakhimardanov
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#include "chainhdsolver_vereshchagin.hpp"
|
| 25 |
+
#include "frames_io.hpp"
|
| 26 |
+
#include "utilities/svd_eigen_HH.hpp"
|
| 27 |
+
|
| 28 |
+
namespace KDL
|
| 29 |
+
{
|
| 30 |
+
|
| 31 |
+
ChainHdSolver_Vereshchagin::ChainHdSolver_Vereshchagin(const Chain& chain_, const Twist &root_acc, const unsigned int nc_) :
|
| 32 |
+
chain(chain_), nj(chain.getNrOfJoints()), ns(chain.getNrOfSegments()), nc(nc_),
|
| 33 |
+
results(ns + 1, segment_info(nc))
|
| 34 |
+
{
|
| 35 |
+
acc_root = root_acc;
|
| 36 |
+
|
| 37 |
+
//Provide the necessary memory for computing the inverse of M0
|
| 38 |
+
nu_sum.resize(nc);
|
| 39 |
+
M_0_inverse.resize(nc, nc);
|
| 40 |
+
Um = Eigen::MatrixXd::Identity(nc, nc);
|
| 41 |
+
Vm = Eigen::MatrixXd::Identity(nc, nc);
|
| 42 |
+
Sm = Eigen::VectorXd::Ones(nc);
|
| 43 |
+
tmpm = Eigen::VectorXd::Ones(nc);
|
| 44 |
+
|
| 45 |
+
// Provide the necessary memory for storing the total torque acting on each joint
|
| 46 |
+
total_torques = Eigen::VectorXd::Zero(nj);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void ChainHdSolver_Vereshchagin::updateInternalDataStructures() {
|
| 50 |
+
ns = chain.getNrOfSegments();
|
| 51 |
+
nj = chain.getNrOfJoints();
|
| 52 |
+
total_torques = Eigen::VectorXd::Zero(nj);
|
| 53 |
+
results.resize(ns+1,segment_info(nc));
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
int ChainHdSolver_Vereshchagin::CartToJnt(const JntArray &q, const JntArray &q_dot, JntArray &q_dotdot, const Jacobian& alfa, const JntArray& beta, const Wrenches& f_ext, const JntArray &ff_torques, JntArray &constraint_torques)
|
| 57 |
+
{
|
| 58 |
+
//Check sizes always
|
| 59 |
+
nj = chain.getNrOfJoints();
|
| 60 |
+
if(ns != chain.getNrOfSegments())
|
| 61 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 62 |
+
if (q.rows() != nj || q_dot.rows() != nj || q_dotdot.rows() != nj || ff_torques.rows() != nj || constraint_torques.rows() != nj || f_ext.size() != ns)
|
| 63 |
+
return (error = E_SIZE_MISMATCH);
|
| 64 |
+
if (alfa.columns() != nc || beta.rows() != nc)
|
| 65 |
+
return (error = E_SIZE_MISMATCH);
|
| 66 |
+
//do an upward recursion for position, velocities and rigid-body bias forces
|
| 67 |
+
this->initial_upwards_sweep(q, q_dot, q_dotdot, f_ext);
|
| 68 |
+
//do an inward recursion for inertia, articulated bias forces and constraints
|
| 69 |
+
this->downwards_sweep(alfa, ff_torques);
|
| 70 |
+
//Solve for the constraint forces
|
| 71 |
+
this->constraint_calculation(beta);
|
| 72 |
+
//do an upward recursion to propagate the result and compute final output
|
| 73 |
+
this->final_upwards_sweep(q_dotdot, constraint_torques);
|
| 74 |
+
return (error = E_NOERROR);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void ChainHdSolver_Vereshchagin::initial_upwards_sweep(const JntArray &q, const JntArray &qdot, const JntArray &qdotdot, const Wrenches& f_ext)
|
| 78 |
+
{
|
| 79 |
+
//if (q.rows() != nj || qdot.rows() != nj || qdotdot.rows() != nj || f_ext.size() != ns)
|
| 80 |
+
// return -1;
|
| 81 |
+
|
| 82 |
+
unsigned int j = 0;
|
| 83 |
+
F_total = Frame::Identity();
|
| 84 |
+
for (unsigned int i = 0; i < ns; i++)
|
| 85 |
+
{
|
| 86 |
+
//Express everything in the segments reference frame (body coordinates)
|
| 87 |
+
//which is at the segments tip, i.e. where the next joint is attached.
|
| 88 |
+
|
| 89 |
+
//Calculate segment properties: X,S,vj,cj
|
| 90 |
+
const Segment& segment = chain.getSegment(i);
|
| 91 |
+
segment_info& s = results[i + 1];
|
| 92 |
+
//The pose between the joint root and the segment tip (tip expressed in joint root coordinates)
|
| 93 |
+
s.F = segment.pose(q(j)); //X pose of each link in link coord system
|
| 94 |
+
|
| 95 |
+
F_total = F_total * s.F; //X pose of the each link in root coord system
|
| 96 |
+
s.F_base = F_total; //X pose of the each link in root coord system for getter functions
|
| 97 |
+
|
| 98 |
+
//The velocity due to the joint motion of the segment expressed in the segments reference frame (tip)
|
| 99 |
+
Twist vj = s.F.M.Inverse(segment.twist(q(j), qdot(j))); //XDot of each link
|
| 100 |
+
//Twist aj = s.F.M.Inverse(segment.twist(q(j), qdotdot(j))); //XDotDot of each link
|
| 101 |
+
|
| 102 |
+
//The unit velocity due to the joint motion of the segment expressed in the segments reference frame (tip)
|
| 103 |
+
s.Z = s.F.M.Inverse(segment.twist(q(j), 1.0));
|
| 104 |
+
//Put Z in the joint root reference frame:
|
| 105 |
+
s.Z = s.F * s.Z;
|
| 106 |
+
|
| 107 |
+
//The total velocity of the segment expressed in the segments reference frame (tip)
|
| 108 |
+
if (i != 0)
|
| 109 |
+
{
|
| 110 |
+
s.v = s.F.Inverse(results[i].v) + vj; // recursive velocity of each link in segment frame
|
| 111 |
+
//s.A=s.F.Inverse(results[i].A)+aj;
|
| 112 |
+
s.A = s.F.M.Inverse(results[i].A);
|
| 113 |
+
}
|
| 114 |
+
else
|
| 115 |
+
{
|
| 116 |
+
s.v = vj;
|
| 117 |
+
s.A = s.F.M.Inverse(acc_root);
|
| 118 |
+
}
|
| 119 |
+
//c[i] = cj + v[i]xvj (remark: cj=0, since our S is not time dependent in local coordinates)
|
| 120 |
+
//The velocity product acceleration
|
| 121 |
+
//std::cout << i << " Initial upward" << s.v << std::endl;
|
| 122 |
+
s.C = s.v*vj; //This is a cross product: cartesian space BIAS acceleration in local link coord.
|
| 123 |
+
//Put C in the joint root reference frame
|
| 124 |
+
s.C = s.F * s.C; //+F_total.M.Inverse(acc_root));
|
| 125 |
+
//The rigid body inertia of the segment, expressed in the segments reference frame (tip)
|
| 126 |
+
s.H = segment.getInertia();
|
| 127 |
+
|
| 128 |
+
//wrench of the rigid body bias forces and the external forces on the segment (in body coordinates, tip)
|
| 129 |
+
//external forces are taken into account through s.U.
|
| 130 |
+
Wrench FextLocal = F_total.M.Inverse() * f_ext[i];
|
| 131 |
+
s.U = s.v * (s.H * s.v) - FextLocal; //f_ext[i];
|
| 132 |
+
if (segment.getJoint().getType() != Joint::Fixed)
|
| 133 |
+
j++;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void ChainHdSolver_Vereshchagin::downwards_sweep(const Jacobian& alfa, const JntArray &ff_torques)
|
| 139 |
+
{
|
| 140 |
+
int j = nj - 1;
|
| 141 |
+
for (int i = ns; i >= 0; i--)
|
| 142 |
+
{
|
| 143 |
+
//Get a handle for the segment we are working on.
|
| 144 |
+
segment_info& s = results[i];
|
| 145 |
+
//For segment N,
|
| 146 |
+
//tilde is in the segment refframe (tip, not joint root)
|
| 147 |
+
//without tilde is at the joint root (the childs tip!!!)
|
| 148 |
+
//P_tilde is the articulated body inertia
|
| 149 |
+
//R_tilde is the sum of external and coriolis/centrifugal forces
|
| 150 |
+
//M is the (unit) acceleration energy already generated at link i
|
| 151 |
+
//G is the (unit) magnitude of the constraint forces at link i
|
| 152 |
+
//E are the (unit) constraint forces due to the constraints
|
| 153 |
+
if (i == (int)ns)
|
| 154 |
+
{
|
| 155 |
+
s.P_tilde = s.H;
|
| 156 |
+
s.R_tilde = s.U;
|
| 157 |
+
s.M.setZero();
|
| 158 |
+
s.G.setZero();
|
| 159 |
+
//changeBase(alfa_N,F_total.M.Inverse(),alfa_N2);
|
| 160 |
+
for (unsigned int r = 0; r < 3; r++)
|
| 161 |
+
for (unsigned int c = 0; c < nc; c++)
|
| 162 |
+
{
|
| 163 |
+
//copy alfa constrain force matrix in E~
|
| 164 |
+
s.E_tilde(r, c) = alfa(r + 3, c);
|
| 165 |
+
s.E_tilde(r + 3, c) = alfa(r, c);
|
| 166 |
+
}
|
| 167 |
+
//Change the reference frame of alfa to the segmentN tip frame
|
| 168 |
+
//F_Total holds end effector frame, if done per segment bases then constraints could be extended to all segments
|
| 169 |
+
Rotation base_to_end = F_total.M.Inverse();
|
| 170 |
+
for (unsigned int c = 0; c < nc; c++)
|
| 171 |
+
{
|
| 172 |
+
Wrench col(Vector(s.E_tilde(3, c), s.E_tilde(4, c), s.E_tilde(5, c)),
|
| 173 |
+
Vector(s.E_tilde(0, c), s.E_tilde(1, c), s.E_tilde(2, c)));
|
| 174 |
+
col = base_to_end*col;
|
| 175 |
+
s.E_tilde.col(c) << Eigen::Vector3d::Map(col.torque.data), Eigen::Vector3d::Map(col.force.data);
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
else
|
| 179 |
+
{
|
| 180 |
+
//For all others:
|
| 181 |
+
//Everything should expressed in the body coordinates of segment i
|
| 182 |
+
segment_info& child = results[i + 1];
|
| 183 |
+
//Copy PZ into a vector so we can do matrix manipulations, put torques above forces
|
| 184 |
+
Vector6d vPZ;
|
| 185 |
+
vPZ << Eigen::Vector3d::Map(child.PZ.torque.data), Eigen::Vector3d::Map(child.PZ.force.data);
|
| 186 |
+
Matrix6d PZDPZt;
|
| 187 |
+
PZDPZt.noalias() = vPZ * vPZ.transpose();
|
| 188 |
+
PZDPZt /= child.D;
|
| 189 |
+
|
| 190 |
+
//equation a) (see Vereshchagin89) PZDPZt=[I,H;H',M]
|
| 191 |
+
//Azamat:articulated body inertia as in Featherstone (7.19)
|
| 192 |
+
s.P_tilde = s.H + child.P - ArticulatedBodyInertia(PZDPZt.bottomRightCorner<3,3>(), PZDPZt.topRightCorner<3,3>(), PZDPZt.topLeftCorner<3,3>());
|
| 193 |
+
//equation b) (see Vereshchagin89)
|
| 194 |
+
//Azamat: bias force as in Featherstone (7.20)
|
| 195 |
+
s.R_tilde = s.U + child.R + child.PC + (child.PZ / child.D) * child.u;
|
| 196 |
+
//equation c) (see Vereshchagin89)
|
| 197 |
+
s.E_tilde = child.E;
|
| 198 |
+
|
| 199 |
+
//Azamat: equation (c) right side term
|
| 200 |
+
s.E_tilde.noalias() -= (vPZ * child.EZ.transpose()) / child.D;
|
| 201 |
+
|
| 202 |
+
//equation d) (see Vereshchagin89)
|
| 203 |
+
s.M = child.M;
|
| 204 |
+
//Azamat: equation (d) right side term
|
| 205 |
+
s.M.noalias() -= (child.EZ * child.EZ.transpose()) / child.D;
|
| 206 |
+
|
| 207 |
+
//equation e) (see Vereshchagin89)
|
| 208 |
+
s.G = child.G;
|
| 209 |
+
Twist CiZDu = child.C + (child.Z / child.D) * child.u;
|
| 210 |
+
Vector6d vCiZDu;
|
| 211 |
+
vCiZDu << Eigen::Vector3d::Map(CiZDu.rot.data), Eigen::Vector3d::Map(CiZDu.vel.data);
|
| 212 |
+
s.G.noalias() += child.E.transpose() * vCiZDu;
|
| 213 |
+
}
|
| 214 |
+
if (i != 0)
|
| 215 |
+
{
|
| 216 |
+
//Transform all results to joint root coordinates of segment i (== body coordinates segment i-1)
|
| 217 |
+
//equation a)
|
| 218 |
+
s.P = s.F * s.P_tilde;
|
| 219 |
+
//equation b)
|
| 220 |
+
s.R = s.F * s.R_tilde;
|
| 221 |
+
//equation c), in matrix: torques above forces, so switch and switch back
|
| 222 |
+
for (unsigned int c = 0; c < nc; c++)
|
| 223 |
+
{
|
| 224 |
+
Wrench col(Vector(s.E_tilde(3, c), s.E_tilde(4, c), s.E_tilde(5, c)),
|
| 225 |
+
Vector(s.E_tilde(0, c), s.E_tilde(1, c), s.E_tilde(2, c)));
|
| 226 |
+
col = s.F*col;
|
| 227 |
+
s.E.col(c) << Eigen::Vector3d::Map(col.torque.data), Eigen::Vector3d::Map(col.force.data);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
//needed for next recursion
|
| 231 |
+
s.PZ = s.P * s.Z;
|
| 232 |
+
|
| 233 |
+
/**
|
| 234 |
+
* Additionally adding joint inertia to s.D, see:
|
| 235 |
+
* - equation a) in Vereshchagin89
|
| 236 |
+
* - equation 9.28, page 188, Featherstone book 2008
|
| 237 |
+
*/
|
| 238 |
+
if (chain.getSegment(i - 1).getJoint().getType() != Joint::Fixed)
|
| 239 |
+
s.D = chain.getSegment(i - 1).getJoint().getInertia() + dot(s.Z, s.PZ);
|
| 240 |
+
else
|
| 241 |
+
s.D = dot(s.Z, s.PZ);
|
| 242 |
+
|
| 243 |
+
s.PC = s.P * s.C;
|
| 244 |
+
|
| 245 |
+
//u=(Q-Z(R+PC)=sum of external forces along the joint axes,
|
| 246 |
+
//R are the forces coming from the children,
|
| 247 |
+
//Q is taken zero (do we need to take the previous calculated torques?
|
| 248 |
+
|
| 249 |
+
//projection of coriolis and centrepital forces into joint subspace (0 0 Z)
|
| 250 |
+
s.totalBias = -dot(s.Z, s.R + s.PC);
|
| 251 |
+
s.u = ff_torques(j) + s.totalBias;
|
| 252 |
+
|
| 253 |
+
//Matrix form of Z, put rotations above translations
|
| 254 |
+
Vector6d vZ;
|
| 255 |
+
vZ << Eigen::Vector3d::Map(s.Z.rot.data), Eigen::Vector3d::Map(s.Z.vel.data);
|
| 256 |
+
s.EZ.noalias() = s.E.transpose() * vZ;
|
| 257 |
+
|
| 258 |
+
if (chain.getSegment(i - 1).getJoint().getType() != Joint::Fixed)
|
| 259 |
+
j--;
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
void ChainHdSolver_Vereshchagin::constraint_calculation(const JntArray& beta)
|
| 265 |
+
{
|
| 266 |
+
//equation f) nu = M_0_inverse*(beta_N - E0_tilde`*acc0 - G0)
|
| 267 |
+
//M_0_inverse, always nc*nc symmetric matrix
|
| 268 |
+
//std::cout<<"M0: "<<results[0].M<<std::endl;
|
| 269 |
+
//results[0].M-=Eigen::MatrixXd::Identity(nc,nc);
|
| 270 |
+
//std::cout<<"augmented M0: "<<results[0].M<<std::endl;
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
//ToDo: Need to check ill conditions
|
| 274 |
+
|
| 275 |
+
//M_0_inverse=results[0].M.inverse();
|
| 276 |
+
svd_eigen_HH(results[0].M, Um, Sm, Vm, tmpm);
|
| 277 |
+
//truncated svd, what would sdls, dls physically mean?
|
| 278 |
+
for (unsigned int i = 0; i < nc; i++)
|
| 279 |
+
if (Sm(i) < 1e-14)
|
| 280 |
+
Sm(i) = 0.0;
|
| 281 |
+
else
|
| 282 |
+
Sm(i) = 1 / Sm(i);
|
| 283 |
+
|
| 284 |
+
results[0].M.noalias() = Vm * Sm.asDiagonal();
|
| 285 |
+
M_0_inverse.noalias() = results[0].M * Um.transpose();
|
| 286 |
+
//results[0].M.ldlt().solve(Eigen::MatrixXd::Identity(nc,nc),&M_0_inverse);
|
| 287 |
+
//results[0].M.computeInverse(&M_0_inverse);
|
| 288 |
+
Vector6d acc;
|
| 289 |
+
acc << Eigen::Vector3d::Map(acc_root.rot.data), Eigen::Vector3d::Map(acc_root.vel.data);
|
| 290 |
+
nu_sum.noalias() = -(results[0].E_tilde.transpose() * acc);
|
| 291 |
+
//nu_sum.setZero();
|
| 292 |
+
nu_sum += beta.data;
|
| 293 |
+
nu_sum -= results[0].G;
|
| 294 |
+
|
| 295 |
+
//equation f) nu = M_0_inverse*(beta_N - E0_tilde`*acc0 - G0)
|
| 296 |
+
nu.noalias() = M_0_inverse * nu_sum;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
void ChainHdSolver_Vereshchagin::final_upwards_sweep(JntArray &q_dotdot, JntArray &constraint_torques)
|
| 300 |
+
{
|
| 301 |
+
unsigned int j = 0;
|
| 302 |
+
|
| 303 |
+
for (unsigned int i = 1; i <= ns; i++)
|
| 304 |
+
{
|
| 305 |
+
segment_info& s = results[i];
|
| 306 |
+
//Calculation of joint and segment accelerations
|
| 307 |
+
//equation g) qdotdot[i] = D^-1*(Q - Z'(R + P(C + acc[i-1]) + E*nu))
|
| 308 |
+
// = D^-1(u - Z'(P*acc[i-1] + E*nu)
|
| 309 |
+
Twist a_g;
|
| 310 |
+
Twist a_p;
|
| 311 |
+
if (i == 1)
|
| 312 |
+
{
|
| 313 |
+
a_p = acc_root;
|
| 314 |
+
}
|
| 315 |
+
else
|
| 316 |
+
{
|
| 317 |
+
a_p = results[i - 1].acc;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
//The contribution of the constraint forces at segment i
|
| 321 |
+
Vector6d tmp = s.E*nu;
|
| 322 |
+
Wrench constraint_force = Wrench(Vector(tmp(3), tmp(4), tmp(5)),
|
| 323 |
+
Vector(tmp(0), tmp(1), tmp(2)));
|
| 324 |
+
|
| 325 |
+
//acceleration components are also computed
|
| 326 |
+
//Contribution of the acceleration of the parent (i-1)
|
| 327 |
+
Wrench parent_force = s.P*a_p;
|
| 328 |
+
double parent_forceProjection = -dot(s.Z, parent_force);
|
| 329 |
+
double parentAccComp = parent_forceProjection / s.D;
|
| 330 |
+
|
| 331 |
+
//The constraint force and acceleration force projected on the joint axes -> axis torque/force
|
| 332 |
+
constraint_torques(j) = -dot(s.Z, constraint_force);
|
| 333 |
+
//The result should be the torque originating from the end-effector constraints
|
| 334 |
+
|
| 335 |
+
// Total torque on the joint resulting from the parent forces, constraint forces and nullspace forces.
|
| 336 |
+
total_torques(j) = s.u + parent_forceProjection + constraint_torques(j);
|
| 337 |
+
// q_dotdot(j) is also equal to: total_torques(j) / s.D
|
| 338 |
+
|
| 339 |
+
s.constAccComp = constraint_torques(j) / s.D;
|
| 340 |
+
s.nullspaceAccComp = s.u / s.D;
|
| 341 |
+
|
| 342 |
+
// Total joint space acceleration resulting from accelerations of parent joints, constraint forces and nullspace forces.
|
| 343 |
+
q_dotdot(j) = (s.nullspaceAccComp + parentAccComp + s.constAccComp);
|
| 344 |
+
// Returns segment's spatial acceleration in link distal-tip coordinates. For use needs to be transformed
|
| 345 |
+
s.acc = s.F.Inverse(a_p + s.Z * q_dotdot(j) + s.C);
|
| 346 |
+
if (chain.getSegment(i - 1).getJoint().getType() != Joint::Fixed)
|
| 347 |
+
j++;
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// Returns Cartesian acceleration of links in robot base coordinates
|
| 352 |
+
void ChainHdSolver_Vereshchagin::getTransformedLinkAcceleration(Twists& x_dotdot)
|
| 353 |
+
{
|
| 354 |
+
assert(x_dotdot.size() == ns + 1);
|
| 355 |
+
x_dotdot[0] = acc_root;
|
| 356 |
+
for (unsigned int i = 1; i < ns + 1; i++)
|
| 357 |
+
x_dotdot[i] = results[i].F_base.M * results[i].acc;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
// Returns total torque acting on each joint (constraints + nature + external forces)
|
| 361 |
+
void ChainHdSolver_Vereshchagin::getTotalTorque(JntArray &total_tau)
|
| 362 |
+
{
|
| 363 |
+
assert(total_tau.data.size() == total_torques.size());
|
| 364 |
+
total_tau.data = total_torques;
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// Returns magnitude of the constraint forces acting on the end-effector: Lagrange Multiplier
|
| 368 |
+
void ChainHdSolver_Vereshchagin::getContraintForceMagnitude(Eigen::VectorXd &nu_)
|
| 369 |
+
{
|
| 370 |
+
assert(nu_.size() == nu.size());
|
| 371 |
+
nu_ = nu;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
/*
|
| 375 |
+
void ChainHdSolver_Vereshchagin::getLinkCartesianPose(Frames& x_base)
|
| 376 |
+
{
|
| 377 |
+
for (int i = 0; i < ns; i++)
|
| 378 |
+
{
|
| 379 |
+
x_base[i] = results[i + 1].F_base;
|
| 380 |
+
}
|
| 381 |
+
return;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
void ChainHdSolver_Vereshchagin::getLinkCartesianVelocity(Twists& xDot_base)
|
| 385 |
+
{
|
| 386 |
+
|
| 387 |
+
for (int i = 0; i < ns; i++)
|
| 388 |
+
{
|
| 389 |
+
xDot_base[i] = results[i + 1].F_base.M * results[i + 1].v;
|
| 390 |
+
}
|
| 391 |
+
return;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
void ChainHdSolver_Vereshchagin::getLinkCartesianAcceleration(Twists& xDotDot_base)
|
| 395 |
+
{
|
| 396 |
+
|
| 397 |
+
for (int i = 0; i < ns; i++)
|
| 398 |
+
{
|
| 399 |
+
xDotDot_base[i] = results[i + 1].F_base.M * results[i + 1].acc;
|
| 400 |
+
//std::cout << "XDotDot_base[i] " << xDotDot_base[i] << std::endl;
|
| 401 |
+
}
|
| 402 |
+
return;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
void ChainHdSolver_Vereshchagin::getLinkPose(Frames& x_local)
|
| 406 |
+
{
|
| 407 |
+
for (int i = 0; i < ns; i++)
|
| 408 |
+
{
|
| 409 |
+
x_local[i] = results[i + 1].F;
|
| 410 |
+
}
|
| 411 |
+
return;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
void ChainHdSolver_Vereshchagin::getLinkVelocity(Twists& xDot_local)
|
| 415 |
+
{
|
| 416 |
+
for (int i = 0; i < ns; i++)
|
| 417 |
+
{
|
| 418 |
+
xDot_local[i] = results[i + 1].v;
|
| 419 |
+
}
|
| 420 |
+
return;
|
| 421 |
+
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
void ChainHdSolver_Vereshchagin::getLinkAcceleration(Twists& xDotdot_local)
|
| 425 |
+
{
|
| 426 |
+
for (int i = 0; i < ns; i++)
|
| 427 |
+
{
|
| 428 |
+
xDotdot_local[i] = results[i + 1].acc;
|
| 429 |
+
}
|
| 430 |
+
return;
|
| 431 |
+
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
void ChainHdSolver_Vereshchagin::getJointBiasAcceleration(JntArray& bias_q_dotdot)
|
| 435 |
+
{
|
| 436 |
+
for (int i = 0; i < ns; i++)
|
| 437 |
+
{
|
| 438 |
+
//this is only force
|
| 439 |
+
double tmp = results[i + 1].totalBias;
|
| 440 |
+
//this is acceleration
|
| 441 |
+
bias_q_dotdot(i) = tmp / results[i + 1].D;
|
| 442 |
+
|
| 443 |
+
//s.totalBias = - dot(s.Z, s.R + s.PC);
|
| 444 |
+
//std::cout << "totalBiasAccComponent" << i << ": " << bias_q_dotdot(i) << std::endl;
|
| 445 |
+
//bias_q_dotdot(i) = s.totalBias/s.D
|
| 446 |
+
|
| 447 |
+
}
|
| 448 |
+
return;
|
| 449 |
+
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
void ChainHdSolver_Vereshchagin::getJointConstraintAcceleration(JntArray& constraint_q_dotdot)
|
| 453 |
+
{
|
| 454 |
+
for (int i = 0; i < ns; i++)
|
| 455 |
+
{
|
| 456 |
+
constraint_q_dotdot(i) = results[i + 1].constAccComp;
|
| 457 |
+
//double tmp = results[i + 1].u;
|
| 458 |
+
//s.u = torques(j) + s.totalBias;
|
| 459 |
+
// std::cout << "s.constraintAccComp" << i << ": " << results[i+1].constAccComp << std::endl;
|
| 460 |
+
//nullspace_q_dotdot(i) = s.u/s.D
|
| 461 |
+
|
| 462 |
+
}
|
| 463 |
+
return;
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
//Check the name it does not seem to be appropriate
|
| 469 |
+
|
| 470 |
+
void ChainHdSolver_Vereshchagin::getJointNullSpaceAcceleration(JntArray& nullspace_q_dotdot)
|
| 471 |
+
{
|
| 472 |
+
for (int i = 0; i < ns; i++)
|
| 473 |
+
{
|
| 474 |
+
nullspace_q_dotdot(i) = results[i + 1].nullspaceAccComp;
|
| 475 |
+
//double tmp = results[i + 1].u;
|
| 476 |
+
//s.u = torques(j) + s.totalBias;
|
| 477 |
+
//std::cout << "s.nullSpaceAccComp" << i << ": " << results[i+1].nullspaceAccComp << std::endl;
|
| 478 |
+
//nullspace_q_dotdot(i) = s.u/s.D
|
| 479 |
+
|
| 480 |
+
}
|
| 481 |
+
return;
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
//This is not only a bias force energy but also includes generalized forces
|
| 487 |
+
//change type of parameter G
|
| 488 |
+
//this method should return array of G's
|
| 489 |
+
|
| 490 |
+
void ChainHdSolver_Vereshchagin::getLinkBiasForceAcceleratoinEnergy(Eigen::VectorXd& G)
|
| 491 |
+
{
|
| 492 |
+
for (int i = 0; i < ns; i++)
|
| 493 |
+
{
|
| 494 |
+
G = results[i + 1].G;
|
| 495 |
+
//double tmp = results[i + 1].u;
|
| 496 |
+
//s.u = torques(j) + s.totalBias;
|
| 497 |
+
//std::cout << "s.G " << i << ": " << results[i+1].G << std::endl;
|
| 498 |
+
//nullspace_q_dotdot(i) = s.u/s.D
|
| 499 |
+
|
| 500 |
+
}
|
| 501 |
+
return;
|
| 502 |
+
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
//this method should return array of R's
|
| 506 |
+
|
| 507 |
+
void ChainHdSolver_Vereshchagin::getLinkBiasForceMatrix(Wrenches& R_tilde)
|
| 508 |
+
{
|
| 509 |
+
for (int i = 0; i < ns; i++)
|
| 510 |
+
{
|
| 511 |
+
R_tilde[i] = results[i + 1].R_tilde;
|
| 512 |
+
//Azamat: bias force as in Featherstone (7.20)
|
| 513 |
+
//s.R_tilde = s.U + child.R + child.PC + child.PZ / child.D * child.u;
|
| 514 |
+
std::cout << "s.R_tilde " << i << ": " << results[i + 1].R_tilde << std::endl;
|
| 515 |
+
}
|
| 516 |
+
return;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
*/
|
| 520 |
+
|
| 521 |
+
}//namespace
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainhdsolver_vereshchagin.hpp
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Author: Herman Bruyninckx
|
| 6 |
+
// Author: Azamat Shakhimardanov
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#ifndef KDL_CHAINHDSOLVER_VERESHCHAGIN_HPP
|
| 25 |
+
#define KDL_CHAINHDSOLVER_VERESHCHAGIN_HPP
|
| 26 |
+
|
| 27 |
+
#include "chainidsolver.hpp"
|
| 28 |
+
#include "frames.hpp"
|
| 29 |
+
#include "articulatedbodyinertia.hpp"
|
| 30 |
+
|
| 31 |
+
#include<Eigen/StdVector>
|
| 32 |
+
|
| 33 |
+
namespace KDL
|
| 34 |
+
{
|
| 35 |
+
/**
|
| 36 |
+
* \brief **Abstract**: Acceleration constrained hybrid dynamics calculations for a chain, based on Vereshchagin 1989.
|
| 37 |
+
* This class creates an instance of the hybrid dynamics solver. The solver analytically calculates the joint space
|
| 38 |
+
* constraint torques and acceleration in a chain when a constraint force(s) is applied to the chain's end-effector
|
| 39 |
+
* (task space / cartesian space). In the robotics literature, this algorithm is also known under the following names:
|
| 40 |
+
* Acceleration Constrained Hybrid Dynamics (ACHD) and Popov-Vereshchagin solver.
|
| 41 |
+
*
|
| 42 |
+
* ## INTRODUCTION
|
| 43 |
+
*
|
| 44 |
+
* In 1970', researchers [1], [2] have developed a hybrid dynamics algorithm for evaluating robot behavior
|
| 45 |
+
* based on the input specification that is defined by the Cartesian acceleration constraints,
|
| 46 |
+
* feed-forward joint torques and external Cartesian wrenches. The solver is derived from a well-known
|
| 47 |
+
* principle of mechanics - **Gauss' principle of least constraint** [6] and provides an analytical (closed-form)
|
| 48 |
+
* solution to the hybrid dynamics problem with linear-time, **O(n)** complexity [3].
|
| 49 |
+
*
|
| 50 |
+
* In general, the Gauss' principle states that the true motion (acceleration) of a system/body is defined
|
| 51 |
+
* by the minimum of a quadratic function that is subject to linear geometric motion constraints [7], [6].
|
| 52 |
+
* The result of this Gauss function represents the **acceleration energy** of a body, which is defined by
|
| 53 |
+
* the product of its mass and the squared distance between its allowed (constrained) acceleration and its free
|
| 54 |
+
* (unconstrained) acceleration [10], [11]. In the case of originally derived Popov-Vereshchagin algorithm [1],
|
| 55 |
+
* geometric motion constraints are Cartesian acceleration constraints imposed on the robot's end-effector.
|
| 56 |
+
* This domain-specific solver minimizes the acceleration energy by performing computational (outward and inward)
|
| 57 |
+
* sweeps along the robot's kinematic chain [3]. Furthermore, by computing the minimum of Gauss function,
|
| 58 |
+
* the Popov-Vereshchagin solver resolves the kinematic redundancy of the robot, when a partial motion (task)
|
| 59 |
+
* specification is provided [2]. A necessary condition that enables this type of closed-form algorithm
|
| 60 |
+
* (an analytical solution to the above-described optimization problem) defines that the robot’s kinematic
|
| 61 |
+
* chain does not consist of closed loops, i.e. the robot’s kinematic chain must be constructed in a serial
|
| 62 |
+
* or tree structure [11]. However, it is always possible to cut these loops and introduce explicit constrains.
|
| 63 |
+
*
|
| 64 |
+
* For evaluating robot dynamics, i.e. resolving its constrained motion, the Popov-Vereshchagin solver is
|
| 65 |
+
* performing three computational sweeps (recursions), along the kinematic chain [3]. More specifically,
|
| 66 |
+
* two sweeps in **outward** and one sweep in **inward** direction. In the case of robot dynamics algorithms,
|
| 67 |
+
* the outward sweep refers to a recursion that is covering a kinematic chain from proximal to distal segments,
|
| 68 |
+
* while the inward sweep is covering a kinematic chain from distal to proximal segments [5]. Additionally,
|
| 69 |
+
* after completing the recursion in the second sweep and before starting the recursion in the last sweep,
|
| 70 |
+
* the solver is computing magnitudes of constraint forces, i.e. the Langrage multiplier (noted as **nu** in
|
| 71 |
+
* the KDL's solver implementation and original solver's publication[2]). More specifically, this operation is
|
| 72 |
+
* performed when the algorithm reaches segment (link) **{0}**, namely the base segment. In this formulation
|
| 73 |
+
* of the solver, the gravity effects are taken into account by setting the base-link's acceleration equal
|
| 74 |
+
* to gravitational acceleration [3].
|
| 75 |
+
*
|
| 76 |
+
* For more detailed description of the algorithm and its representation, the reader can refer to [3], [5], [11].
|
| 77 |
+
*
|
| 78 |
+
* ## INTERFACES
|
| 79 |
+
*
|
| 80 |
+
* ### Solver's Input
|
| 81 |
+
*
|
| 82 |
+
* For computing solutions to the constrained hybrid dynamics problem, this original derivation of
|
| 83 |
+
* the Popov-Vereshchagin solver [3] takes into account the following inputs:
|
| 84 |
+
*
|
| 85 |
+
* * Robot's **model** defined by: kinematic parameters of the chain, segments' mass and rigid-body
|
| 86 |
+
* inertia, and effective inertia of each joint rotor -> **chain** parameter in solver's constructor
|
| 87 |
+
*
|
| 88 |
+
* * **Root** acceleration of the robot's base segment (usually gravitational) -> **root_acc** parameter
|
| 89 |
+
* in solver's constructor
|
| 90 |
+
*
|
| 91 |
+
* * Current joint configuration (angles) -> **q** parameter in the **CartToJnt** function
|
| 92 |
+
*
|
| 93 |
+
* * Current joint velocities -> **q_dot** parameter in the **CartToJnt** function
|
| 94 |
+
*
|
| 95 |
+
* * Motion drivers:
|
| 96 |
+
* * - **Cartesian Acceleration Constraints** imposed on the end-effector segment -> **alpha** and
|
| 97 |
+
* **beta** parameters in the **CartToJnt** function
|
| 98 |
+
* * - **Cartesian External Wrench** acting on each segment -> **f_ext** parameter in the **CartToJnt** function
|
| 99 |
+
* * - **Feed-Forward Torque** acting on each joint -> **ff_torques** parameter in the **CartToJnt** function
|
| 100 |
+
*
|
| 101 |
+
* The following outlines the above-listed task interfaces in more detail.
|
| 102 |
+
*
|
| 103 |
+
* #### Cartesian Acceleration Constraints: alpha & beta
|
| 104 |
+
*
|
| 105 |
+
* This first type of motion driver can be used for specifying **physical** constraints such as contacts with environment [3],
|
| 106 |
+
* or **artificial** (i.e. task-imposed) constraints defined by the operational space task definition for the end-effector
|
| 107 |
+
* (tool-tip) segment. **Note**: the Vereshchagin solver expects that the input Cartesian Acceleration Constraints, i.e.
|
| 108 |
+
* unit constraint forces in alpha parameters, are expressed w.r.t. robot's base frame. However, the acceleration energy
|
| 109 |
+
* setpoints, i.e. beta parameters, are expressed w.r.t. above-defined unit constraint forces. More specifically, each DOF
|
| 110 |
+
* (element) in beta parameter corresponds to its respective DOF (column) of the unit constraint force matrix (alpha) [11].
|
| 111 |
+
*
|
| 112 |
+
* To use this interface, a user should define **i)** the active constraint directions via **alpha** parameter, which is
|
| 113 |
+
* a **6 x m** matrix of spatial unit constraint forces, and **ii)** acceleration energy setpoints via **beta**, which is
|
| 114 |
+
* a **m x 1** vector. Here, the number of constraints **m**, or in another words number of spatial unit constraint forces
|
| 115 |
+
* is not required to always be equal to **6**, which means that a human programmer can leave some of the degrees of freedom
|
| 116 |
+
* unspecified [2] for this motion driver, and still produce valid joint control commands [5]. For example, if we want to
|
| 117 |
+
* constrain the motion of the end-effector segment in only one direction, namely linear **x**-direction, we can define
|
| 118 |
+
* the constraint as [3]:
|
| 119 |
+
*
|
| 120 |
+
* **alpha** =
|
| 121 |
+
* | |
|
| 122 |
+
* | --|
|
| 123 |
+
* | 1 |
|
| 124 |
+
* | 0 |
|
| 125 |
+
* | 0 |
|
| 126 |
+
* | 0 |
|
| 127 |
+
* | 0 |
|
| 128 |
+
* | 0 |
|
| 129 |
+
*
|
| 130 |
+
* **beta** = | 0 |
|
| 131 |
+
*
|
| 132 |
+
* Note that here, the first three rows of matrix **alpha** represent linear elements and the last three rows represent
|
| 133 |
+
* angular elements, of the spatial unit force defined in Plücker coordinates [4]. By giving zero value to acceleration
|
| 134 |
+
* energy setpoint (**beta**), we are defining that the end-effector is not allowed to have linear acceleration in **x**
|
| 135 |
+
* direction. Or in other words, we are restricting the robot from producing any acceleration energy in that specified direction.
|
| 136 |
+
*
|
| 137 |
+
* Another example includes the specification of constraints in **5 DOFs**. We can constrain the motion of robot's end-effector
|
| 138 |
+
* such that it is only allowed to **freely** move in the linear **z**-direction, without performing linear motions in **x**
|
| 139 |
+
* and **y** and angular motions in **x**, **y** and **z** directions:
|
| 140 |
+
*
|
| 141 |
+
* **alpha** =
|
| 142 |
+
* | | | | | |
|
| 143 |
+
* | --| --| --| --| --|
|
| 144 |
+
* | 1 | 0 | 0 | 0 | 0 |
|
| 145 |
+
* | 0 | 1 | 0 | 0 | 0 |
|
| 146 |
+
* | 0 | 0 | 0 | 0 | 0 |
|
| 147 |
+
* | 0 | 0 | 1 | 0 | 0 |
|
| 148 |
+
* | 0 | 0 | 0 | 1 | 0 |
|
| 149 |
+
* | 0 | 0 | 0 | 0 | 1 |
|
| 150 |
+
*
|
| 151 |
+
* **beta** =
|
| 152 |
+
* | |
|
| 153 |
+
* | --|
|
| 154 |
+
* | 0 |
|
| 155 |
+
* | 0 |
|
| 156 |
+
* | 0 |
|
| 157 |
+
* | 0 |
|
| 158 |
+
* | 0 |
|
| 159 |
+
*
|
| 160 |
+
* For both above-described task examples, the Acceleration Constrained Hybrid Dynamics (ACHD) solver will compute
|
| 161 |
+
* valid control (constraint) joint torques, even though some of the Cartesian DOFs are left unspecified
|
| 162 |
+
* (e.g. in the case of the second example that would be end-effector's **z**-direction). More specifically:
|
| 163 |
+
* ``Underconstrained motion specifications are naturally resolved using Gauss' principle of least constraint`` [5].
|
| 164 |
+
* This means that in those directions in which the robot is not constrained by the task definition, its motions will
|
| 165 |
+
* be controlled by the nature. For instance, in the second example, natural resolution of the robot motion would define
|
| 166 |
+
* that the end-effector "**falls**" in the linear **z** direction due to effects of gravity, with the assumption that
|
| 167 |
+
* gravity forces are acting along $z$-direction.
|
| 168 |
+
*
|
| 169 |
+
* Moreover, the motion specification in the second example is equivalent to:
|
| 170 |
+
*
|
| 171 |
+
* **alpha** =
|
| 172 |
+
* | | | | | | |
|
| 173 |
+
* | --| --| --| --| --| --|
|
| 174 |
+
* | 1 | 0 | 0 | 0 | 0 | 0 |
|
| 175 |
+
* | 0 | 1 | 0 | 0 | 0 | 0 |
|
| 176 |
+
* | 0 | 0 | 0 | 0 | 0 | 0 |
|
| 177 |
+
* | 0 | 0 | 0 | 1 | 0 | 0 |
|
| 178 |
+
* | 0 | 0 | 0 | 0 | 1 | 0 |
|
| 179 |
+
* | 0 | 0 | 0 | 0 | 0 | 1 |
|
| 180 |
+
* (note that elements in the third column are all zeros, meaning z-linear constraint is deactivated)
|
| 181 |
+
*
|
| 182 |
+
* **beta** =
|
| 183 |
+
* | |
|
| 184 |
+
* | --|
|
| 185 |
+
* | 0 |
|
| 186 |
+
* | 0 |
|
| 187 |
+
* | 0 |
|
| 188 |
+
* | 0 |
|
| 189 |
+
* | 0 |
|
| 190 |
+
* | 0 |
|
| 191 |
+
*
|
| 192 |
+
* The last example involves the full specification of the desired end-effector motion (in this case,
|
| 193 |
+
* not necessarily zero accelerations), i.e. specification of constraints in all 6 **DOFs**:
|
| 194 |
+
*
|
| 195 |
+
* **alpha** =
|
| 196 |
+
* | | | | | | |
|
| 197 |
+
* | --| --| --| --| --| --|
|
| 198 |
+
* | 1 | 0 | 0 | 0 | 0 | 0 |
|
| 199 |
+
* | 0 | 1 | 0 | 0 | 0 | 0 |
|
| 200 |
+
* | 0 | 0 | 1 | 0 | 0 | 0 |
|
| 201 |
+
* | 0 | 0 | 0 | 1 | 0 | 0 |
|
| 202 |
+
* | 0 | 0 | 0 | 0 | 1 | 0 |
|
| 203 |
+
* | 0 | 0 | 0 | 0 | 0 | 1 |
|
| 204 |
+
*
|
| 205 |
+
* **beta** = **alpha^T * X_dotdot_N**
|
| 206 |
+
*
|
| 207 |
+
* Here, **N** stands for the index of the last robot's segment, end-effector (tool-tip). The reader should note
|
| 208 |
+
* that we can directly assign values (magnitudes) of the desired (task-defined) spatial acceleration **6 x 1**
|
| 209 |
+
* vector **X_dotdot_N** to the **6 x 1** vector of acceleration energy (**beta**) [3]. Even though physical
|
| 210 |
+
* dimensions (units) of these two vectors are not the same, the property of matrix **alpha** (it contains
|
| 211 |
+
* **unit** vectors), permits that we can assign values of desired accelerations to acceleration energy setpoints,
|
| 212 |
+
* in respective directions. Namely, each column of matrix **alpha** has the value of **1** in the respective
|
| 213 |
+
* direction in which constraint force works, thus it follows that the value of acceleration energy setpoint is
|
| 214 |
+
* the same as the value of Cartesian acceleration, in the respective direction.
|
| 215 |
+
*
|
| 216 |
+
* #### External Forces: f_ext
|
| 217 |
+
*
|
| 218 |
+
* This type of driver can be used for specifying **physical** (but not artificial, i.e. not task-introduced)
|
| 219 |
+
* Cartesian wrenches acting on each of the robot's segments [11]. Examples for a **physical** force on a segment can be:
|
| 220 |
+
* **i)** a known weight at the robot's gripper, for instance, a grasped cup or **ii)** a force from a human pushing
|
| 221 |
+
* the robot [5]. Note that the implementation of Vereshchagin solver in KDL expects the provided **f_ext** is
|
| 222 |
+
* expressed w.r.t. robot's base frame, which is in contrast to the case of KDL's RNE solver.
|
| 223 |
+
*
|
| 224 |
+
* ### Feed-Forward Joint Torques: ff_torque
|
| 225 |
+
*
|
| 226 |
+
* This type of motion driver can be used for specifying **physical** (but not artificial, i.e. not task-introduced)
|
| 227 |
+
* joint torques, for example, spring and/or damper-based torques (e.g. friction effects) in robot's joints [11].
|
| 228 |
+
*
|
| 229 |
+
* Additional examples on using these input interfaces can be found in "../tests/solvertest.cpp":
|
| 230 |
+
*
|
| 231 |
+
* * VereshchaginTest() function - an example on how to use all interfaces of this solver for computing
|
| 232 |
+
* the solution to the Hybrid Dynamics (HD) problem.
|
| 233 |
+
*
|
| 234 |
+
* * FdAndVereshchaginSolversConsistencyTest() function - an example on how to only use this solver for
|
| 235 |
+
* computing the solution to the Featherstone's (i.e. Articulated Body Algorithm (ABA)) version of
|
| 236 |
+
* the Forward Dynamics (FD) problem.
|
| 237 |
+
*
|
| 238 |
+
* ### Solver's Output
|
| 239 |
+
*
|
| 240 |
+
* This recursive dynamics solver is computing several quantities that represent solutions to both, inverse and
|
| 241 |
+
* forward dynamics problems, or in other words solutions to the constrained hybrid dynamics problem.
|
| 242 |
+
* More specifically, the output interface of the original Popov-Vereshchagin algorithm consists of [3], [5]:
|
| 243 |
+
*
|
| 244 |
+
* * Magnitudes of constraint forces that act on the end-effector, denoted by the Lagrange multiplier **nu**
|
| 245 |
+
* in the solver's implementation and original solver's publication[2].
|
| 246 |
+
*
|
| 247 |
+
* * Joint constraint torques required for achieving the desired (acceleration-constraints-defined) behavior of
|
| 248 |
+
* the robot: **constraint_torque**. These torques represent control commands that should be sent to robot's joint drivers.
|
| 249 |
+
*
|
| 250 |
+
* * Argument that defines the solution to the originally formulated optimization problem in **Gauss' principle**.
|
| 251 |
+
* In other words, the joint accelerations **q_dotdot** resulting from the total torque acting on each joint (**total_torque**),
|
| 252 |
+
* i.e. from the aforementioned constraint torques and all natural and external forces acting on the system.
|
| 253 |
+
*
|
| 254 |
+
* * The resulting and complete spatial accelerations of each segment in the kinematic chain: **X_dotdot**
|
| 255 |
+
*
|
| 256 |
+
* Furthermore, if necessary, a complete spatial vector of imposed constraint forces can be computed [3],
|
| 257 |
+
* from the following relation: **alpha * nu**.
|
| 258 |
+
*
|
| 259 |
+
* The reader should note that this **constraint_torque** is the **necessary** control command that a user is supposed
|
| 260 |
+
* to send to robot's joints, to achieve the motion that is computed (resolved) by the Popov-Vereshchagin solver.
|
| 261 |
+
* More specifically, here **constraint_torque** represent solution to the **Inverse Dynamics (ID)** problem.
|
| 262 |
+
* Nevertheless, the reason why a user is not supposed to use the **total_torque** values as the control commands
|
| 263 |
+
* for robot's joints, is the fact that the torque contributions that represent the difference between **total_torque**
|
| 264 |
+
* and **constraint_torque** already exist (act) on robot joints. More specifically, these **additional (residual)**
|
| 265 |
+
* contributions are produced on the joints by the already existing natural forces that act on the system [11].
|
| 266 |
+
*
|
| 267 |
+
* On the other side, joint accelerations, namely **q_dotdot** provide solution to the **Forward Dynamics (FD)** problem
|
| 268 |
+
* and these quantities can be used for both control (integrate to joint positions/velocities) and simulation purposes [11].
|
| 269 |
+
*
|
| 270 |
+
* ## PRACTICAL INSIGHTS/CONSIDERATIONS
|
| 271 |
+
*
|
| 272 |
+
* The Popov-Vereshchagin hybrid dynamics solver enables a user to achieve many types of operational space tasks [11].
|
| 273 |
+
* In other words, various controllers can be implemented **around** the aforementioned interfaces of the algorithm.
|
| 274 |
+
* Examples can be controllers for hybrid force/position control, impedance control, etc. However, there are some practical
|
| 275 |
+
* insights about this algorithm that need to taken into account.
|
| 276 |
+
*
|
| 277 |
+
* ### Prioritizations between motion drivers (interfaces)
|
| 278 |
+
*
|
| 279 |
+
* The original derivation of this solver, which is considered in this library, prioritizes Cartesian acceleration constrains
|
| 280 |
+
* (specified for the end-effector segment) over other two motion drivers (Cartesian external wrenches and feedforward joint torques) [11].
|
| 281 |
+
* In practice, this means the following:
|
| 282 |
+
*
|
| 283 |
+
* * If the external wrenches and/or feedforward joint torques contribute positively (i.e. assist) in producing Cartesian accelerations
|
| 284 |
+
* (specified via acceleration constraint interface), the Vereshchagin solver will take advantage of these forces to compute
|
| 285 |
+
* (acceleration-) energy optimal motions.
|
| 286 |
+
*
|
| 287 |
+
* * On the other hand, if the aforementioned external wrenches and/or feedforward joint torques contribute negatively (i.e. interfere)
|
| 288 |
+
* the Cartesian accelerations, the Vereshchagin solver will compensate all of those forces to correctly produce constrained
|
| 289 |
+
* accelerations of the end-effector. More specifically, additional torque commands will be computed under
|
| 290 |
+
* **constrained joint torques** (**ctrl_torques** in this implementation), to overcome those "disturbances".
|
| 291 |
+
*
|
| 292 |
+
* Nevertheless, the above-described prioritization can be changed (see [3] & [5] for more details) but those features are not implemented in KDL.
|
| 293 |
+
*
|
| 294 |
+
* ### Using the algorithm for solving forward dynamics (FD) problem
|
| 295 |
+
*
|
| 296 |
+
* The reader should note that the Popov-Vereshchagin solver represents an extension to the well-known forward-dynamics
|
| 297 |
+
* Articulated Body Algorithm (ABA) developed by Featherstone and described in [4] (moreover, Featherstone mentioned Vereshchagin solver
|
| 298 |
+
* in his book [4], page 117). This means that the Popov-Vereshchagin solver can also be purely used as this Articulated Body Algorithm
|
| 299 |
+
* forward-dynamics algorithm. In that case, it is necessary for the user to deactivate all Cartesian acceleration constraints (it is sufficient
|
| 300 |
+
* to set all elements in **alpha** matrix to zero) and proceed using other two interfaces as in the case of standard FD solver. More specifically,
|
| 301 |
+
* use **f_ext** input to define **physical** external wrenches acting on the robot's body (should be expressed w.r.t. robot's base frame) and
|
| 302 |
+
* **ff_torque** input to define command torques acting in robot's joints. The resulting robot's motion can be taken from **q_dotdot** and
|
| 303 |
+
* **X_dotdot** solver's outputs.
|
| 304 |
+
*
|
| 305 |
+
* Nevertheless, the Popov-Vereshchagin solver can also be used for solving more advanced forward dynamics problems, than those solved by ABA [4].
|
| 306 |
+
* More specifically, if this solver is used in a certain simulation environment for the use-case of simulating robot behaviors, all three
|
| 307 |
+
* interfaces can be exploited for defining a more descriptive robot's state. Here, a user can exploit the Cartesian acceleration constraint
|
| 308 |
+
* interface to specify different constraints imposed on the end-effector, along with other interfaces, and simulate what would be the robot's
|
| 309 |
+
* behavior due to these constraints and environmental impacts. Here, the resulting robot's motion can, as well, be taken from **q_dotdot** and
|
| 310 |
+
* **X_dotdot** solver's outputs. For example, MuJoCo framework (see MuJoCo's documentation) also uses Gauss' principle of least constraint to
|
| 311 |
+
* simulate constraint forces in certain situations, however, there, final derivation of this principle in the software is different. However, in
|
| 312 |
+
* the case of this more advanced forward dynamics computations, the user needs to be aware of prioritizations between input interfaces
|
| 313 |
+
* (mentioned in "Prioritizations" section above) and internal policies on
|
| 314 |
+
* handling singularities (mentioned in "Singularities and matrix inversions" section below).
|
| 315 |
+
*
|
| 316 |
+
* ### Singularities and matrix inversions
|
| 317 |
+
*
|
| 318 |
+
* To find the minimal-energy solution to the Inverse Dynamics (ID) problem, i.e. find the Langrage multiplier **nu**, the solver needs to compute
|
| 319 |
+
* the inverse of a so-called "acceleration constraint coupling matrix"[3] in the balance equation before starting the third sweep.
|
| 320 |
+
* However, the robot's configuration has a direct impact on this matrix and its inversion. Namely, if the robot is in a singular configuration for
|
| 321 |
+
* the task specified via acceleration constraints, this matrix will become rank-deficient. This means that it is not possible to find a feasible
|
| 322 |
+
* solution for that particular end-effector's DOF that is (or DOFs that are) lost due to the singular configuration. In other words, it is not
|
| 323 |
+
* possible to find **constraint torques** that will satisfy imposed acceleration constraints in that DOF/DOFs. Nevertheless, in this situation,
|
| 324 |
+
* it is still possible to find the (energy-optimal) solution for other "non-singular" DOFs. For that reason, in KDL's implementation of the solver,
|
| 325 |
+
* matrix inverse is found by using the SVD technique to construct a pseudo inverse. Additionally, in this implementation, a control policy is
|
| 326 |
+
* introduced via the truncated-SVD method to deactivate, i.e. more specifically **ignore**, acceleration constraints for the DOFs that are lost due
|
| 327 |
+
* to robot's singular configuration. Of course, this is a choice (control policy), i.e. only one option for solving the singularity problem and
|
| 328 |
+
* producing safe joint commands. It is left for the user to explore other control policies (options) for this particular problem if of course,
|
| 329 |
+
* the user is not satisfied with the current control policy.
|
| 330 |
+
*
|
| 331 |
+
* ### Supported robot models
|
| 332 |
+
*
|
| 333 |
+
* KDL's current implementation of the Vereshchagin HD solver supports only robot chains that have equal number of joints and segments.
|
| 334 |
+
* Moreover, this implementation can only compute dynamics for **serial** type of chains, i.e. currently, **tree** robot structures are not supported
|
| 335 |
+
* in this solver. Nevertheless, the original solver's derivation has been extended in [3] to account for multiple motion constraints imposed
|
| 336 |
+
* on a **tree** robot structure. This extension does not only account for acceleration constraints imposed on multiple end-effectors but also for
|
| 337 |
+
* acceleration constraints imposed on more proximal segments. However, the above-mentioned extensions are currently not implemented in this version of KDL.
|
| 338 |
+
*
|
| 339 |
+
* ## REFERENCES
|
| 340 |
+
*
|
| 341 |
+
* [1] E. P. Popov, A. F. Vereshchagin, and S. L. Zenkevich, "Manipulyatsionnye roboty: Dinamika i algoritmy", Nauka, Moscow, 1978.
|
| 342 |
+
*
|
| 343 |
+
* [2] A. F. Vereshchagin, “Modelling and control of motion of manipulation robots”, Soviet Journal of Computer and Systems Sciences, vol. 27, pp. 29–38, 1989.
|
| 344 |
+
*
|
| 345 |
+
* [3] A. Shakhimardanov, “Composable robot motion stack: Implementing constrained hybrid dynamics using semantic models of kinematic chains”, PhD thesis, KU Leuven, 2015.
|
| 346 |
+
*
|
| 347 |
+
* [4] R. Featherstone, Rigid body dynamics algorithms. Springer, 2008.
|
| 348 |
+
*
|
| 349 |
+
* [5] S. Schneider and H. Bruyninckx, “Exploiting linearity in dynamics solvers for the design of composable robotic manipulation architectures”, in IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2019.
|
| 350 |
+
*
|
| 351 |
+
* [6] H. Bruyninckx and O. Khatib, "Gauss’ principle and the dynamics of redundant and constrained manipulators", in IEEE International Conference on Robotics and Automation, 2000.
|
| 352 |
+
*
|
| 353 |
+
* [7] C. F. Gauß, "Über ein neues allgemeines Grundgesetz der Mechanik.", Journal für die reine und angewandte Mathematik, vol. 4, pp. 232–235, 1829.
|
| 354 |
+
*
|
| 355 |
+
* [8] A. F. Vereshchagin, “Computer simulation of the dynamics of complicated mechanisms of robot-manipulators”, Engineering Cybernetics, 12(6), pp. 65–70, 1974.
|
| 356 |
+
*
|
| 357 |
+
* [9] E. P. Popov, "Control of robots-manipulators", Engineering Cybernetics, 1974.
|
| 358 |
+
*
|
| 359 |
+
* [10] E. Ramm, “Principles of least action and of least constraint”, GAMM-Mitteilungen, vol. 34, pp. 164–182, 2011.
|
| 360 |
+
*
|
| 361 |
+
* [11] D. Vukcevic, "Lazy Robot Control by Relaxation of Motion and Force Constraints." Technical Report/Hochschule Bonn-Rhein-Sieg University of Applied Sciences, Department of Computer Science, 2020.
|
| 362 |
+
*
|
| 363 |
+
* @ingroup KinematicFamily
|
| 364 |
+
*/
|
| 365 |
+
|
| 366 |
+
class ChainHdSolver_Vereshchagin : KDL::SolverI
|
| 367 |
+
{
|
| 368 |
+
typedef std::vector<Twist> Twists;
|
| 369 |
+
typedef std::vector<Frame> Frames;
|
| 370 |
+
typedef Eigen::Matrix<double, 6, 1 > Vector6d;
|
| 371 |
+
typedef Eigen::Matrix<double, 6, 6 > Matrix6d;
|
| 372 |
+
typedef Eigen::Matrix<double, 6, Eigen::Dynamic> Matrix6Xd;
|
| 373 |
+
|
| 374 |
+
public:
|
| 375 |
+
/**
|
| 376 |
+
* Constructor for the solver, it will allocate all the necessary memory
|
| 377 |
+
* \param chain The kinematic chain to calculate the hybrid dynamics for. An internal copy will be made.
|
| 378 |
+
* \param root_acc The acceleration twist of the root segment to use during the calculation (usually contains gravity).
|
| 379 |
+
* Note: This solver takes gravity acceleration with opposite sign comparead to the KDL's FD and RNE solvers
|
| 380 |
+
* \param nc Number of constraints imposed on the robot's end-effector (maximum is 6).
|
| 381 |
+
*/
|
| 382 |
+
ChainHdSolver_Vereshchagin(const Chain& chain, const Twist &root_acc, const unsigned int nc);
|
| 383 |
+
|
| 384 |
+
~ChainHdSolver_Vereshchagin()
|
| 385 |
+
{
|
| 386 |
+
};
|
| 387 |
+
|
| 388 |
+
/**
|
| 389 |
+
* This method calculates joint space constraint torques and accelerations.
|
| 390 |
+
* It returns 0 when it succeeds, otherwise -1 or -2 for nonmatching matrix and array sizes.
|
| 391 |
+
* Input parameters:
|
| 392 |
+
* \param q The current joint positions
|
| 393 |
+
* \param q_dot The current joint velocities
|
| 394 |
+
* \param alpha The active constraint directions (unit constraint forces expressed w.r.t. robot's base frame)
|
| 395 |
+
* \param beta The acceleration energy setpoints (expressed w.r.t. above-defined unit constraint forces)
|
| 396 |
+
* \param f_ext The external forces (no gravity, it is given in root acceleration) on the segments
|
| 397 |
+
* \param ff_torques The feed-forward joint space torques
|
| 398 |
+
*
|
| 399 |
+
* Output parameters:
|
| 400 |
+
* \param q_dotdot The resulting joint accelerations
|
| 401 |
+
* \param constraint_torques The resulting joint constraint torques (what each joint feels due to the constraint forces acting on the end-effector)
|
| 402 |
+
*
|
| 403 |
+
* @return error/success code
|
| 404 |
+
*/
|
| 405 |
+
int CartToJnt(const JntArray &q, const JntArray &q_dot, JntArray &q_dotdot, const Jacobian& alfa, const JntArray& beta, const Wrenches& f_ext, const JntArray &ff_torques, JntArray &constraint_torques);
|
| 406 |
+
|
| 407 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 408 |
+
virtual void updateInternalDataStructures();
|
| 409 |
+
|
| 410 |
+
//Returns cartesian acceleration of links in base coordinates
|
| 411 |
+
void getTransformedLinkAcceleration(Twists& x_dotdot);
|
| 412 |
+
|
| 413 |
+
// Returns total torque acting on each joint (constraints + nature + external forces)
|
| 414 |
+
void getTotalTorque(JntArray &total_tau);
|
| 415 |
+
|
| 416 |
+
// Returns magnitude of the constraint forces acting on the end-effector: Lagrange Multiplier
|
| 417 |
+
void getContraintForceMagnitude(Eigen::VectorXd &nu_);
|
| 418 |
+
|
| 419 |
+
/*
|
| 420 |
+
//Returns cartesian positions of links in base coordinates
|
| 421 |
+
void getLinkCartesianPose(Frames& x_base);
|
| 422 |
+
//Returns cartesian velocities of links in base coordinates
|
| 423 |
+
void getLinkCartesianVelocity(Twists& xDot_base);
|
| 424 |
+
//Returns cartesian acceleration of links in base coordinates
|
| 425 |
+
void getLinkCartesianAcceleration(Twists& xDotDot_base);
|
| 426 |
+
//Returns cartesian positions of links in link tip coordinates
|
| 427 |
+
void getLinkPose(Frames& x_local);
|
| 428 |
+
//Returns cartesian velocities of links in link tip coordinates
|
| 429 |
+
void getLinkVelocity(Twists& xDot_local);
|
| 430 |
+
//Returns cartesian acceleration of links in link tip coordinates
|
| 431 |
+
void getLinkAcceleration(Twists& xDotdot_local);
|
| 432 |
+
//Acceleration energy due to unit constraint forces at the end-effector
|
| 433 |
+
void getLinkUnitForceAccelerationEnergy(Eigen::MatrixXd& M);
|
| 434 |
+
//Acceleration energy due to arm configuration: bias force plus input joint torques
|
| 435 |
+
void getLinkBiasForceAcceleratoinEnergy(Eigen::VectorXd& G);
|
| 436 |
+
|
| 437 |
+
void getLinkUnitForceMatrix(Matrix6Xd& E_tilde);
|
| 438 |
+
|
| 439 |
+
void getLinkBiasForceMatrix(Wrenches& R_tilde);
|
| 440 |
+
|
| 441 |
+
void getJointBiasAcceleration(JntArray &bias_q_dotdot);
|
| 442 |
+
*/
|
| 443 |
+
private:
|
| 444 |
+
/**
|
| 445 |
+
* This method calculates all cartesian space poses, twists, bias accelerations.
|
| 446 |
+
* External forces are also taken into account in this outward sweep.
|
| 447 |
+
*/
|
| 448 |
+
void initial_upwards_sweep(const JntArray &q, const JntArray &q_dot, const JntArray &q_dotdot, const Wrenches& f_ext);
|
| 449 |
+
/**
|
| 450 |
+
* This method is a force balance sweep. It calculates articulated body inertias and bias forces.
|
| 451 |
+
* Additionally, acceleration energies generated by bias forces and unit forces are calculated here.
|
| 452 |
+
*/
|
| 453 |
+
void downwards_sweep(const Jacobian& alfa, const JntArray& ff_torques);
|
| 454 |
+
/**
|
| 455 |
+
* This method calculates constraint force magnitudes.
|
| 456 |
+
*
|
| 457 |
+
*/
|
| 458 |
+
void constraint_calculation(const JntArray& beta);
|
| 459 |
+
/**
|
| 460 |
+
* This method puts all acceleration contributions (constraint, bias, nullspace and parent accelerations) together.
|
| 461 |
+
*
|
| 462 |
+
*/
|
| 463 |
+
void final_upwards_sweep(JntArray &q_dotdot, JntArray &constraint_torques);
|
| 464 |
+
|
| 465 |
+
private:
|
| 466 |
+
const Chain& chain;
|
| 467 |
+
unsigned int nj;
|
| 468 |
+
unsigned int ns;
|
| 469 |
+
unsigned int nc;
|
| 470 |
+
Twist acc_root;
|
| 471 |
+
Jacobian alfa_N;
|
| 472 |
+
Jacobian alfa_N2;
|
| 473 |
+
Eigen::MatrixXd M_0_inverse;
|
| 474 |
+
Eigen::MatrixXd Um;
|
| 475 |
+
Eigen::MatrixXd Vm;
|
| 476 |
+
JntArray beta_N;
|
| 477 |
+
Eigen::VectorXd nu;
|
| 478 |
+
Eigen::VectorXd nu_sum;
|
| 479 |
+
Eigen::VectorXd Sm;
|
| 480 |
+
Eigen::VectorXd tmpm;
|
| 481 |
+
Eigen::VectorXd total_torques; // all the contributions that are felt at the joint: constraints + nature + external forces
|
| 482 |
+
Wrench qdotdot_sum;
|
| 483 |
+
Frame F_total;
|
| 484 |
+
|
| 485 |
+
struct segment_info
|
| 486 |
+
{
|
| 487 |
+
Frame F; //local pose with respect to previous link in segments coordinates
|
| 488 |
+
Frame F_base; // pose of a segment in root coordinates
|
| 489 |
+
Twist Z; //Unit twist
|
| 490 |
+
Twist v; //twist
|
| 491 |
+
Twist acc; //acceleration twist
|
| 492 |
+
Wrench U; //wrench p of the bias forces (in cartesian space)
|
| 493 |
+
Wrench R; //wrench p of the bias forces
|
| 494 |
+
Wrench R_tilde; //vector of wrench p of the bias forces (new) in matrix form
|
| 495 |
+
Twist C; //constraint
|
| 496 |
+
Twist A; //constraint
|
| 497 |
+
ArticulatedBodyInertia H; //I (expressed in 6*6 matrix)
|
| 498 |
+
ArticulatedBodyInertia P; //I (expressed in 6*6 matrix)
|
| 499 |
+
ArticulatedBodyInertia P_tilde; //I (expressed in 6*6 matrix)
|
| 500 |
+
Wrench PZ; //vector U[i] = I_A[i]*S[i]
|
| 501 |
+
Wrench PC; //vector E[i] = I_A[i]*c[i]
|
| 502 |
+
double D; //vector D[i] = S[i]^T*U[i]
|
| 503 |
+
Matrix6Xd E; //matrix with virtual unit constraint force due to acceleration constraints
|
| 504 |
+
Matrix6Xd E_tilde;
|
| 505 |
+
Eigen::MatrixXd M; //acceleration energy already generated at link i
|
| 506 |
+
Eigen::VectorXd G; //magnitude of the constraint forces already generated at link i
|
| 507 |
+
Eigen::VectorXd EZ; //K[i] = Etiltde'*Z
|
| 508 |
+
double nullspaceAccComp; //Azamat: constribution of joint space u[i] forces to joint space acceleration
|
| 509 |
+
double constAccComp; //Azamat: constribution of joint space constraint forces to joint space acceleration
|
| 510 |
+
double biasAccComp; //Azamat: constribution of joint space bias forces to joint space acceleration
|
| 511 |
+
double totalBias; //Azamat: R+PC (centrepital+coriolis) in joint subspace
|
| 512 |
+
double u; //vector u[i] = torques(i) - S[i]^T*(p_A[i] + I_A[i]*C[i]) in joint subspace. Azamat: In code u[i] = torques(i) - s[i].totalBias
|
| 513 |
+
|
| 514 |
+
segment_info(unsigned int nc):
|
| 515 |
+
D(0),nullspaceAccComp(0),constAccComp(0),biasAccComp(0),totalBias(0),u(0)
|
| 516 |
+
{
|
| 517 |
+
E.resize(6, nc);
|
| 518 |
+
E_tilde.resize(6, nc);
|
| 519 |
+
G.resize(nc);
|
| 520 |
+
M.resize(nc, nc);
|
| 521 |
+
EZ.resize(nc);
|
| 522 |
+
E.setZero();
|
| 523 |
+
E_tilde.setZero();
|
| 524 |
+
M.setZero();
|
| 525 |
+
G.setZero();
|
| 526 |
+
EZ.setZero();
|
| 527 |
+
};
|
| 528 |
+
};
|
| 529 |
+
|
| 530 |
+
std::vector<segment_info, Eigen::aligned_allocator<segment_info> > results;
|
| 531 |
+
|
| 532 |
+
};
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
#endif // KDL_CHAINHDSOLVER_VERESHCHAGIN_HPP
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver.hpp
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2009 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_IDSOLVER_HPP
|
| 23 |
+
#define KDL_CHAIN_IDSOLVER_HPP
|
| 24 |
+
|
| 25 |
+
#include "chain.hpp"
|
| 26 |
+
#include "frames.hpp"
|
| 27 |
+
#include "jntarray.hpp"
|
| 28 |
+
#include "solveri.hpp"
|
| 29 |
+
|
| 30 |
+
namespace KDL
|
| 31 |
+
{
|
| 32 |
+
|
| 33 |
+
typedef std::vector<Wrench> Wrenches;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* \brief This <strong>abstract</strong> class encapsulates the inverse
|
| 37 |
+
* dynamics solver for a KDL::Chain.
|
| 38 |
+
*
|
| 39 |
+
*/
|
| 40 |
+
class ChainIdSolver : public KDL::SolverI
|
| 41 |
+
{
|
| 42 |
+
public:
|
| 43 |
+
/**
|
| 44 |
+
* Calculate inverse dynamics, from joint positions, velocity, acceleration, external forces
|
| 45 |
+
* to joint torques/forces.
|
| 46 |
+
*
|
| 47 |
+
* @param q input joint positions
|
| 48 |
+
* @param q_dot input joint velocities
|
| 49 |
+
* @param q_dotdot input joint accelerations
|
| 50 |
+
*
|
| 51 |
+
* @param torque output joint torques
|
| 52 |
+
*
|
| 53 |
+
* @return if < 0 something went wrong
|
| 54 |
+
*/
|
| 55 |
+
virtual int CartToJnt(const JntArray &q, const JntArray &q_dot, const JntArray &q_dotdot, const Wrenches& f_ext,JntArray &torques)=0;
|
| 56 |
+
|
| 57 |
+
// Need functions to return the manipulator mass, coriolis and gravity matrices - Lagrangian Formulation.
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_recursive_newton_euler.cpp
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2009 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainidsolver_recursive_newton_euler.hpp"
|
| 23 |
+
#include "frames_io.hpp"
|
| 24 |
+
|
| 25 |
+
namespace KDL{
|
| 26 |
+
|
| 27 |
+
ChainIdSolver_RNE::ChainIdSolver_RNE(const Chain& chain_,Vector grav):
|
| 28 |
+
chain(chain_),nj(chain.getNrOfJoints()),ns(chain.getNrOfSegments()),
|
| 29 |
+
X(ns),S(ns),v(ns),a(ns),f(ns)
|
| 30 |
+
{
|
| 31 |
+
ag=-Twist(grav,Vector::Zero());
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void ChainIdSolver_RNE::updateInternalDataStructures() {
|
| 35 |
+
nj = chain.getNrOfJoints();
|
| 36 |
+
ns = chain.getNrOfSegments();
|
| 37 |
+
X.resize(ns);
|
| 38 |
+
S.resize(ns);
|
| 39 |
+
v.resize(ns);
|
| 40 |
+
a.resize(ns);
|
| 41 |
+
f.resize(ns);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
int ChainIdSolver_RNE::CartToJnt(const JntArray &q, const JntArray &q_dot, const JntArray &q_dotdot, const Wrenches& f_ext,JntArray &torques)
|
| 45 |
+
{
|
| 46 |
+
if(nj != chain.getNrOfJoints() || ns != chain.getNrOfSegments())
|
| 47 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 48 |
+
|
| 49 |
+
//Check sizes when in debug mode
|
| 50 |
+
if(q.rows()!=nj || q_dot.rows()!=nj || q_dotdot.rows()!=nj || torques.rows()!=nj || f_ext.size()!=ns)
|
| 51 |
+
return (error = E_SIZE_MISMATCH);
|
| 52 |
+
unsigned int j=0;
|
| 53 |
+
|
| 54 |
+
//Sweep from root to leaf
|
| 55 |
+
for(unsigned int i=0;i<ns;i++){
|
| 56 |
+
double q_,qdot_,qdotdot_;
|
| 57 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 58 |
+
q_=q(j);
|
| 59 |
+
qdot_=q_dot(j);
|
| 60 |
+
qdotdot_=q_dotdot(j);
|
| 61 |
+
j++;
|
| 62 |
+
}else
|
| 63 |
+
q_=qdot_=qdotdot_=0.0;
|
| 64 |
+
|
| 65 |
+
//Calculate segment properties: X,S,vj,cj
|
| 66 |
+
X[i]=chain.getSegment(i).pose(q_);//Remark this is the inverse of the
|
| 67 |
+
//frame for transformations from
|
| 68 |
+
//the parent to the current coord frame
|
| 69 |
+
//Transform velocity and unit velocity to segment frame
|
| 70 |
+
Twist vj=X[i].M.Inverse(chain.getSegment(i).twist(q_,qdot_));
|
| 71 |
+
S[i]=X[i].M.Inverse(chain.getSegment(i).twist(q_,1.0));
|
| 72 |
+
//We can take cj=0, see remark section 3.5, page 55 since the unit velocity vector S of our joints is always time constant
|
| 73 |
+
//calculate velocity and acceleration of the segment (in segment coordinates)
|
| 74 |
+
if(i==0){
|
| 75 |
+
v[i]=vj;
|
| 76 |
+
a[i]=X[i].Inverse(ag)+S[i]*qdotdot_+v[i]*vj;
|
| 77 |
+
}else{
|
| 78 |
+
v[i]=X[i].Inverse(v[i-1])+vj;
|
| 79 |
+
a[i]=X[i].Inverse(a[i-1])+S[i]*qdotdot_+v[i]*vj;
|
| 80 |
+
}
|
| 81 |
+
//Calculate the force for the joint
|
| 82 |
+
//Collect RigidBodyInertia and external forces
|
| 83 |
+
RigidBodyInertia Ii=chain.getSegment(i).getInertia();
|
| 84 |
+
f[i]=Ii*a[i]+v[i]*(Ii*v[i])-f_ext[i];
|
| 85 |
+
//std::cout << "a[i]=" << a[i] << "\n f[i]=" << f[i] << "\n S[i]" << S[i] << std::endl;
|
| 86 |
+
}
|
| 87 |
+
//Sweep from leaf to root
|
| 88 |
+
j=nj-1;
|
| 89 |
+
for(int i=ns-1;i>=0;i--){
|
| 90 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 91 |
+
torques(j)=dot(S[i],f[i]);
|
| 92 |
+
torques(j)+=chain.getSegment(i).getJoint().getInertia()*q_dotdot(j); // add torque from joint inertia
|
| 93 |
+
--j;
|
| 94 |
+
}
|
| 95 |
+
if(i!=0)
|
| 96 |
+
f[i-1]=f[i-1]+X[i]*f[i];
|
| 97 |
+
}
|
| 98 |
+
return (error = E_NOERROR);
|
| 99 |
+
}
|
| 100 |
+
}//namespace
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_recursive_newton_euler.hpp
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2009 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_IKSOLVER_RECURSIVE_NEWTON_EULER_HPP
|
| 23 |
+
#define KDL_CHAIN_IKSOLVER_RECURSIVE_NEWTON_EULER_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainidsolver.hpp"
|
| 26 |
+
|
| 27 |
+
namespace KDL{
|
| 28 |
+
/**
|
| 29 |
+
* \brief Recursive newton euler inverse dynamics solver
|
| 30 |
+
*
|
| 31 |
+
* The algorithm implementation is based on the book "Rigid Body
|
| 32 |
+
* Dynamics Algorithms" of Roy Featherstone, 2008
|
| 33 |
+
* (ISBN:978-0-387-74314-1) See page 96 for the pseudo-code.
|
| 34 |
+
*
|
| 35 |
+
* It calculates the torques for the joints, given the motion of
|
| 36 |
+
* the joints (q,qdot,qdotdot), external forces on the segments
|
| 37 |
+
* (expressed in the segments reference frame) and the dynamical
|
| 38 |
+
* parameters of the segments.
|
| 39 |
+
*/
|
| 40 |
+
class ChainIdSolver_RNE : public ChainIdSolver{
|
| 41 |
+
public:
|
| 42 |
+
/**
|
| 43 |
+
* Constructor for the solver, it will allocate all the necessary memory
|
| 44 |
+
* \param chain The kinematic chain to calculate the inverse dynamics for, an internal copy will be made.
|
| 45 |
+
* \param grav The gravity vector to use during the calculation.
|
| 46 |
+
*/
|
| 47 |
+
ChainIdSolver_RNE(const Chain& chain,Vector grav);
|
| 48 |
+
~ChainIdSolver_RNE(){};
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Function to calculate from Cartesian forces to joint torques.
|
| 52 |
+
* Input parameters;
|
| 53 |
+
* \param q The current joint positions
|
| 54 |
+
* \param q_dot The current joint velocities
|
| 55 |
+
* \param q_dotdot The current joint accelerations
|
| 56 |
+
* \param f_ext The external forces (no gravity) on the segments
|
| 57 |
+
* Output parameters:
|
| 58 |
+
* \param torques the resulting torques for the joints
|
| 59 |
+
*/
|
| 60 |
+
int CartToJnt(const JntArray &q, const JntArray &q_dot, const JntArray &q_dotdot, const Wrenches& f_ext,JntArray &torques);
|
| 61 |
+
|
| 62 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 63 |
+
virtual void updateInternalDataStructures();
|
| 64 |
+
|
| 65 |
+
private:
|
| 66 |
+
const Chain& chain;
|
| 67 |
+
unsigned int nj;
|
| 68 |
+
unsigned int ns;
|
| 69 |
+
std::vector<Frame> X;
|
| 70 |
+
std::vector<Twist> S;
|
| 71 |
+
std::vector<Twist> v;
|
| 72 |
+
std::vector<Twist> a;
|
| 73 |
+
std::vector<Wrench> f;
|
| 74 |
+
Twist ag;
|
| 75 |
+
};
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_vereshchagin.cpp
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2009 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Author: Herman Bruyninckx
|
| 6 |
+
// Author: Azamat Shakhimardanov
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#include "chainidsolver_vereshchagin.hpp"
|
| 25 |
+
|
| 26 |
+
#include <iostream>
|
| 27 |
+
|
| 28 |
+
namespace KDL
|
| 29 |
+
{
|
| 30 |
+
|
| 31 |
+
ChainIdSolver_Vereshchagin::ChainIdSolver_Vereshchagin(const Chain& chain_, const Twist &root_acc, const unsigned int nc_) : ChainHdSolver_Vereshchagin(chain_, root_acc, nc_)
|
| 32 |
+
{
|
| 33 |
+
std::cout << "ChainIdSolver_Vereshchagin is renamed to ChainHdSolver_Vereshchagin in version 1.5. The old name will be dropped in version 1.6" << std::endl;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainidsolver_vereshchagin.hpp
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2009 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Author: Herman Bruyninckx
|
| 6 |
+
// Author: Azamat Shakhimardanov
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#ifndef KDL_CHAINIDSOLVER_VERESHCHAGIN_HPP
|
| 25 |
+
#define KDL_CHAINIDSOLVER_VERESHCHAGIN_HPP
|
| 26 |
+
|
| 27 |
+
#include "chainhdsolver_vereshchagin.hpp"
|
| 28 |
+
|
| 29 |
+
namespace KDL
|
| 30 |
+
{
|
| 31 |
+
|
| 32 |
+
class ChainIdSolver_Vereshchagin : public ChainHdSolver_Vereshchagin
|
| 33 |
+
{
|
| 34 |
+
public:
|
| 35 |
+
ChainIdSolver_Vereshchagin(const Chain& chain, const Twist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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_IKSOLVER_HPP
|
| 23 |
+
#define KDL_CHAIN_IKSOLVER_HPP
|
| 24 |
+
|
| 25 |
+
#include "chain.hpp"
|
| 26 |
+
#include "frames.hpp"
|
| 27 |
+
#include "framevel.hpp"
|
| 28 |
+
#include "frameacc.hpp"
|
| 29 |
+
#include "jntarray.hpp"
|
| 30 |
+
#include "jntarrayvel.hpp"
|
| 31 |
+
#include "jntarrayacc.hpp"
|
| 32 |
+
#include "solveri.hpp"
|
| 33 |
+
|
| 34 |
+
namespace KDL {
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* \brief This <strong>abstract</strong> class encapsulates the inverse
|
| 38 |
+
* position solver for a KDL::Chain.
|
| 39 |
+
*
|
| 40 |
+
* @ingroup KinematicFamily
|
| 41 |
+
*/
|
| 42 |
+
class ChainIkSolverPos : public KDL::SolverI {
|
| 43 |
+
public:
|
| 44 |
+
/**
|
| 45 |
+
* Calculate inverse position kinematics, from cartesian
|
| 46 |
+
*coordinates to joint coordinates.
|
| 47 |
+
*
|
| 48 |
+
* @param q_init initial guess of the joint coordinates
|
| 49 |
+
* @param p_in input cartesian coordinates
|
| 50 |
+
* @param q_out output joint coordinates
|
| 51 |
+
*
|
| 52 |
+
* @return if < 0 something went wrong
|
| 53 |
+
*/
|
| 54 |
+
virtual int CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out)=0;
|
| 55 |
+
|
| 56 |
+
virtual ~ChainIkSolverPos(){};
|
| 57 |
+
virtual void updateInternalDataStructures()=0;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* \brief This <strong>abstract</strong> class encapsulates the inverse
|
| 62 |
+
* velocity solver for a KDL::Chain.
|
| 63 |
+
*
|
| 64 |
+
* @ingroup KinematicFamily
|
| 65 |
+
*/
|
| 66 |
+
class ChainIkSolverVel : public KDL::SolverI {
|
| 67 |
+
public:
|
| 68 |
+
/**
|
| 69 |
+
* Calculate inverse velocity kinematics, from joint positions
|
| 70 |
+
*and cartesian velocity to joint velocities.
|
| 71 |
+
*
|
| 72 |
+
* @param q_in input joint positions
|
| 73 |
+
* @param v_in input cartesian velocity
|
| 74 |
+
* @param qdot_out output joint velocities
|
| 75 |
+
*
|
| 76 |
+
* @return if < 0 something went wrong
|
| 77 |
+
*/
|
| 78 |
+
virtual int CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)=0;
|
| 79 |
+
/**
|
| 80 |
+
* Calculate inverse position and velocity kinematics, from
|
| 81 |
+
*cartesian position and velocity to joint positions and velocities.
|
| 82 |
+
*
|
| 83 |
+
* @param q_init initial joint positions
|
| 84 |
+
* @param v_in input cartesian position and velocity
|
| 85 |
+
* @param q_out output joint position and velocity
|
| 86 |
+
*
|
| 87 |
+
* @return if < 0 something went wrong
|
| 88 |
+
*/
|
| 89 |
+
virtual int CartToJnt(const JntArray& q_init, const FrameVel& v_in, JntArrayVel& q_out)=0;
|
| 90 |
+
|
| 91 |
+
virtual ~ChainIkSolverVel(){};
|
| 92 |
+
virtual void updateInternalDataStructures()=0;
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* \brief This <strong>abstract</strong> class encapsulates the inverse
|
| 97 |
+
* acceleration solver for a KDL::Chain.
|
| 98 |
+
*
|
| 99 |
+
* @ingroup KinematicFamily
|
| 100 |
+
*/
|
| 101 |
+
|
| 102 |
+
class ChainIkSolverAcc : public KDL::SolverI {
|
| 103 |
+
public:
|
| 104 |
+
/**
|
| 105 |
+
* Calculate inverse acceleration kinematics from joint
|
| 106 |
+
* positions, joint velocities and cartesian acceleration to joint accelerations.
|
| 107 |
+
*
|
| 108 |
+
* @param q_in input joint positions
|
| 109 |
+
* @param qdot_in input joint velocities
|
| 110 |
+
* @param a_in input cartesian acceleration
|
| 111 |
+
* @param qdotdot_out output joint accelerations
|
| 112 |
+
*
|
| 113 |
+
* @return if < 0 something went wrong
|
| 114 |
+
*/
|
| 115 |
+
virtual int CartToJnt(const JntArray& q_in, const JntArray& qdot_in, const Twist a_in,
|
| 116 |
+
JntArray& qdotdot_out)=0;
|
| 117 |
+
/**
|
| 118 |
+
* Calculate inverse position, velocity and acceration
|
| 119 |
+
*kinematics from cartesian coordinates to joint coordinates
|
| 120 |
+
*
|
| 121 |
+
* @param q_init initial guess for joint positions
|
| 122 |
+
* @param a_in input cartesian position, velocity and acceleration
|
| 123 |
+
* @param q_out output joint position, velocity and acceleration
|
| 124 |
+
*
|
| 125 |
+
* @return if < 0 something went wrong
|
| 126 |
+
*/
|
| 127 |
+
virtual int CartTojnt(const JntArray& q_init, const FrameAcc& a_in,
|
| 128 |
+
JntArrayAcc& q_out)=0;
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Calculate inverse velocity and acceleration kinematics from
|
| 132 |
+
* joint positions and cartesian velocity and acceleration to
|
| 133 |
+
* joint velocities and accelerations.
|
| 134 |
+
*
|
| 135 |
+
* @param q_in input joint positions
|
| 136 |
+
* @param v_in input cartesian velocity
|
| 137 |
+
* @param a_in input cartesian acceleration
|
| 138 |
+
* @param qdot_out output joint velocities
|
| 139 |
+
* @param qdotdot_out output joint accelerations
|
| 140 |
+
*
|
| 141 |
+
* @return if < 0 something went wrong
|
| 142 |
+
*/
|
| 143 |
+
virtual int CartToJnt(const JntArray& q_in, const Twist& v_in, const Twist& a_in,
|
| 144 |
+
JntArray& qdot_out, JntArray& qdotdot_out)=0;
|
| 145 |
+
/**
|
| 146 |
+
* Calculate inverse position and acceleration kinematics from
|
| 147 |
+
*joint velocities and cartesian position and acceleration to
|
| 148 |
+
*joint positions and accelerations
|
| 149 |
+
*
|
| 150 |
+
* @param q_init initial guess for joint positions
|
| 151 |
+
* @param p_in input cartesian position
|
| 152 |
+
* @param qdot_in input joint velocities
|
| 153 |
+
* @param a_in input cartesian acceleration
|
| 154 |
+
* @param q_out output joint positions
|
| 155 |
+
* @param qdotdot_out output joint accelerations
|
| 156 |
+
*
|
| 157 |
+
* @return if < 0 something went wrong
|
| 158 |
+
*/
|
| 159 |
+
virtual int CartTojnt(const JntArray& q_init, const Frame& p_in, const JntArray& qdot_in, const Twist& a_in,
|
| 160 |
+
JntArray& q_out, JntArray& qdotdot_out)=0;
|
| 161 |
+
|
| 162 |
+
virtual void updateInternalDataStructures()=0;
|
| 163 |
+
virtual ~ChainIkSolverAcc(){};
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
}//end of namespace KDL
|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|
+
/**
|
| 2 |
+
\file chainiksolverpos_lma.cpp
|
| 3 |
+
\brief computing inverse position kinematics using Levenberg-Marquardt.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
/**************************************************************************
|
| 7 |
+
begin : May 2012
|
| 8 |
+
copyright : (C) 2012 Erwin Aertbelien
|
| 9 |
+
email : firstname.lastname@mech.kuleuven.ac.be
|
| 10 |
+
|
| 11 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 12 |
+
|
| 13 |
+
***************************************************************************
|
| 14 |
+
* This library is free software; you can redistribute it and/or *
|
| 15 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 16 |
+
* License as published by the Free Software Foundation; either *
|
| 17 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 18 |
+
* *
|
| 19 |
+
* This library is distributed in the hope that it will be useful, *
|
| 20 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 21 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 22 |
+
* Lesser General Public License for more details. *
|
| 23 |
+
* *
|
| 24 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 25 |
+
* License along with this library; if not, write to the Free Software *
|
| 26 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 27 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 28 |
+
* *
|
| 29 |
+
***************************************************************************/
|
| 30 |
+
|
| 31 |
+
#include "chainiksolverpos_lma.hpp"
|
| 32 |
+
#include <iostream>
|
| 33 |
+
|
| 34 |
+
namespace KDL {
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
template <typename Derived>
|
| 40 |
+
inline void Twist_to_Eigen(const KDL::Twist& t,Eigen::MatrixBase<Derived>& e) {
|
| 41 |
+
e(0)=t.vel.data[0];
|
| 42 |
+
e(1)=t.vel.data[1];
|
| 43 |
+
e(2)=t.vel.data[2];
|
| 44 |
+
e(3)=t.rot.data[0];
|
| 45 |
+
e(4)=t.rot.data[1];
|
| 46 |
+
e(5)=t.rot.data[2];
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
ChainIkSolverPos_LMA::ChainIkSolverPos_LMA(
|
| 51 |
+
const KDL::Chain& _chain,
|
| 52 |
+
const Eigen::Matrix<double,6,1>& _l,
|
| 53 |
+
double _eps,
|
| 54 |
+
int _maxiter,
|
| 55 |
+
double _eps_joints
|
| 56 |
+
) :
|
| 57 |
+
chain(_chain),
|
| 58 |
+
nj(chain.getNrOfJoints()),
|
| 59 |
+
ns(chain.getNrOfSegments()),
|
| 60 |
+
lastNrOfIter(0),
|
| 61 |
+
lastDifference(0),
|
| 62 |
+
lastTransDiff(0),
|
| 63 |
+
lastRotDiff(0),
|
| 64 |
+
lastSV(nj),
|
| 65 |
+
jac(6, nj),
|
| 66 |
+
grad(nj),
|
| 67 |
+
display_information(false),
|
| 68 |
+
maxiter(_maxiter),
|
| 69 |
+
eps(_eps),
|
| 70 |
+
eps_joints(_eps_joints),
|
| 71 |
+
L(_l.cast<ScalarType>()),
|
| 72 |
+
T_base_jointroot(nj),
|
| 73 |
+
T_base_jointtip(nj),
|
| 74 |
+
q(nj),
|
| 75 |
+
A(nj, nj),
|
| 76 |
+
tmp(nj),
|
| 77 |
+
ldlt(nj),
|
| 78 |
+
svd(6, nj,Eigen::ComputeThinU | Eigen::ComputeThinV),
|
| 79 |
+
diffq(nj),
|
| 80 |
+
q_new(nj),
|
| 81 |
+
original_Aii(nj)
|
| 82 |
+
{}
|
| 83 |
+
|
| 84 |
+
ChainIkSolverPos_LMA::ChainIkSolverPos_LMA(
|
| 85 |
+
const KDL::Chain& _chain,
|
| 86 |
+
double _eps,
|
| 87 |
+
int _maxiter,
|
| 88 |
+
double _eps_joints
|
| 89 |
+
) :
|
| 90 |
+
chain(_chain),
|
| 91 |
+
nj(chain.getNrOfJoints()),
|
| 92 |
+
ns(chain.getNrOfSegments()),
|
| 93 |
+
lastNrOfIter(0),
|
| 94 |
+
lastDifference(0),
|
| 95 |
+
lastTransDiff(0),
|
| 96 |
+
lastRotDiff(0),
|
| 97 |
+
lastSV(nj>6?6:nj),
|
| 98 |
+
jac(6, nj),
|
| 99 |
+
grad(nj),
|
| 100 |
+
display_information(false),
|
| 101 |
+
maxiter(_maxiter),
|
| 102 |
+
eps(_eps),
|
| 103 |
+
eps_joints(_eps_joints),
|
| 104 |
+
T_base_jointroot(nj),
|
| 105 |
+
T_base_jointtip(nj),
|
| 106 |
+
q(nj),
|
| 107 |
+
A(nj, nj),
|
| 108 |
+
ldlt(nj),
|
| 109 |
+
svd(6, nj,Eigen::ComputeThinU | Eigen::ComputeThinV),
|
| 110 |
+
diffq(nj),
|
| 111 |
+
q_new(nj),
|
| 112 |
+
original_Aii(nj)
|
| 113 |
+
{
|
| 114 |
+
L(0)=1;
|
| 115 |
+
L(1)=1;
|
| 116 |
+
L(2)=1;
|
| 117 |
+
L(3)=0.01;
|
| 118 |
+
L(4)=0.01;
|
| 119 |
+
L(5)=0.01;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
void ChainIkSolverPos_LMA::updateInternalDataStructures() {
|
| 123 |
+
nj = chain.getNrOfJoints();
|
| 124 |
+
ns = chain.getNrOfSegments();
|
| 125 |
+
lastSV.conservativeResize(nj>6?6:nj);
|
| 126 |
+
jac.conservativeResize(Eigen::NoChange, nj);
|
| 127 |
+
grad.conservativeResize(nj);
|
| 128 |
+
T_base_jointroot.resize(nj);
|
| 129 |
+
T_base_jointtip.resize(nj);
|
| 130 |
+
q.conservativeResize(nj);
|
| 131 |
+
A.conservativeResize(nj, nj);
|
| 132 |
+
ldlt = Eigen::LDLT<MatrixXq>(nj);
|
| 133 |
+
svd = Eigen::JacobiSVD<MatrixXq>(6, nj,Eigen::ComputeThinU | Eigen::ComputeThinV);
|
| 134 |
+
diffq.conservativeResize(nj);
|
| 135 |
+
q_new.conservativeResize(nj);
|
| 136 |
+
original_Aii.conservativeResize(nj);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
ChainIkSolverPos_LMA::~ChainIkSolverPos_LMA() {}
|
| 140 |
+
|
| 141 |
+
void ChainIkSolverPos_LMA::compute_fwdpos(const VectorXq& q) {
|
| 142 |
+
using namespace KDL;
|
| 143 |
+
unsigned int jointndx=0;
|
| 144 |
+
T_base_head = Frame::Identity(); // frame w.r.t. base of head
|
| 145 |
+
for (unsigned int i=0;i<chain.getNrOfSegments();i++) {
|
| 146 |
+
const Segment& segment = chain.getSegment(i);
|
| 147 |
+
if (segment.getJoint().getType()!=Joint::Fixed) {
|
| 148 |
+
T_base_jointroot[jointndx] = T_base_head;
|
| 149 |
+
T_base_head = T_base_head * segment.pose(q(jointndx));
|
| 150 |
+
T_base_jointtip[jointndx] = T_base_head;
|
| 151 |
+
jointndx++;
|
| 152 |
+
} else {
|
| 153 |
+
T_base_head = T_base_head * segment.pose(0.0);
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
void ChainIkSolverPos_LMA::compute_jacobian(const VectorXq& q) {
|
| 159 |
+
using namespace KDL;
|
| 160 |
+
unsigned int jointndx=0;
|
| 161 |
+
for (unsigned int i=0;i<chain.getNrOfSegments();i++) {
|
| 162 |
+
const Segment& segment = chain.getSegment(i);
|
| 163 |
+
if (segment.getJoint().getType()!=Joint::Fixed) {
|
| 164 |
+
// compute twist of the end effector motion caused by joint [jointndx]; expressed in base frame, with vel. ref. point equal to the end effector
|
| 165 |
+
KDL::Twist t = ( T_base_jointroot[jointndx].M * segment.twist(q(jointndx),1.0) ).RefPoint( T_base_head.p - T_base_jointtip[jointndx].p);
|
| 166 |
+
jac(0,jointndx)=t[0];
|
| 167 |
+
jac(1,jointndx)=t[1];
|
| 168 |
+
jac(2,jointndx)=t[2];
|
| 169 |
+
jac(3,jointndx)=t[3];
|
| 170 |
+
jac(4,jointndx)=t[4];
|
| 171 |
+
jac(5,jointndx)=t[5];
|
| 172 |
+
jointndx++;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
void ChainIkSolverPos_LMA::display_jac(const KDL::JntArray& jval) {
|
| 178 |
+
VectorXq q;
|
| 179 |
+
q = jval.data.cast<ScalarType>();
|
| 180 |
+
compute_fwdpos(q);
|
| 181 |
+
compute_jacobian(q);
|
| 182 |
+
svd.compute(jac);
|
| 183 |
+
std::cout << "Singular values : " << svd.singularValues().transpose()<<"\n";
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
int ChainIkSolverPos_LMA::CartToJnt(const KDL::JntArray& q_init, const KDL::Frame& T_base_goal, KDL::JntArray& q_out) {
|
| 188 |
+
if (nj != chain.getNrOfJoints())
|
| 189 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 190 |
+
|
| 191 |
+
if (nj != q_init.rows() || nj != q_out.rows())
|
| 192 |
+
return (error = E_SIZE_MISMATCH);
|
| 193 |
+
|
| 194 |
+
using namespace KDL;
|
| 195 |
+
double v = 2;
|
| 196 |
+
double tau = 10;
|
| 197 |
+
double rho;
|
| 198 |
+
double lambda;
|
| 199 |
+
Twist t;
|
| 200 |
+
double delta_pos_norm;
|
| 201 |
+
Eigen::Matrix<ScalarType,6,1> delta_pos;
|
| 202 |
+
Eigen::Matrix<ScalarType,6,1> delta_pos_new;
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
q=q_init.data.cast<ScalarType>();
|
| 206 |
+
compute_fwdpos(q);
|
| 207 |
+
Twist_to_Eigen( diff( T_base_head, T_base_goal), delta_pos );
|
| 208 |
+
delta_pos=L.asDiagonal()*delta_pos;
|
| 209 |
+
delta_pos_norm = delta_pos.norm();
|
| 210 |
+
if (delta_pos_norm<eps) {
|
| 211 |
+
lastNrOfIter =0 ;
|
| 212 |
+
Twist_to_Eigen( diff( T_base_head, T_base_goal), delta_pos );
|
| 213 |
+
lastDifference = delta_pos.norm();
|
| 214 |
+
lastTransDiff = delta_pos.topRows(3).norm();
|
| 215 |
+
lastRotDiff = delta_pos.bottomRows(3).norm();
|
| 216 |
+
svd.compute(jac);
|
| 217 |
+
original_Aii = svd.singularValues();
|
| 218 |
+
lastSV = svd.singularValues();
|
| 219 |
+
q_out.data = q.cast<double>();
|
| 220 |
+
return (error = E_NOERROR);
|
| 221 |
+
}
|
| 222 |
+
compute_jacobian(q);
|
| 223 |
+
jac = L.asDiagonal()*jac;
|
| 224 |
+
|
| 225 |
+
lambda = tau;
|
| 226 |
+
double dnorm = 1;
|
| 227 |
+
for (unsigned int i=0;i<maxiter;++i) {
|
| 228 |
+
|
| 229 |
+
svd.compute(jac);
|
| 230 |
+
original_Aii = svd.singularValues();
|
| 231 |
+
for (unsigned int j=0;j<original_Aii.rows();++j) {
|
| 232 |
+
original_Aii(j) = original_Aii(j)/( original_Aii(j)*original_Aii(j)+lambda);
|
| 233 |
+
|
| 234 |
+
}
|
| 235 |
+
tmp = svd.matrixU().transpose()*delta_pos;
|
| 236 |
+
tmp = original_Aii.cwiseProduct(tmp);
|
| 237 |
+
diffq = svd.matrixV()*tmp;
|
| 238 |
+
grad = jac.transpose()*delta_pos;
|
| 239 |
+
if (display_information) {
|
| 240 |
+
std::cout << "------- iteration " << i << " ----------------\n"
|
| 241 |
+
<< " q = " << q.transpose() << "\n"
|
| 242 |
+
<< " weighted jac = \n" << jac << "\n"
|
| 243 |
+
<< " lambda = " << lambda << "\n"
|
| 244 |
+
<< " eigenvalues = " << svd.singularValues().transpose() << "\n"
|
| 245 |
+
<< " difference = " << delta_pos.transpose() << "\n"
|
| 246 |
+
<< " difference norm= " << delta_pos_norm << "\n"
|
| 247 |
+
<< " proj. on grad. = " << grad << "\n";
|
| 248 |
+
std::cout << std::endl;
|
| 249 |
+
}
|
| 250 |
+
dnorm = diffq.lpNorm<Eigen::Infinity>();
|
| 251 |
+
if (dnorm < eps_joints) {
|
| 252 |
+
lastDifference = delta_pos_norm;
|
| 253 |
+
lastNrOfIter = i;
|
| 254 |
+
lastSV = svd.singularValues();
|
| 255 |
+
q_out.data = q.cast<double>();
|
| 256 |
+
compute_fwdpos(q);
|
| 257 |
+
Twist_to_Eigen( diff( T_base_head, T_base_goal), delta_pos );
|
| 258 |
+
lastTransDiff = delta_pos.topRows(3).norm();
|
| 259 |
+
lastRotDiff = delta_pos.bottomRows(3).norm();
|
| 260 |
+
return (error = E_INCREMENT_JOINTS_TOO_SMALL);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
if (grad.transpose()*grad < eps_joints*eps_joints ) {
|
| 265 |
+
compute_fwdpos(q);
|
| 266 |
+
Twist_to_Eigen( diff( T_base_head, T_base_goal), delta_pos );
|
| 267 |
+
lastDifference = delta_pos_norm;
|
| 268 |
+
lastTransDiff = delta_pos.topRows(3).norm();
|
| 269 |
+
lastRotDiff = delta_pos.bottomRows(3).norm();
|
| 270 |
+
lastSV = svd.singularValues();
|
| 271 |
+
lastNrOfIter = i;
|
| 272 |
+
q_out.data = q.cast<double>();
|
| 273 |
+
return (error = E_GRADIENT_JOINTS_TOO_SMALL);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
q_new = q+diffq;
|
| 277 |
+
compute_fwdpos(q_new);
|
| 278 |
+
Twist_to_Eigen( diff( T_base_head, T_base_goal), delta_pos_new );
|
| 279 |
+
delta_pos_new = L.asDiagonal()*delta_pos_new;
|
| 280 |
+
double delta_pos_new_norm = delta_pos_new.norm();
|
| 281 |
+
rho = delta_pos_norm*delta_pos_norm - delta_pos_new_norm*delta_pos_new_norm;
|
| 282 |
+
rho /= diffq.transpose()*(lambda*diffq + grad);
|
| 283 |
+
if (rho > 0) {
|
| 284 |
+
q = q_new;
|
| 285 |
+
delta_pos = delta_pos_new;
|
| 286 |
+
delta_pos_norm = delta_pos_new_norm;
|
| 287 |
+
if (delta_pos_norm<eps) {
|
| 288 |
+
Twist_to_Eigen( diff( T_base_head, T_base_goal), delta_pos );
|
| 289 |
+
lastDifference = delta_pos_norm;
|
| 290 |
+
lastTransDiff = delta_pos.topRows(3).norm();
|
| 291 |
+
lastRotDiff = delta_pos.bottomRows(3).norm();
|
| 292 |
+
lastSV = svd.singularValues();
|
| 293 |
+
lastNrOfIter = i;
|
| 294 |
+
q_out.data = q.cast<double>();
|
| 295 |
+
return (error = E_NOERROR);
|
| 296 |
+
}
|
| 297 |
+
compute_jacobian(q_new);
|
| 298 |
+
jac = L.asDiagonal()*jac;
|
| 299 |
+
double tmp=2*rho-1;
|
| 300 |
+
lambda = lambda*max(1/3.0, 1-tmp*tmp*tmp);
|
| 301 |
+
v = 2;
|
| 302 |
+
} else {
|
| 303 |
+
lambda = lambda*v;
|
| 304 |
+
v = 2*v;
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
lastDifference = delta_pos_norm;
|
| 308 |
+
lastTransDiff = delta_pos.topRows(3).norm();
|
| 309 |
+
lastRotDiff = delta_pos.bottomRows(3).norm();
|
| 310 |
+
lastSV = svd.singularValues();
|
| 311 |
+
lastNrOfIter = maxiter;
|
| 312 |
+
q_out.data = q.cast<double>();
|
| 313 |
+
return (error = E_MAX_ITERATIONS_EXCEEDED);
|
| 314 |
+
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
const char* ChainIkSolverPos_LMA::strError(const int error) const
|
| 318 |
+
{
|
| 319 |
+
if (E_GRADIENT_JOINTS_TOO_SMALL == error) return "The gradient of E towards the joints is to small";
|
| 320 |
+
else if (E_INCREMENT_JOINTS_TOO_SMALL == error) return "The joint position increments are to small";
|
| 321 |
+
else return SolverI::strError(error);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
}//namespace KDL
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_lma.hpp
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef KDL_CHAINIKSOLVERPOS_GN_HPP
|
| 2 |
+
#define KDL_CHAINIKSOLVERPOS_GN_HPP
|
| 3 |
+
/**
|
| 4 |
+
\file chainiksolverpos_lma.hpp
|
| 5 |
+
\brief computing inverse position kinematics using Levenberg-Marquardt.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
/**************************************************************************
|
| 9 |
+
begin : May 2012
|
| 10 |
+
copyright : (C) 2012 Erwin Aertbelien
|
| 11 |
+
email : firstname.lastname@mech.kuleuven.ac.be
|
| 12 |
+
|
| 13 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 14 |
+
|
| 15 |
+
***************************************************************************
|
| 16 |
+
* This library is free software; you can redistribute it and/or *
|
| 17 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 18 |
+
* License as published by the Free Software Foundation; either *
|
| 19 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 20 |
+
* *
|
| 21 |
+
* This library is distributed in the hope that it will be useful, *
|
| 22 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 23 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 24 |
+
* Lesser General Public License for more details. *
|
| 25 |
+
* *
|
| 26 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 27 |
+
* License along with this library; if not, write to the Free Software *
|
| 28 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 29 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 30 |
+
* *
|
| 31 |
+
***************************************************************************/
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
#include "chainiksolver.hpp"
|
| 35 |
+
#include "chain.hpp"
|
| 36 |
+
#include <Eigen/Dense>
|
| 37 |
+
|
| 38 |
+
namespace KDL
|
| 39 |
+
{
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* \brief Solver for the inverse position kinematics that uses Levenberg-Marquardt.
|
| 43 |
+
*
|
| 44 |
+
* The robustness and speed of this solver is improved in several ways:
|
| 45 |
+
* - by using a Levenberg-Marquardt method that automatically adapts the damping when
|
| 46 |
+
* computing the inverse damped least squares inverse velocity kinematics.
|
| 47 |
+
* - by using an internal implementation of forward position kinematics and the
|
| 48 |
+
* Jacobian kinematics. This implementation is more numerically robust,
|
| 49 |
+
* is able to cache previous computations, and implements an \f$ \mathcal{O}(N) \f$
|
| 50 |
+
* algorithm for the computation of the Jacobian (with \f$N\f$, the number of joints, and for
|
| 51 |
+
* a fixed size task space).
|
| 52 |
+
* - by providing a way to specify the weights in task space, you can weigh rotations wrt translations.
|
| 53 |
+
* This is important e.g. to specify that rotations do not matter for the problem at hand, or to
|
| 54 |
+
* specify how important you judge rotations w.r.t. translations, typically in S.I.-units, ([m],[rad]),
|
| 55 |
+
* the rotations are over-specified, this can be avoided using the weight matrix. <B>Weights also
|
| 56 |
+
* make the solver more robust </B>.
|
| 57 |
+
* - only the constructors call <B>memory allocation</B>.
|
| 58 |
+
*
|
| 59 |
+
* De general principles behind the optimisation is inspired on:
|
| 60 |
+
* Jorge Nocedal, Stephen J. Wright, Numerical Optimization,Springer-Verlag New York, 1999.
|
| 61 |
+
|
| 62 |
+
* \ingroup KinematicFamily
|
| 63 |
+
*/
|
| 64 |
+
class ChainIkSolverPos_LMA : public KDL::ChainIkSolverPos
|
| 65 |
+
{
|
| 66 |
+
private:
|
| 67 |
+
typedef double ScalarType;
|
| 68 |
+
typedef Eigen::Matrix<ScalarType,Eigen::Dynamic,Eigen::Dynamic> MatrixXq;
|
| 69 |
+
typedef Eigen::Matrix<ScalarType,Eigen::Dynamic,1> VectorXq;
|
| 70 |
+
public:
|
| 71 |
+
|
| 72 |
+
static const int E_GRADIENT_JOINTS_TOO_SMALL = -100;
|
| 73 |
+
static const int E_INCREMENT_JOINTS_TOO_SMALL = -101;
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* \brief constructs an ChainIkSolverPos_LMA solver.
|
| 77 |
+
*
|
| 78 |
+
* The default parameters are chosen to be applicable to industrial-size robots
|
| 79 |
+
* (e.g. 0.5 to 3 meters range in task space), with an accuracy that is more then
|
| 80 |
+
* sufficient for typical industrial applications.
|
| 81 |
+
*
|
| 82 |
+
* Weights are applied in task space, i.e. the kinematic solver minimizes:
|
| 83 |
+
* \f$ E = \Delta \mathbf{x}^T \mathbf{L} \mathbf{L}^T \Delta \mathbf{x} \f$, with \f$\mathbf{L}\f$ a diagonal matrix.
|
| 84 |
+
*
|
| 85 |
+
* \param _chain specifies the kinematic chain.
|
| 86 |
+
* \param _l specifies the "square root" of the weight (diagonal) matrix in task space. This diagonal matrix is specified as a vector.
|
| 87 |
+
* \param _eps specifies the desired accuracy in task space; <B>after</B> weighing with
|
| 88 |
+
* the weight matrix, it is applied on \f$E\f$.
|
| 89 |
+
* \param _maxiter specifies the maximum number of iterations.
|
| 90 |
+
* \param _eps_joints specifies that the algorithm has to stop when the computed joint angle increments are
|
| 91 |
+
* smaller then _eps_joints. This is to avoid unnecessary computations up to _maxiter when the joint angle
|
| 92 |
+
* increments are so small that they effectively (in floating point) do not change the joint angles any more. The default
|
| 93 |
+
* is a few digits above numerical accuracy.
|
| 94 |
+
*/
|
| 95 |
+
ChainIkSolverPos_LMA(
|
| 96 |
+
const KDL::Chain& _chain,
|
| 97 |
+
const Eigen::Matrix<double,6,1>& _l,
|
| 98 |
+
double _eps=1E-5,
|
| 99 |
+
int _maxiter=500,
|
| 100 |
+
double _eps_joints=1E-15
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* \brief identical the full constructor for ChainIkSolverPos_LMA, but provides for a default weight matrix.
|
| 105 |
+
*
|
| 106 |
+
* \f$\mathbf{L} = \mathrm{diag}\left( \begin{bmatrix} 1 & 1 & 1 & 0.01 & 0.01 & 0.01 \end{bmatrix} \right) \f$.
|
| 107 |
+
*/
|
| 108 |
+
ChainIkSolverPos_LMA(
|
| 109 |
+
const KDL::Chain& _chain,
|
| 110 |
+
double _eps=1E-5,
|
| 111 |
+
int _maxiter=500,
|
| 112 |
+
double _eps_joints=1E-15
|
| 113 |
+
);
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* \brief computes the inverse position kinematics.
|
| 117 |
+
*
|
| 118 |
+
* \param q_init initial joint position.
|
| 119 |
+
* \param T_base_goal goal position expressed with respect to the robot base.
|
| 120 |
+
* \param q_out joint position that achieves the specified goal position (if successful).
|
| 121 |
+
* \return E_NOERROR if successful,
|
| 122 |
+
* E_GRADIENT_JOINTS_TOO_SMALL the gradient of \f$ E \f$ towards the joints is to small,
|
| 123 |
+
* E_INCREMENT_JOINTS_TOO_SMALL if joint position increments are to small,
|
| 124 |
+
* E_MAX_ITER_EXCEEDED if number of iterations is exceeded.
|
| 125 |
+
*/
|
| 126 |
+
virtual int CartToJnt(const KDL::JntArray& q_init, const KDL::Frame& T_base_goal, KDL::JntArray& q_out);
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* \brief destructor.
|
| 130 |
+
*/
|
| 131 |
+
virtual ~ChainIkSolverPos_LMA();
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* \brief for internal use only.
|
| 135 |
+
*
|
| 136 |
+
* Only exposed for test and diagnostic purposes.
|
| 137 |
+
*/
|
| 138 |
+
void compute_fwdpos(const VectorXq& q);
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* \brief for internal use only.
|
| 142 |
+
* Only exposed for test and diagnostic purposes.
|
| 143 |
+
* compute_fwdpos(q) should always have been called before.
|
| 144 |
+
*/
|
| 145 |
+
void compute_jacobian(const VectorXq& q);
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* \brief for internal use only.
|
| 149 |
+
* Only exposed for test and diagnostic purposes.
|
| 150 |
+
*/
|
| 151 |
+
void display_jac(const KDL::JntArray& jval);
|
| 152 |
+
|
| 153 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 154 |
+
void updateInternalDataStructures();
|
| 155 |
+
|
| 156 |
+
/// @copydoc KDL::SolverI::strError()
|
| 157 |
+
virtual const char* strError(const int error) const;
|
| 158 |
+
|
| 159 |
+
private:
|
| 160 |
+
const KDL::Chain& chain;
|
| 161 |
+
unsigned int nj;
|
| 162 |
+
unsigned int ns;
|
| 163 |
+
|
| 164 |
+
public:
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* \brief contains the last number of iterations for an execution of CartToJnt.
|
| 169 |
+
*/
|
| 170 |
+
int lastNrOfIter;
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* \brief contains the last value for \f$ E \f$ after an execution of CartToJnt.
|
| 174 |
+
*/
|
| 175 |
+
double lastDifference;
|
| 176 |
+
|
| 177 |
+
/**
|
| 178 |
+
* \brief contains the last value for the (unweighted) translational difference after an execution of CartToJnt.
|
| 179 |
+
*/
|
| 180 |
+
double lastTransDiff;
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* \brief contains the last value for the (unweighted) rotational difference after an execution of CartToJnt.
|
| 184 |
+
*/
|
| 185 |
+
double lastRotDiff;
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* \brief contains the last values for the singular values of the weighted Jacobian after an execution of CartToJnt.
|
| 189 |
+
*/
|
| 190 |
+
VectorXq lastSV;
|
| 191 |
+
|
| 192 |
+
/**
|
| 193 |
+
* \brief for internal use only.
|
| 194 |
+
*
|
| 195 |
+
* contains the last value for the Jacobian after an execution of compute_jacobian.
|
| 196 |
+
*/
|
| 197 |
+
MatrixXq jac;
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* \brief for internal use only.
|
| 201 |
+
*
|
| 202 |
+
* contains the gradient of the error criterion after an execution of CartToJnt.
|
| 203 |
+
*/
|
| 204 |
+
VectorXq grad;
|
| 205 |
+
/**
|
| 206 |
+
* \brief for internal use only.
|
| 207 |
+
*
|
| 208 |
+
* contains the last value for the position of the tip of the robot (head) with respect to the base, after an execution of compute_jacobian.
|
| 209 |
+
*/
|
| 210 |
+
KDL::Frame T_base_head;
|
| 211 |
+
|
| 212 |
+
/**
|
| 213 |
+
* \brief display information on each iteration step to the console.
|
| 214 |
+
*/
|
| 215 |
+
bool display_information;
|
| 216 |
+
private:
|
| 217 |
+
// additional specification of the inverse position kinematics problem:
|
| 218 |
+
unsigned int maxiter;
|
| 219 |
+
double eps;
|
| 220 |
+
double eps_joints;
|
| 221 |
+
Eigen::Matrix<ScalarType,6,1> L;
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
// state of compute_fwdpos and compute_jacobian:
|
| 226 |
+
std::vector<KDL::Frame> T_base_jointroot;
|
| 227 |
+
std::vector<KDL::Frame> T_base_jointtip;
|
| 228 |
+
// need 2 vectors because of the somewhat strange definition of segment.hpp
|
| 229 |
+
// you could also recompute jointtip out of jointroot,
|
| 230 |
+
// but then you'll need more expensive cos/sin functions.
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
// the following are state of CartToJnt that is pre-allocated:
|
| 234 |
+
|
| 235 |
+
VectorXq q;
|
| 236 |
+
MatrixXq A;
|
| 237 |
+
VectorXq tmp;
|
| 238 |
+
Eigen::LDLT<MatrixXq> ldlt;
|
| 239 |
+
Eigen::JacobiSVD<MatrixXq> svd;
|
| 240 |
+
VectorXq diffq;
|
| 241 |
+
VectorXq q_new;
|
| 242 |
+
VectorXq original_Aii;
|
| 243 |
+
};
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
} // namespace KDL
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr.cpp
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainiksolverpos_nr.hpp"
|
| 23 |
+
|
| 24 |
+
namespace KDL
|
| 25 |
+
{
|
| 26 |
+
ChainIkSolverPos_NR::ChainIkSolverPos_NR(const Chain& _chain,ChainFkSolverPos& _fksolver,ChainIkSolverVel& _iksolver,
|
| 27 |
+
unsigned int _maxiter, double _eps):
|
| 28 |
+
chain(_chain),nj (chain.getNrOfJoints()),
|
| 29 |
+
iksolver(_iksolver),fksolver(_fksolver),
|
| 30 |
+
delta_q(_chain.getNrOfJoints()),
|
| 31 |
+
maxiter(_maxiter),eps(_eps)
|
| 32 |
+
{
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void ChainIkSolverPos_NR::updateInternalDataStructures() {
|
| 36 |
+
nj = chain.getNrOfJoints();
|
| 37 |
+
iksolver.updateInternalDataStructures();
|
| 38 |
+
fksolver.updateInternalDataStructures();
|
| 39 |
+
delta_q.resize(nj);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
int ChainIkSolverPos_NR::CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out)
|
| 43 |
+
{
|
| 44 |
+
if (nj != chain.getNrOfJoints())
|
| 45 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 46 |
+
|
| 47 |
+
if(q_init.rows() != nj || q_out.rows() != nj)
|
| 48 |
+
return (error = E_SIZE_MISMATCH);
|
| 49 |
+
|
| 50 |
+
q_out = q_init;
|
| 51 |
+
|
| 52 |
+
unsigned int i;
|
| 53 |
+
for(i=0;i<maxiter;i++){
|
| 54 |
+
if (E_NOERROR > fksolver.JntToCart(q_out,f) )
|
| 55 |
+
return (error = E_FKSOLVERPOS_FAILED);
|
| 56 |
+
delta_twist = diff(f,p_in);
|
| 57 |
+
const int rc = iksolver.CartToJnt(q_out,delta_twist,delta_q);
|
| 58 |
+
if (E_NOERROR > rc)
|
| 59 |
+
return (error = E_IKSOLVER_FAILED);
|
| 60 |
+
// we chose to continue if the child solver returned a positive
|
| 61 |
+
// "error", which may simply indicate a degraded solution
|
| 62 |
+
Add(q_out,delta_q,q_out);
|
| 63 |
+
if(Equal(delta_twist,Twist::Zero(),eps))
|
| 64 |
+
// converged, but possibly with a degraded solution
|
| 65 |
+
return (rc > E_NOERROR ? E_DEGRADED : E_NOERROR);
|
| 66 |
+
}
|
| 67 |
+
return (error = E_MAX_ITERATIONS_EXCEEDED); // failed to converge
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
ChainIkSolverPos_NR::~ChainIkSolverPos_NR()
|
| 71 |
+
{
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
const char* ChainIkSolverPos_NR::strError(const int error) const
|
| 75 |
+
{
|
| 76 |
+
if (E_IKSOLVER_FAILED == error) return "Child IK solver failed";
|
| 77 |
+
else if (E_FKSOLVERPOS_FAILED == error) return "Child FK solver failed";
|
| 78 |
+
else return SolverI::strError(error);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr.hpp
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDLCHAINIKSOLVERPOS_NR_HPP
|
| 23 |
+
#define KDLCHAINIKSOLVERPOS_NR_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainiksolver.hpp"
|
| 26 |
+
#include "chainfksolver.hpp"
|
| 27 |
+
|
| 28 |
+
namespace KDL {
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Implementation of a general inverse position kinematics
|
| 32 |
+
* algorithm based on Newton-Raphson iterations to calculate the
|
| 33 |
+
* position transformation from Cartesian to joint space of a general
|
| 34 |
+
* KDL::Chain.
|
| 35 |
+
*
|
| 36 |
+
* @ingroup KinematicFamily
|
| 37 |
+
*/
|
| 38 |
+
class ChainIkSolverPos_NR : public ChainIkSolverPos
|
| 39 |
+
{
|
| 40 |
+
public:
|
| 41 |
+
static const int E_IKSOLVER_FAILED = -100; //! Child IK solver vel failed
|
| 42 |
+
static const int E_FKSOLVERPOS_FAILED = -101; //! Child FK solver failed
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Constructor of the solver, it needs the chain, a forward
|
| 46 |
+
* position kinematics solver and an inverse velocity
|
| 47 |
+
* kinematics solver for that chain.
|
| 48 |
+
*
|
| 49 |
+
* @param chain the chain to calculate the inverse position for
|
| 50 |
+
* @param fksolver a forward position kinematics solver
|
| 51 |
+
* @param iksolver an inverse velocity kinematics solver
|
| 52 |
+
* @param maxiter the maximum Newton-Raphson iterations,
|
| 53 |
+
* default: 100
|
| 54 |
+
* @param eps the precision for the position, used to end the
|
| 55 |
+
* iterations, default: epsilon (defined in kdl.hpp)
|
| 56 |
+
*
|
| 57 |
+
* @return
|
| 58 |
+
*/
|
| 59 |
+
ChainIkSolverPos_NR(const Chain& chain,ChainFkSolverPos& fksolver,ChainIkSolverVel& iksolver,
|
| 60 |
+
unsigned int maxiter=100,double eps=1e-6);
|
| 61 |
+
~ChainIkSolverPos_NR();
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Find an output joint pose \a q_out, given a starting joint pose
|
| 65 |
+
* \a q_init and a desired cartesian pose \a p_in
|
| 66 |
+
*
|
| 67 |
+
* @return:
|
| 68 |
+
* E_NOERROR=solution converged to <eps in maxiter
|
| 69 |
+
* E_DEGRADED=solution converged to <eps in maxiter, but solution is
|
| 70 |
+
* degraded in quality (e.g. pseudo-inverse in iksolver is singular)
|
| 71 |
+
* E_IKSOLVER_FAILED=velocity solver failed
|
| 72 |
+
* E_NO_CONVERGE=solution did not converge (e.g. large displacement, low iterations)
|
| 73 |
+
*/
|
| 74 |
+
virtual int CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out);
|
| 75 |
+
|
| 76 |
+
/// @copydoc KDL::SolverI::strError()
|
| 77 |
+
virtual const char* strError(const int error) const;
|
| 78 |
+
|
| 79 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 80 |
+
virtual void updateInternalDataStructures();
|
| 81 |
+
private:
|
| 82 |
+
const Chain& chain;
|
| 83 |
+
|
| 84 |
+
unsigned int nj;
|
| 85 |
+
ChainIkSolverVel& iksolver;
|
| 86 |
+
ChainFkSolverPos& fksolver;
|
| 87 |
+
JntArray delta_q;
|
| 88 |
+
Frame f;
|
| 89 |
+
Twist delta_twist;
|
| 90 |
+
|
| 91 |
+
unsigned int maxiter;
|
| 92 |
+
double eps;
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr_jl.cpp
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
// Copyright (C) 2008 Mikael Mayer
|
| 3 |
+
// Copyright (C) 2008 Julia Jesse
|
| 4 |
+
|
| 5 |
+
// Version: 1.0
|
| 6 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#include "chainiksolverpos_nr_jl.hpp"
|
| 25 |
+
|
| 26 |
+
#include <limits>
|
| 27 |
+
|
| 28 |
+
namespace KDL
|
| 29 |
+
{
|
| 30 |
+
ChainIkSolverPos_NR_JL::ChainIkSolverPos_NR_JL(const Chain& _chain, const JntArray& _q_min, const JntArray& _q_max, ChainFkSolverPos& _fksolver,ChainIkSolverVel& _iksolver,
|
| 31 |
+
unsigned int _maxiter, double _eps):
|
| 32 |
+
chain(_chain), nj(chain.getNrOfJoints()),
|
| 33 |
+
q_min(_q_min), q_max(_q_max),
|
| 34 |
+
iksolver(_iksolver), fksolver(_fksolver),
|
| 35 |
+
delta_q(_chain.getNrOfJoints()),
|
| 36 |
+
maxiter(_maxiter),eps(_eps)
|
| 37 |
+
{
|
| 38 |
+
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
ChainIkSolverPos_NR_JL::ChainIkSolverPos_NR_JL(const Chain& _chain, ChainFkSolverPos& _fksolver,ChainIkSolverVel& _iksolver,
|
| 42 |
+
unsigned int _maxiter, double _eps):
|
| 43 |
+
chain(_chain), nj(chain.getNrOfJoints()),
|
| 44 |
+
q_min(nj), q_max(nj),
|
| 45 |
+
iksolver(_iksolver), fksolver(_fksolver),
|
| 46 |
+
delta_q(nj),
|
| 47 |
+
maxiter(_maxiter),eps(_eps)
|
| 48 |
+
{
|
| 49 |
+
q_min.data.setConstant(std::numeric_limits<double>::min());
|
| 50 |
+
q_max.data.setConstant(std::numeric_limits<double>::max());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
void ChainIkSolverPos_NR_JL::updateInternalDataStructures() {
|
| 54 |
+
nj = chain.getNrOfJoints();
|
| 55 |
+
q_min.data.conservativeResizeLike(Eigen::VectorXd::Constant(nj,std::numeric_limits<double>::min()));
|
| 56 |
+
q_max.data.conservativeResizeLike(Eigen::VectorXd::Constant(nj,std::numeric_limits<double>::max()));
|
| 57 |
+
iksolver.updateInternalDataStructures();
|
| 58 |
+
fksolver.updateInternalDataStructures();
|
| 59 |
+
delta_q.resize(nj);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
int ChainIkSolverPos_NR_JL::CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out)
|
| 63 |
+
{
|
| 64 |
+
if(nj != chain.getNrOfJoints())
|
| 65 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 66 |
+
|
| 67 |
+
if(nj != q_init.rows() || nj != q_out.rows() || nj != q_min.rows() || nj != q_max.rows())
|
| 68 |
+
return (error = E_SIZE_MISMATCH);
|
| 69 |
+
|
| 70 |
+
q_out = q_init;
|
| 71 |
+
|
| 72 |
+
unsigned int i;
|
| 73 |
+
for(i=0;i<maxiter;i++){
|
| 74 |
+
if ( fksolver.JntToCart(q_out,f) < 0)
|
| 75 |
+
return (error = E_FKSOLVERPOS_FAILED);
|
| 76 |
+
delta_twist = diff(f,p_in);
|
| 77 |
+
|
| 78 |
+
if(Equal(delta_twist,Twist::Zero(),eps))
|
| 79 |
+
break;
|
| 80 |
+
|
| 81 |
+
if ( iksolver.CartToJnt(q_out,delta_twist,delta_q) < 0)
|
| 82 |
+
return (error = E_IKSOLVERVEL_FAILED);
|
| 83 |
+
Add(q_out,delta_q,q_out);
|
| 84 |
+
|
| 85 |
+
for(unsigned int j=0; j<q_min.rows(); j++) {
|
| 86 |
+
if(q_out(j) < q_min(j))
|
| 87 |
+
q_out(j) = q_min(j);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
for(unsigned int j=0; j<q_max.rows(); j++) {
|
| 92 |
+
if(q_out(j) > q_max(j))
|
| 93 |
+
q_out(j) = q_max(j);
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
if(i!=maxiter)
|
| 98 |
+
return (error = E_NOERROR);
|
| 99 |
+
else
|
| 100 |
+
return (error = E_MAX_ITERATIONS_EXCEEDED);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
int ChainIkSolverPos_NR_JL::setJointLimits(const JntArray& q_min_in, const JntArray& q_max_in) {
|
| 104 |
+
if (q_min_in.rows() != nj || q_max_in.rows() != nj)
|
| 105 |
+
return (error = E_SIZE_MISMATCH);
|
| 106 |
+
q_min = q_min_in;
|
| 107 |
+
q_max = q_max_in;
|
| 108 |
+
return (error = E_NOERROR);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
ChainIkSolverPos_NR_JL::~ChainIkSolverPos_NR_JL()
|
| 112 |
+
{
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
const char* ChainIkSolverPos_NR_JL::strError(const int error) const
|
| 116 |
+
{
|
| 117 |
+
if (E_FKSOLVERPOS_FAILED == error) return "Internal forward position solver failed.";
|
| 118 |
+
else if (E_IKSOLVERVEL_FAILED == error) return "Internal inverse velocity solver failed.";
|
| 119 |
+
else return SolverI::strError(error);
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_nr_jl.hpp
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007-2008 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
// Copyright (C) 2008 Mikael Mayer
|
| 3 |
+
// Copyright (C) 2008 Julia Jesse
|
| 4 |
+
|
| 5 |
+
// Version: 1.0
|
| 6 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 7 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 8 |
+
// URL: http://www.orocos.org/kdl
|
| 9 |
+
|
| 10 |
+
// This library is free software; you can redistribute it and/or
|
| 11 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 12 |
+
// License as published by the Free Software Foundation; either
|
| 13 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 14 |
+
|
| 15 |
+
// This library is distributed in the hope that it will be useful,
|
| 16 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 |
+
// Lesser General Public License for more details.
|
| 19 |
+
|
| 20 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 21 |
+
// License along with this library; if not, write to the Free Software
|
| 22 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
|
| 24 |
+
#ifndef KDLCHAINIKSOLVERPOS_NR_JL_HPP
|
| 25 |
+
#define KDLCHAINIKSOLVERPOS_NR_JL_HPP
|
| 26 |
+
|
| 27 |
+
#include "chainiksolver.hpp"
|
| 28 |
+
#include "chainfksolver.hpp"
|
| 29 |
+
|
| 30 |
+
namespace KDL {
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Implementation of a general inverse position kinematics
|
| 34 |
+
* algorithm based on Newton-Raphson iterations to calculate the
|
| 35 |
+
* position transformation from Cartesian to joint space of a general
|
| 36 |
+
* KDL::Chain. Takes joint limits into account.
|
| 37 |
+
*
|
| 38 |
+
* @ingroup KinematicFamily
|
| 39 |
+
*/
|
| 40 |
+
class ChainIkSolverPos_NR_JL : public ChainIkSolverPos
|
| 41 |
+
{
|
| 42 |
+
public:
|
| 43 |
+
|
| 44 |
+
static const int E_IKSOLVERVEL_FAILED = -100; //! Child IK solver vel failed
|
| 45 |
+
static const int E_FKSOLVERPOS_FAILED = -101; //! Child FK solver failed
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Constructor of the solver, it needs the chain, a forward
|
| 49 |
+
* position kinematics solver and an inverse velocity
|
| 50 |
+
* kinematics solver for that chain.
|
| 51 |
+
*
|
| 52 |
+
* @param chain the chain to calculate the inverse position for
|
| 53 |
+
* @param q_min the minimum joint positions
|
| 54 |
+
* @param q_max the maximum joint positions
|
| 55 |
+
* @param fksolver a forward position kinematics solver
|
| 56 |
+
* @param iksolver an inverse velocity kinematics solver
|
| 57 |
+
* @param maxiter the maximum Newton-Raphson iterations,
|
| 58 |
+
* default: 100
|
| 59 |
+
* @param eps the precision for the position, used to end the
|
| 60 |
+
* iterations, default: epsilon (defined in kdl.hpp)
|
| 61 |
+
*
|
| 62 |
+
* @return
|
| 63 |
+
*/
|
| 64 |
+
ChainIkSolverPos_NR_JL(const Chain& chain,const JntArray& q_min, const JntArray& q_max, ChainFkSolverPos& fksolver,ChainIkSolverVel& iksolver,unsigned int maxiter=100,double eps=1e-6);
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Constructor of the solver, it needs the chain, a forward
|
| 68 |
+
* position kinematics solver and an inverse velocity
|
| 69 |
+
* kinematics solver for that chain.
|
| 70 |
+
*
|
| 71 |
+
* @param chain the chain to calculate the inverse position for
|
| 72 |
+
* @param fksolver a forward position kinematics solver
|
| 73 |
+
* @param iksolver an inverse velocity kinematics solver
|
| 74 |
+
* @param maxiter the maximum Newton-Raphson iterations,
|
| 75 |
+
* default: 100
|
| 76 |
+
* @param eps the precision for the position, used to end the
|
| 77 |
+
* iterations, default: epsilon (defined in kdl.hpp)
|
| 78 |
+
*
|
| 79 |
+
* @return
|
| 80 |
+
*/
|
| 81 |
+
ChainIkSolverPos_NR_JL(const Chain& chain, ChainFkSolverPos& fksolver,ChainIkSolverVel& iksolver,unsigned int maxiter=100,double eps=1e-6);
|
| 82 |
+
|
| 83 |
+
~ChainIkSolverPos_NR_JL();
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Calculates the joint values that correspond to the input pose given an initial guess.
|
| 88 |
+
* @param q_init Initial guess for the joint values.
|
| 89 |
+
* @param p_in The input pose of the chain tip.
|
| 90 |
+
* @param q_out The resulting output joint values
|
| 91 |
+
* @return E_MAX_ITERATIONS_EXCEEDED if the maximum number of iterations was exceeded before a result was found
|
| 92 |
+
* E_NOT_UP_TO_DATE if the internal data is not up to date with the chain
|
| 93 |
+
* E_SIZE_MISMATCH if the size of the input/output data does not match the chain.
|
| 94 |
+
*/
|
| 95 |
+
virtual int CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out);
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Function to set the joint limits.
|
| 99 |
+
* @param q_min minimum values for the joints
|
| 100 |
+
* @param q_max maximum values for the joints
|
| 101 |
+
* @return E_SIZE_MISMATCH if input sizes do not match the chain
|
| 102 |
+
*/
|
| 103 |
+
int setJointLimits(const JntArray& q_min, const JntArray& q_max);
|
| 104 |
+
|
| 105 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 106 |
+
virtual void updateInternalDataStructures();
|
| 107 |
+
|
| 108 |
+
/// @copydoc KDL::SolverI::strError()
|
| 109 |
+
const char* strError(const int error) const;
|
| 110 |
+
|
| 111 |
+
private:
|
| 112 |
+
const Chain& chain;
|
| 113 |
+
unsigned int nj;
|
| 114 |
+
JntArray q_min;
|
| 115 |
+
JntArray q_max;
|
| 116 |
+
ChainIkSolverVel& iksolver;
|
| 117 |
+
ChainFkSolverPos& fksolver;
|
| 118 |
+
JntArray delta_q;
|
| 119 |
+
unsigned int maxiter;
|
| 120 |
+
double eps;
|
| 121 |
+
|
| 122 |
+
Frame f;
|
| 123 |
+
Twist delta_twist;
|
| 124 |
+
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv.cpp
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainiksolvervel_pinv.hpp"
|
| 23 |
+
|
| 24 |
+
namespace KDL
|
| 25 |
+
{
|
| 26 |
+
ChainIkSolverVel_pinv::ChainIkSolverVel_pinv(const Chain& _chain,double _eps,int _maxiter):
|
| 27 |
+
chain(_chain),
|
| 28 |
+
jnt2jac(chain),
|
| 29 |
+
nj(chain.getNrOfJoints()),
|
| 30 |
+
jac(nj),
|
| 31 |
+
svd(jac),
|
| 32 |
+
U(6,JntArray(nj)),
|
| 33 |
+
S(nj),
|
| 34 |
+
V(nj,JntArray(nj)),
|
| 35 |
+
tmp(nj),
|
| 36 |
+
eps(_eps),
|
| 37 |
+
maxiter(_maxiter),
|
| 38 |
+
nrZeroSigmas(0),
|
| 39 |
+
svdResult(0)
|
| 40 |
+
{
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void ChainIkSolverVel_pinv::updateInternalDataStructures() {
|
| 44 |
+
jnt2jac.updateInternalDataStructures();
|
| 45 |
+
nj = chain.getNrOfJoints();
|
| 46 |
+
jac.resize(nj);
|
| 47 |
+
svd = SVD_HH(jac);
|
| 48 |
+
for(unsigned int i = 0 ; i < U.size(); i++)
|
| 49 |
+
U[i].resize(nj);
|
| 50 |
+
S.resize(nj);
|
| 51 |
+
V.resize(nj);
|
| 52 |
+
for(unsigned int i = 0 ; i < V.size(); i++)
|
| 53 |
+
V[i].resize(nj);
|
| 54 |
+
tmp.resize(nj);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
ChainIkSolverVel_pinv::~ChainIkSolverVel_pinv()
|
| 58 |
+
{
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
int ChainIkSolverVel_pinv::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)
|
| 63 |
+
{
|
| 64 |
+
if (nj != chain.getNrOfJoints())
|
| 65 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 66 |
+
|
| 67 |
+
if (nj != q_in.rows() || nj != qdot_out.rows())
|
| 68 |
+
return (error = E_SIZE_MISMATCH);
|
| 69 |
+
|
| 70 |
+
//Let the ChainJntToJacSolver calculate the jacobian "jac" for
|
| 71 |
+
//the current joint positions "q_in"
|
| 72 |
+
error = jnt2jac.JntToJac(q_in,jac);
|
| 73 |
+
if (error < E_NOERROR) return error;
|
| 74 |
+
|
| 75 |
+
double sum;
|
| 76 |
+
unsigned int i,j;
|
| 77 |
+
|
| 78 |
+
// Initialize near zero singular value counter
|
| 79 |
+
nrZeroSigmas = 0 ;
|
| 80 |
+
|
| 81 |
+
//Do a singular value decomposition of "jac" with maximum
|
| 82 |
+
//iterations "maxiter", put the results in "U", "S" and "V"
|
| 83 |
+
//jac = U*S*Vt
|
| 84 |
+
svdResult = svd.calculate(jac,U,S,V,maxiter);
|
| 85 |
+
if (0 != svdResult)
|
| 86 |
+
{
|
| 87 |
+
qdot_out.data.setZero();
|
| 88 |
+
return (error = E_SVD_FAILED);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// We have to calculate qdot_out = jac_pinv*v_in
|
| 92 |
+
// Using the svd decomposition this becomes(jac_pinv=V*S_pinv*Ut):
|
| 93 |
+
// qdot_out = V*S_pinv*Ut*v_in
|
| 94 |
+
|
| 95 |
+
//first we calculate Ut*v_in
|
| 96 |
+
for (i=0;i<jac.columns();i++) {
|
| 97 |
+
sum = 0.0;
|
| 98 |
+
for (j=0;j<jac.rows();j++) {
|
| 99 |
+
sum+= U[j](i)*v_in(j);
|
| 100 |
+
}
|
| 101 |
+
//If the singular value is too small (<eps), don't invert it but
|
| 102 |
+
//set the inverted singular value to zero (truncated svd)
|
| 103 |
+
if ( fabs(S(i))<eps ) {
|
| 104 |
+
tmp(i) = 0.0 ;
|
| 105 |
+
// Count number of singular values near zero
|
| 106 |
+
++nrZeroSigmas ;
|
| 107 |
+
}
|
| 108 |
+
else {
|
| 109 |
+
tmp(i) = sum/S(i) ;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
//tmp is now: tmp=S_pinv*Ut*v_in, we still have to premultiply
|
| 113 |
+
//it with V to get qdot_out
|
| 114 |
+
for (i=0;i<jac.columns();i++) {
|
| 115 |
+
sum = 0.0;
|
| 116 |
+
for (j=0;j<jac.columns();j++) {
|
| 117 |
+
sum+=V[i](j)*tmp(j);
|
| 118 |
+
}
|
| 119 |
+
//Put the result in qdot_out
|
| 120 |
+
qdot_out(i)=sum;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Note if the solution is singular, i.e. if number of near zero
|
| 124 |
+
// singular values is greater than the full rank of jac
|
| 125 |
+
if ( nrZeroSigmas > (jac.columns()-jac.rows()) ) {
|
| 126 |
+
return (error = E_CONVERGE_PINV_SINGULAR); // converged but pinv singular
|
| 127 |
+
} else {
|
| 128 |
+
return (error = E_NOERROR); // have converged
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
const char* ChainIkSolverVel_pinv::strError(const int error) const
|
| 133 |
+
{
|
| 134 |
+
if (E_CONVERGE_PINV_SINGULAR == error) return "Converged put pseudo inverse of jacobian is singular.";
|
| 135 |
+
else return SolverI::strError(error);
|
| 136 |
+
}
|
| 137 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv.hpp
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_IKSOLVERVEL_PINV_HPP
|
| 23 |
+
#define KDL_CHAIN_IKSOLVERVEL_PINV_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainiksolver.hpp"
|
| 26 |
+
#include "chainjnttojacsolver.hpp"
|
| 27 |
+
#include "utilities/svd_HH.hpp"
|
| 28 |
+
|
| 29 |
+
namespace KDL
|
| 30 |
+
{
|
| 31 |
+
/**
|
| 32 |
+
* Implementation of a inverse velocity kinematics algorithm based
|
| 33 |
+
* on the generalize pseudo inverse to calculate the velocity
|
| 34 |
+
* transformation from Cartesian to joint space of a general
|
| 35 |
+
* KDL::Chain. It uses a svd-calculation based on householders
|
| 36 |
+
* rotations.
|
| 37 |
+
*
|
| 38 |
+
* @ingroup KinematicFamily
|
| 39 |
+
*/
|
| 40 |
+
class ChainIkSolverVel_pinv : public ChainIkSolverVel
|
| 41 |
+
{
|
| 42 |
+
public:
|
| 43 |
+
/// solution converged but (pseudo)inverse is singular
|
| 44 |
+
static const int E_CONVERGE_PINV_SINGULAR = +100;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Constructor of the solver
|
| 48 |
+
*
|
| 49 |
+
* @param chain the chain to calculate the inverse velocity
|
| 50 |
+
* kinematics for
|
| 51 |
+
* @param eps if a singular value is below this value, its
|
| 52 |
+
* inverse is set to zero, default: 0.00001
|
| 53 |
+
* @param maxiter maximum iterations for the svd calculation,
|
| 54 |
+
* default: 150
|
| 55 |
+
*
|
| 56 |
+
*/
|
| 57 |
+
explicit ChainIkSolverVel_pinv(const Chain& chain,double eps=0.00001,int maxiter=150);
|
| 58 |
+
~ChainIkSolverVel_pinv();
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Find an output joint velocity \a qdot_out, given a starting joint pose
|
| 62 |
+
* \a q_init and a desired cartesian velocity \a v_in
|
| 63 |
+
*
|
| 64 |
+
* @return
|
| 65 |
+
* E_NOERROR=solution converged to <eps in maxiter
|
| 66 |
+
* E_SVD_FAILED=SVD computation failed
|
| 67 |
+
* E_CONVERGE_PINV_SINGULAR=solution converged but (pseudo)inverse is singular
|
| 68 |
+
*
|
| 69 |
+
* @note if E_CONVERGE_PINV_SINGULAR returned then converged and can
|
| 70 |
+
* continue motion, but have degraded solution
|
| 71 |
+
*
|
| 72 |
+
* @note If E_SVD_FAILED returned, then getSvdResult() returns the error code
|
| 73 |
+
* from the SVD algorithm.
|
| 74 |
+
*/
|
| 75 |
+
virtual int CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out);
|
| 76 |
+
/**
|
| 77 |
+
* not (yet) implemented.
|
| 78 |
+
*
|
| 79 |
+
*/
|
| 80 |
+
virtual int CartToJnt(const JntArray& /*q_init*/, const FrameVel& /*v_in*/, JntArrayVel& /*q_out*/){return (error = E_NOT_IMPLEMENTED);};
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Retrieve the number of singular values of the jacobian that are < eps;
|
| 84 |
+
* if the number of near zero singular values is > jac.col()-jac.row(),
|
| 85 |
+
* then the jacobian pseudoinverse is singular
|
| 86 |
+
*/
|
| 87 |
+
unsigned int getNrZeroSigmas()const {return nrZeroSigmas;};
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Retrieve the latest return code from the SVD algorithm
|
| 91 |
+
* @return 0 if CartToJnt() not yet called, otherwise latest SVD result code.
|
| 92 |
+
*/
|
| 93 |
+
int getSVDResult()const {return svdResult;};
|
| 94 |
+
|
| 95 |
+
/// @copydoc KDL::SolverI::strError()
|
| 96 |
+
virtual const char* strError(const int error) const;
|
| 97 |
+
|
| 98 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 99 |
+
virtual void updateInternalDataStructures();
|
| 100 |
+
private:
|
| 101 |
+
const Chain& chain;
|
| 102 |
+
ChainJntToJacSolver jnt2jac;
|
| 103 |
+
unsigned int nj;
|
| 104 |
+
Jacobian jac;
|
| 105 |
+
SVD_HH svd;
|
| 106 |
+
std::vector<JntArray> U;
|
| 107 |
+
JntArray S;
|
| 108 |
+
std::vector<JntArray> V;
|
| 109 |
+
JntArray tmp;
|
| 110 |
+
double eps;
|
| 111 |
+
int maxiter;
|
| 112 |
+
unsigned int nrZeroSigmas;
|
| 113 |
+
int svdResult;
|
| 114 |
+
|
| 115 |
+
};
|
| 116 |
+
}
|
| 117 |
+
#endif
|
| 118 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_givens.cpp
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainiksolvervel_pinv_givens.hpp"
|
| 23 |
+
#include "utilities/svd_eigen_Macie.hpp"
|
| 24 |
+
|
| 25 |
+
namespace KDL
|
| 26 |
+
{
|
| 27 |
+
ChainIkSolverVel_pinv_givens::ChainIkSolverVel_pinv_givens(const Chain& _chain):
|
| 28 |
+
chain(_chain),
|
| 29 |
+
nj(chain.getNrOfJoints()),
|
| 30 |
+
jnt2jac(chain),
|
| 31 |
+
jac(nj),
|
| 32 |
+
transpose(nj>6),toggle(true),
|
| 33 |
+
m(static_cast<unsigned int>(max(6,nj))),
|
| 34 |
+
n(static_cast<unsigned int>(min(6,nj))),
|
| 35 |
+
jac_eigen(m,n),
|
| 36 |
+
U(Eigen::MatrixXd::Identity(m,m)),
|
| 37 |
+
V(Eigen::MatrixXd::Identity(n,n)),
|
| 38 |
+
B(m,n),
|
| 39 |
+
S(n),
|
| 40 |
+
tempi(m),
|
| 41 |
+
UY(Eigen::VectorXd::Zero(6)),
|
| 42 |
+
SUY(Eigen::VectorXd::Zero(nj)),
|
| 43 |
+
qdot_eigen(nj),
|
| 44 |
+
v_in_eigen(6)
|
| 45 |
+
{
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void ChainIkSolverVel_pinv_givens::updateInternalDataStructures() {
|
| 49 |
+
nj = chain.getNrOfJoints();
|
| 50 |
+
jnt2jac.updateInternalDataStructures();
|
| 51 |
+
jac.resize(nj);
|
| 52 |
+
transpose = (nj > 6);
|
| 53 |
+
m = static_cast<unsigned int>(max(6,nj));
|
| 54 |
+
n = static_cast<unsigned int>(min(6,nj));
|
| 55 |
+
jac_eigen.conservativeResize(m,n);
|
| 56 |
+
U.conservativeResizeLike(Eigen::MatrixXd::Identity(m,m));
|
| 57 |
+
V.conservativeResizeLike(Eigen::MatrixXd::Identity(n,n));
|
| 58 |
+
B.conservativeResize(m,n);
|
| 59 |
+
S.conservativeResize(n);
|
| 60 |
+
tempi.conservativeResize(m);
|
| 61 |
+
SUY.conservativeResizeLike(Eigen::VectorXd::Zero(nj));
|
| 62 |
+
qdot_eigen.conservativeResize(nj);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
ChainIkSolverVel_pinv_givens::~ChainIkSolverVel_pinv_givens()
|
| 66 |
+
{
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
int ChainIkSolverVel_pinv_givens::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)
|
| 71 |
+
{
|
| 72 |
+
if (nj != chain.getNrOfJoints())
|
| 73 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 74 |
+
|
| 75 |
+
if (nj != q_in.rows() || nj != qdot_out.rows())
|
| 76 |
+
return (error = E_SIZE_MISMATCH);
|
| 77 |
+
|
| 78 |
+
toggle=!toggle;
|
| 79 |
+
|
| 80 |
+
error = jnt2jac.JntToJac(q_in,jac);
|
| 81 |
+
if (E_NOERROR > error )
|
| 82 |
+
return error;
|
| 83 |
+
|
| 84 |
+
for(unsigned int i=0;i<6;i++)
|
| 85 |
+
v_in_eigen(i)=v_in(i);
|
| 86 |
+
|
| 87 |
+
for(unsigned int i=0;i<m;i++){
|
| 88 |
+
for(unsigned int j=0;j<n;j++)
|
| 89 |
+
if(transpose)
|
| 90 |
+
jac_eigen(i,j)=jac(j,i);
|
| 91 |
+
else
|
| 92 |
+
jac_eigen(i,j)=jac(i,j);
|
| 93 |
+
}
|
| 94 |
+
svd_eigen_Macie(jac_eigen,U,S,V,B,tempi,1e-15,toggle);
|
| 95 |
+
|
| 96 |
+
if(transpose)
|
| 97 |
+
UY.noalias() = V.transpose() * v_in_eigen;
|
| 98 |
+
else
|
| 99 |
+
UY.noalias() = U.transpose() * v_in_eigen;
|
| 100 |
+
|
| 101 |
+
for (unsigned int i = 0; i < n; i++){
|
| 102 |
+
double wi = UY(i);
|
| 103 |
+
double alpha = S(i);
|
| 104 |
+
|
| 105 |
+
if (alpha != 0)
|
| 106 |
+
alpha = 1.0 / alpha;
|
| 107 |
+
else
|
| 108 |
+
alpha = 0.0;
|
| 109 |
+
SUY(i)= alpha * wi;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if(transpose)
|
| 113 |
+
qdot_eigen.noalias() = U * SUY;
|
| 114 |
+
else
|
| 115 |
+
qdot_eigen.noalias() = V * SUY;
|
| 116 |
+
|
| 117 |
+
for (unsigned int j=0;j<chain.getNrOfJoints();j++)
|
| 118 |
+
qdot_out(j)=qdot_eigen(j);
|
| 119 |
+
|
| 120 |
+
return (error = E_NOERROR);
|
| 121 |
+
}
|
| 122 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_givens.hpp
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
#ifndef KDL_CHAIN_IKSOLVERVEL_PINV_GIVENS_HPP
|
| 4 |
+
#define KDL_CHAIN_IKSOLVERVEL_PINV_GIVENS_HPP
|
| 5 |
+
|
| 6 |
+
#include "chainiksolver.hpp"
|
| 7 |
+
#include "chainjnttojacsolver.hpp"
|
| 8 |
+
|
| 9 |
+
#include <Eigen/Core>
|
| 10 |
+
|
| 11 |
+
namespace KDL
|
| 12 |
+
{
|
| 13 |
+
/**
|
| 14 |
+
* Implementation of a inverse velocity kinematics algorithm based
|
| 15 |
+
* on the generalize pseudo inverse to calculate the velocity
|
| 16 |
+
* transformation from Cartesian to joint space of a general
|
| 17 |
+
* KDL::Chain. It uses a svd-calculation based on householders
|
| 18 |
+
* rotations.
|
| 19 |
+
*
|
| 20 |
+
* @ingroup KinematicFamily
|
| 21 |
+
*/
|
| 22 |
+
class ChainIkSolverVel_pinv_givens : public ChainIkSolverVel
|
| 23 |
+
{
|
| 24 |
+
public:
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Constructor of the solver
|
| 28 |
+
*
|
| 29 |
+
* @param chain the chain to calculate the inverse velocity
|
| 30 |
+
* kinematics for
|
| 31 |
+
*
|
| 32 |
+
*/
|
| 33 |
+
explicit ChainIkSolverVel_pinv_givens(const Chain& chain);
|
| 34 |
+
~ChainIkSolverVel_pinv_givens();
|
| 35 |
+
|
| 36 |
+
virtual int CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out);
|
| 37 |
+
/**
|
| 38 |
+
* not (yet) implemented.
|
| 39 |
+
*
|
| 40 |
+
*/
|
| 41 |
+
virtual int CartToJnt(const JntArray& /*q_init*/, const FrameVel& /*v_in*/, JntArrayVel& /*q_out*/){return (error = E_NOT_IMPLEMENTED);};
|
| 42 |
+
|
| 43 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 44 |
+
virtual void updateInternalDataStructures();
|
| 45 |
+
|
| 46 |
+
private:
|
| 47 |
+
const Chain& chain;
|
| 48 |
+
unsigned int nj;
|
| 49 |
+
ChainJntToJacSolver jnt2jac;
|
| 50 |
+
Jacobian jac;
|
| 51 |
+
bool transpose,toggle;
|
| 52 |
+
unsigned int m,n;
|
| 53 |
+
Eigen::MatrixXd jac_eigen,U,V,B;
|
| 54 |
+
Eigen::VectorXd S,tempi,UY,SUY,qdot_eigen,v_in_eigen;
|
| 55 |
+
};
|
| 56 |
+
}
|
| 57 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_nso.cpp
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainiksolvervel_pinv_nso.hpp"
|
| 23 |
+
#include "utilities/svd_eigen_HH.hpp"
|
| 24 |
+
|
| 25 |
+
namespace KDL
|
| 26 |
+
{
|
| 27 |
+
ChainIkSolverVel_pinv_nso::ChainIkSolverVel_pinv_nso(const Chain& _chain, const JntArray& _opt_pos, const JntArray& _weights, double _eps, int _maxiter, double _alpha):
|
| 28 |
+
chain(_chain),
|
| 29 |
+
jnt2jac(chain),
|
| 30 |
+
nj(chain.getNrOfJoints()),
|
| 31 |
+
jac(nj),
|
| 32 |
+
U(Eigen::MatrixXd::Zero(6,nj)),
|
| 33 |
+
S(Eigen::VectorXd::Zero(nj)),
|
| 34 |
+
Sinv(Eigen::VectorXd::Zero(nj)),
|
| 35 |
+
V(Eigen::MatrixXd::Zero(nj,nj)),
|
| 36 |
+
tmp(Eigen::VectorXd::Zero(nj)),
|
| 37 |
+
tmp2(Eigen::VectorXd::Zero(nj)),
|
| 38 |
+
eps(_eps),
|
| 39 |
+
maxiter(_maxiter),
|
| 40 |
+
svdResult(0),
|
| 41 |
+
alpha(_alpha),
|
| 42 |
+
weights(_weights),
|
| 43 |
+
opt_pos(_opt_pos)
|
| 44 |
+
{
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
ChainIkSolverVel_pinv_nso::ChainIkSolverVel_pinv_nso(const Chain& _chain, double _eps, int _maxiter, double _alpha):
|
| 48 |
+
chain(_chain),
|
| 49 |
+
jnt2jac(chain),
|
| 50 |
+
nj(chain.getNrOfJoints()),
|
| 51 |
+
jac(nj),
|
| 52 |
+
U(Eigen::MatrixXd::Zero(6,nj)),
|
| 53 |
+
S(Eigen::VectorXd::Zero(nj)),
|
| 54 |
+
Sinv(Eigen::VectorXd::Zero(nj)),
|
| 55 |
+
V(Eigen::MatrixXd::Zero(nj,nj)),
|
| 56 |
+
tmp(Eigen::VectorXd::Zero(nj)),
|
| 57 |
+
tmp2(Eigen::VectorXd::Zero(nj)),
|
| 58 |
+
eps(_eps),
|
| 59 |
+
maxiter(_maxiter),
|
| 60 |
+
svdResult(0),
|
| 61 |
+
alpha(_alpha)
|
| 62 |
+
{
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void ChainIkSolverVel_pinv_nso::updateInternalDataStructures() {
|
| 66 |
+
jnt2jac.updateInternalDataStructures();
|
| 67 |
+
nj = chain.getNrOfJoints();
|
| 68 |
+
jac.resize(nj);
|
| 69 |
+
U.conservativeResizeLike(Eigen::MatrixXd::Zero(6,nj));
|
| 70 |
+
S.conservativeResizeLike(Eigen::VectorXd::Zero(nj));
|
| 71 |
+
Sinv.conservativeResizeLike(Eigen::VectorXd::Zero(nj));
|
| 72 |
+
V.conservativeResizeLike(Eigen::MatrixXd::Zero(nj,nj));
|
| 73 |
+
tmp.conservativeResizeLike(Eigen::VectorXd::Zero(nj));
|
| 74 |
+
tmp2.conservativeResizeLike(Eigen::VectorXd::Zero(nj));
|
| 75 |
+
opt_pos.data.conservativeResizeLike(Eigen::VectorXd::Zero(nj));
|
| 76 |
+
weights.data.conservativeResizeLike(Eigen::VectorXd::Ones(nj));
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
ChainIkSolverVel_pinv_nso::~ChainIkSolverVel_pinv_nso()
|
| 80 |
+
{
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
int ChainIkSolverVel_pinv_nso::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)
|
| 85 |
+
{
|
| 86 |
+
if (nj != chain.getNrOfJoints())
|
| 87 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 88 |
+
|
| 89 |
+
if (nj != q_in.rows() || nj != qdot_out.rows() || nj != opt_pos.rows() || nj != weights.rows())
|
| 90 |
+
return (error = E_SIZE_MISMATCH);
|
| 91 |
+
//Let the ChainJntToJacSolver calculate the jacobian "jac" for
|
| 92 |
+
//the current joint positions "q_in"
|
| 93 |
+
error = jnt2jac.JntToJac(q_in,jac);
|
| 94 |
+
if (error < E_NOERROR) return error;
|
| 95 |
+
|
| 96 |
+
//Do a singular value decomposition of "jac" with maximum
|
| 97 |
+
//iterations "maxiter", put the results in "U", "S" and "V"
|
| 98 |
+
//jac = U*S*Vt
|
| 99 |
+
svdResult = svd_eigen_HH(jac.data,U,S,V,tmp,maxiter);
|
| 100 |
+
if (0 != svdResult)
|
| 101 |
+
{
|
| 102 |
+
qdot_out.data.setZero() ;
|
| 103 |
+
return error = E_SVD_FAILED;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
unsigned int i;
|
| 107 |
+
|
| 108 |
+
// We have to calculate qdot_out = jac_pinv*v_in
|
| 109 |
+
// Using the svd decomposition this becomes(jac_pinv=V*S_pinv*Ut):
|
| 110 |
+
// qdot_out = V*S_pinv*Ut*v_in
|
| 111 |
+
|
| 112 |
+
// S^-1
|
| 113 |
+
for (i = 0; i < nj; ++i) {
|
| 114 |
+
Sinv(i) = fabs(S(i))<eps ? 0.0 : 1.0/S(i);
|
| 115 |
+
}
|
| 116 |
+
for (i = 0; i < 6; ++i) {
|
| 117 |
+
tmp(i) = v_in(i);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
qdot_out.data = V * Sinv.asDiagonal() * U.transpose() * tmp.head(6);
|
| 121 |
+
|
| 122 |
+
// Now onto NULL space
|
| 123 |
+
// Given the cost function g, and the current joints q, desired joints qd, and weights w:
|
| 124 |
+
// t = g(q) = 1/2 * Sum( w_i * (q_i - qd_i)^2 )
|
| 125 |
+
//
|
| 126 |
+
// The jacobian Jc is:
|
| 127 |
+
// t_dot = Jc(q) * q_dot
|
| 128 |
+
// Jc = dt/dq = w_j * (q_i - qd_i) [1 x nj vector]
|
| 129 |
+
//
|
| 130 |
+
// The pseudo inverse (^-1) is
|
| 131 |
+
// Jc^-1 = w_j * (q_i - qd_i) / A [nj x 1 vector]
|
| 132 |
+
// A = Sum( w_i^2 * (q_i - qd_i)^2 )
|
| 133 |
+
//
|
| 134 |
+
// We can set the change as the step needed to remove the error times a value alpha:
|
| 135 |
+
// t_dot = -2 * alpha * t
|
| 136 |
+
//
|
| 137 |
+
// When we put it together and project into the nullspace, the final result is
|
| 138 |
+
// q'_out += (I_n - J^-1 * J) * Jc^-1 * (-2 * alpha * g(q))
|
| 139 |
+
|
| 140 |
+
double g = 0; // g(q)
|
| 141 |
+
double A = 0; // normalizing term
|
| 142 |
+
for (i = 0; i < nj; ++i) {
|
| 143 |
+
double qd = q_in(i) - opt_pos(i);
|
| 144 |
+
g += 0.5 * qd*qd * weights(i);
|
| 145 |
+
A += qd*qd * weights(i)*weights(i);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
if (A > 1e-9) {
|
| 149 |
+
// Calculate inverse Jacobian Jc^-1
|
| 150 |
+
for (i = 0; i < nj; ++i) {
|
| 151 |
+
tmp(i) = weights(i)*(q_in(i) - opt_pos(i)) / A;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
// Calculate J^-1 * J * Jc^-1 = V*S^-1*U' * U*S*V' * tmp
|
| 155 |
+
tmp2 = V * Sinv.asDiagonal() * U.transpose() * U * S.asDiagonal() * V.transpose() * tmp;
|
| 156 |
+
|
| 157 |
+
for (i = 0; i < nj; ++i) {
|
| 158 |
+
//std::cerr << i <<": "<< qdot_out(i) <<", "<< -2*alpha*g * (tmp(i) - tmp2(i)) << std::endl;
|
| 159 |
+
qdot_out(i) += -2*alpha*g * (tmp(i) - tmp2(i));
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
//return the return value of the svd decomposition
|
| 163 |
+
return (error = E_NOERROR);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
int ChainIkSolverVel_pinv_nso::setWeights(const JntArray & _weights)
|
| 167 |
+
{
|
| 168 |
+
if (nj != _weights.rows())
|
| 169 |
+
return (error = E_SIZE_MISMATCH);
|
| 170 |
+
weights = _weights;
|
| 171 |
+
return (error = E_NOERROR);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
int ChainIkSolverVel_pinv_nso::setOptPos(const JntArray & _opt_pos)
|
| 175 |
+
{
|
| 176 |
+
if (nj != _opt_pos.rows())
|
| 177 |
+
return (error = E_SIZE_MISMATCH);
|
| 178 |
+
opt_pos = _opt_pos;
|
| 179 |
+
return (error = E_NOERROR);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
int ChainIkSolverVel_pinv_nso::setAlpha(const double _alpha)
|
| 183 |
+
{
|
| 184 |
+
alpha = _alpha;
|
| 185 |
+
return 0;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_pinv_nso.hpp
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_IKSOLVERVEL_PINV_NSO_HPP
|
| 23 |
+
#define KDL_CHAIN_IKSOLVERVEL_PINV_NSO_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainiksolver.hpp"
|
| 26 |
+
#include "chainjnttojacsolver.hpp"
|
| 27 |
+
#include <Eigen/Core>
|
| 28 |
+
|
| 29 |
+
namespace KDL
|
| 30 |
+
{
|
| 31 |
+
/**
|
| 32 |
+
* Implementation of a inverse velocity kinematics algorithm based
|
| 33 |
+
* on the generalize pseudo inverse to calculate the velocity
|
| 34 |
+
* transformation from Cartesian to joint space of a general
|
| 35 |
+
* KDL::Chain. It uses a svd-calculation based on householders
|
| 36 |
+
* rotations.
|
| 37 |
+
*
|
| 38 |
+
* In case of a redundant robot this solver optimizes the following criterium:
|
| 39 |
+
* g=0.5*sum(weight*(Desired_joint_positions - actual_joint_positions))^2 as described in
|
| 40 |
+
* A. Liegeois. Automatic supervisory control of the configuration and
|
| 41 |
+
* behavior of multibody mechanisms. IEEE Transactions on Systems, Man, and
|
| 42 |
+
* Cybernetics, 7(12):868–871, 1977
|
| 43 |
+
*
|
| 44 |
+
* @ingroup KinematicFamily
|
| 45 |
+
*/
|
| 46 |
+
class ChainIkSolverVel_pinv_nso : public ChainIkSolverVel
|
| 47 |
+
{
|
| 48 |
+
public:
|
| 49 |
+
/**
|
| 50 |
+
* Constructor of the solver
|
| 51 |
+
*
|
| 52 |
+
* @param chain the chain to calculate the inverse velocity
|
| 53 |
+
* kinematics for
|
| 54 |
+
* @param opt_pos the desired positions of the chain used by to resolve the redundancy
|
| 55 |
+
* @param weights the weights applied in the joint space
|
| 56 |
+
* @param eps if a singular value is below this value, its
|
| 57 |
+
* inverse is set to zero, default: 0.00001
|
| 58 |
+
* @param maxiter maximum iterations for the svd calculation,
|
| 59 |
+
* default: 150
|
| 60 |
+
* @param alpha the null-space velocity gain
|
| 61 |
+
*
|
| 62 |
+
*/
|
| 63 |
+
ChainIkSolverVel_pinv_nso(const Chain& chain, const JntArray& opt_pos, const JntArray& weights, double eps=0.00001,int maxiter=150, double alpha = 0.25);
|
| 64 |
+
explicit ChainIkSolverVel_pinv_nso(const Chain& chain, double eps=0.00001,int maxiter=150, double alpha = 0.25);
|
| 65 |
+
~ChainIkSolverVel_pinv_nso();
|
| 66 |
+
|
| 67 |
+
virtual int CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out);
|
| 68 |
+
/**
|
| 69 |
+
* not (yet) implemented.
|
| 70 |
+
*
|
| 71 |
+
*/
|
| 72 |
+
virtual int CartToJnt(const JntArray& /*q_init*/, const FrameVel& /*v_in*/, JntArrayVel& /*q_out*/){return (error = E_NOT_IMPLEMENTED);};
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Request the joint weights for optimization criterion
|
| 76 |
+
*
|
| 77 |
+
*
|
| 78 |
+
* @return const reference to the joint weights
|
| 79 |
+
*/
|
| 80 |
+
const JntArray& getWeights()const
|
| 81 |
+
{
|
| 82 |
+
return weights;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Request the optimal joint positions
|
| 87 |
+
*
|
| 88 |
+
*
|
| 89 |
+
* @return const reference to the optimal joint positions
|
| 90 |
+
*/
|
| 91 |
+
const JntArray& getOptPos()const
|
| 92 |
+
{
|
| 93 |
+
return opt_pos;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Request null space velocity gain
|
| 98 |
+
*
|
| 99 |
+
*
|
| 100 |
+
* @return const reference to the null space velocity gain
|
| 101 |
+
*/
|
| 102 |
+
const double& getAlpha()const
|
| 103 |
+
{
|
| 104 |
+
return alpha;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
*Set joint weights for optimization criterion
|
| 109 |
+
*
|
| 110 |
+
*@param weights the joint weights
|
| 111 |
+
*
|
| 112 |
+
*/
|
| 113 |
+
virtual int setWeights(const JntArray &weights);
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
*Set optimal joint positions
|
| 117 |
+
*
|
| 118 |
+
*@param opt_pos optimal joint positions
|
| 119 |
+
*
|
| 120 |
+
*/
|
| 121 |
+
virtual int setOptPos(const JntArray &opt_pos);
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
*Set null space velocity gain
|
| 125 |
+
*
|
| 126 |
+
*@param alpha NUllspace velocity cgain
|
| 127 |
+
*
|
| 128 |
+
*/
|
| 129 |
+
virtual int setAlpha(const double alpha);
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* Retrieve the latest return code from the SVD algorithm
|
| 133 |
+
* @return 0 if CartToJnt() not yet called, otherwise latest SVD result code.
|
| 134 |
+
*/
|
| 135 |
+
int getSVDResult()const {return svdResult;};
|
| 136 |
+
|
| 137 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 138 |
+
virtual void updateInternalDataStructures();
|
| 139 |
+
|
| 140 |
+
private:
|
| 141 |
+
const Chain& chain;
|
| 142 |
+
ChainJntToJacSolver jnt2jac;
|
| 143 |
+
unsigned int nj;
|
| 144 |
+
Jacobian jac;
|
| 145 |
+
Eigen::MatrixXd U;
|
| 146 |
+
Eigen::VectorXd S;
|
| 147 |
+
Eigen::VectorXd Sinv;
|
| 148 |
+
Eigen::MatrixXd V;
|
| 149 |
+
Eigen::VectorXd tmp;
|
| 150 |
+
Eigen::VectorXd tmp2;
|
| 151 |
+
double eps;
|
| 152 |
+
int maxiter;
|
| 153 |
+
int svdResult;
|
| 154 |
+
double alpha;
|
| 155 |
+
JntArray weights;
|
| 156 |
+
JntArray opt_pos;
|
| 157 |
+
};
|
| 158 |
+
}
|
| 159 |
+
#endif
|
| 160 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainiksolvervel_wdls.cpp
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainiksolvervel_wdls.hpp"
|
| 23 |
+
#include "utilities/svd_eigen_HH.hpp"
|
| 24 |
+
|
| 25 |
+
namespace KDL
|
| 26 |
+
{
|
| 27 |
+
|
| 28 |
+
ChainIkSolverVel_wdls::ChainIkSolverVel_wdls(const Chain& _chain,double _eps,int _maxiter):
|
| 29 |
+
chain(_chain),
|
| 30 |
+
jnt2jac(chain),
|
| 31 |
+
nj(chain.getNrOfJoints()),
|
| 32 |
+
jac(nj),
|
| 33 |
+
U(Eigen::MatrixXd::Zero(6,nj)),
|
| 34 |
+
S(Eigen::VectorXd::Zero(nj)),
|
| 35 |
+
V(Eigen::MatrixXd::Zero(nj,nj)),
|
| 36 |
+
eps(_eps),
|
| 37 |
+
maxiter(_maxiter),
|
| 38 |
+
tmp(Eigen::VectorXd::Zero(nj)),
|
| 39 |
+
tmp_jac(Eigen::MatrixXd::Zero(6,nj)),
|
| 40 |
+
tmp_jac_weight1(Eigen::MatrixXd::Zero(6,nj)),
|
| 41 |
+
tmp_jac_weight2(Eigen::MatrixXd::Zero(6,nj)),
|
| 42 |
+
tmp_ts(Eigen::MatrixXd::Zero(6,6)),
|
| 43 |
+
tmp_js(Eigen::MatrixXd::Zero(nj,nj)),
|
| 44 |
+
weight_ts(Eigen::MatrixXd::Identity(6,6)),
|
| 45 |
+
weight_js(Eigen::MatrixXd::Identity(nj,nj)),
|
| 46 |
+
lambda(0.0),
|
| 47 |
+
lambda_scaled(0.0),
|
| 48 |
+
nrZeroSigmas(0),
|
| 49 |
+
svdResult(0),
|
| 50 |
+
sigmaMin(0)
|
| 51 |
+
{
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void ChainIkSolverVel_wdls::updateInternalDataStructures() {
|
| 55 |
+
jnt2jac.updateInternalDataStructures();
|
| 56 |
+
nj = chain.getNrOfJoints();
|
| 57 |
+
jac.resize(nj);
|
| 58 |
+
Eigen::MatrixXd z6nj = Eigen::MatrixXd::Zero(6,nj);
|
| 59 |
+
Eigen::VectorXd znj = Eigen::VectorXd::Zero(nj);
|
| 60 |
+
Eigen::MatrixXd znjnj = Eigen::MatrixXd::Zero(nj,nj);
|
| 61 |
+
U.conservativeResizeLike(z6nj);
|
| 62 |
+
S.conservativeResizeLike(znj);
|
| 63 |
+
V.conservativeResizeLike(znjnj);
|
| 64 |
+
tmp.conservativeResizeLike(znj);
|
| 65 |
+
tmp_jac.conservativeResizeLike(z6nj);
|
| 66 |
+
tmp_jac_weight1.conservativeResizeLike(z6nj);
|
| 67 |
+
tmp_jac_weight2.conservativeResizeLike(z6nj);
|
| 68 |
+
tmp_js.conservativeResizeLike(znjnj);
|
| 69 |
+
weight_js.conservativeResizeLike(Eigen::MatrixXd::Identity(nj,nj));
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
ChainIkSolverVel_wdls::~ChainIkSolverVel_wdls()
|
| 73 |
+
{
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
int ChainIkSolverVel_wdls::setWeightJS(const Eigen::MatrixXd& Mq){
|
| 77 |
+
if(nj != chain.getNrOfJoints())
|
| 78 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 79 |
+
|
| 80 |
+
if (Mq.size() != weight_js.size())
|
| 81 |
+
return (error = E_SIZE_MISMATCH);
|
| 82 |
+
weight_js = Mq;
|
| 83 |
+
return (error = E_NOERROR);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
int ChainIkSolverVel_wdls::setWeightTS(const Eigen::MatrixXd& Mx){
|
| 87 |
+
if (Mx.size() != weight_ts.size())
|
| 88 |
+
return (error = E_SIZE_MISMATCH);
|
| 89 |
+
weight_ts = Mx;
|
| 90 |
+
return (error = E_NOERROR);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
void ChainIkSolverVel_wdls::setLambda(const double lambda_in)
|
| 94 |
+
{
|
| 95 |
+
lambda=lambda_in;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void ChainIkSolverVel_wdls::setEps(const double eps_in)
|
| 99 |
+
{
|
| 100 |
+
eps=eps_in;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
void ChainIkSolverVel_wdls::setMaxIter(const int maxiter_in)
|
| 104 |
+
{
|
| 105 |
+
maxiter=maxiter_in;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
int ChainIkSolverVel_wdls::getSigma(Eigen::VectorXd& Sout)
|
| 109 |
+
{
|
| 110 |
+
if (Sout.size() != S.size())
|
| 111 |
+
return (error = E_SIZE_MISMATCH);
|
| 112 |
+
Sout=S;
|
| 113 |
+
return (error = E_NOERROR);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
int ChainIkSolverVel_wdls::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)
|
| 117 |
+
{
|
| 118 |
+
if(nj != chain.getNrOfJoints())
|
| 119 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 120 |
+
|
| 121 |
+
if(nj != q_in.rows() || nj != qdot_out.rows())
|
| 122 |
+
return (error = E_SIZE_MISMATCH);
|
| 123 |
+
error = jnt2jac.JntToJac(q_in,jac);
|
| 124 |
+
if ( error < E_NOERROR) return error;
|
| 125 |
+
|
| 126 |
+
double sum;
|
| 127 |
+
unsigned int i,j;
|
| 128 |
+
|
| 129 |
+
// Initialize (internal) return values
|
| 130 |
+
nrZeroSigmas = 0 ;
|
| 131 |
+
sigmaMin = 0.;
|
| 132 |
+
lambda_scaled = 0.;
|
| 133 |
+
|
| 134 |
+
/*
|
| 135 |
+
for (i=0;i<jac.rows();i++) {
|
| 136 |
+
for (j=0;j<jac.columns();j++)
|
| 137 |
+
tmp_jac(i,j) = jac(i,j);
|
| 138 |
+
}
|
| 139 |
+
*/
|
| 140 |
+
|
| 141 |
+
// Create the Weighted jacobian
|
| 142 |
+
tmp_jac_weight1 = jac.data.lazyProduct(weight_js);
|
| 143 |
+
tmp_jac_weight2 = weight_ts.lazyProduct(tmp_jac_weight1);
|
| 144 |
+
|
| 145 |
+
// Compute the SVD of the weighted jacobian
|
| 146 |
+
svdResult = svd_eigen_HH(tmp_jac_weight2,U,S,V,tmp,maxiter);
|
| 147 |
+
if (0 != svdResult)
|
| 148 |
+
{
|
| 149 |
+
qdot_out.data.setZero() ;
|
| 150 |
+
return (error = E_SVD_FAILED);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
//Pre-multiply U and V by the task space and joint space weighting matrix respectively
|
| 154 |
+
tmp_ts = weight_ts.lazyProduct(U.topLeftCorner(6,6));
|
| 155 |
+
tmp_js = weight_js.lazyProduct(V);
|
| 156 |
+
|
| 157 |
+
// Minimum of six largest singular values of J is S(5) if number of joints >=6 and 0 for <6
|
| 158 |
+
if ( jac.columns() >= 6 ) {
|
| 159 |
+
sigmaMin = S(5);
|
| 160 |
+
}
|
| 161 |
+
else {
|
| 162 |
+
sigmaMin = 0.;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// tmp = (Si*U'*Ly*y),
|
| 166 |
+
for (i=0;i<jac.columns();i++) {
|
| 167 |
+
sum = 0.0;
|
| 168 |
+
for (j=0;j<jac.rows();j++) {
|
| 169 |
+
if(i<6)
|
| 170 |
+
sum+= tmp_ts(j,i)*v_in(j);
|
| 171 |
+
else
|
| 172 |
+
sum+=0.0;
|
| 173 |
+
}
|
| 174 |
+
// If sigmaMin > eps, then wdls is not active and lambda_scaled = 0 (default value)
|
| 175 |
+
// If sigmaMin < eps, then wdls is active and lambda_scaled is scaled from 0 to lambda
|
| 176 |
+
// Note: singular values are always positive so sigmaMin >=0
|
| 177 |
+
if ( sigmaMin < eps )
|
| 178 |
+
{
|
| 179 |
+
lambda_scaled = sqrt(1.0-(sigmaMin/eps)*(sigmaMin/eps))*lambda ;
|
| 180 |
+
}
|
| 181 |
+
if(fabs(S(i))<eps) {
|
| 182 |
+
if (i<6) {
|
| 183 |
+
// Scale lambda to size of singular value sigmaMin
|
| 184 |
+
tmp(i) = sum*((S(i)/(S(i)*S(i)+lambda_scaled*lambda_scaled)));
|
| 185 |
+
}
|
| 186 |
+
else {
|
| 187 |
+
tmp(i)=0.0; // S(i)=0 for i>=6 due to cols>rows
|
| 188 |
+
}
|
| 189 |
+
// Count number of singular values near zero
|
| 190 |
+
++nrZeroSigmas ;
|
| 191 |
+
}
|
| 192 |
+
else {
|
| 193 |
+
tmp(i) = sum/S(i);
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/*
|
| 198 |
+
// x = Lx^-1*V*tmp + x
|
| 199 |
+
for (i=0;i<jac.columns();i++) {
|
| 200 |
+
sum = 0.0;
|
| 201 |
+
for (j=0;j<jac.columns();j++) {
|
| 202 |
+
sum+=tmp_js(i,j)*tmp(j);
|
| 203 |
+
}
|
| 204 |
+
qdot_out(i)=sum;
|
| 205 |
+
}
|
| 206 |
+
*/
|
| 207 |
+
qdot_out.data=tmp_js.lazyProduct(tmp);
|
| 208 |
+
|
| 209 |
+
// If number of near zero singular values is greater than the full rank
|
| 210 |
+
// of jac, then wdls is active
|
| 211 |
+
if ( nrZeroSigmas > (jac.columns()-jac.rows()) ) {
|
| 212 |
+
return (error = E_CONVERGE_PINV_SINGULAR); // converged but pinv singular
|
| 213 |
+
} else {
|
| 214 |
+
return (error = E_NOERROR); // have converged
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
const char* ChainIkSolverVel_wdls::strError(const int error) const
|
| 219 |
+
{
|
| 220 |
+
if (E_CONVERGE_PINV_SINGULAR == error) return "Converged put pseudo inverse of jacobian is singular.";
|
| 221 |
+
else return SolverI::strError(error);
|
| 222 |
+
}
|
| 223 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAIN_IKSOLVERVEL_WDLS_HPP
|
| 23 |
+
#define KDL_CHAIN_IKSOLVERVEL_WDLS_HPP
|
| 24 |
+
|
| 25 |
+
#include "chainiksolver.hpp"
|
| 26 |
+
#include "chainjnttojacsolver.hpp"
|
| 27 |
+
#include <Eigen/Core>
|
| 28 |
+
|
| 29 |
+
namespace KDL
|
| 30 |
+
{
|
| 31 |
+
/**
|
| 32 |
+
* Implementation of a inverse velocity kinematics algorithm based
|
| 33 |
+
* on the weighted pseudo inverse with damped least-square to calculate the velocity
|
| 34 |
+
* transformation from Cartesian to joint space of a general
|
| 35 |
+
* KDL::Chain. It uses a svd-calculation based on householders
|
| 36 |
+
* rotations.
|
| 37 |
+
*
|
| 38 |
+
* J# = M_q*Vb*pinv_dls(Db)*Ub'*M_x
|
| 39 |
+
*
|
| 40 |
+
* where B = Mx*J*Mq
|
| 41 |
+
*
|
| 42 |
+
* and B = Ub*Db*Vb' is the SVD decomposition of B
|
| 43 |
+
*
|
| 44 |
+
* Mq and Mx represent, respectively, the joint-space and task-space weighting
|
| 45 |
+
* matrices.
|
| 46 |
+
* Please refer to the documentation of setWeightJS(const Eigen::MatrixXd& Mq)
|
| 47 |
+
* and setWeightTS(const Eigen::MatrixXd& Mx) for details on the effects of
|
| 48 |
+
* these matrices.
|
| 49 |
+
*
|
| 50 |
+
* For more details on Weighted Pseudo Inverse, see :
|
| 51 |
+
* 1) [Ben Israel 03] A. Ben Israel & T.N.E. Greville.
|
| 52 |
+
* Generalized Inverses : Theory and Applications,
|
| 53 |
+
* second edition. Springer, 2003. ISBN 0-387-00293-6.
|
| 54 |
+
*
|
| 55 |
+
* 2) [Doty 93] K. L. Doty, C. Melchiorri & C. Boniveto.
|
| 56 |
+
* A theory of generalized inverses applied to Robotics.
|
| 57 |
+
* The International Journal of Robotics Research,
|
| 58 |
+
* vol. 12, no. 1, pages 1-19, february 1993.
|
| 59 |
+
*
|
| 60 |
+
*
|
| 61 |
+
* @ingroup KinematicFamily
|
| 62 |
+
*/
|
| 63 |
+
class ChainIkSolverVel_wdls : public ChainIkSolverVel
|
| 64 |
+
{
|
| 65 |
+
public:
|
| 66 |
+
/// solution converged but (pseudo)inverse is singular
|
| 67 |
+
static const int E_CONVERGE_PINV_SINGULAR = +100;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Constructor of the solver
|
| 71 |
+
*
|
| 72 |
+
* @param chain the chain to calculate the inverse velocity
|
| 73 |
+
* kinematics for
|
| 74 |
+
* @param eps if a singular value is below this value, its
|
| 75 |
+
* inverse is set to zero, default: 0.00001
|
| 76 |
+
* @param maxiter maximum iterations for the svd calculation,
|
| 77 |
+
* default: 150
|
| 78 |
+
*
|
| 79 |
+
*/
|
| 80 |
+
|
| 81 |
+
explicit ChainIkSolverVel_wdls(const Chain& chain,double eps=0.00001,int maxiter=150);
|
| 82 |
+
//=ublas::identity_matrix<double>
|
| 83 |
+
~ChainIkSolverVel_wdls();
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Find an output joint velocity \a qdot_out, given a starting joint pose
|
| 87 |
+
* \a q_init and a desired cartesian velocity \a v_in
|
| 88 |
+
*
|
| 89 |
+
* @return
|
| 90 |
+
* E_NOERROR=svd solution converged in maxiter
|
| 91 |
+
* E_SVD_FAILED=svd solution failed
|
| 92 |
+
* E_CONVERGE_PINV_SINGULAR=svd solution converged but (pseudo)inverse singular
|
| 93 |
+
*
|
| 94 |
+
* @note if E_CONVERGE_PINV_SINGULAR returned then converged and can
|
| 95 |
+
* continue motion, but have degraded solution
|
| 96 |
+
*
|
| 97 |
+
* @note If E_SVD_FAILED returned, then getSvdResult() returns the error
|
| 98 |
+
* code from the SVD algorithm.
|
| 99 |
+
*/
|
| 100 |
+
virtual int CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out);
|
| 101 |
+
/**
|
| 102 |
+
* not (yet) implemented.
|
| 103 |
+
*
|
| 104 |
+
*/
|
| 105 |
+
virtual int CartToJnt(const JntArray& /*q_init*/, const FrameVel& /*v_in*/, JntArrayVel& /*q_out*/){return -1;};
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Set the joint space weighting matrix
|
| 109 |
+
*
|
| 110 |
+
* @param weight_js joint space weighting symmetric matrix,
|
| 111 |
+
* default : identity. M_q : This matrix being used as a
|
| 112 |
+
* weight for the norm of the joint space speed it HAS TO BE
|
| 113 |
+
* symmetric and positive definite. We can actually deal with
|
| 114 |
+
* matrices containing a symmetric and positive definite block
|
| 115 |
+
* and 0s otherwise. Taking a diagonal matrix as an example, a
|
| 116 |
+
* 0 on the diagonal means that the corresponding joints will
|
| 117 |
+
* not contribute to the motion of the system. On the other
|
| 118 |
+
* hand, the bigger the value, the most the corresponding
|
| 119 |
+
* joint will contribute to the overall motion. The obtained
|
| 120 |
+
* solution q_dot will actually minimize the weighted norm
|
| 121 |
+
* sqrt(q_dot'*(M_q^-2)*q_dot). In the special case we deal
|
| 122 |
+
* with, it does not make sense to invert M_q but what is
|
| 123 |
+
* important is the physical meaning of all this : a joint
|
| 124 |
+
* that has a zero weight in M_q will not contribute to the
|
| 125 |
+
* motion of the system and this is equivalent to saying that
|
| 126 |
+
* it gets an infinite weight in the norm computation. For
|
| 127 |
+
* more detailed explanation : vincent.padois@upmc.fr
|
| 128 |
+
*
|
| 129 |
+
* @return success/error code
|
| 130 |
+
*/
|
| 131 |
+
int setWeightJS(const Eigen::MatrixXd& Mq);
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Set the task space weighting matrix
|
| 135 |
+
*
|
| 136 |
+
* @param weight_ts task space weighting symmetric matrix,
|
| 137 |
+
* default: identity M_x : This matrix being used as a weight
|
| 138 |
+
* for the norm of the error (in terms of task space speed) it
|
| 139 |
+
* HAS TO BE symmetric and positive definite. We can actually
|
| 140 |
+
* deal with matrices containing a symmetric and positive
|
| 141 |
+
* definite block and 0s otherwise. Taking a diagonal matrix
|
| 142 |
+
* as an example, a 0 on the diagonal means that the
|
| 143 |
+
* corresponding task coordinate will not be taken into
|
| 144 |
+
* account (ie the corresponding error can be really big). If
|
| 145 |
+
* the rank of the jacobian is equal to the number of task
|
| 146 |
+
* space coordinates which do not have a 0 weight in M_x, the
|
| 147 |
+
* weighting will actually not impact the results (ie there is
|
| 148 |
+
* an exact solution to the velocity inverse kinematics
|
| 149 |
+
* problem). In cases without an exact solution, the bigger
|
| 150 |
+
* the value, the most the corresponding task coordinate will
|
| 151 |
+
* be taken into account (ie the more the corresponding error
|
| 152 |
+
* will be reduced). The obtained solution will minimize the
|
| 153 |
+
* weighted norm sqrt(|x_dot-Jq_dot|'*(M_x^2)*|x_dot-Jq_dot|).
|
| 154 |
+
* For more detailed explanation : vincent.padois@upmc.fr
|
| 155 |
+
*
|
| 156 |
+
* @return success/error code
|
| 157 |
+
*/
|
| 158 |
+
int setWeightTS(const Eigen::MatrixXd& Mx);
|
| 159 |
+
|
| 160 |
+
/**
|
| 161 |
+
* Set lambda
|
| 162 |
+
*/
|
| 163 |
+
void setLambda(const double lambda);
|
| 164 |
+
/**
|
| 165 |
+
* Set eps
|
| 166 |
+
*/
|
| 167 |
+
void setEps(const double eps_in);
|
| 168 |
+
/**
|
| 169 |
+
* Set maxIter
|
| 170 |
+
*/
|
| 171 |
+
void setMaxIter(const int maxiter_in);
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* Request the number of singular values of the jacobian that are < eps;
|
| 175 |
+
* if the number of near zero singular values is > jac.col()-jac.row(),
|
| 176 |
+
* then the jacobian pseudoinverse is singular
|
| 177 |
+
*/
|
| 178 |
+
unsigned int getNrZeroSigmas()const {return nrZeroSigmas;};
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Request the minimum of the first six singular values
|
| 182 |
+
*/
|
| 183 |
+
double getSigmaMin()const {return sigmaMin;};
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* Request the six singular values of the Jacobian
|
| 187 |
+
*/
|
| 188 |
+
int getSigma(Eigen::VectorXd& Sout);
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* Request the value of eps
|
| 192 |
+
*/
|
| 193 |
+
double getEps()const {return eps;};
|
| 194 |
+
|
| 195 |
+
/**
|
| 196 |
+
* Request the value of lambda for the minimum
|
| 197 |
+
*/
|
| 198 |
+
double getLambda()const {return lambda;};
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Request the scaled value of lambda for the minimum
|
| 202 |
+
* singular value 1-6
|
| 203 |
+
*/
|
| 204 |
+
double getLambdaScaled()const {return lambda_scaled;};
|
| 205 |
+
|
| 206 |
+
/**
|
| 207 |
+
* Retrieve the latest return code from the SVD algorithm
|
| 208 |
+
* @return 0 if CartToJnt() not yet called, otherwise latest SVD result code.
|
| 209 |
+
*/
|
| 210 |
+
int getSVDResult()const {return svdResult;};
|
| 211 |
+
|
| 212 |
+
/// @copydoc KDL::SolverI::strError()
|
| 213 |
+
virtual const char* strError(const int error) const;
|
| 214 |
+
|
| 215 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures()
|
| 216 |
+
virtual void updateInternalDataStructures();
|
| 217 |
+
|
| 218 |
+
private:
|
| 219 |
+
const Chain& chain;
|
| 220 |
+
ChainJntToJacSolver jnt2jac;
|
| 221 |
+
unsigned int nj;
|
| 222 |
+
Jacobian jac;
|
| 223 |
+
Eigen::MatrixXd U;
|
| 224 |
+
Eigen::VectorXd S;
|
| 225 |
+
Eigen::MatrixXd V;
|
| 226 |
+
double eps;
|
| 227 |
+
int maxiter;
|
| 228 |
+
Eigen::VectorXd tmp;
|
| 229 |
+
Eigen::MatrixXd tmp_jac;
|
| 230 |
+
Eigen::MatrixXd tmp_jac_weight1;
|
| 231 |
+
Eigen::MatrixXd tmp_jac_weight2;
|
| 232 |
+
Eigen::MatrixXd tmp_ts;
|
| 233 |
+
Eigen::MatrixXd tmp_js;
|
| 234 |
+
Eigen::MatrixXd weight_ts;
|
| 235 |
+
Eigen::MatrixXd weight_js;
|
| 236 |
+
double lambda;
|
| 237 |
+
double lambda_scaled;
|
| 238 |
+
unsigned int nrZeroSigmas ;
|
| 239 |
+
int svdResult;
|
| 240 |
+
double sigmaMin;
|
| 241 |
+
};
|
| 242 |
+
}
|
| 243 |
+
#endif
|
| 244 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacdotsolver.cpp
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Computes the Jacobian time derivative
|
| 3 |
+
Copyright (C) 2015 Antoine Hoarau <hoarau [at] isir.upmc.fr>
|
| 4 |
+
|
| 5 |
+
This library is free software; you can redistribute it and/or
|
| 6 |
+
modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
License as published by the Free Software Foundation; either
|
| 8 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 9 |
+
|
| 10 |
+
This library is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
Lesser General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
License along with this library; if not, write to the Free Software
|
| 17 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#include "chainjnttojacdotsolver.hpp"
|
| 22 |
+
|
| 23 |
+
namespace KDL
|
| 24 |
+
{
|
| 25 |
+
|
| 26 |
+
const int ChainJntToJacDotSolver::E_JAC_DOT_FAILED;
|
| 27 |
+
const int ChainJntToJacDotSolver::E_JACSOLVER_FAILED;
|
| 28 |
+
const int ChainJntToJacDotSolver::E_FKSOLVERPOS_FAILED;
|
| 29 |
+
|
| 30 |
+
const int ChainJntToJacDotSolver::HYBRID;
|
| 31 |
+
const int ChainJntToJacDotSolver::BODYFIXED;
|
| 32 |
+
const int ChainJntToJacDotSolver::INERTIAL;
|
| 33 |
+
|
| 34 |
+
ChainJntToJacDotSolver::ChainJntToJacDotSolver(const Chain& _chain):
|
| 35 |
+
chain(_chain),
|
| 36 |
+
locked_joints_(chain.getNrOfJoints(),false),
|
| 37 |
+
nr_of_unlocked_joints_(chain.getNrOfJoints()),
|
| 38 |
+
jac_solver_(chain),
|
| 39 |
+
jac_(chain.getNrOfJoints()),
|
| 40 |
+
jac_dot_(chain.getNrOfJoints()),
|
| 41 |
+
representation_(HYBRID),
|
| 42 |
+
fk_solver_(chain)
|
| 43 |
+
{
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
void ChainJntToJacDotSolver::updateInternalDataStructures() {
|
| 47 |
+
locked_joints_.resize(chain.getNrOfJoints(),false);
|
| 48 |
+
this->setLockedJoints(locked_joints_);
|
| 49 |
+
jac_solver_.updateInternalDataStructures();
|
| 50 |
+
jac_.resize(chain.getNrOfJoints());
|
| 51 |
+
jac_dot_.resize(chain.getNrOfJoints());
|
| 52 |
+
fk_solver_.updateInternalDataStructures();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
int ChainJntToJacDotSolver::JntToJacDot(const JntArrayVel& q_in, Twist& jac_dot_q_dot, int seg_nr)
|
| 56 |
+
{
|
| 57 |
+
error = JntToJacDot(q_in,jac_dot_,seg_nr);
|
| 58 |
+
if (error != E_NOERROR) {
|
| 59 |
+
return error;
|
| 60 |
+
}
|
| 61 |
+
MultiplyJacobian(jac_dot_,q_in.qdot,jac_dot_q_dot);
|
| 62 |
+
return (error = E_NOERROR);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
int ChainJntToJacDotSolver::JntToJacDot(const JntArrayVel& q_in, Jacobian& jdot, int seg_nr)
|
| 66 |
+
{
|
| 67 |
+
if(locked_joints_.size() != chain.getNrOfJoints())
|
| 68 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 69 |
+
|
| 70 |
+
unsigned int segmentNr;
|
| 71 |
+
if(seg_nr<0)
|
| 72 |
+
segmentNr=chain.getNrOfSegments();
|
| 73 |
+
else
|
| 74 |
+
segmentNr = seg_nr;
|
| 75 |
+
|
| 76 |
+
//Initialize Jacobian to zero since only segmentNr columns are computed
|
| 77 |
+
SetToZero(jdot) ;
|
| 78 |
+
|
| 79 |
+
if(q_in.q.rows()!=chain.getNrOfJoints() || nr_of_unlocked_joints_!=jdot.columns())
|
| 80 |
+
return (error = E_SIZE_MISMATCH);
|
| 81 |
+
else if(segmentNr>chain.getNrOfSegments())
|
| 82 |
+
return (error = E_OUT_OF_RANGE);
|
| 83 |
+
|
| 84 |
+
// First compute the jacobian in the Hybrid representation
|
| 85 |
+
if (jac_solver_.JntToJac(q_in.q,jac_,segmentNr) != E_NOERROR)
|
| 86 |
+
return (error = E_JACSOLVER_FAILED);
|
| 87 |
+
|
| 88 |
+
// Change the reference frame and/or the reference point
|
| 89 |
+
if (representation_ != HYBRID) // If HYBRID do nothing is this is the default.
|
| 90 |
+
{
|
| 91 |
+
if (fk_solver_.JntToCart(q_in.q,F_bs_ee_,segmentNr) != E_NOERROR)
|
| 92 |
+
return (error = E_FKSOLVERPOS_FAILED);
|
| 93 |
+
if (representation_ == BODYFIXED) {
|
| 94 |
+
// Ref Frame {ee}, Ref Point {ee}
|
| 95 |
+
jac_.changeBase(F_bs_ee_.M.Inverse());
|
| 96 |
+
} else if (representation_ == INERTIAL) {
|
| 97 |
+
// Ref Frame {bs}, Ref Point {bs}
|
| 98 |
+
jac_.changeRefPoint(-F_bs_ee_.p);
|
| 99 |
+
} else {
|
| 100 |
+
return (error = E_JAC_DOT_FAILED);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// Let's compute Jdot in the corresponding representation
|
| 105 |
+
int k=0;
|
| 106 |
+
for(unsigned int i=0;i<segmentNr;++i)
|
| 107 |
+
{
|
| 108 |
+
//Only increase joint nr if the segment has a joint
|
| 109 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 110 |
+
|
| 111 |
+
for(unsigned int j=0;j<chain.getNrOfJoints();++j)
|
| 112 |
+
{
|
| 113 |
+
// Column J is the sum of all partial derivatives ref (41)
|
| 114 |
+
if(!locked_joints_[j])
|
| 115 |
+
jac_dot_k_ += getPartialDerivative(jac_,j,k,representation_) * q_in.qdot(j);
|
| 116 |
+
}
|
| 117 |
+
jdot.setColumn(k++,jac_dot_k_);
|
| 118 |
+
SetToZero(jac_dot_k_);
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
return (error = E_NOERROR);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
const Twist& ChainJntToJacDotSolver::getPartialDerivative(const KDL::Jacobian& J,
|
| 126 |
+
const unsigned int& joint_idx,
|
| 127 |
+
const unsigned int& column_idx,
|
| 128 |
+
const int& representation)
|
| 129 |
+
{
|
| 130 |
+
switch(representation)
|
| 131 |
+
{
|
| 132 |
+
case HYBRID:
|
| 133 |
+
return getPartialDerivativeHybrid(J,joint_idx,column_idx);
|
| 134 |
+
case BODYFIXED:
|
| 135 |
+
return getPartialDerivativeBodyFixed(J,joint_idx,column_idx);
|
| 136 |
+
case INERTIAL:
|
| 137 |
+
return getPartialDerivativeInertial(J,joint_idx,column_idx);
|
| 138 |
+
default:
|
| 139 |
+
SetToZero(this->t_djdq_);
|
| 140 |
+
return t_djdq_;
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
const Twist& ChainJntToJacDotSolver::getPartialDerivativeHybrid(const KDL::Jacobian& bs_J_ee,
|
| 145 |
+
const unsigned int& joint_idx,
|
| 146 |
+
const unsigned int& column_idx)
|
| 147 |
+
{
|
| 148 |
+
int j=joint_idx;
|
| 149 |
+
int i=column_idx;
|
| 150 |
+
|
| 151 |
+
jac_j_ = bs_J_ee.getColumn(j);
|
| 152 |
+
jac_i_ = bs_J_ee.getColumn(i);
|
| 153 |
+
|
| 154 |
+
SetToZero(t_djdq_);
|
| 155 |
+
|
| 156 |
+
if(j < i)
|
| 157 |
+
{
|
| 158 |
+
// P_{\Delta}({}_{bs}J^{j}) ref (20)
|
| 159 |
+
t_djdq_.vel = jac_j_.rot * jac_i_.vel;
|
| 160 |
+
t_djdq_.rot = jac_j_.rot * jac_i_.rot;
|
| 161 |
+
}else if(j > i)
|
| 162 |
+
{
|
| 163 |
+
// M_{\Delta}({}_{bs}J^{j}) ref (23)
|
| 164 |
+
SetToZero(t_djdq_.rot);
|
| 165 |
+
t_djdq_.vel = -jac_j_.vel * jac_i_.rot;
|
| 166 |
+
}else if(j == i)
|
| 167 |
+
{
|
| 168 |
+
// ref (40)
|
| 169 |
+
SetToZero(t_djdq_.rot);
|
| 170 |
+
t_djdq_.vel = jac_i_.rot * jac_i_.vel;
|
| 171 |
+
}
|
| 172 |
+
return t_djdq_;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
const Twist& ChainJntToJacDotSolver::getPartialDerivativeBodyFixed(const Jacobian& ee_J_ee,
|
| 176 |
+
const unsigned int& joint_idx,
|
| 177 |
+
const unsigned int& column_idx)
|
| 178 |
+
{
|
| 179 |
+
int j=joint_idx;
|
| 180 |
+
int i=column_idx;
|
| 181 |
+
|
| 182 |
+
SetToZero(t_djdq_);
|
| 183 |
+
|
| 184 |
+
if(j > i)
|
| 185 |
+
{
|
| 186 |
+
jac_j_ = ee_J_ee.getColumn(j);
|
| 187 |
+
jac_i_ = ee_J_ee.getColumn(i);
|
| 188 |
+
|
| 189 |
+
// - S_d_(ee_J^j) * ee_J^ee ref (23)
|
| 190 |
+
t_djdq_.vel = jac_j_.rot * jac_i_.vel + jac_j_.vel * jac_i_.rot;
|
| 191 |
+
t_djdq_.rot = jac_j_.rot * jac_i_.rot;
|
| 192 |
+
t_djdq_ = -t_djdq_;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
return t_djdq_;
|
| 196 |
+
}
|
| 197 |
+
const Twist& ChainJntToJacDotSolver::getPartialDerivativeInertial(const KDL::Jacobian& bs_J_bs,
|
| 198 |
+
const unsigned int& joint_idx,
|
| 199 |
+
const unsigned int& column_idx)
|
| 200 |
+
{
|
| 201 |
+
int j=joint_idx;
|
| 202 |
+
int i=column_idx;
|
| 203 |
+
|
| 204 |
+
SetToZero(t_djdq_);
|
| 205 |
+
|
| 206 |
+
if(j < i)
|
| 207 |
+
{
|
| 208 |
+
jac_j_ = bs_J_bs.getColumn(j);
|
| 209 |
+
jac_i_ = bs_J_bs.getColumn(i);
|
| 210 |
+
|
| 211 |
+
// S_d_(bs_J^j) * bs_J^bs ref (23)
|
| 212 |
+
t_djdq_.vel = jac_j_.rot * jac_i_.vel + jac_j_.vel * jac_i_.rot;
|
| 213 |
+
t_djdq_.rot = jac_j_.rot * jac_i_.rot;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
return t_djdq_;
|
| 217 |
+
}
|
| 218 |
+
void ChainJntToJacDotSolver::setRepresentation(const int& representation)
|
| 219 |
+
{
|
| 220 |
+
if(representation == HYBRID ||
|
| 221 |
+
representation == BODYFIXED ||
|
| 222 |
+
representation == INERTIAL)
|
| 223 |
+
this->representation_ = representation;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
int ChainJntToJacDotSolver::setLockedJoints(const std::vector<bool>& locked_joints)
|
| 228 |
+
{
|
| 229 |
+
if(locked_joints.size()!=locked_joints_.size())
|
| 230 |
+
return E_SIZE_MISMATCH;
|
| 231 |
+
locked_joints_=locked_joints;
|
| 232 |
+
nr_of_unlocked_joints_=0;
|
| 233 |
+
for(unsigned int i=0;i<locked_joints_.size();i++){
|
| 234 |
+
if(!locked_joints_[i])
|
| 235 |
+
nr_of_unlocked_joints_++;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
return (error = E_NOERROR);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
const char* ChainJntToJacDotSolver::strError(const int error) const
|
| 242 |
+
{
|
| 243 |
+
if (E_JAC_DOT_FAILED == error) return "Jac Dot Failed";
|
| 244 |
+
else if (E_JACSOLVER_FAILED == error) return "Jac Solver Failed";
|
| 245 |
+
else if (E_FKSOLVERPOS_FAILED == error) return "FK Position Solver Failed";
|
| 246 |
+
return SolverI::strError(error);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
ChainJntToJacDotSolver::~ChainJntToJacDotSolver()
|
| 250 |
+
{
|
| 251 |
+
}
|
| 252 |
+
} // namespace KDL
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacdotsolver.hpp
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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Hoarau <hoarau [at] isir.upmc.fr>
|
| 4 |
+
|
| 5 |
+
This library is free software; you can redistribute it and/or
|
| 6 |
+
modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
License as published by the Free Software Foundation; either
|
| 8 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 9 |
+
|
| 10 |
+
This library is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
Lesser General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
License along with this library; if not, write to the Free Software
|
| 17 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#ifndef KDL_CHAINJNTTOJACDOTSOLVER_HPP
|
| 22 |
+
#define KDL_CHAINJNTTOJACDOTSOLVER_HPP
|
| 23 |
+
|
| 24 |
+
#include "solveri.hpp"
|
| 25 |
+
#include "frames.hpp"
|
| 26 |
+
#include "jntarrayvel.hpp"
|
| 27 |
+
#include "jacobian.hpp"
|
| 28 |
+
#include "chain.hpp"
|
| 29 |
+
#include "framevel.hpp"
|
| 30 |
+
#include "chainjnttojacsolver.hpp"
|
| 31 |
+
#include "chainfksolverpos_recursive.hpp"
|
| 32 |
+
|
| 33 |
+
namespace KDL
|
| 34 |
+
{
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* @brief Computes the Jacobian time derivative (Jdot) by calculating the
|
| 38 |
+
* partial derivatives regarding to a joint angle, in the Hybrid, Body-fixed
|
| 39 |
+
* or Inertial representation.
|
| 40 |
+
*
|
| 41 |
+
* This work is based on :
|
| 42 |
+
* Symbolic differentiation of the velocity mapping for a serial kinematic chain
|
| 43 |
+
* H. Bruyninckx, J. De Schutter
|
| 44 |
+
* doi:10.1016/0094-114X(95)00069-B
|
| 45 |
+
*
|
| 46 |
+
* url : http://www.sciencedirect.com/science/article/pii/0094114X9500069B
|
| 47 |
+
*/
|
| 48 |
+
class ChainJntToJacDotSolver : public SolverI
|
| 49 |
+
{
|
| 50 |
+
public:
|
| 51 |
+
static const int E_JAC_DOT_FAILED = -100;
|
| 52 |
+
static const int E_JACSOLVER_FAILED = -101;
|
| 53 |
+
static const int E_FKSOLVERPOS_FAILED = -102;
|
| 54 |
+
|
| 55 |
+
// Hybrid representation ref Frame: base, ref Point: end-effector
|
| 56 |
+
static const int HYBRID = 0;
|
| 57 |
+
// Body-fixed representation ref Frame: end-effector, ref Point: end-effector
|
| 58 |
+
static const int BODYFIXED = 1;
|
| 59 |
+
// Inertial representation ref Frame: base, ref Point: base
|
| 60 |
+
static const int INERTIAL = 2;
|
| 61 |
+
|
| 62 |
+
explicit ChainJntToJacDotSolver(const Chain& chain);
|
| 63 |
+
virtual ~ChainJntToJacDotSolver();
|
| 64 |
+
/**
|
| 65 |
+
* @brief Computes \f$ {}_{bs}\dot{J}^{ee}.\dot{q} \f$
|
| 66 |
+
*
|
| 67 |
+
* @param q_in Current joint positions and velocities
|
| 68 |
+
* @param jac_dot_q_dot The twist representing Jdot*qdot
|
| 69 |
+
* @param seg_nr The final segment to compute
|
| 70 |
+
* @return int 0 if no errors happened
|
| 71 |
+
*/
|
| 72 |
+
virtual int JntToJacDot(const KDL::JntArrayVel& q_in, KDL::Twist& jac_dot_q_dot, int seg_nr = -1);
|
| 73 |
+
/**
|
| 74 |
+
* @brief Computes \f$ {}_{bs}\dot{J}^{ee} \f$
|
| 75 |
+
*
|
| 76 |
+
* @param q_in Current joint positions and velocities
|
| 77 |
+
* @param jdot The jacobian time derivative in the configured representation
|
| 78 |
+
* (HYBRID, BODYFIXED or INERTIAL)
|
| 79 |
+
* @param seg_nr The final segment to compute
|
| 80 |
+
* @return int 0 if no errors happened
|
| 81 |
+
*/
|
| 82 |
+
virtual int JntToJacDot(const KDL::JntArrayVel& q_in, KDL::Jacobian& jdot, int seg_nr = -1);
|
| 83 |
+
int setLockedJoints(const std::vector<bool>& locked_joints);
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* @brief JntToJacDot() will compute in the Hybrid representation (ref Frame: base, ref Point: end-effector)
|
| 87 |
+
*
|
| 88 |
+
*
|
| 89 |
+
* @return void
|
| 90 |
+
*/
|
| 91 |
+
void setHybridRepresentation(){setRepresentation(HYBRID);}
|
| 92 |
+
/**
|
| 93 |
+
* @brief JntToJacDot() will compute in the Body-fixed representation (ref Frame: end-effector, ref Point: end-effector)
|
| 94 |
+
*
|
| 95 |
+
* @return void
|
| 96 |
+
*/
|
| 97 |
+
void setBodyFixedRepresentation(){setRepresentation(BODYFIXED);}
|
| 98 |
+
/**
|
| 99 |
+
* @brief JntToJacDot() will compute in the Inertial representation (ref Frame: base, ref Point: base)
|
| 100 |
+
*
|
| 101 |
+
* @return void
|
| 102 |
+
*/
|
| 103 |
+
void setInertialRepresentation(){setRepresentation(INERTIAL);}
|
| 104 |
+
/**
|
| 105 |
+
* @brief Sets the internal variable for the representation (with a check on the value)
|
| 106 |
+
*
|
| 107 |
+
* @param representation The representation for Jdot : HYBRID,BODYFIXED or INERTIAL
|
| 108 |
+
* @return void
|
| 109 |
+
*/
|
| 110 |
+
void setRepresentation(const int& representation);
|
| 111 |
+
|
| 112 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 113 |
+
virtual void updateInternalDataStructures();
|
| 114 |
+
|
| 115 |
+
/// @copydoc KDL::SolverI::strError()
|
| 116 |
+
virtual const char* strError(const int error) const;
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
protected:
|
| 120 |
+
/**
|
| 121 |
+
* @brief Computes \f$ \frac{\partial {}_{bs}J^{i,ee}}{\partial q^{j}}.\dot{q}^{j} \f$
|
| 122 |
+
*
|
| 123 |
+
* @param bs_J_ee The Jacobian expressed in the base frame with the end effector as the reference point (default in KDL Jacobian Solver)
|
| 124 |
+
* @param joint_idx The index of the current joint (j in the formula)
|
| 125 |
+
* @param column_idx The index of the current column (i in the formula)
|
| 126 |
+
* @return Twist The twist representing dJi/dqj .qdotj
|
| 127 |
+
*/
|
| 128 |
+
const Twist& getPartialDerivativeHybrid(const Jacobian& bs_J_ee,
|
| 129 |
+
const unsigned int& joint_idx,
|
| 130 |
+
const unsigned int& column_idx);
|
| 131 |
+
/**
|
| 132 |
+
* @brief Computes \f$ \frac{\partial {}_{ee}J^{i,ee}}{\partial q^{j}}.\dot{q}^{j} \f$
|
| 133 |
+
*
|
| 134 |
+
* @param bs_J_ee The Jacobian expressed in the end effector frame with the end effector as the reference point
|
| 135 |
+
* @param joint_idx The indice of the current joint (j in the formula)
|
| 136 |
+
* @param column_idx The indice of the current column (i in the formula)
|
| 137 |
+
* @return Twist The twist representing dJi/dqj .qdotj
|
| 138 |
+
*/
|
| 139 |
+
const Twist& getPartialDerivativeBodyFixed(const Jacobian& ee_J_ee,
|
| 140 |
+
const unsigned int& joint_idx,
|
| 141 |
+
const unsigned int& column_idx);
|
| 142 |
+
/**
|
| 143 |
+
* @brief Computes \f$ \frac{\partial {}_{bs}J^{i,bs}}{\partial q^{j}}.\dot{q}^{j} \f$
|
| 144 |
+
*
|
| 145 |
+
* @param ee_J_ee The Jacobian expressed in the base frame with the base as the reference point
|
| 146 |
+
* @param joint_idx The indice of the current joint (j in the formula)
|
| 147 |
+
* @param column_idx The indice of the current column (i in the formula)
|
| 148 |
+
* @return Twist The twist representing dJi/dqj .qdotj
|
| 149 |
+
*/
|
| 150 |
+
const Twist& getPartialDerivativeInertial(const Jacobian& bs_J_bs,
|
| 151 |
+
const unsigned int& joint_idx,
|
| 152 |
+
const unsigned int& column_idx);
|
| 153 |
+
/**
|
| 154 |
+
* @brief Computes \f$ \frac{\partial J^{i,ee}}{\partial q^{j}}.\dot{q}^{j} \f$
|
| 155 |
+
*
|
| 156 |
+
* @param bs_J_bs The Jacobian expressed in the base frame with the end effector as the reference point
|
| 157 |
+
* @param joint_idx The indice of the current joint (j in the formula)
|
| 158 |
+
* @param column_idx The indice of the current column (i in the formula)
|
| 159 |
+
* @param representation The representation (Hybrid,Body-fixed,Inertial) in which you want to get dJ/dqj .qdotj
|
| 160 |
+
* @return Twist The twist representing dJi/dqj .qdotj
|
| 161 |
+
*/
|
| 162 |
+
const Twist& getPartialDerivative(const Jacobian& J,
|
| 163 |
+
const unsigned int& joint_idx,
|
| 164 |
+
const unsigned int& column_idx,
|
| 165 |
+
const int& representation);
|
| 166 |
+
private:
|
| 167 |
+
|
| 168 |
+
const Chain& chain;
|
| 169 |
+
std::vector<bool> locked_joints_;
|
| 170 |
+
unsigned int nr_of_unlocked_joints_;
|
| 171 |
+
ChainJntToJacSolver jac_solver_;
|
| 172 |
+
Jacobian jac_;
|
| 173 |
+
Jacobian jac_dot_;
|
| 174 |
+
int representation_;
|
| 175 |
+
ChainFkSolverPos_recursive fk_solver_;
|
| 176 |
+
Frame F_bs_ee_;
|
| 177 |
+
Twist jac_dot_k_;
|
| 178 |
+
Twist jac_j_, jac_i_;
|
| 179 |
+
Twist t_djdq_;
|
| 180 |
+
};
|
| 181 |
+
|
| 182 |
+
}
|
| 183 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacsolver.cpp
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "chainjnttojacsolver.hpp"
|
| 23 |
+
|
| 24 |
+
namespace KDL
|
| 25 |
+
{
|
| 26 |
+
ChainJntToJacSolver::ChainJntToJacSolver(const Chain& _chain):
|
| 27 |
+
chain(_chain),locked_joints_(chain.getNrOfJoints(),false)
|
| 28 |
+
{
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
void ChainJntToJacSolver::updateInternalDataStructures() {
|
| 32 |
+
locked_joints_.resize(chain.getNrOfJoints(),false);
|
| 33 |
+
}
|
| 34 |
+
ChainJntToJacSolver::~ChainJntToJacSolver()
|
| 35 |
+
{
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
int ChainJntToJacSolver::setLockedJoints(const std::vector<bool> locked_joints)
|
| 39 |
+
{
|
| 40 |
+
if(locked_joints_.size() != chain.getNrOfJoints())
|
| 41 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 42 |
+
if(locked_joints.size()!=locked_joints_.size())
|
| 43 |
+
return (error = E_SIZE_MISMATCH);
|
| 44 |
+
locked_joints_=locked_joints;
|
| 45 |
+
return (error = E_NOERROR);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
int ChainJntToJacSolver::JntToJac(const JntArray& q_in, Jacobian& jac, int seg_nr)
|
| 49 |
+
{
|
| 50 |
+
if(locked_joints_.size() != chain.getNrOfJoints())
|
| 51 |
+
return (error = E_NOT_UP_TO_DATE);
|
| 52 |
+
unsigned int segmentNr;
|
| 53 |
+
if(seg_nr<0)
|
| 54 |
+
segmentNr=chain.getNrOfSegments();
|
| 55 |
+
else
|
| 56 |
+
segmentNr = seg_nr;
|
| 57 |
+
|
| 58 |
+
//Initialize Jacobian to zero since only segmentNr columns are computed
|
| 59 |
+
SetToZero(jac) ;
|
| 60 |
+
|
| 61 |
+
if( q_in.rows()!=chain.getNrOfJoints() || jac.columns() != chain.getNrOfJoints())
|
| 62 |
+
return (error = E_SIZE_MISMATCH);
|
| 63 |
+
else if(segmentNr>chain.getNrOfSegments())
|
| 64 |
+
return (error = E_OUT_OF_RANGE);
|
| 65 |
+
|
| 66 |
+
T_tmp = Frame::Identity();
|
| 67 |
+
SetToZero(t_tmp);
|
| 68 |
+
int j=0;
|
| 69 |
+
int k=0;
|
| 70 |
+
Frame total;
|
| 71 |
+
for (unsigned int i=0;i<segmentNr;i++) {
|
| 72 |
+
//Calculate new Frame_base_ee
|
| 73 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 74 |
+
//pose of the new end-point expressed in the base
|
| 75 |
+
total = T_tmp*chain.getSegment(i).pose(q_in(j));
|
| 76 |
+
//changing base of new segment's twist to base frame if it is not locked
|
| 77 |
+
//t_tmp = T_tmp.M*chain.getSegment(i).twist(1.0);
|
| 78 |
+
if(!locked_joints_[j])
|
| 79 |
+
t_tmp = T_tmp.M*chain.getSegment(i).twist(q_in(j),1.0);
|
| 80 |
+
}else{
|
| 81 |
+
total = T_tmp*chain.getSegment(i).pose(0.0);
|
| 82 |
+
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
//Changing Refpoint of all columns to new ee
|
| 86 |
+
changeRefPoint(jac,total.p-T_tmp.p,jac);
|
| 87 |
+
|
| 88 |
+
//Only increase jointnr if the segment has a joint
|
| 89 |
+
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) {
|
| 90 |
+
//Only put the twist inside if it is not locked
|
| 91 |
+
if(!locked_joints_[j])
|
| 92 |
+
jac.setColumn(k++,t_tmp);
|
| 93 |
+
j++;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
T_tmp = total;
|
| 97 |
+
}
|
| 98 |
+
return (error = E_NOERROR);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/chainjnttojacsolver.hpp
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CHAINJNTTOJACSOLVER_HPP
|
| 23 |
+
#define KDL_CHAINJNTTOJACSOLVER_HPP
|
| 24 |
+
|
| 25 |
+
#include "solveri.hpp"
|
| 26 |
+
#include "frames.hpp"
|
| 27 |
+
#include "jacobian.hpp"
|
| 28 |
+
#include "jntarray.hpp"
|
| 29 |
+
#include "chain.hpp"
|
| 30 |
+
|
| 31 |
+
namespace KDL
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* @brief Class to calculate the jacobian of a general
|
| 35 |
+
* KDL::Chain, it is used by other solvers.
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
class ChainJntToJacSolver : public SolverI
|
| 39 |
+
{
|
| 40 |
+
public:
|
| 41 |
+
|
| 42 |
+
explicit ChainJntToJacSolver(const Chain& chain);
|
| 43 |
+
virtual ~ChainJntToJacSolver();
|
| 44 |
+
/**
|
| 45 |
+
* Calculate the jacobian expressed in the base frame of the
|
| 46 |
+
* chain, with reference point at the end effector of the
|
| 47 |
+
* *chain. The algorithm is similar to the one used in
|
| 48 |
+
* KDL::ChainFkSolverVel_recursive
|
| 49 |
+
*
|
| 50 |
+
* @param q_in input joint positions
|
| 51 |
+
* @param jac output jacobian
|
| 52 |
+
* @param seg_nr The final segment to compute
|
| 53 |
+
* @return success/error code
|
| 54 |
+
*/
|
| 55 |
+
virtual int JntToJac(const JntArray& q_in, Jacobian& jac, int seg_nr=-1);
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
*
|
| 59 |
+
* @param locked_joints new values for locked joints
|
| 60 |
+
* @return success/error code
|
| 61 |
+
*/
|
| 62 |
+
int setLockedJoints(const std::vector<bool> locked_joints);
|
| 63 |
+
|
| 64 |
+
/// @copydoc KDL::SolverI::updateInternalDataStructures
|
| 65 |
+
virtual void updateInternalDataStructures();
|
| 66 |
+
|
| 67 |
+
private:
|
| 68 |
+
const Chain& chain;
|
| 69 |
+
Twist t_tmp;
|
| 70 |
+
Frame T_tmp;
|
| 71 |
+
std::vector<bool> locked_joints_;
|
| 72 |
+
};
|
| 73 |
+
}
|
| 74 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/config.h.in
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2014 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Brian Jensen <Jensen dot J dot Brian at gmail dot com>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_CONFIG_H
|
| 23 |
+
#define KDL_CONFIG_H
|
| 24 |
+
|
| 25 |
+
#define KDL_VERSION_MAJOR @KDL_VERSION_MAJOR@
|
| 26 |
+
#define KDL_VERSION_MINOR @KDL_VERSION_MINOR@
|
| 27 |
+
#define KDL_VERSION_PATCH @KDL_VERSION_PATCH@
|
| 28 |
+
|
| 29 |
+
#define KDL_VERSION (KDL_VERSION_MAJOR << 16) | (KDL_VERSION_MINOR << 8) | KDL_VERSION_PATCH
|
| 30 |
+
|
| 31 |
+
#define KDL_VERSION_STRING "@KDL_VERSION@"
|
| 32 |
+
|
| 33 |
+
//Set which version of the Tree Interface to use
|
| 34 |
+
#cmakedefine HAVE_STL_CONTAINER_INCOMPLETE_TYPES
|
| 35 |
+
#cmakedefine KDL_USE_NEW_TREE_INTERFACE
|
| 36 |
+
|
| 37 |
+
#endif //#define KDL_CONFIG_H
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc.cpp
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \author
|
| 3 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 4 |
+
*
|
| 5 |
+
* \version
|
| 6 |
+
* ORO_Geometry V0.2
|
| 7 |
+
*
|
| 8 |
+
* \par History
|
| 9 |
+
* - $log$
|
| 10 |
+
*
|
| 11 |
+
* \par Release
|
| 12 |
+
* $Id: rrframes.cpp,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 13 |
+
* $Name: $
|
| 14 |
+
****************************************************************************/
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#include "frameacc.hpp"
|
| 18 |
+
|
| 19 |
+
namespace KDL {
|
| 20 |
+
|
| 21 |
+
#ifndef KDL_INLINE
|
| 22 |
+
#include "frameacc.inl"
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
}
|
| 26 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc.hpp
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \file
|
| 3 |
+
* This file contains the definition of classes for a
|
| 4 |
+
* Rall Algebra of (subset of) the classes defined in frames,
|
| 5 |
+
* i.e. classes that contain a set (value,derivative,2nd derivative)
|
| 6 |
+
* and define operations on that set
|
| 7 |
+
* this classes are useful for automatic differentiation ( <-> symbolic diff ,
|
| 8 |
+
* <-> numeric diff).
|
| 9 |
+
* Defines VectorAcc, RotationAcc, FrameAcc, doubleAcc.
|
| 10 |
+
* Look at the corresponding classes Vector Rotation Frame Twist and
|
| 11 |
+
* Wrench for the semantics of the methods.
|
| 12 |
+
*
|
| 13 |
+
* It also contains the 2nd derivative <-> RFrames.h
|
| 14 |
+
*
|
| 15 |
+
* \author
|
| 16 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 17 |
+
*
|
| 18 |
+
* \version
|
| 19 |
+
* ORO_Geometry V0.2
|
| 20 |
+
*
|
| 21 |
+
* \par History
|
| 22 |
+
* - $log$
|
| 23 |
+
*
|
| 24 |
+
* \par Release
|
| 25 |
+
* $Id: rrframes.h,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 26 |
+
* $Name: $
|
| 27 |
+
****************************************************************************/
|
| 28 |
+
|
| 29 |
+
#ifndef RRFRAMES_H
|
| 30 |
+
#define RRFRAMES_H
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
#include "utilities/rall2d.h"
|
| 34 |
+
#include "frames.hpp"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
namespace KDL {
|
| 38 |
+
|
| 39 |
+
class TwistAcc;
|
| 40 |
+
typedef Rall2d<double,double,double> doubleAcc;
|
| 41 |
+
|
| 42 |
+
// Equal is friend function, but default arguments for friends are forbidden (§8.3.6.4)
|
| 43 |
+
class FrameAcc;
|
| 44 |
+
class RotationAcc;
|
| 45 |
+
class VectorAcc;
|
| 46 |
+
|
| 47 |
+
IMETHOD bool Equal(const FrameAcc& r1,const FrameAcc& r2,double eps=epsilon);
|
| 48 |
+
IMETHOD bool Equal(const Frame& r1,const FrameAcc& r2,double eps=epsilon);
|
| 49 |
+
IMETHOD bool Equal(const FrameAcc& r1,const Frame& r2,double eps=epsilon);
|
| 50 |
+
IMETHOD bool Equal(const RotationAcc& r1,const RotationAcc& r2,double eps=epsilon);
|
| 51 |
+
IMETHOD bool Equal(const Rotation& r1,const RotationAcc& r2,double eps=epsilon);
|
| 52 |
+
IMETHOD bool Equal(const RotationAcc& r1,const Rotation& r2,double eps=epsilon);
|
| 53 |
+
IMETHOD bool Equal(const TwistAcc& a,const TwistAcc& b,double eps=epsilon);
|
| 54 |
+
IMETHOD bool Equal(const Twist& a,const TwistAcc& b,double eps=epsilon);
|
| 55 |
+
IMETHOD bool Equal(const TwistAcc& a,const Twist& b,double eps=epsilon);
|
| 56 |
+
IMETHOD bool Equal(const VectorAcc& r1,const VectorAcc& r2,double eps=epsilon);
|
| 57 |
+
IMETHOD bool Equal(const Vector& r1,const VectorAcc& r2,double eps=epsilon);
|
| 58 |
+
IMETHOD bool Equal(const VectorAcc& r1,const Vector& r2,double eps=epsilon);
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class VectorAcc
|
| 62 |
+
{
|
| 63 |
+
public:
|
| 64 |
+
Vector p; //!< position vector
|
| 65 |
+
Vector v; //!< velocity vector
|
| 66 |
+
Vector dv; //!< acceleration vector
|
| 67 |
+
public:
|
| 68 |
+
VectorAcc():p(),v(),dv() {}
|
| 69 |
+
explicit VectorAcc(const Vector& _p):p(_p),v(Vector::Zero()),dv(Vector::Zero()) {}
|
| 70 |
+
VectorAcc(const Vector& _p,const Vector& _v):p(_p),v(_v),dv(Vector::Zero()) {}
|
| 71 |
+
VectorAcc(const Vector& _p,const Vector& _v,const Vector& _dv):
|
| 72 |
+
p(_p),v(_v),dv(_dv) {}
|
| 73 |
+
IMETHOD VectorAcc& operator = (const VectorAcc& arg);
|
| 74 |
+
IMETHOD VectorAcc& operator = (const Vector& arg);
|
| 75 |
+
IMETHOD VectorAcc& operator += (const VectorAcc& arg);
|
| 76 |
+
IMETHOD VectorAcc& operator -= (const VectorAcc& arg);
|
| 77 |
+
IMETHOD static VectorAcc Zero();
|
| 78 |
+
IMETHOD void ReverseSign();
|
| 79 |
+
IMETHOD doubleAcc Norm(double eps=epsilon);
|
| 80 |
+
IMETHOD friend VectorAcc operator + (const VectorAcc& r1,const VectorAcc& r2);
|
| 81 |
+
IMETHOD friend VectorAcc operator - (const VectorAcc& r1,const VectorAcc& r2);
|
| 82 |
+
IMETHOD friend VectorAcc operator + (const Vector& r1,const VectorAcc& r2);
|
| 83 |
+
IMETHOD friend VectorAcc operator - (const Vector& r1,const VectorAcc& r2);
|
| 84 |
+
IMETHOD friend VectorAcc operator + (const VectorAcc& r1,const Vector& r2);
|
| 85 |
+
IMETHOD friend VectorAcc operator - (const VectorAcc& r1,const Vector& r2);
|
| 86 |
+
IMETHOD friend VectorAcc operator * (const VectorAcc& r1,const VectorAcc& r2);
|
| 87 |
+
IMETHOD friend VectorAcc operator * (const VectorAcc& r1,const Vector& r2);
|
| 88 |
+
IMETHOD friend VectorAcc operator * (const Vector& r1,const VectorAcc& r2);
|
| 89 |
+
IMETHOD friend VectorAcc operator * (const VectorAcc& r1,double r2);
|
| 90 |
+
IMETHOD friend VectorAcc operator * (double r1,const VectorAcc& r2);
|
| 91 |
+
IMETHOD friend VectorAcc operator * (const doubleAcc& r1,const VectorAcc& r2);
|
| 92 |
+
IMETHOD friend VectorAcc operator * (const VectorAcc& r2,const doubleAcc& r1);
|
| 93 |
+
IMETHOD friend VectorAcc operator*(const Rotation& R,const VectorAcc& x);
|
| 94 |
+
|
| 95 |
+
IMETHOD friend VectorAcc operator / (const VectorAcc& r1,double r2);
|
| 96 |
+
IMETHOD friend VectorAcc operator / (const VectorAcc& r2,const doubleAcc& r1);
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
IMETHOD friend bool Equal(const VectorAcc& r1,const VectorAcc& r2,double eps);
|
| 100 |
+
IMETHOD friend bool Equal(const Vector& r1,const VectorAcc& r2,double eps);
|
| 101 |
+
IMETHOD friend bool Equal(const VectorAcc& r1,const Vector& r2,double eps);
|
| 102 |
+
IMETHOD friend VectorAcc operator - (const VectorAcc& r);
|
| 103 |
+
IMETHOD friend doubleAcc dot(const VectorAcc& lhs,const VectorAcc& rhs);
|
| 104 |
+
IMETHOD friend doubleAcc dot(const VectorAcc& lhs,const Vector& rhs);
|
| 105 |
+
IMETHOD friend doubleAcc dot(const Vector& lhs,const VectorAcc& rhs);
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class RotationAcc
|
| 110 |
+
{
|
| 111 |
+
public:
|
| 112 |
+
Rotation R; //!< rotation matrix
|
| 113 |
+
Vector w; //!< angular velocity vector
|
| 114 |
+
Vector dw; //!< angular acceration vector
|
| 115 |
+
public:
|
| 116 |
+
RotationAcc():R(),w() {}
|
| 117 |
+
explicit RotationAcc(const Rotation& _R):R(_R),w(Vector::Zero()){}
|
| 118 |
+
RotationAcc(const Rotation& _R,const Vector& _w,const Vector& _dw):
|
| 119 |
+
R(_R),w(_w),dw(_dw) {}
|
| 120 |
+
IMETHOD RotationAcc& operator = (const RotationAcc& arg);
|
| 121 |
+
IMETHOD RotationAcc& operator = (const Rotation& arg);
|
| 122 |
+
IMETHOD static RotationAcc Identity();
|
| 123 |
+
IMETHOD RotationAcc Inverse() const;
|
| 124 |
+
IMETHOD VectorAcc Inverse(const VectorAcc& arg) const;
|
| 125 |
+
IMETHOD VectorAcc Inverse(const Vector& arg) const;
|
| 126 |
+
IMETHOD VectorAcc operator*(const VectorAcc& arg) const;
|
| 127 |
+
IMETHOD VectorAcc operator*(const Vector& arg) const;
|
| 128 |
+
|
| 129 |
+
// Rotations
|
| 130 |
+
// The SetRot.. functions set the value of *this to the appropriate rotation matrix.
|
| 131 |
+
// The Rot... static functions give the value of the appropriate rotation matrix back.
|
| 132 |
+
// The DoRot... functions apply a rotation R to *this,such that *this = *this * R.
|
| 133 |
+
// IMETHOD void DoRotX(const doubleAcc& angle);
|
| 134 |
+
// IMETHOD void DoRotY(const doubleAcc& angle);
|
| 135 |
+
// IMETHOD void DoRotZ(const doubleAcc& angle);
|
| 136 |
+
// IMETHOD static RRotation RotX(const doubleAcc& angle);
|
| 137 |
+
// IMETHOD static RRotation RotY(const doubleAcc& angle);
|
| 138 |
+
// IMETHOD static RRotation RotZ(const doubleAcc& angle);
|
| 139 |
+
|
| 140 |
+
// IMETHOD void SetRot(const Vector& rotaxis,const doubleAcc& angle);
|
| 141 |
+
// Along an arbitrary axes. The norm of rotvec is neglected.
|
| 142 |
+
// IMETHOD static RotationAcc Rot(const Vector& rotvec,const doubleAcc& angle);
|
| 143 |
+
// rotvec has arbitrary norm
|
| 144 |
+
// rotation around a constant vector !
|
| 145 |
+
// IMETHOD static RotationAcc Rot2(const Vector& rotvec,const doubleAcc& angle);
|
| 146 |
+
// rotvec is normalized.
|
| 147 |
+
// rotation around a constant vector !
|
| 148 |
+
|
| 149 |
+
IMETHOD friend RotationAcc operator* (const RotationAcc& r1,const RotationAcc& r2);
|
| 150 |
+
IMETHOD friend RotationAcc operator* (const Rotation& r1,const RotationAcc& r2);
|
| 151 |
+
IMETHOD friend RotationAcc operator* (const RotationAcc& r1,const Rotation& r2);
|
| 152 |
+
IMETHOD friend bool Equal(const RotationAcc& r1,const RotationAcc& r2,double eps);
|
| 153 |
+
IMETHOD friend bool Equal(const Rotation& r1,const RotationAcc& r2,double eps);
|
| 154 |
+
IMETHOD friend bool Equal(const RotationAcc& r1,const Rotation& r2,double eps);
|
| 155 |
+
IMETHOD TwistAcc Inverse(const TwistAcc& arg) const;
|
| 156 |
+
IMETHOD TwistAcc Inverse(const Twist& arg) const;
|
| 157 |
+
IMETHOD TwistAcc operator * (const TwistAcc& arg) const;
|
| 158 |
+
IMETHOD TwistAcc operator * (const Twist& arg) const;
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class FrameAcc
|
| 163 |
+
{
|
| 164 |
+
public:
|
| 165 |
+
RotationAcc M; //!< Rotation,angular velocity, and angular acceleration of frame.
|
| 166 |
+
VectorAcc p; //!< Translation, velocity and acceleration of origin.
|
| 167 |
+
public:
|
| 168 |
+
FrameAcc(){}
|
| 169 |
+
explicit FrameAcc(const Frame& _T):M(_T.M),p(_T.p) {}
|
| 170 |
+
FrameAcc(const Frame& _T,const Twist& _t,const Twist& _dt):
|
| 171 |
+
M(_T.M,_t.rot,_dt.rot),p(_T.p,_t.vel,_dt.vel) {}
|
| 172 |
+
FrameAcc(const RotationAcc& _M,const VectorAcc& _p):M(_M),p(_p) {}
|
| 173 |
+
|
| 174 |
+
IMETHOD FrameAcc& operator = (const FrameAcc& arg);
|
| 175 |
+
IMETHOD FrameAcc& operator = (const Frame& arg);
|
| 176 |
+
IMETHOD static FrameAcc Identity();
|
| 177 |
+
IMETHOD FrameAcc Inverse() const;
|
| 178 |
+
IMETHOD VectorAcc Inverse(const VectorAcc& arg) const;
|
| 179 |
+
IMETHOD VectorAcc operator*(const VectorAcc& arg) const;
|
| 180 |
+
IMETHOD VectorAcc operator*(const Vector& arg) const;
|
| 181 |
+
IMETHOD VectorAcc Inverse(const Vector& arg) const;
|
| 182 |
+
IMETHOD Frame GetFrame() const;
|
| 183 |
+
IMETHOD Twist GetTwist() const;
|
| 184 |
+
IMETHOD Twist GetAccTwist() const;
|
| 185 |
+
IMETHOD friend FrameAcc operator * (const FrameAcc& f1,const FrameAcc& f2);
|
| 186 |
+
IMETHOD friend FrameAcc operator * (const Frame& f1,const FrameAcc& f2);
|
| 187 |
+
IMETHOD friend FrameAcc operator * (const FrameAcc& f1,const Frame& f2);
|
| 188 |
+
IMETHOD friend bool Equal(const FrameAcc& r1,const FrameAcc& r2,double eps);
|
| 189 |
+
IMETHOD friend bool Equal(const Frame& r1,const FrameAcc& r2,double eps);
|
| 190 |
+
IMETHOD friend bool Equal(const FrameAcc& r1,const Frame& r2,double eps);
|
| 191 |
+
|
| 192 |
+
IMETHOD TwistAcc Inverse(const TwistAcc& arg) const;
|
| 193 |
+
IMETHOD TwistAcc Inverse(const Twist& arg) const;
|
| 194 |
+
IMETHOD TwistAcc operator * (const TwistAcc& arg) const;
|
| 195 |
+
IMETHOD TwistAcc operator * (const Twist& arg) const;
|
| 196 |
+
};
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
//very similar to Wrench class.
|
| 200 |
+
class TwistAcc
|
| 201 |
+
{
|
| 202 |
+
public:
|
| 203 |
+
VectorAcc vel; //!< translational velocity and its 1st and 2nd derivative
|
| 204 |
+
VectorAcc rot; //!< rotational velocity and its 1st and 2nd derivative
|
| 205 |
+
public:
|
| 206 |
+
|
| 207 |
+
TwistAcc():vel(),rot() {};
|
| 208 |
+
TwistAcc(const VectorAcc& _vel,const VectorAcc& _rot):vel(_vel),rot(_rot) {};
|
| 209 |
+
|
| 210 |
+
IMETHOD TwistAcc& operator-=(const TwistAcc& arg);
|
| 211 |
+
IMETHOD TwistAcc& operator+=(const TwistAcc& arg);
|
| 212 |
+
|
| 213 |
+
IMETHOD friend TwistAcc operator*(const TwistAcc& lhs,double rhs);
|
| 214 |
+
IMETHOD friend TwistAcc operator*(double lhs,const TwistAcc& rhs);
|
| 215 |
+
IMETHOD friend TwistAcc operator/(const TwistAcc& lhs,double rhs);
|
| 216 |
+
|
| 217 |
+
IMETHOD friend TwistAcc operator*(const TwistAcc& lhs,const doubleAcc& rhs);
|
| 218 |
+
IMETHOD friend TwistAcc operator*(const doubleAcc& lhs,const TwistAcc& rhs);
|
| 219 |
+
IMETHOD friend TwistAcc operator/(const TwistAcc& lhs,const doubleAcc& rhs);
|
| 220 |
+
|
| 221 |
+
IMETHOD friend TwistAcc operator+(const TwistAcc& lhs,const TwistAcc& rhs);
|
| 222 |
+
IMETHOD friend TwistAcc operator-(const TwistAcc& lhs,const TwistAcc& rhs);
|
| 223 |
+
IMETHOD friend TwistAcc operator-(const TwistAcc& arg);
|
| 224 |
+
|
| 225 |
+
IMETHOD friend void SetToZero(TwistAcc& v);
|
| 226 |
+
|
| 227 |
+
static IMETHOD TwistAcc Zero();
|
| 228 |
+
|
| 229 |
+
IMETHOD void ReverseSign();
|
| 230 |
+
|
| 231 |
+
IMETHOD TwistAcc RefPoint(const VectorAcc& v_base_AB);
|
| 232 |
+
// Changes the reference point of the RTwist.
|
| 233 |
+
// The RVector v_base_AB is expressed in the same base as the RTwist
|
| 234 |
+
// The RVector v_base_AB is a RVector from the old point to
|
| 235 |
+
// the new point.
|
| 236 |
+
// Complexity : 6M+6A
|
| 237 |
+
|
| 238 |
+
IMETHOD friend bool Equal(const TwistAcc& a,const TwistAcc& b,double eps);
|
| 239 |
+
IMETHOD friend bool Equal(const Twist& a,const TwistAcc& b,double eps);
|
| 240 |
+
IMETHOD friend bool Equal(const TwistAcc& a,const Twist& b,double eps);
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
IMETHOD Twist GetTwist() const;
|
| 244 |
+
IMETHOD Twist GetTwistDot() const;
|
| 245 |
+
|
| 246 |
+
friend class RotationAcc;
|
| 247 |
+
friend class FrameAcc;
|
| 248 |
+
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
#ifdef KDL_INLINE
|
| 252 |
+
#include "frameacc.inl"
|
| 253 |
+
#endif
|
| 254 |
+
|
| 255 |
+
} // namespace KDL
|
| 256 |
+
|
| 257 |
+
template<> struct std::hash<KDL::doubleAcc>
|
| 258 |
+
{
|
| 259 |
+
std::size_t operator()(KDL::doubleAcc const& da) const noexcept
|
| 260 |
+
{
|
| 261 |
+
size_t seed = 0;
|
| 262 |
+
KDL::hash_combine(seed, da.t);
|
| 263 |
+
KDL::hash_combine(seed, da.d);
|
| 264 |
+
KDL::hash_combine(seed, da.dd);
|
| 265 |
+
return seed;
|
| 266 |
+
}
|
| 267 |
+
};
|
| 268 |
+
|
| 269 |
+
template<> struct std::hash<KDL::VectorAcc>
|
| 270 |
+
{
|
| 271 |
+
std::size_t operator()(KDL::VectorAcc const& va) const noexcept
|
| 272 |
+
{
|
| 273 |
+
size_t seed = 0;
|
| 274 |
+
KDL::hash_combine(seed, va.p);
|
| 275 |
+
KDL::hash_combine(seed, va.v);
|
| 276 |
+
KDL::hash_combine(seed, va.dv);
|
| 277 |
+
return seed;
|
| 278 |
+
}
|
| 279 |
+
};
|
| 280 |
+
|
| 281 |
+
template<> struct std::hash<KDL::RotationAcc>
|
| 282 |
+
{
|
| 283 |
+
std::size_t operator()(KDL::RotationAcc const& ra) const noexcept
|
| 284 |
+
{
|
| 285 |
+
size_t seed = 0;
|
| 286 |
+
KDL::hash_combine(seed, ra.R);
|
| 287 |
+
KDL::hash_combine(seed, ra.w);
|
| 288 |
+
KDL::hash_combine(seed, ra.dw);
|
| 289 |
+
return seed;
|
| 290 |
+
}
|
| 291 |
+
};
|
| 292 |
+
|
| 293 |
+
template<> struct std::hash<KDL::FrameAcc>
|
| 294 |
+
{
|
| 295 |
+
std::size_t operator()(KDL::FrameAcc const& fa) const noexcept
|
| 296 |
+
{
|
| 297 |
+
size_t seed = 0;
|
| 298 |
+
KDL::hash_combine(seed, fa.M);
|
| 299 |
+
KDL::hash_combine(seed, fa.p);
|
| 300 |
+
return seed;
|
| 301 |
+
}
|
| 302 |
+
};
|
| 303 |
+
|
| 304 |
+
template<> struct std::hash<KDL::TwistAcc>
|
| 305 |
+
{
|
| 306 |
+
std::size_t operator()(KDL::TwistAcc const& ta) const noexcept
|
| 307 |
+
{
|
| 308 |
+
size_t seed = 0;
|
| 309 |
+
KDL::hash_combine(seed, ta.vel);
|
| 310 |
+
KDL::hash_combine(seed, ta.rot);
|
| 311 |
+
return seed;
|
| 312 |
+
}
|
| 313 |
+
};
|
| 314 |
+
|
| 315 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc.inl
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \file
|
| 3 |
+
* provides inline functions of rrframes.h
|
| 4 |
+
*
|
| 5 |
+
* \author
|
| 6 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 7 |
+
*
|
| 8 |
+
* \version
|
| 9 |
+
* ORO_Geometry V0.2
|
| 10 |
+
*
|
| 11 |
+
* \par History
|
| 12 |
+
* - $log$
|
| 13 |
+
*
|
| 14 |
+
* \par Release
|
| 15 |
+
* $Id: rrframes.inl,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 16 |
+
* $Name: $
|
| 17 |
+
****************************************************************************/
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
/////////////////// VectorAcc /////////////////////////////////////
|
| 23 |
+
|
| 24 |
+
VectorAcc operator + (const VectorAcc& r1,const VectorAcc& r2) {
|
| 25 |
+
return VectorAcc(r1.p+r2.p,r1.v+r2.v,r1.dv+r2.dv);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
VectorAcc operator - (const VectorAcc& r1,const VectorAcc& r2) {
|
| 29 |
+
return VectorAcc(r1.p-r2.p, r1.v-r2.v, r1.dv-r2.dv);
|
| 30 |
+
}
|
| 31 |
+
VectorAcc operator + (const Vector& r1,const VectorAcc& r2) {
|
| 32 |
+
return VectorAcc(r1+r2.p,r2.v,r2.dv);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
VectorAcc operator - (const Vector& r1,const VectorAcc& r2) {
|
| 36 |
+
return VectorAcc(r1-r2.p, -r2.v, -r2.dv);
|
| 37 |
+
}
|
| 38 |
+
VectorAcc operator + (const VectorAcc& r1,const Vector& r2) {
|
| 39 |
+
return VectorAcc(r1.p+r2,r1.v,r1.dv);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
VectorAcc operator - (const VectorAcc& r1,const Vector& r2) {
|
| 43 |
+
return VectorAcc(r1.p-r2, r1.v, r1.dv);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// unary -
|
| 47 |
+
VectorAcc operator - (const VectorAcc& r) {
|
| 48 |
+
return VectorAcc(-r.p,-r.v,-r.dv);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// cross prod.
|
| 52 |
+
VectorAcc operator * (const VectorAcc& r1,const VectorAcc& r2) {
|
| 53 |
+
return VectorAcc(r1.p*r2.p,
|
| 54 |
+
r1.p*r2.v+r1.v*r2.p,
|
| 55 |
+
r1.dv*r2.p+2*r1.v*r2.v+r1.p*r2.dv
|
| 56 |
+
);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
VectorAcc operator * (const VectorAcc& r1,const Vector& r2) {
|
| 60 |
+
return VectorAcc(r1.p*r2, r1.v*r2, r1.dv*r2 );
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
VectorAcc operator * (const Vector& r1,const VectorAcc& r2) {
|
| 64 |
+
return VectorAcc(r1*r2.p, r1*r2.v, r1*r2.dv );
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
// scalar mult.
|
| 70 |
+
VectorAcc operator * (double r1,const VectorAcc& r2) {
|
| 71 |
+
return VectorAcc(r1*r2.p, r1*r2.v, r1*r2.dv );
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
VectorAcc operator * (const VectorAcc& r1,double r2) {
|
| 75 |
+
return VectorAcc(r1.p*r2, r1.v*r2, r1.dv*r2 );
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
VectorAcc operator * (const doubleAcc& r1,const VectorAcc& r2) {
|
| 79 |
+
return VectorAcc(r1.t*r2.p,
|
| 80 |
+
r1.t*r2.v + r1.d*r2.p,
|
| 81 |
+
r1.t*r2.dv + 2*r1.d*r2.v + r1.dd*r2.p
|
| 82 |
+
);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
VectorAcc operator * (const VectorAcc& r2,const doubleAcc& r1) {
|
| 86 |
+
return VectorAcc(r1.t*r2.p,
|
| 87 |
+
r1.t*r2.v + r1.d*r2.p,
|
| 88 |
+
r1.t*r2.dv + 2*r1.d*r2.v + r1.dd*r2.p
|
| 89 |
+
);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
VectorAcc& VectorAcc::operator = (const VectorAcc& arg) {
|
| 93 |
+
p=arg.p;
|
| 94 |
+
v=arg.v;
|
| 95 |
+
dv=arg.dv;
|
| 96 |
+
return *this;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
VectorAcc& VectorAcc::operator = (const Vector& arg) {
|
| 100 |
+
p=arg;
|
| 101 |
+
v=Vector::Zero();
|
| 102 |
+
dv=Vector::Zero();
|
| 103 |
+
return *this;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
VectorAcc& VectorAcc::operator += (const VectorAcc& arg) {
|
| 107 |
+
p+=arg.p;
|
| 108 |
+
v+=arg.v;
|
| 109 |
+
dv+= arg.dv;
|
| 110 |
+
return *this;
|
| 111 |
+
}
|
| 112 |
+
VectorAcc& VectorAcc::operator -= (const VectorAcc& arg) {
|
| 113 |
+
p-=arg.p;
|
| 114 |
+
v-=arg.v;
|
| 115 |
+
dv-=arg.dv;
|
| 116 |
+
return *this;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
VectorAcc VectorAcc::Zero() {
|
| 120 |
+
return VectorAcc(Vector::Zero(),Vector::Zero(),Vector::Zero());
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void VectorAcc::ReverseSign() {
|
| 124 |
+
p.ReverseSign();
|
| 125 |
+
v.ReverseSign();
|
| 126 |
+
dv.ReverseSign();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
doubleAcc VectorAcc::Norm(double eps) {
|
| 130 |
+
doubleAcc res;
|
| 131 |
+
res.t = p.Norm(eps);
|
| 132 |
+
res.d = dot(p,v)/res.t;
|
| 133 |
+
res.dd = (dot(p,dv)+dot(v,v)-res.d*res.d)/res.t;
|
| 134 |
+
return res;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
doubleAcc dot(const VectorAcc& lhs,const VectorAcc& rhs) {
|
| 138 |
+
return doubleAcc( dot(lhs.p,rhs.p),
|
| 139 |
+
dot(lhs.p,rhs.v)+dot(lhs.v,rhs.p),
|
| 140 |
+
dot(lhs.p,rhs.dv)+2*dot(lhs.v,rhs.v)+dot(lhs.dv,rhs.p)
|
| 141 |
+
);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
doubleAcc dot(const VectorAcc& lhs,const Vector& rhs) {
|
| 145 |
+
return doubleAcc( dot(lhs.p,rhs),
|
| 146 |
+
dot(lhs.v,rhs),
|
| 147 |
+
dot(lhs.dv,rhs)
|
| 148 |
+
);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
doubleAcc dot(const Vector& lhs,const VectorAcc& rhs) {
|
| 152 |
+
return doubleAcc( dot(lhs,rhs.p),
|
| 153 |
+
dot(lhs,rhs.v),
|
| 154 |
+
dot(lhs,rhs.dv)
|
| 155 |
+
);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
bool Equal(const VectorAcc& r1,const VectorAcc& r2,double eps) {
|
| 160 |
+
return (Equal(r1.p,r2.p,eps)
|
| 161 |
+
&& Equal(r1.v,r2.v,eps)
|
| 162 |
+
&& Equal(r1.dv,r2.dv,eps)
|
| 163 |
+
);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
bool Equal(const Vector& r1,const VectorAcc& r2,double eps) {
|
| 167 |
+
return (Equal(r1,r2.p,eps)
|
| 168 |
+
&& Equal(Vector::Zero(),r2.v,eps)
|
| 169 |
+
&& Equal(Vector::Zero(),r2.dv,eps)
|
| 170 |
+
);
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
bool Equal(const VectorAcc& r1,const Vector& r2,double eps) {
|
| 174 |
+
return (Equal(r1.p,r2,eps)
|
| 175 |
+
&& Equal(r1.v,Vector::Zero(),eps)
|
| 176 |
+
&& Equal(r1.dv,Vector::Zero(),eps)
|
| 177 |
+
);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
VectorAcc operator / (const VectorAcc& r1,double r2) {
|
| 181 |
+
return r1*(1.0/r2);
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
VectorAcc operator / (const VectorAcc& r2,const doubleAcc& r1) {
|
| 185 |
+
return r2*(1.0/r1);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
/////////////////// RotationAcc /////////////////////////////////////
|
| 191 |
+
|
| 192 |
+
RotationAcc operator* (const RotationAcc& r1,const RotationAcc& r2) {
|
| 193 |
+
return RotationAcc( r1.R * r2.R,
|
| 194 |
+
r1.w + r1.R*r2.w,
|
| 195 |
+
r1.dw + r1.w*(r1.R*r2.w) + r1.R*r2.dw
|
| 196 |
+
);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
RotationAcc operator* (const Rotation& r1,const RotationAcc& r2) {
|
| 200 |
+
return RotationAcc( r1*r2.R, r1*r2.w, r1*r2.dw);
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
RotationAcc operator* (const RotationAcc& r1,const Rotation& r2) {
|
| 204 |
+
return RotationAcc( r1.R*r2, r1.w, r1.dw );
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
RotationAcc& RotationAcc::operator = (const RotationAcc& arg) {
|
| 208 |
+
R=arg.R;
|
| 209 |
+
w=arg.w;
|
| 210 |
+
dw=arg.dw;
|
| 211 |
+
return *this;
|
| 212 |
+
}
|
| 213 |
+
RotationAcc& RotationAcc::operator = (const Rotation& arg) {
|
| 214 |
+
R = arg;
|
| 215 |
+
w = Vector::Zero();
|
| 216 |
+
dw = Vector::Zero();
|
| 217 |
+
return *this;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
RotationAcc RotationAcc::Identity() {
|
| 221 |
+
return RotationAcc(Rotation::Identity(),Vector::Zero(),Vector::Zero());
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
RotationAcc RotationAcc::Inverse() const {
|
| 225 |
+
return RotationAcc(R.Inverse(),-R.Inverse(w),-R.Inverse(dw));
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
VectorAcc RotationAcc::Inverse(const VectorAcc& arg) const {
|
| 229 |
+
VectorAcc tmp;
|
| 230 |
+
tmp.p = R.Inverse(arg.p);
|
| 231 |
+
tmp.v = R.Inverse(arg.v - w * arg.p);
|
| 232 |
+
tmp.dv = R.Inverse(arg.dv - dw*arg.p - w*(arg.v+R*tmp.v));
|
| 233 |
+
return tmp;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
VectorAcc RotationAcc::Inverse(const Vector& arg) const {
|
| 237 |
+
VectorAcc tmp;
|
| 238 |
+
tmp.p = R.Inverse(arg);
|
| 239 |
+
tmp.v = R.Inverse(-w*arg);
|
| 240 |
+
tmp.dv = R.Inverse(-dw*arg - w*(R*tmp.v));
|
| 241 |
+
return tmp;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
VectorAcc RotationAcc::operator*(const VectorAcc& arg) const {
|
| 246 |
+
VectorAcc tmp;
|
| 247 |
+
tmp.p = R*arg.p;
|
| 248 |
+
tmp.dv = R*arg.v;
|
| 249 |
+
tmp.v = w*tmp.p + tmp.dv;
|
| 250 |
+
tmp.dv = dw*tmp.p + w*(tmp.v + tmp.dv) + R*arg.dv;
|
| 251 |
+
return tmp;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
VectorAcc operator*(const Rotation& R,const VectorAcc& x) {
|
| 255 |
+
return VectorAcc(R*x.p,R*x.v,R*x.dv);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
VectorAcc RotationAcc::operator*(const Vector& arg) const {
|
| 259 |
+
VectorAcc tmp;
|
| 260 |
+
tmp.p = R*arg;
|
| 261 |
+
tmp.v = w*tmp.p;
|
| 262 |
+
tmp.dv = dw*tmp.p + w*tmp.v;
|
| 263 |
+
return tmp;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/*
|
| 267 |
+
// = Rotations
|
| 268 |
+
// The Rot... static functions give the value of the appropriate rotation matrix back.
|
| 269 |
+
// The DoRot... functions apply a rotation R to *this,such that *this = *this * R.
|
| 270 |
+
|
| 271 |
+
void RRotation::DoRotX(const RDouble& angle) {
|
| 272 |
+
w+=R*Vector(angle.grad,0,0);
|
| 273 |
+
R.DoRotX(angle.t);
|
| 274 |
+
}
|
| 275 |
+
RotationAcc RotationAcc::RotX(const doubleAcc& angle) {
|
| 276 |
+
return RotationAcc(Rotation::RotX(angle.t),
|
| 277 |
+
Vector(angle.d,0,0),
|
| 278 |
+
Vector(angle.dd,0,0)
|
| 279 |
+
);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
void RRotation::DoRotY(const RDouble& angle) {
|
| 283 |
+
w+=R*Vector(0,angle.grad,0);
|
| 284 |
+
R.DoRotY(angle.t);
|
| 285 |
+
}
|
| 286 |
+
RotationAcc RotationAcc::RotY(const doubleAcc& angle) {
|
| 287 |
+
return RotationAcc(
|
| 288 |
+
Rotation::RotX(angle.t),
|
| 289 |
+
Vector(0,angle.d,0),
|
| 290 |
+
Vector(0,angle.dd,0)
|
| 291 |
+
);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
void RRotation::DoRotZ(const RDouble& angle) {
|
| 295 |
+
w+=R*Vector(0,0,angle.grad);
|
| 296 |
+
R.DoRotZ(angle.t);
|
| 297 |
+
}
|
| 298 |
+
RotationAcc RotationAcc::RotZ(const doubleAcc& angle) {
|
| 299 |
+
return RotationAcc(
|
| 300 |
+
Rotation::RotZ(angle.t),
|
| 301 |
+
Vector(0,0,angle.d),
|
| 302 |
+
Vector(0,0,angle.dd)
|
| 303 |
+
);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
RRotation RRotation::Rot(const Vector& rotvec,const RDouble& angle)
|
| 308 |
+
// rotvec has arbitrary norm
|
| 309 |
+
// rotation around a constant vector !
|
| 310 |
+
{
|
| 311 |
+
Vector v = rotvec.Normalize();
|
| 312 |
+
return RRotation(Rotation::Rot2(v,angle.t),v*angle.grad);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
RRotation RRotation::Rot2(const Vector& rotvec,const RDouble& angle)
|
| 316 |
+
// rotvec is normalized.
|
| 317 |
+
{
|
| 318 |
+
return RRotation(Rotation::Rot2(rotvec,angle.t),rotvec*angle.grad);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
*/
|
| 322 |
+
|
| 323 |
+
bool Equal(const RotationAcc& r1,const RotationAcc& r2,double eps) {
|
| 324 |
+
return (Equal(r1.w,r2.w,eps) && Equal(r1.R,r2.R,eps) && Equal(r1.dw,r2.dw,eps) );
|
| 325 |
+
}
|
| 326 |
+
bool Equal(const Rotation& r1,const RotationAcc& r2,double eps) {
|
| 327 |
+
return (Equal(Vector::Zero(),r2.w,eps) && Equal(r1,r2.R,eps) &&
|
| 328 |
+
Equal(Vector::Zero(),r2.dw,eps) );
|
| 329 |
+
}
|
| 330 |
+
bool Equal(const RotationAcc& r1,const Rotation& r2,double eps) {
|
| 331 |
+
return (Equal(r1.w,Vector::Zero(),eps) && Equal(r1.R,r2,eps) &&
|
| 332 |
+
Equal(r1.dw,Vector::Zero(),eps) );
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
// Methods and operators related to FrameAcc
|
| 337 |
+
// They all delegate most of the work to RotationAcc and VectorAcc
|
| 338 |
+
FrameAcc& FrameAcc::operator = (const FrameAcc& arg) {
|
| 339 |
+
M=arg.M;
|
| 340 |
+
p=arg.p;
|
| 341 |
+
return *this;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
FrameAcc FrameAcc::Identity() {
|
| 345 |
+
return FrameAcc(RotationAcc::Identity(),VectorAcc::Zero());
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
FrameAcc operator *(const FrameAcc& lhs,const FrameAcc& rhs)
|
| 350 |
+
{
|
| 351 |
+
return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 352 |
+
}
|
| 353 |
+
FrameAcc operator *(const FrameAcc& lhs,const Frame& rhs)
|
| 354 |
+
{
|
| 355 |
+
return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 356 |
+
}
|
| 357 |
+
FrameAcc operator *(const Frame& lhs,const FrameAcc& rhs)
|
| 358 |
+
{
|
| 359 |
+
return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
VectorAcc FrameAcc::operator *(const VectorAcc & arg) const
|
| 363 |
+
{
|
| 364 |
+
return M*arg+p;
|
| 365 |
+
}
|
| 366 |
+
VectorAcc FrameAcc::operator *(const Vector & arg) const
|
| 367 |
+
{
|
| 368 |
+
return M*arg+p;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
VectorAcc FrameAcc::Inverse(const VectorAcc& arg) const
|
| 372 |
+
{
|
| 373 |
+
return M.Inverse(arg-p);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
VectorAcc FrameAcc::Inverse(const Vector& arg) const
|
| 377 |
+
{
|
| 378 |
+
return M.Inverse(arg-p);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
FrameAcc FrameAcc::Inverse() const
|
| 382 |
+
{
|
| 383 |
+
return FrameAcc(M.Inverse(),-M.Inverse(p));
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
FrameAcc& FrameAcc::operator =(const Frame & arg)
|
| 387 |
+
{
|
| 388 |
+
M = arg.M;
|
| 389 |
+
p = arg.p;
|
| 390 |
+
return *this;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
bool Equal(const FrameAcc& r1,const FrameAcc& r2,double eps) {
|
| 394 |
+
return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
|
| 395 |
+
}
|
| 396 |
+
bool Equal(const Frame& r1,const FrameAcc& r2,double eps) {
|
| 397 |
+
return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
|
| 398 |
+
}
|
| 399 |
+
bool Equal(const FrameAcc& r1,const Frame& r2,double eps) {
|
| 400 |
+
return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
Frame FrameAcc::GetFrame() const {
|
| 405 |
+
return Frame(M.R,p.p);
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
Twist FrameAcc::GetTwist() const {
|
| 410 |
+
return Twist(p.v,M.w);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
Twist FrameAcc::GetAccTwist() const {
|
| 415 |
+
return Twist(p.dv,M.dw);
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
TwistAcc TwistAcc::Zero()
|
| 435 |
+
{
|
| 436 |
+
return TwistAcc(VectorAcc::Zero(),VectorAcc::Zero());
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
void TwistAcc::ReverseSign()
|
| 441 |
+
{
|
| 442 |
+
vel.ReverseSign();
|
| 443 |
+
rot.ReverseSign();
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
TwistAcc TwistAcc::RefPoint(const VectorAcc& v_base_AB)
|
| 447 |
+
// Changes the reference point of the TwistAcc.
|
| 448 |
+
// The RVector v_base_AB is expressed in the same base as the TwistAcc
|
| 449 |
+
// The RVector v_base_AB is a RVector from the old point to
|
| 450 |
+
// the new point.
|
| 451 |
+
// Complexity : 6M+6A
|
| 452 |
+
{
|
| 453 |
+
return TwistAcc(this->vel+this->rot*v_base_AB,this->rot);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
TwistAcc& TwistAcc::operator-=(const TwistAcc& arg)
|
| 457 |
+
{
|
| 458 |
+
vel-=arg.vel;
|
| 459 |
+
rot -=arg.rot;
|
| 460 |
+
return *this;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
TwistAcc& TwistAcc::operator+=(const TwistAcc& arg)
|
| 464 |
+
{
|
| 465 |
+
vel+=arg.vel;
|
| 466 |
+
rot +=arg.rot;
|
| 467 |
+
return *this;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
TwistAcc operator*(const TwistAcc& lhs,double rhs)
|
| 472 |
+
{
|
| 473 |
+
return TwistAcc(lhs.vel*rhs,lhs.rot*rhs);
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
TwistAcc operator*(double lhs,const TwistAcc& rhs)
|
| 477 |
+
{
|
| 478 |
+
return TwistAcc(lhs*rhs.vel,lhs*rhs.rot);
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
TwistAcc operator/(const TwistAcc& lhs,double rhs)
|
| 482 |
+
{
|
| 483 |
+
return TwistAcc(lhs.vel/rhs,lhs.rot/rhs);
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
TwistAcc operator*(const TwistAcc& lhs,const doubleAcc& rhs)
|
| 488 |
+
{
|
| 489 |
+
return TwistAcc(lhs.vel*rhs,lhs.rot*rhs);
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
TwistAcc operator*(const doubleAcc& lhs,const TwistAcc& rhs)
|
| 493 |
+
{
|
| 494 |
+
return TwistAcc(lhs*rhs.vel,lhs*rhs.rot);
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
TwistAcc operator/(const TwistAcc& lhs,const doubleAcc& rhs)
|
| 498 |
+
{
|
| 499 |
+
return TwistAcc(lhs.vel/rhs,lhs.rot/rhs);
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
// addition of TwistAcc's
|
| 505 |
+
TwistAcc operator+(const TwistAcc& lhs,const TwistAcc& rhs)
|
| 506 |
+
{
|
| 507 |
+
return TwistAcc(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
TwistAcc operator-(const TwistAcc& lhs,const TwistAcc& rhs)
|
| 511 |
+
{
|
| 512 |
+
return TwistAcc(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
// unary -
|
| 516 |
+
TwistAcc operator-(const TwistAcc& arg)
|
| 517 |
+
{
|
| 518 |
+
return TwistAcc(-arg.vel,-arg.rot);
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
TwistAcc RotationAcc::Inverse(const TwistAcc& arg) const
|
| 526 |
+
{
|
| 527 |
+
return TwistAcc(Inverse(arg.vel),Inverse(arg.rot));
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
TwistAcc RotationAcc::operator * (const TwistAcc& arg) const
|
| 531 |
+
{
|
| 532 |
+
return TwistAcc((*this)*arg.vel,(*this)*arg.rot);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
TwistAcc RotationAcc::Inverse(const Twist& arg) const
|
| 536 |
+
{
|
| 537 |
+
return TwistAcc(Inverse(arg.vel),Inverse(arg.rot));
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
TwistAcc RotationAcc::operator * (const Twist& arg) const
|
| 541 |
+
{
|
| 542 |
+
return TwistAcc((*this)*arg.vel,(*this)*arg.rot);
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
TwistAcc FrameAcc::operator * (const TwistAcc& arg) const
|
| 547 |
+
{
|
| 548 |
+
TwistAcc tmp;
|
| 549 |
+
tmp.rot = M*arg.rot;
|
| 550 |
+
tmp.vel = M*arg.vel+p*tmp.rot;
|
| 551 |
+
return tmp;
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
TwistAcc FrameAcc::operator * (const Twist& arg) const
|
| 555 |
+
{
|
| 556 |
+
TwistAcc tmp;
|
| 557 |
+
tmp.rot = M*arg.rot;
|
| 558 |
+
tmp.vel = M*arg.vel+p*tmp.rot;
|
| 559 |
+
return tmp;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
TwistAcc FrameAcc::Inverse(const TwistAcc& arg) const
|
| 563 |
+
{
|
| 564 |
+
TwistAcc tmp;
|
| 565 |
+
tmp.rot = M.Inverse(arg.rot);
|
| 566 |
+
tmp.vel = M.Inverse(arg.vel-p*arg.rot);
|
| 567 |
+
return tmp;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
TwistAcc FrameAcc::Inverse(const Twist& arg) const
|
| 571 |
+
{
|
| 572 |
+
TwistAcc tmp;
|
| 573 |
+
tmp.rot = M.Inverse(arg.rot);
|
| 574 |
+
tmp.vel = M.Inverse(arg.vel-p*arg.rot);
|
| 575 |
+
return tmp;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
Twist TwistAcc::GetTwist() const {
|
| 579 |
+
return Twist(vel.p,rot.p);
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
Twist TwistAcc::GetTwistDot() const {
|
| 583 |
+
return Twist(vel.v,rot.v);
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
bool Equal(const TwistAcc& a,const TwistAcc& b,double eps) {
|
| 587 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 588 |
+
Equal(a.vel,b.vel,eps) );
|
| 589 |
+
}
|
| 590 |
+
bool Equal(const Twist& a,const TwistAcc& b,double eps) {
|
| 591 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 592 |
+
Equal(a.vel,b.vel,eps) );
|
| 593 |
+
}
|
| 594 |
+
bool Equal(const TwistAcc& a,const Twist& b,double eps) {
|
| 595 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 596 |
+
Equal(a.vel,b.vel,eps) );
|
| 597 |
+
}
|
| 598 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frameacc_io.hpp
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \file
|
| 3 |
+
* Defines I/O related routines to the FrameAccs classes defined in
|
| 4 |
+
* FrameAccs.h
|
| 5 |
+
*
|
| 6 |
+
* \author
|
| 7 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 8 |
+
*
|
| 9 |
+
* \version
|
| 10 |
+
* ORO_Geometry V0.2
|
| 11 |
+
*
|
| 12 |
+
* \par History
|
| 13 |
+
* - $log$
|
| 14 |
+
*
|
| 15 |
+
* \par Release
|
| 16 |
+
* $Id: rrframes_io.h,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 17 |
+
* $Name: $
|
| 18 |
+
****************************************************************************/
|
| 19 |
+
#ifndef RRFRAMES_IO
|
| 20 |
+
#define RRFRAMES_IO
|
| 21 |
+
|
| 22 |
+
#include "utilities/utility_io.h"
|
| 23 |
+
#include "utilities/rall2d_io.h"
|
| 24 |
+
|
| 25 |
+
#include "frames_io.hpp"
|
| 26 |
+
#include "frameacc.hpp"
|
| 27 |
+
|
| 28 |
+
namespace KDL {
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
// Output...
|
| 32 |
+
inline std::ostream& operator << (std::ostream& os,const VectorAcc& r) {
|
| 33 |
+
os << "{" << r.p << "," << r.v << "," << r.dv << "}" << std::endl;
|
| 34 |
+
return os;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
inline std::ostream& operator << (std::ostream& os,const RotationAcc& r) {
|
| 38 |
+
os << "{" << std::endl << r.R << "," << std::endl << r.w <<
|
| 39 |
+
"," << std::endl << r.dw << std::endl << "}" << std::endl;
|
| 40 |
+
return os;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
inline std::ostream& operator << (std::ostream& os,const FrameAcc& r) {
|
| 45 |
+
os << "{" << std::endl << r.M << "," << std::endl << r.p << "}" << std::endl;
|
| 46 |
+
return os;
|
| 47 |
+
}
|
| 48 |
+
inline std::ostream& operator << (std::ostream& os,const TwistAcc& r) {
|
| 49 |
+
os << "{" << std::endl << r.vel << "," << std::endl << r.rot << std::endl << "}" << std::endl;
|
| 50 |
+
return os;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
} // namespace Frame
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames.cpp
ADDED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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
frames.cxx - description
|
| 3 |
+
-------------------------
|
| 4 |
+
begin : June 2006
|
| 5 |
+
copyright : (C) 2006 Erwin Aertbelien
|
| 6 |
+
email : firstname.lastname@mech.kuleuven.ac.be
|
| 7 |
+
|
| 8 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 9 |
+
|
| 10 |
+
***************************************************************************
|
| 11 |
+
* This library is free software; you can redistribute it and/or *
|
| 12 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 13 |
+
* License as published by the Free Software Foundation; either *
|
| 14 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 15 |
+
* *
|
| 16 |
+
* This library is distributed in the hope that it will be useful, *
|
| 17 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 18 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 19 |
+
* Lesser General Public License for more details. *
|
| 20 |
+
* *
|
| 21 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 22 |
+
* License along with this library; if not, write to the Free Software *
|
| 23 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 24 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 25 |
+
* *
|
| 26 |
+
***************************************************************************/
|
| 27 |
+
|
| 28 |
+
#include "frames.hpp"
|
| 29 |
+
#include "utilities/utility.h"
|
| 30 |
+
|
| 31 |
+
#include <algorithm>
|
| 32 |
+
|
| 33 |
+
namespace KDL {
|
| 34 |
+
|
| 35 |
+
#ifndef KDL_INLINE
|
| 36 |
+
#include "frames.inl"
|
| 37 |
+
#endif
|
| 38 |
+
|
| 39 |
+
void Frame::Make4x4(double * d)
|
| 40 |
+
{
|
| 41 |
+
int i;
|
| 42 |
+
int j;
|
| 43 |
+
for (i=0;i<3;i++) {
|
| 44 |
+
for (j=0;j<3;j++)
|
| 45 |
+
d[i*4+j]=M(i,j);
|
| 46 |
+
d[i*4+3] = p(i);
|
| 47 |
+
}
|
| 48 |
+
for (j=0;j<3;j++)
|
| 49 |
+
d[12+j] = 0.;
|
| 50 |
+
d[15] = 1;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
Frame Frame::DH_Craig1989(double a,double alpha,double d,double theta)
|
| 54 |
+
// returns Modified Denavit-Hartenberg parameters (According to Craig)
|
| 55 |
+
{
|
| 56 |
+
double ct,st,ca,sa;
|
| 57 |
+
ct = cos(theta);
|
| 58 |
+
st = sin(theta);
|
| 59 |
+
sa = sin(alpha);
|
| 60 |
+
ca = cos(alpha);
|
| 61 |
+
return Frame(Rotation(
|
| 62 |
+
ct, -st, 0,
|
| 63 |
+
st*ca, ct*ca, -sa,
|
| 64 |
+
st*sa, ct*sa, ca ),
|
| 65 |
+
Vector(
|
| 66 |
+
a, -sa*d, ca*d )
|
| 67 |
+
);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
Frame Frame::DH(double a,double alpha,double d,double theta)
|
| 71 |
+
// returns Denavit-Hartenberg parameters (Non-Modified DH)
|
| 72 |
+
{
|
| 73 |
+
double ct,st,ca,sa;
|
| 74 |
+
ct = cos(theta);
|
| 75 |
+
st = sin(theta);
|
| 76 |
+
sa = sin(alpha);
|
| 77 |
+
ca = cos(alpha);
|
| 78 |
+
return Frame(Rotation(
|
| 79 |
+
ct, -st*ca, st*sa,
|
| 80 |
+
st, ct*ca, -ct*sa,
|
| 81 |
+
0, sa, ca ),
|
| 82 |
+
Vector(
|
| 83 |
+
a*ct, a*st, d )
|
| 84 |
+
);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
double Vector2::Norm(double eps) const
|
| 88 |
+
{
|
| 89 |
+
double tmp1 = fabs(data[0]);
|
| 90 |
+
double tmp2 = fabs(data[1]);
|
| 91 |
+
|
| 92 |
+
if (tmp1 < eps && tmp2 < eps)
|
| 93 |
+
return 0;
|
| 94 |
+
|
| 95 |
+
if (tmp1 > tmp2) {
|
| 96 |
+
return tmp1*sqrt(1+sqr(data[1]/data[0]));
|
| 97 |
+
} else {
|
| 98 |
+
return tmp2*sqrt(1+sqr(data[0]/data[1]));
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
// makes v a unitvector and returns the norm of v.
|
| 102 |
+
// if v is smaller than eps, Vector(1,0) is returned with norm 0.
|
| 103 |
+
// if this is not good, check the return value of this method.
|
| 104 |
+
double Vector2::Normalize(double eps) {
|
| 105 |
+
double v = this->Norm();
|
| 106 |
+
if (v < eps) {
|
| 107 |
+
*this = Vector2(1,0);
|
| 108 |
+
return 0;
|
| 109 |
+
} else {
|
| 110 |
+
*this = (*this)/v;
|
| 111 |
+
return v;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
// do some effort not to lose precision
|
| 117 |
+
double Vector::Norm(double eps) const
|
| 118 |
+
{
|
| 119 |
+
double tmp1;
|
| 120 |
+
double tmp2;
|
| 121 |
+
tmp1 = fabs(data[0]);
|
| 122 |
+
tmp2 = fabs(data[1]);
|
| 123 |
+
if (tmp1 >= tmp2) {
|
| 124 |
+
tmp2=fabs(data[2]);
|
| 125 |
+
if (tmp1 >= tmp2) {
|
| 126 |
+
if (tmp1 < eps) {
|
| 127 |
+
// only to everything exactly zero case, all other are handled correctly
|
| 128 |
+
return 0;
|
| 129 |
+
}
|
| 130 |
+
return tmp1*sqrt(1+sqr(data[1]/data[0])+sqr(data[2]/data[0]));
|
| 131 |
+
} else {
|
| 132 |
+
return tmp2*sqrt(1+sqr(data[0]/data[2])+sqr(data[1]/data[2]));
|
| 133 |
+
}
|
| 134 |
+
} else {
|
| 135 |
+
tmp1=fabs(data[2]);
|
| 136 |
+
if (tmp2 > tmp1) {
|
| 137 |
+
return tmp2*sqrt(1+sqr(data[0]/data[1])+sqr(data[2]/data[1]));
|
| 138 |
+
} else {
|
| 139 |
+
return tmp1*sqrt(1+sqr(data[0]/data[2])+sqr(data[1]/data[2]));
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// makes v a unitvector and returns the norm of v.
|
| 145 |
+
// if v is smaller than eps, Vector(1,0,0) is returned with norm 0.
|
| 146 |
+
// if this is not good, check the return value of this method.
|
| 147 |
+
double Vector::Normalize(double eps) {
|
| 148 |
+
double v = this->Norm();
|
| 149 |
+
if (v < eps) {
|
| 150 |
+
*this = Vector(1,0,0);
|
| 151 |
+
return 0;
|
| 152 |
+
} else {
|
| 153 |
+
*this = (*this)/v;
|
| 154 |
+
return v;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
bool Equal(const Rotation& a,const Rotation& b,double eps) {
|
| 160 |
+
return (Equal(a.data[0],b.data[0],eps) &&
|
| 161 |
+
Equal(a.data[1],b.data[1],eps) &&
|
| 162 |
+
Equal(a.data[2],b.data[2],eps) &&
|
| 163 |
+
Equal(a.data[3],b.data[3],eps) &&
|
| 164 |
+
Equal(a.data[4],b.data[4],eps) &&
|
| 165 |
+
Equal(a.data[5],b.data[5],eps) &&
|
| 166 |
+
Equal(a.data[6],b.data[6],eps) &&
|
| 167 |
+
Equal(a.data[7],b.data[7],eps) &&
|
| 168 |
+
Equal(a.data[8],b.data[8],eps) );
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
Rotation operator *(const Rotation& lhs,const Rotation& rhs)
|
| 174 |
+
// Complexity : 27M+27A
|
| 175 |
+
{
|
| 176 |
+
return Rotation(
|
| 177 |
+
lhs.data[0]*rhs.data[0]+lhs.data[1]*rhs.data[3]+lhs.data[2]*rhs.data[6],
|
| 178 |
+
lhs.data[0]*rhs.data[1]+lhs.data[1]*rhs.data[4]+lhs.data[2]*rhs.data[7],
|
| 179 |
+
lhs.data[0]*rhs.data[2]+lhs.data[1]*rhs.data[5]+lhs.data[2]*rhs.data[8],
|
| 180 |
+
lhs.data[3]*rhs.data[0]+lhs.data[4]*rhs.data[3]+lhs.data[5]*rhs.data[6],
|
| 181 |
+
lhs.data[3]*rhs.data[1]+lhs.data[4]*rhs.data[4]+lhs.data[5]*rhs.data[7],
|
| 182 |
+
lhs.data[3]*rhs.data[2]+lhs.data[4]*rhs.data[5]+lhs.data[5]*rhs.data[8],
|
| 183 |
+
lhs.data[6]*rhs.data[0]+lhs.data[7]*rhs.data[3]+lhs.data[8]*rhs.data[6],
|
| 184 |
+
lhs.data[6]*rhs.data[1]+lhs.data[7]*rhs.data[4]+lhs.data[8]*rhs.data[7],
|
| 185 |
+
lhs.data[6]*rhs.data[2]+lhs.data[7]*rhs.data[5]+lhs.data[8]*rhs.data[8]
|
| 186 |
+
);
|
| 187 |
+
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
Rotation Rotation::Quaternion(double x,double y,double z, double w)
|
| 191 |
+
{
|
| 192 |
+
double x2, y2, z2, w2;
|
| 193 |
+
x2 = x*x; y2 = y*y; z2 = z*z; w2 = w*w;
|
| 194 |
+
return Rotation(w2+x2-y2-z2, 2*x*y-2*w*z, 2*x*z+2*w*y,
|
| 195 |
+
2*x*y+2*w*z, w2-x2+y2-z2, 2*y*z-2*w*x,
|
| 196 |
+
2*x*z-2*w*y, 2*y*z+2*w*x, w2-x2-y2+z2);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/* From the following sources:
|
| 200 |
+
http://web.archive.org/web/20041029003853/http:/www.j3d.org/matrix_faq/matrfaq_latest.html
|
| 201 |
+
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
|
| 202 |
+
RobOOP::quaternion.cpp
|
| 203 |
+
*/
|
| 204 |
+
void Rotation::GetQuaternion(double& x,double& y,double& z, double& w) const
|
| 205 |
+
{
|
| 206 |
+
double trace = (*this)(0,0) + (*this)(1,1) + (*this)(2,2);
|
| 207 |
+
double epsilon=1E-12;
|
| 208 |
+
if( trace > epsilon ){
|
| 209 |
+
double s = 0.5 / sqrt(trace + 1.0);
|
| 210 |
+
w = 0.25 / s;
|
| 211 |
+
x = ( (*this)(2,1) - (*this)(1,2) ) * s;
|
| 212 |
+
y = ( (*this)(0,2) - (*this)(2,0) ) * s;
|
| 213 |
+
z = ( (*this)(1,0) - (*this)(0,1) ) * s;
|
| 214 |
+
}else{
|
| 215 |
+
if ( (*this)(0,0) > (*this)(1,1) && (*this)(0,0) > (*this)(2,2) ){
|
| 216 |
+
double s = 2.0 * sqrt( 1.0 + (*this)(0,0) - (*this)(1,1) - (*this)(2,2));
|
| 217 |
+
w = ((*this)(2,1) - (*this)(1,2) ) / s;
|
| 218 |
+
x = 0.25 * s;
|
| 219 |
+
y = ((*this)(0,1) + (*this)(1,0) ) / s;
|
| 220 |
+
z = ((*this)(0,2) + (*this)(2,0) ) / s;
|
| 221 |
+
} else if ((*this)(1,1) > (*this)(2,2)) {
|
| 222 |
+
double s = 2.0 * sqrt( 1.0 + (*this)(1,1) - (*this)(0,0) - (*this)(2,2));
|
| 223 |
+
w = ((*this)(0,2) - (*this)(2,0) ) / s;
|
| 224 |
+
x = ((*this)(0,1) + (*this)(1,0) ) / s;
|
| 225 |
+
y = 0.25 * s;
|
| 226 |
+
z = ((*this)(1,2) + (*this)(2,1) ) / s;
|
| 227 |
+
}else {
|
| 228 |
+
double s = 2.0 * sqrt( 1.0 + (*this)(2,2) - (*this)(0,0) - (*this)(1,1) );
|
| 229 |
+
w = ((*this)(1,0) - (*this)(0,1) ) / s;
|
| 230 |
+
x = ((*this)(0,2) + (*this)(2,0) ) / s;
|
| 231 |
+
y = ((*this)(1,2) + (*this)(2,1) ) / s;
|
| 232 |
+
z = 0.25 * s;
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
Rotation Rotation::RPY(double roll,double pitch,double yaw)
|
| 238 |
+
{
|
| 239 |
+
double ca1,cb1,cc1,sa1,sb1,sc1;
|
| 240 |
+
ca1 = cos(yaw); sa1 = sin(yaw);
|
| 241 |
+
cb1 = cos(pitch);sb1 = sin(pitch);
|
| 242 |
+
cc1 = cos(roll);sc1 = sin(roll);
|
| 243 |
+
return Rotation(ca1*cb1,ca1*sb1*sc1 - sa1*cc1,ca1*sb1*cc1 + sa1*sc1,
|
| 244 |
+
sa1*cb1,sa1*sb1*sc1 + ca1*cc1,sa1*sb1*cc1 - ca1*sc1,
|
| 245 |
+
-sb1,cb1*sc1,cb1*cc1);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
// Gives back a rotation matrix specified with RPY convention
|
| 249 |
+
void Rotation::GetRPY(double& roll,double& pitch,double& yaw) const
|
| 250 |
+
{
|
| 251 |
+
double epsilon=1E-12;
|
| 252 |
+
pitch = atan2(-data[6], sqrt( sqr(data[0]) +sqr(data[3]) ) );
|
| 253 |
+
if ( fabs(pitch) > (PI_2-epsilon) ) {
|
| 254 |
+
yaw = atan2( -data[1], data[4]);
|
| 255 |
+
roll = 0.0 ;
|
| 256 |
+
} else {
|
| 257 |
+
roll = atan2(data[7], data[8]);
|
| 258 |
+
yaw = atan2(data[3], data[0]);
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
Rotation Rotation::EulerZYZ(double Alfa,double Beta,double Gamma) {
|
| 263 |
+
double sa,ca,sb,cb,sg,cg;
|
| 264 |
+
sa = sin(Alfa);ca = cos(Alfa);
|
| 265 |
+
sb = sin(Beta);cb = cos(Beta);
|
| 266 |
+
sg = sin(Gamma);cg = cos(Gamma);
|
| 267 |
+
return Rotation( ca*cb*cg-sa*sg, -ca*cb*sg-sa*cg, ca*sb,
|
| 268 |
+
sa*cb*cg+ca*sg, -sa*cb*sg+ca*cg, sa*sb,
|
| 269 |
+
-sb*cg , sb*sg, cb
|
| 270 |
+
);
|
| 271 |
+
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
void Rotation::GetEulerZYZ(double& alpha,double& beta,double& gamma) const {
|
| 276 |
+
double epsilon = 1E-12;
|
| 277 |
+
if (fabs(data[8]) > 1-epsilon ) {
|
| 278 |
+
gamma=0.0;
|
| 279 |
+
if (data[8]>0) {
|
| 280 |
+
beta = 0.0;
|
| 281 |
+
alpha= atan2(data[3],data[0]);
|
| 282 |
+
} else {
|
| 283 |
+
beta = PI;
|
| 284 |
+
alpha= atan2(-data[3],-data[0]);
|
| 285 |
+
}
|
| 286 |
+
} else {
|
| 287 |
+
alpha=atan2(data[5], data[2]);
|
| 288 |
+
beta=atan2(sqrt( sqr(data[6]) +sqr(data[7]) ),data[8]);
|
| 289 |
+
gamma=atan2(data[7], -data[6]);
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
Rotation Rotation::Rot(const Vector& rotaxis,double angle) {
|
| 294 |
+
// The formula is
|
| 295 |
+
// V.(V.tr) + st*[V x] + ct*(I-V.(V.tr))
|
| 296 |
+
// can be found by multiplying it with an arbitrary vector p
|
| 297 |
+
// and noting that this vector is rotated.
|
| 298 |
+
Vector rotvec = rotaxis;
|
| 299 |
+
rotvec.Normalize();
|
| 300 |
+
return Rotation::Rot2(rotvec,angle);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
Rotation Rotation::Rot2(const Vector& rotvec,double angle) {
|
| 304 |
+
// rotvec should be normalized !
|
| 305 |
+
// The formula is
|
| 306 |
+
// V.(V.tr) + st*[V x] + ct*(I-V.(V.tr))
|
| 307 |
+
// can be found by multiplying it with an arbitrary vector p
|
| 308 |
+
// and noting that this vector is rotated.
|
| 309 |
+
double ct = cos(angle);
|
| 310 |
+
double st = sin(angle);
|
| 311 |
+
double vt = 1-ct;
|
| 312 |
+
double m_vt_0=vt*rotvec(0);
|
| 313 |
+
double m_vt_1=vt*rotvec(1);
|
| 314 |
+
double m_vt_2=vt*rotvec(2);
|
| 315 |
+
double m_st_0=rotvec(0)*st;
|
| 316 |
+
double m_st_1=rotvec(1)*st;
|
| 317 |
+
double m_st_2=rotvec(2)*st;
|
| 318 |
+
double m_vt_0_1=m_vt_0*rotvec(1);
|
| 319 |
+
double m_vt_0_2=m_vt_0*rotvec(2);
|
| 320 |
+
double m_vt_1_2=m_vt_1*rotvec(2);
|
| 321 |
+
return Rotation(
|
| 322 |
+
ct + m_vt_0*rotvec(0),
|
| 323 |
+
-m_st_2 + m_vt_0_1,
|
| 324 |
+
m_st_1 + m_vt_0_2,
|
| 325 |
+
m_st_2 + m_vt_0_1,
|
| 326 |
+
ct + m_vt_1*rotvec(1),
|
| 327 |
+
-m_st_0 + m_vt_1_2,
|
| 328 |
+
-m_st_1 + m_vt_0_2,
|
| 329 |
+
m_st_0 + m_vt_1_2,
|
| 330 |
+
ct + m_vt_2*rotvec(2)
|
| 331 |
+
);
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
Vector Rotation::GetRot() const
|
| 337 |
+
// Returns a vector with the direction of the equiv. axis
|
| 338 |
+
// and its norm is angle
|
| 339 |
+
{
|
| 340 |
+
Vector axis;
|
| 341 |
+
double angle;
|
| 342 |
+
angle = Rotation::GetRotAngle(axis,epsilon);
|
| 343 |
+
return axis * angle;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
/** Returns the rotation angle around the equiv. axis
|
| 349 |
+
* @param axis the rotation axis is returned in this variable
|
| 350 |
+
* @param eps : in the case of angle == 0 : rot axis is undefined and chosen
|
| 351 |
+
* to be the Z-axis
|
| 352 |
+
* in the case of angle == PI : 2 solutions, positive Z-component
|
| 353 |
+
* of the axis is chosen.
|
| 354 |
+
* @result returns the rotation angle (between [0..PI] )
|
| 355 |
+
* /todo :
|
| 356 |
+
* Check corresponding routines in rframes and rrframes
|
| 357 |
+
*/
|
| 358 |
+
double Rotation::GetRotAngle(Vector& axis,double eps) const {
|
| 359 |
+
double angle,x,y,z; // variables for result
|
| 360 |
+
double epsilon = eps; // margin to allow for rounding errors
|
| 361 |
+
double epsilon2 = eps*10; // margin to distinguish between 0 and 180 degrees
|
| 362 |
+
|
| 363 |
+
// optional check that input is pure rotation, 'isRotationMatrix' is defined at:
|
| 364 |
+
// http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/
|
| 365 |
+
|
| 366 |
+
if ((std::abs(data[1] - data[3]) < epsilon)
|
| 367 |
+
&& (std::abs(data[2] - data[6])< epsilon)
|
| 368 |
+
&& (std::abs(data[5] - data[7]) < epsilon))
|
| 369 |
+
{
|
| 370 |
+
// singularity found
|
| 371 |
+
// first check for identity matrix which must have +1 for all terms
|
| 372 |
+
// in leading diagonal and zero in other terms
|
| 373 |
+
if ((std::abs(data[1] + data[3]) < epsilon2)
|
| 374 |
+
&& (std::abs(data[2] + data[6]) < epsilon2)
|
| 375 |
+
&& (std::abs(data[5] + data[7]) < epsilon2)
|
| 376 |
+
&& (std::abs(data[0] + data[4] + data[8]-3) < epsilon2))
|
| 377 |
+
{
|
| 378 |
+
// this singularity is identity matrix so angle = 0, axis is arbitrary
|
| 379 |
+
// Choose 0, 0, 1 to pass orocos tests
|
| 380 |
+
axis = KDL::Vector(0,0,1);
|
| 381 |
+
angle = 0.0;
|
| 382 |
+
return angle;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
// otherwise this singularity is angle = 180
|
| 386 |
+
angle = PI;
|
| 387 |
+
double xx = (data[0] + 1) / 2;
|
| 388 |
+
double yy = (data[4] + 1) / 2;
|
| 389 |
+
double zz = (data[8] + 1) / 2;
|
| 390 |
+
double xy = (data[1] + data[3]) / 4;
|
| 391 |
+
double xz = (data[2] + data[6]) / 4;
|
| 392 |
+
double yz = (data[5] + data[7]) / 4;
|
| 393 |
+
|
| 394 |
+
if ((xx > yy) && (xx > zz))
|
| 395 |
+
{
|
| 396 |
+
// data[0] is the largest diagonal term
|
| 397 |
+
x = sqrt(xx);
|
| 398 |
+
y = xy/x;
|
| 399 |
+
z = xz/x;
|
| 400 |
+
}
|
| 401 |
+
else if (yy > zz)
|
| 402 |
+
{
|
| 403 |
+
// data[4] is the largest diagonal term
|
| 404 |
+
y = sqrt(yy);
|
| 405 |
+
x = xy/y;
|
| 406 |
+
z = yz/y;
|
| 407 |
+
}
|
| 408 |
+
else
|
| 409 |
+
{
|
| 410 |
+
// data[8] is the largest diagonal term so base result on this
|
| 411 |
+
z = sqrt(zz);
|
| 412 |
+
x = xz/z;
|
| 413 |
+
y = yz/z;
|
| 414 |
+
}
|
| 415 |
+
axis = KDL::Vector(x, y, z);
|
| 416 |
+
return angle; // return 180 deg rotation
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
double f = (data[0] + data[4] + data[8] - 1) / 2;
|
| 420 |
+
|
| 421 |
+
x = (data[7] - data[5]);
|
| 422 |
+
y = (data[2] - data[6]);
|
| 423 |
+
z = (data[3] - data[1]);
|
| 424 |
+
axis = KDL::Vector(x, y, z);
|
| 425 |
+
angle = atan2(axis.Norm()/2,f);
|
| 426 |
+
axis.Normalize();
|
| 427 |
+
return angle;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
bool operator==(const Rotation& a,const Rotation& b) {
|
| 431 |
+
#ifdef KDL_USE_EQUAL
|
| 432 |
+
return Equal(a,b);
|
| 433 |
+
#else
|
| 434 |
+
return ( a.data[0]==b.data[0] &&
|
| 435 |
+
a.data[1]==b.data[1] &&
|
| 436 |
+
a.data[2]==b.data[2] &&
|
| 437 |
+
a.data[3]==b.data[3] &&
|
| 438 |
+
a.data[4]==b.data[4] &&
|
| 439 |
+
a.data[5]==b.data[5] &&
|
| 440 |
+
a.data[6]==b.data[6] &&
|
| 441 |
+
a.data[7]==b.data[7] &&
|
| 442 |
+
a.data[8]==b.data[8] );
|
| 443 |
+
#endif
|
| 444 |
+
}
|
| 445 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames.hpp
ADDED
|
@@ -0,0 +1,1354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
frames.hpp `- description
|
| 3 |
+
-------------------------
|
| 4 |
+
begin : June 2006
|
| 5 |
+
copyright : (C) 2006 Erwin Aertbelien
|
| 6 |
+
email : firstname.lastname@mech.kuleuven.be
|
| 7 |
+
|
| 8 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 9 |
+
|
| 10 |
+
***************************************************************************
|
| 11 |
+
* This library is free software; you can redistribute it and/or *
|
| 12 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 13 |
+
* License as published by the Free Software Foundation; either *
|
| 14 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 15 |
+
* *
|
| 16 |
+
* This library is distributed in the hope that it will be useful, *
|
| 17 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 18 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 19 |
+
* Lesser General Public License for more details. *
|
| 20 |
+
* *
|
| 21 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 22 |
+
* License along with this library; if not, write to the Free Software *
|
| 23 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 24 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 25 |
+
* *
|
| 26 |
+
***************************************************************************/
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* \file
|
| 30 |
+
* \warning
|
| 31 |
+
* Efficienty can be improved by writing p2 = A*(B*(C*p1))) instead of
|
| 32 |
+
* p2=A*B*C*p1
|
| 33 |
+
*
|
| 34 |
+
* \par PROPOSED NAMING CONVENTION FOR FRAME-like OBJECTS
|
| 35 |
+
*
|
| 36 |
+
* \verbatim
|
| 37 |
+
* A naming convention of objects of the type defined in this file :
|
| 38 |
+
* (1) Frame : F...
|
| 39 |
+
* Rotation : R ...
|
| 40 |
+
* (2) Twist : T ...
|
| 41 |
+
* Wrench : W ...
|
| 42 |
+
* Vector : V ...
|
| 43 |
+
* This prefix is followed by :
|
| 44 |
+
* for category (1) :
|
| 45 |
+
* F_A_B : w.r.t. frame A, frame B expressed
|
| 46 |
+
* ( each column of F_A_B corresponds to an axis of B,
|
| 47 |
+
* expressed w.r.t. frame A )
|
| 48 |
+
* in mathematical convention :
|
| 49 |
+
* A
|
| 50 |
+
* F_A_B == F
|
| 51 |
+
* B
|
| 52 |
+
*
|
| 53 |
+
* for category (2) :
|
| 54 |
+
* V_B : a vector expressed w.r.t. frame B
|
| 55 |
+
*
|
| 56 |
+
* This can also be prepended by a name :
|
| 57 |
+
* e.g. : temporaryV_B
|
| 58 |
+
*
|
| 59 |
+
* With this convention one can write :
|
| 60 |
+
*
|
| 61 |
+
* F_A_B = F_B_A.Inverse();
|
| 62 |
+
* F_A_C = F_A_B * F_B_C;
|
| 63 |
+
* V_B = F_B_C * V_C; // both translation and rotation
|
| 64 |
+
* V_B = R_B_C * V_C; // only rotation
|
| 65 |
+
* \endverbatim
|
| 66 |
+
*
|
| 67 |
+
* \par CONVENTIONS FOR WHEN USED WITH ROBOTS :
|
| 68 |
+
*
|
| 69 |
+
* \verbatim
|
| 70 |
+
* world : represents the frame ([1 0 0,0 1 0,0 0 1],[0 0 0]')
|
| 71 |
+
* mp : represents mounting plate of a robot
|
| 72 |
+
* (i.e. everything before MP is constructed by robot manufacturer
|
| 73 |
+
* everything after MP is tool )
|
| 74 |
+
* tf : represents task frame of a robot
|
| 75 |
+
* (i.e. frame in which motion and force control is expressed)
|
| 76 |
+
* sf : represents sensor frame of a robot
|
| 77 |
+
* (i.e. frame at which the forces measured by the force sensor
|
| 78 |
+
* are expressed )
|
| 79 |
+
*
|
| 80 |
+
* Frame F_world_mp=...;
|
| 81 |
+
* Frame F_mp_sf(..)
|
| 82 |
+
* Frame F_mp_tf(,.)
|
| 83 |
+
*
|
| 84 |
+
* Wrench are measured in sensor frame SF, so one could write :
|
| 85 |
+
* Wrench_tf = F_mp_tf.Inverse()* ( F_mp_sf * Wrench_sf );
|
| 86 |
+
* \endverbatim
|
| 87 |
+
*
|
| 88 |
+
* \par CONVENTIONS REGARDING UNITS :
|
| 89 |
+
* Any consistent series of units can be used, e.g. N,mm,Nmm,..mm/sec
|
| 90 |
+
*
|
| 91 |
+
* \par Twist and Wrench transformations
|
| 92 |
+
* 3 different types of transformations do exist for the twists
|
| 93 |
+
* and wrenches.
|
| 94 |
+
*
|
| 95 |
+
* \verbatim
|
| 96 |
+
* 1) Frame * Twist or Frame * Wrench :
|
| 97 |
+
* this transforms both the velocity/force reference point
|
| 98 |
+
* and the basis to which the twist/wrench are expressed.
|
| 99 |
+
* 2) Rotation * Twist or Rotation * Wrench :
|
| 100 |
+
* this transforms the basis to which the twist/wrench are
|
| 101 |
+
* expressed, but leaves the reference point intact.
|
| 102 |
+
* 3) Twist.RefPoint(v_base_AB) or Wrench.RefPoint(v_base_AB)
|
| 103 |
+
* this transforms only the reference point. v is expressed
|
| 104 |
+
* in the same base as the twist/wrench and points from the
|
| 105 |
+
* old reference point to the new reference point.
|
| 106 |
+
* \endverbatim
|
| 107 |
+
*
|
| 108 |
+
*\par Spatial cross products
|
| 109 |
+
* Let m be a 6D motion vector (Twist) and f be a 6D force vector (Wrench)
|
| 110 |
+
* attached to a rigid body moving with a certain velocity v (Twist). Then
|
| 111 |
+
*\verbatim
|
| 112 |
+
* 1) m_dot = v cross m or Twist=Twist*Twist
|
| 113 |
+
* 2) f_dot = v cross f or Wrench=Twist*Wrench
|
| 114 |
+
*\endverbatim
|
| 115 |
+
*
|
| 116 |
+
* \par Complexity
|
| 117 |
+
* Sometimes the amount of work is given in the documentation
|
| 118 |
+
* e.g. 6M+3A means 6 multiplications and 3 additions.
|
| 119 |
+
*
|
| 120 |
+
* \author
|
| 121 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 122 |
+
*
|
| 123 |
+
****************************************************************************/
|
| 124 |
+
#ifndef KDL_FRAMES_H
|
| 125 |
+
#define KDL_FRAMES_H
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
#include "utilities/kdl-config.h"
|
| 129 |
+
#include "utilities/utility.h"
|
| 130 |
+
#include "utilities/hash_combine.h"
|
| 131 |
+
|
| 132 |
+
#include <functional>
|
| 133 |
+
|
| 134 |
+
/////////////////////////////////////////////////////////////
|
| 135 |
+
|
| 136 |
+
namespace KDL {
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class Vector;
|
| 140 |
+
class Rotation;
|
| 141 |
+
class Frame;
|
| 142 |
+
class Wrench;
|
| 143 |
+
class Twist;
|
| 144 |
+
class Vector2;
|
| 145 |
+
class Rotation2;
|
| 146 |
+
class Frame2;
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
// Equal is friend function, but default arguments for friends are forbidden (§8.3.6.4)
|
| 150 |
+
inline bool Equal(const Vector& a,const Vector& b,double eps=epsilon);
|
| 151 |
+
inline bool Equal(const Frame& a,const Frame& b,double eps=epsilon);
|
| 152 |
+
inline bool Equal(const Twist& a,const Twist& b,double eps=epsilon);
|
| 153 |
+
inline bool Equal(const Wrench& a,const Wrench& b,double eps=epsilon);
|
| 154 |
+
inline bool Equal(const Vector2& a,const Vector2& b,double eps=epsilon);
|
| 155 |
+
inline bool Equal(const Rotation2& a,const Rotation2& b,double eps=epsilon);
|
| 156 |
+
inline bool Equal(const Frame2& a,const Frame2& b,double eps=epsilon);
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* \brief A concrete implementation of a 3 dimensional vector class
|
| 161 |
+
*/
|
| 162 |
+
class Vector
|
| 163 |
+
{
|
| 164 |
+
public:
|
| 165 |
+
double data[3];
|
| 166 |
+
//! Does not initialise the Vector to zero. use Vector::Zero() or SetToZero for that
|
| 167 |
+
inline Vector() {data[0]=data[1]=data[2] = 0.0;}
|
| 168 |
+
|
| 169 |
+
//! Constructs a vector out of the three values x, y and z
|
| 170 |
+
inline Vector(double x,double y, double z);
|
| 171 |
+
|
| 172 |
+
//! Assignment operator. The normal copy by value semantics.
|
| 173 |
+
inline Vector(const Vector& arg);
|
| 174 |
+
|
| 175 |
+
//! Assignment operator. The normal copy by value semantics.
|
| 176 |
+
inline Vector& operator = ( const Vector& arg);
|
| 177 |
+
|
| 178 |
+
//! Access to elements, range checked when NDEBUG is not set, from 0..2
|
| 179 |
+
inline double operator()(int index) const;
|
| 180 |
+
|
| 181 |
+
//! Access to elements, range checked when NDEBUG is not set, from 0..2
|
| 182 |
+
inline double& operator() (int index);
|
| 183 |
+
|
| 184 |
+
//! Equivalent to double operator()(int index) const
|
| 185 |
+
double operator[] ( int index ) const
|
| 186 |
+
{
|
| 187 |
+
return this->operator() ( index );
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
//! Equivalent to double& operator()(int index)
|
| 191 |
+
double& operator[] ( int index )
|
| 192 |
+
{
|
| 193 |
+
return this->operator() ( index );
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
inline double x() const;
|
| 197 |
+
inline double y() const;
|
| 198 |
+
inline double z() const;
|
| 199 |
+
inline void x(double);
|
| 200 |
+
inline void y(double);
|
| 201 |
+
inline void z(double);
|
| 202 |
+
|
| 203 |
+
//! Reverses the sign of the Vector object itself
|
| 204 |
+
inline void ReverseSign();
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
//! subtracts a vector from the Vector object itself
|
| 208 |
+
inline Vector& operator-=(const Vector& arg);
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
//! Adds a vector from the Vector object itself
|
| 212 |
+
inline Vector& operator +=(const Vector& arg);
|
| 213 |
+
|
| 214 |
+
//! Scalar multiplication is defined
|
| 215 |
+
inline friend Vector operator*(const Vector& lhs,double rhs);
|
| 216 |
+
//! Scalar multiplication is defined
|
| 217 |
+
inline friend Vector operator*(double lhs,const Vector& rhs);
|
| 218 |
+
//! Scalar division is defined
|
| 219 |
+
|
| 220 |
+
inline friend Vector operator/(const Vector& lhs,double rhs);
|
| 221 |
+
inline friend Vector operator+(const Vector& lhs,const Vector& rhs);
|
| 222 |
+
inline friend Vector operator-(const Vector& lhs,const Vector& rhs);
|
| 223 |
+
inline friend Vector operator*(const Vector& lhs,const Vector& rhs);
|
| 224 |
+
inline friend Vector operator-(const Vector& arg);
|
| 225 |
+
inline friend double dot(const Vector& lhs,const Vector& rhs);
|
| 226 |
+
|
| 227 |
+
//! To have a uniform operator to put an element to zero, for scalar values
|
| 228 |
+
//! and for objects.
|
| 229 |
+
inline friend void SetToZero(Vector& v);
|
| 230 |
+
|
| 231 |
+
//! @return a zero vector
|
| 232 |
+
inline static Vector Zero();
|
| 233 |
+
|
| 234 |
+
/** Normalizes this vector and returns it norm
|
| 235 |
+
* makes v a unitvector and returns the norm of v.
|
| 236 |
+
* if v is smaller than eps, Vector(1,0,0) is returned with norm 0.
|
| 237 |
+
* if this is not good, check the return value of this method.
|
| 238 |
+
*/
|
| 239 |
+
double Normalize(double eps=epsilon);
|
| 240 |
+
|
| 241 |
+
//! @return the norm of the vector
|
| 242 |
+
double Norm(double eps=epsilon) const;
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
//! a 3D vector where the 2D vector v is put in the XY plane
|
| 247 |
+
inline void Set2DXY(const Vector2& v);
|
| 248 |
+
//! a 3D vector where the 2D vector v is put in the YZ plane
|
| 249 |
+
inline void Set2DYZ(const Vector2& v);
|
| 250 |
+
//! a 3D vector where the 2D vector v is put in the ZX plane
|
| 251 |
+
inline void Set2DZX(const Vector2& v);
|
| 252 |
+
//! a 3D vector where the 2D vector v_XY is put in the XY plane of the frame F_someframe_XY.
|
| 253 |
+
inline void Set2DPlane(const Frame& F_someframe_XY,const Vector2& v_XY);
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 257 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 258 |
+
inline friend bool Equal(const Vector& a,const Vector& b,double eps);
|
| 259 |
+
|
| 260 |
+
//! The literal equality operator==(), also identical.
|
| 261 |
+
inline friend bool operator==(const Vector& a,const Vector& b);
|
| 262 |
+
//! The literal inequality operator!=().
|
| 263 |
+
inline friend bool operator!=(const Vector& a,const Vector& b);
|
| 264 |
+
|
| 265 |
+
friend class Rotation;
|
| 266 |
+
friend class Frame;
|
| 267 |
+
};
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
\brief represents rotations in 3 dimensional space.
|
| 272 |
+
|
| 273 |
+
This class represents a rotation matrix with the following
|
| 274 |
+
conventions :
|
| 275 |
+
\verbatim
|
| 276 |
+
Suppose V2 = R*V, (1)
|
| 277 |
+
V is expressed in frame B
|
| 278 |
+
V2 is expressed in frame A
|
| 279 |
+
This matrix R consists of 3 columns [ X,Y,Z ],
|
| 280 |
+
X,Y, and Z contain the axes of frame B, expressed in frame A
|
| 281 |
+
Because of linearity expr(1) is valid.
|
| 282 |
+
\endverbatim
|
| 283 |
+
This class only represents rotational_interpolation, not translation
|
| 284 |
+
Two interpretations are possible for rotation angles.
|
| 285 |
+
* if you rotate with angle around X frame A to have frame B,
|
| 286 |
+
then the result of SetRotX is equal to frame B expressed wrt A.
|
| 287 |
+
In code:
|
| 288 |
+
\verbatim
|
| 289 |
+
Rotation R;
|
| 290 |
+
F_A_B = R.SetRotX(angle);
|
| 291 |
+
\endverbatim
|
| 292 |
+
* Secondly, if you take the following code :
|
| 293 |
+
\verbatim
|
| 294 |
+
Vector p,p2; Rotation R;
|
| 295 |
+
R.SetRotX(angle);
|
| 296 |
+
p2 = R*p;
|
| 297 |
+
\endverbatim
|
| 298 |
+
then the frame p2 is rotated around X axis with (-angle).
|
| 299 |
+
Analogue reasonings can be applyd to SetRotY,SetRotZ,SetRot
|
| 300 |
+
\par type
|
| 301 |
+
Concrete implementation
|
| 302 |
+
*/
|
| 303 |
+
class Rotation
|
| 304 |
+
{
|
| 305 |
+
public:
|
| 306 |
+
double data[9];
|
| 307 |
+
|
| 308 |
+
inline Rotation() {
|
| 309 |
+
*this = Rotation::Identity();
|
| 310 |
+
}
|
| 311 |
+
inline Rotation(double Xx,double Yx,double Zx,
|
| 312 |
+
double Xy,double Yy,double Zy,
|
| 313 |
+
double Xz,double Yz,double Zz);
|
| 314 |
+
inline Rotation(const Vector& x,const Vector& y,const Vector& z);
|
| 315 |
+
|
| 316 |
+
inline Rotation(const Rotation& arg);
|
| 317 |
+
|
| 318 |
+
inline Rotation& operator=(const Rotation& arg);
|
| 319 |
+
|
| 320 |
+
//! Defines a multiplication R*V between a Rotation R and a Vector V.
|
| 321 |
+
//! Complexity : 9M+6A
|
| 322 |
+
inline Vector operator*(const Vector& v) const;
|
| 323 |
+
|
| 324 |
+
//! Access to elements 0..2,0..2, bounds are checked when NDEBUG is not set
|
| 325 |
+
inline double& operator()(int i,int j);
|
| 326 |
+
|
| 327 |
+
//! Access to elements 0..2,0..2, bounds are checked when NDEBUG is not set
|
| 328 |
+
inline double operator() (int i,int j) const;
|
| 329 |
+
|
| 330 |
+
friend Rotation operator *(const Rotation& lhs,const Rotation& rhs);
|
| 331 |
+
|
| 332 |
+
//! Sets the value of *this to its inverse.
|
| 333 |
+
inline void SetInverse();
|
| 334 |
+
|
| 335 |
+
//! Gives back the inverse rotation matrix of *this.
|
| 336 |
+
inline Rotation Inverse() const;
|
| 337 |
+
|
| 338 |
+
//! The same as R.Inverse()*v but more efficient.
|
| 339 |
+
inline Vector Inverse(const Vector& v) const;
|
| 340 |
+
|
| 341 |
+
//! The same as R.Inverse()*arg but more efficient.
|
| 342 |
+
inline Wrench Inverse(const Wrench& arg) const;
|
| 343 |
+
|
| 344 |
+
//! The same as R.Inverse()*arg but more efficient.
|
| 345 |
+
inline Twist Inverse(const Twist& arg) const;
|
| 346 |
+
|
| 347 |
+
//! Gives back an identity rotaton matrix
|
| 348 |
+
inline static Rotation Identity();
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
// = Rotations
|
| 352 |
+
//! The Rot... static functions give the value of the appropriate rotation matrix back.
|
| 353 |
+
inline static Rotation RotX(double angle);
|
| 354 |
+
//! The Rot... static functions give the value of the appropriate rotation matrix back.
|
| 355 |
+
inline static Rotation RotY(double angle);
|
| 356 |
+
//! The Rot... static functions give the value of the appropriate rotation matrix back.
|
| 357 |
+
inline static Rotation RotZ(double angle);
|
| 358 |
+
//! The DoRot... functions apply a rotation R to *this,such that *this = *this * Rot..
|
| 359 |
+
//! DoRot... functions are only defined when they can be executed more efficiently
|
| 360 |
+
inline void DoRotX(double angle);
|
| 361 |
+
//! The DoRot... functions apply a rotation R to *this,such that *this = *this * Rot..
|
| 362 |
+
//! DoRot... functions are only defined when they can be executed more efficiently
|
| 363 |
+
inline void DoRotY(double angle);
|
| 364 |
+
//! The DoRot... functions apply a rotation R to *this,such that *this = *this * Rot..
|
| 365 |
+
//! DoRot... functions are only defined when they can be executed more efficiently
|
| 366 |
+
inline void DoRotZ(double angle);
|
| 367 |
+
|
| 368 |
+
//! Along an arbitrary axes. It is not necessary to normalize rotvec.
|
| 369 |
+
//! returns identity rotation matrix in the case that the norm of rotvec
|
| 370 |
+
//! is to small to be used.
|
| 371 |
+
// @see Rot2 if you want to handle this error in another way.
|
| 372 |
+
static Rotation Rot(const Vector& rotvec,double angle);
|
| 373 |
+
|
| 374 |
+
//! Along an arbitrary axes. rotvec should be normalized.
|
| 375 |
+
static Rotation Rot2(const Vector& rotvec,double angle);
|
| 376 |
+
|
| 377 |
+
//! Returns a vector with the direction of the equiv. axis
|
| 378 |
+
//! and its norm is angle
|
| 379 |
+
Vector GetRot() const;
|
| 380 |
+
|
| 381 |
+
/** Returns the rotation angle around the equiv. axis
|
| 382 |
+
* @param axis the rotation axis is returned in this variable
|
| 383 |
+
* @param eps : in the case of angle == 0 : rot axis is undefined and chosen
|
| 384 |
+
* to be +/- Z-axis
|
| 385 |
+
* in the case of angle == PI : 2 solutions, positive Z-component
|
| 386 |
+
* of the axis is chosen.
|
| 387 |
+
* @result returns the rotation angle (between [0..PI] )
|
| 388 |
+
*/
|
| 389 |
+
double GetRotAngle(Vector& axis,double eps=epsilon) const;
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
/** Gives back a rotation matrix specified with EulerZYZ convention :
|
| 393 |
+
* - First rotate around Z with alfa,
|
| 394 |
+
* - then around the new Y with beta,
|
| 395 |
+
* - then around new Z with gamma.
|
| 396 |
+
* Invariants:
|
| 397 |
+
* - EulerZYX(alpha,beta,gamma) == EulerZYX(alpha +/- PHI, -beta, gamma +/- PI)
|
| 398 |
+
* - (angle + 2*k*PI)
|
| 399 |
+
**/
|
| 400 |
+
static Rotation EulerZYZ(double Alfa,double Beta,double Gamma);
|
| 401 |
+
|
| 402 |
+
/** Gives back the EulerZYZ convention description of the rotation matrix :
|
| 403 |
+
First rotate around Z with alpha,
|
| 404 |
+
then around the new Y with beta, then around
|
| 405 |
+
new Z with gamma.
|
| 406 |
+
|
| 407 |
+
Variables are bound by:
|
| 408 |
+
- (-PI < alpha <= PI),
|
| 409 |
+
- (0 <= beta <= PI),
|
| 410 |
+
- (-PI < gamma <= PI)
|
| 411 |
+
|
| 412 |
+
if beta==0 or beta==PI, then alpha and gamma are not unique, in this case gamma is chosen to be zero.
|
| 413 |
+
Invariants:
|
| 414 |
+
- EulerZYX(alpha,beta,gamma) == EulerZYX(alpha +/- PI, -beta, gamma +/- PI)
|
| 415 |
+
- angle + 2*k*PI
|
| 416 |
+
*/
|
| 417 |
+
void GetEulerZYZ(double& alpha,double& beta,double& gamma) const;
|
| 418 |
+
|
| 419 |
+
//! Gives back a rotation matrix specified with Quaternion convention
|
| 420 |
+
//! the norm of (x,y,z,w) should be equal to 1
|
| 421 |
+
static Rotation Quaternion(double x,double y,double z, double w);
|
| 422 |
+
|
| 423 |
+
//! Get the quaternion of this matrix
|
| 424 |
+
//! \post the norm of (x,y,z,w) is 1
|
| 425 |
+
void GetQuaternion(double& x,double& y,double& z, double& w) const;
|
| 426 |
+
|
| 427 |
+
/**
|
| 428 |
+
*
|
| 429 |
+
* Gives back a rotation matrix specified with RPY convention:
|
| 430 |
+
* first rotate around X with roll, then around the
|
| 431 |
+
* old Y with pitch, then around old Z with yaw
|
| 432 |
+
*
|
| 433 |
+
* Invariants:
|
| 434 |
+
* - RPY(roll,pitch,yaw) == RPY( roll +/- PI, PI-pitch, yaw +/- PI )
|
| 435 |
+
* - angles + 2*k*PI
|
| 436 |
+
*/
|
| 437 |
+
static Rotation RPY(double roll,double pitch,double yaw);
|
| 438 |
+
|
| 439 |
+
/** Gives back a vector in RPY coordinates, variables are bound by
|
| 440 |
+
- -PI <= roll <= PI
|
| 441 |
+
- -PI <= Yaw <= PI
|
| 442 |
+
- -PI/2 <= PITCH <= PI/2
|
| 443 |
+
|
| 444 |
+
convention :
|
| 445 |
+
- first rotate around X with roll,
|
| 446 |
+
- then around the old Y with pitch,
|
| 447 |
+
- then around old Z with yaw
|
| 448 |
+
|
| 449 |
+
if pitch == PI/2 or pitch == -PI/2, multiple solutions for gamma and alpha exist. The solution where roll==0
|
| 450 |
+
is chosen.
|
| 451 |
+
|
| 452 |
+
Invariants:
|
| 453 |
+
- RPY(roll,pitch,yaw) == RPY( roll +/- PI, PI-pitch, yaw +/- PI )
|
| 454 |
+
- angles + 2*k*PI
|
| 455 |
+
|
| 456 |
+
**/
|
| 457 |
+
void GetRPY(double& roll,double& pitch,double& yaw) const;
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
/** EulerZYX constructs a Rotation from the Euler ZYX parameters:
|
| 461 |
+
* - First rotate around Z with alfa,
|
| 462 |
+
* - then around the new Y with beta,
|
| 463 |
+
* - then around new X with gamma.
|
| 464 |
+
*
|
| 465 |
+
* Closely related to RPY-convention.
|
| 466 |
+
*
|
| 467 |
+
* Invariants:
|
| 468 |
+
* - EulerZYX(alpha,beta,gamma) == EulerZYX(alpha +/- PI, PI-beta, gamma +/- PI)
|
| 469 |
+
* - (angle + 2*k*PI)
|
| 470 |
+
**/
|
| 471 |
+
inline static Rotation EulerZYX(double Alfa,double Beta,double Gamma) {
|
| 472 |
+
return RPY(Gamma,Beta,Alfa);
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
/** GetEulerZYX gets the euler ZYX parameters of a rotation :
|
| 476 |
+
* First rotate around Z with alfa,
|
| 477 |
+
* then around the new Y with beta, then around
|
| 478 |
+
* new X with gamma.
|
| 479 |
+
*
|
| 480 |
+
* Range of the results of GetEulerZYX :
|
| 481 |
+
* - -PI <= alfa <= PI
|
| 482 |
+
* - -PI <= gamma <= PI
|
| 483 |
+
* - -PI/2 <= beta <= PI/2
|
| 484 |
+
*
|
| 485 |
+
* if beta == PI/2 or beta == -PI/2, multiple solutions for gamma and alpha exist. The solution where gamma==0
|
| 486 |
+
* is chosen.
|
| 487 |
+
*
|
| 488 |
+
*
|
| 489 |
+
* Invariants:
|
| 490 |
+
* - EulerZYX(alpha,beta,gamma) == EulerZYX(alpha +/- PI, PI-beta, gamma +/- PI)
|
| 491 |
+
* - and also (angle + 2*k*PI)
|
| 492 |
+
*
|
| 493 |
+
* Closely related to RPY-convention.
|
| 494 |
+
**/
|
| 495 |
+
inline void GetEulerZYX(double& Alfa,double& Beta,double& Gamma) const {
|
| 496 |
+
GetRPY(Gamma,Beta,Alfa);
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
//! Transformation of the base to which the twist is expressed.
|
| 500 |
+
//! Complexity : 18M+12A
|
| 501 |
+
//! @see Frame*Twist for a transformation that also transforms
|
| 502 |
+
//! the velocity reference point.
|
| 503 |
+
inline Twist operator * (const Twist& arg) const;
|
| 504 |
+
|
| 505 |
+
//! Transformation of the base to which the wrench is expressed.
|
| 506 |
+
//! Complexity : 18M+12A
|
| 507 |
+
//! @see Frame*Wrench for a transformation that also transforms
|
| 508 |
+
//! the force reference point.
|
| 509 |
+
inline Wrench operator * (const Wrench& arg) const;
|
| 510 |
+
|
| 511 |
+
//! Access to the underlying unitvectors of the rotation matrix
|
| 512 |
+
inline Vector UnitX() const {
|
| 513 |
+
return Vector(data[0],data[3],data[6]);
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
//! Access to the underlying unitvectors of the rotation matrix
|
| 517 |
+
inline void UnitX(const Vector& X) {
|
| 518 |
+
data[0] = X(0);
|
| 519 |
+
data[3] = X(1);
|
| 520 |
+
data[6] = X(2);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
//! Access to the underlying unitvectors of the rotation matrix
|
| 524 |
+
inline Vector UnitY() const {
|
| 525 |
+
return Vector(data[1],data[4],data[7]);
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
//! Access to the underlying unitvectors of the rotation matrix
|
| 529 |
+
inline void UnitY(const Vector& X) {
|
| 530 |
+
data[1] = X(0);
|
| 531 |
+
data[4] = X(1);
|
| 532 |
+
data[7] = X(2);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
//! Access to the underlying unitvectors of the rotation matrix
|
| 536 |
+
inline Vector UnitZ() const {
|
| 537 |
+
return Vector(data[2],data[5],data[8]);
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
//! Access to the underlying unitvectors of the rotation matrix
|
| 541 |
+
inline void UnitZ(const Vector& X) {
|
| 542 |
+
data[2] = X(0);
|
| 543 |
+
data[5] = X(1);
|
| 544 |
+
data[8] = X(2);
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 548 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 549 |
+
friend bool Equal(const Rotation& a,const Rotation& b,double eps);
|
| 550 |
+
|
| 551 |
+
//! The literal equality operator==(), also identical.
|
| 552 |
+
friend bool operator==(const Rotation& a,const Rotation& b);
|
| 553 |
+
//! The literal inequality operator!=()
|
| 554 |
+
friend bool operator!=(const Rotation& a,const Rotation& b);
|
| 555 |
+
|
| 556 |
+
friend class Frame;
|
| 557 |
+
};
|
| 558 |
+
bool operator==(const Rotation& a,const Rotation& b);
|
| 559 |
+
bool Equal(const Rotation& a,const Rotation& b,double eps=epsilon);
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
/**
|
| 564 |
+
\brief represents a frame transformation in 3D space (rotation + translation)
|
| 565 |
+
|
| 566 |
+
if V2 = Frame*V1 (V2 expressed in frame A, V1 expressed in frame B)
|
| 567 |
+
then V2 = Frame.M*V1+Frame.p
|
| 568 |
+
|
| 569 |
+
Frame.M contains columns that represent the axes of frame B wrt frame A
|
| 570 |
+
Frame.p contains the origin of frame B expressed in frame A.
|
| 571 |
+
*/
|
| 572 |
+
class Frame {
|
| 573 |
+
public:
|
| 574 |
+
Vector p; //!< origine of the Frame
|
| 575 |
+
Rotation M; //!< Orientation of the Frame
|
| 576 |
+
|
| 577 |
+
public:
|
| 578 |
+
|
| 579 |
+
inline Frame(const Rotation& R,const Vector& V);
|
| 580 |
+
|
| 581 |
+
//! The rotation matrix defaults to identity
|
| 582 |
+
explicit inline Frame(const Vector& V);
|
| 583 |
+
//! The position matrix defaults to zero
|
| 584 |
+
explicit inline Frame(const Rotation& R);
|
| 585 |
+
|
| 586 |
+
inline Frame() {}
|
| 587 |
+
//! The copy constructor. Normal copy by value semantics.
|
| 588 |
+
inline Frame(const Frame& arg);
|
| 589 |
+
|
| 590 |
+
//! Reads data from an double array
|
| 591 |
+
//\TODO should be formulated as a constructor
|
| 592 |
+
void Make4x4(double* d);
|
| 593 |
+
|
| 594 |
+
//! Treats a frame as a 4x4 matrix and returns element i,j
|
| 595 |
+
//! Access to elements 0..3,0..3, bounds are checked when NDEBUG is not set
|
| 596 |
+
inline double operator()(int i,int j);
|
| 597 |
+
|
| 598 |
+
//! Treats a frame as a 4x4 matrix and returns element i,j
|
| 599 |
+
//! Access to elements 0..3,0..3, bounds are checked when NDEBUG is not set
|
| 600 |
+
inline double operator() (int i,int j) const;
|
| 601 |
+
|
| 602 |
+
// = Inverse
|
| 603 |
+
//! Gives back inverse transformation of a Frame
|
| 604 |
+
inline Frame Inverse() const;
|
| 605 |
+
|
| 606 |
+
//! The same as p2=R.Inverse()*p but more efficient.
|
| 607 |
+
inline Vector Inverse(const Vector& arg) const;
|
| 608 |
+
|
| 609 |
+
//! The same as p2=R.Inverse()*p but more efficient.
|
| 610 |
+
inline Wrench Inverse(const Wrench& arg) const;
|
| 611 |
+
|
| 612 |
+
//! The same as p2=R.Inverse()*p but more efficient.
|
| 613 |
+
inline Twist Inverse(const Twist& arg) const;
|
| 614 |
+
|
| 615 |
+
//! Normal copy-by-value semantics.
|
| 616 |
+
inline Frame& operator = (const Frame& arg);
|
| 617 |
+
|
| 618 |
+
//! Transformation of the base to which the vector
|
| 619 |
+
//! is expressed.
|
| 620 |
+
inline Vector operator * (const Vector& arg) const;
|
| 621 |
+
|
| 622 |
+
//! Transformation of both the force reference point
|
| 623 |
+
//! and of the base to which the wrench is expressed.
|
| 624 |
+
//! look at Rotation*Wrench operator for a transformation
|
| 625 |
+
//! of only the base to which the twist is expressed.
|
| 626 |
+
//!
|
| 627 |
+
//! Complexity : 24M+18A
|
| 628 |
+
inline Wrench operator * (const Wrench& arg) const;
|
| 629 |
+
|
| 630 |
+
//! Transformation of both the velocity reference point
|
| 631 |
+
//! and of the base to which the twist is expressed.
|
| 632 |
+
//! look at Rotation*Twist for a transformation of only the
|
| 633 |
+
//! base to which the twist is expressed.
|
| 634 |
+
//!
|
| 635 |
+
//! Complexity : 24M+18A
|
| 636 |
+
inline Twist operator * (const Twist& arg) const;
|
| 637 |
+
|
| 638 |
+
//! Composition of two frames.
|
| 639 |
+
inline friend Frame operator *(const Frame& lhs,const Frame& rhs);
|
| 640 |
+
|
| 641 |
+
//! @return the identity transformation Frame(Rotation::Identity(),Vector::Zero()).
|
| 642 |
+
inline static Frame Identity();
|
| 643 |
+
|
| 644 |
+
//! The twist <t_this> is expressed wrt the current
|
| 645 |
+
//! frame. This frame is integrated into an updated frame with
|
| 646 |
+
//! <samplefrequency>. Very simple first order integration rule.
|
| 647 |
+
inline void Integrate(const Twist& t_this,double frequency);
|
| 648 |
+
|
| 649 |
+
/*
|
| 650 |
+
// DH_Craig1989 : constructs a transformationmatrix
|
| 651 |
+
// T_link(i-1)_link(i) with the Denavit-Hartenberg convention as
|
| 652 |
+
// described in the Craigs book: Craig, J. J.,Introduction to
|
| 653 |
+
// Robotics: Mechanics and Control, Addison-Wesley,
|
| 654 |
+
// isbn:0-201-10326-5, 1986.
|
| 655 |
+
//
|
| 656 |
+
// Note that the frame is a redundant way to express the information
|
| 657 |
+
// in the DH-convention.
|
| 658 |
+
// \verbatim
|
| 659 |
+
// Parameters in full : a(i-1),alpha(i-1),d(i),theta(i)
|
| 660 |
+
//
|
| 661 |
+
// axis i-1 is connected by link i-1 to axis i numbering axis 1
|
| 662 |
+
// to axis n link 0 (immobile base) to link n
|
| 663 |
+
//
|
| 664 |
+
// link length a(i-1) length of the mutual perpendicular line
|
| 665 |
+
// (normal) between the 2 axes. This normal runs from (i-1) to
|
| 666 |
+
// (i) axis.
|
| 667 |
+
//
|
| 668 |
+
// link twist alpha(i-1): construct plane perpendicular to the
|
| 669 |
+
// normal project axis(i-1) and axis(i) into plane angle from
|
| 670 |
+
// (i-1) to (i) measured in the direction of the normal
|
| 671 |
+
//
|
| 672 |
+
// link offset d(i) signed distance between normal (i-1) to (i)
|
| 673 |
+
// and normal (i) to (i+1) along axis i joint angle theta(i)
|
| 674 |
+
// signed angle between normal (i-1) to (i) and normal (i) to
|
| 675 |
+
// (i+1) along axis i
|
| 676 |
+
//
|
| 677 |
+
// First and last joints : a(0)= a(n) = 0
|
| 678 |
+
// alpha(0) = alpha(n) = 0
|
| 679 |
+
//
|
| 680 |
+
// PRISMATIC : theta(1) = 0 d(1) arbitrarily
|
| 681 |
+
//
|
| 682 |
+
// REVOLUTE : theta(1) arbitrarily d(1) = 0
|
| 683 |
+
//
|
| 684 |
+
// Not unique : if intersecting joint axis 2 choices for normal
|
| 685 |
+
// Frame assignment of the DH convention : Z(i-1) follows axis
|
| 686 |
+
// (i-1) X(i-1) is the normal between axis(i-1) and axis(i)
|
| 687 |
+
// Y(i-1) follows out of Z(i-1) and X(i-1)
|
| 688 |
+
//
|
| 689 |
+
// a(i-1) = distance from Z(i-1) to Z(i) along X(i-1)
|
| 690 |
+
// alpha(i-1) = angle between Z(i-1) to Z(i) along X(i-1)
|
| 691 |
+
// d(i) = distance from X(i-1) to X(i) along Z(i)
|
| 692 |
+
// theta(i) = angle between X(i-1) to X(i) along X(i)
|
| 693 |
+
// \endverbatim
|
| 694 |
+
*/
|
| 695 |
+
static Frame DH_Craig1989(double a,double alpha,double d,double theta);
|
| 696 |
+
|
| 697 |
+
// DH : constructs a transformationmatrix T_link(i-1)_link(i) with
|
| 698 |
+
// the Denavit-Hartenberg convention as described in the original
|
| 699 |
+
// publictation: Denavit, J. and Hartenberg, R. S., A kinematic
|
| 700 |
+
// notation for lower-pair mechanisms based on matrices, ASME
|
| 701 |
+
// Journal of Applied Mechanics, 23:215-221, 1955.
|
| 702 |
+
|
| 703 |
+
static Frame DH(double a,double alpha,double d,double theta);
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 707 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 708 |
+
inline friend bool Equal(const Frame& a,const Frame& b,double eps);
|
| 709 |
+
|
| 710 |
+
//! The literal equality operator==(), also identical.
|
| 711 |
+
inline friend bool operator==(const Frame& a,const Frame& b);
|
| 712 |
+
//! The literal inequality operator!=().
|
| 713 |
+
inline friend bool operator!=(const Frame& a,const Frame& b);
|
| 714 |
+
};
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
/**
|
| 718 |
+
* \brief represents both translational and rotational velocities.
|
| 719 |
+
*
|
| 720 |
+
* This class represents a twist. A twist is the combination of translational
|
| 721 |
+
* velocity and rotational velocity applied at one point.
|
| 722 |
+
*/
|
| 723 |
+
class Twist {
|
| 724 |
+
public:
|
| 725 |
+
Vector vel; //!< The velocity of that point
|
| 726 |
+
Vector rot; //!< The rotational velocity of that point.
|
| 727 |
+
public:
|
| 728 |
+
|
| 729 |
+
//! The default constructor initialises to Zero via the constructor of Vector.
|
| 730 |
+
Twist():vel(),rot() {};
|
| 731 |
+
|
| 732 |
+
Twist(const Vector& _vel,const Vector& _rot):vel(_vel),rot(_rot) {};
|
| 733 |
+
|
| 734 |
+
inline Twist& operator-=(const Twist& arg);
|
| 735 |
+
inline Twist& operator+=(const Twist& arg);
|
| 736 |
+
//! index-based access to components, first vel(0..2), then rot(3..5)
|
| 737 |
+
inline double& operator()(int i);
|
| 738 |
+
|
| 739 |
+
//! index-based access to components, first vel(0..2), then rot(3..5)
|
| 740 |
+
//! For use with a const Twist
|
| 741 |
+
inline double operator()(int i) const;
|
| 742 |
+
|
| 743 |
+
double operator[] ( int index ) const
|
| 744 |
+
{
|
| 745 |
+
return this->operator() ( index );
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
double& operator[] ( int index )
|
| 749 |
+
{
|
| 750 |
+
return this->operator() ( index );
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
inline friend Twist operator*(const Twist& lhs,double rhs);
|
| 754 |
+
inline friend Twist operator*(double lhs,const Twist& rhs);
|
| 755 |
+
inline friend Twist operator/(const Twist& lhs,double rhs);
|
| 756 |
+
inline friend Twist operator+(const Twist& lhs,const Twist& rhs);
|
| 757 |
+
inline friend Twist operator-(const Twist& lhs,const Twist& rhs);
|
| 758 |
+
inline friend Twist operator-(const Twist& arg);
|
| 759 |
+
inline friend double dot(const Twist& lhs,const Wrench& rhs);
|
| 760 |
+
inline friend double dot(const Wrench& rhs,const Twist& lhs);
|
| 761 |
+
inline friend void SetToZero(Twist& v);
|
| 762 |
+
/// Spatial cross product for 6d motion vectors, beware all of them have to be expressed in the same reference frame/point
|
| 763 |
+
inline friend Twist operator*(const Twist& lhs,const Twist& rhs);
|
| 764 |
+
/// Spatial cross product for 6d force vectors, beware all of them have to be expressed in the same reference frame/point
|
| 765 |
+
inline friend Wrench operator*(const Twist& lhs,const Wrench& rhs);
|
| 766 |
+
|
| 767 |
+
//! @return a zero Twist : Twist(Vector::Zero(),Vector::Zero())
|
| 768 |
+
static inline Twist Zero();
|
| 769 |
+
|
| 770 |
+
//! Reverses the sign of the twist
|
| 771 |
+
inline void ReverseSign();
|
| 772 |
+
|
| 773 |
+
//! Changes the reference point of the twist.
|
| 774 |
+
//! The vector v_base_AB is expressed in the same base as the twist
|
| 775 |
+
//! The vector v_base_AB is a vector from the old point to
|
| 776 |
+
//! the new point.
|
| 777 |
+
//!
|
| 778 |
+
//! Complexity : 6M+6A
|
| 779 |
+
inline Twist RefPoint(const Vector& v_base_AB) const;
|
| 780 |
+
|
| 781 |
+
|
| 782 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 783 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 784 |
+
inline friend bool Equal(const Twist& a,const Twist& b,double eps);
|
| 785 |
+
|
| 786 |
+
//! The literal equality operator==(), also identical.
|
| 787 |
+
inline friend bool operator==(const Twist& a,const Twist& b);
|
| 788 |
+
//! The literal inequality operator!=().
|
| 789 |
+
inline friend bool operator!=(const Twist& a,const Twist& b);
|
| 790 |
+
|
| 791 |
+
// = Friends
|
| 792 |
+
friend class Rotation;
|
| 793 |
+
friend class Frame;
|
| 794 |
+
};
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
/**
|
| 798 |
+
* \brief represents both translational and rotational acceleration.
|
| 799 |
+
*
|
| 800 |
+
* This class represents an acceleration twist. A acceleration twist is
|
| 801 |
+
* the combination of translational
|
| 802 |
+
* acceleration and rotational acceleration applied at one point.
|
| 803 |
+
*/
|
| 804 |
+
/*
|
| 805 |
+
class AccelerationTwist {
|
| 806 |
+
public:
|
| 807 |
+
Vector trans; //!< The translational acceleration of that point
|
| 808 |
+
Vector rot; //!< The rotational acceleration of that point.
|
| 809 |
+
public:
|
| 810 |
+
|
| 811 |
+
//! The default constructor initialises to Zero via the constructor of Vector.
|
| 812 |
+
AccelerationTwist():trans(),rot() {};
|
| 813 |
+
|
| 814 |
+
AccelerationTwist(const Vector& _trans,const Vector& _rot):trans(_trans),rot(_rot) {};
|
| 815 |
+
|
| 816 |
+
inline AccelerationTwist& operator-=(const AccelerationTwist& arg);
|
| 817 |
+
inline AccelerationTwist& operator+=(const AccelerationTwist& arg);
|
| 818 |
+
//! index-based access to components, first vel(0..2), then rot(3..5)
|
| 819 |
+
inline double& operator()(int i);
|
| 820 |
+
|
| 821 |
+
//! index-based access to components, first vel(0..2), then rot(3..5)
|
| 822 |
+
//! For use with a const AccelerationTwist
|
| 823 |
+
inline double operator()(int i) const;
|
| 824 |
+
|
| 825 |
+
double operator[] ( int index ) const
|
| 826 |
+
{
|
| 827 |
+
return this->operator() ( index );
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
double& operator[] ( int index )
|
| 831 |
+
{
|
| 832 |
+
return this->operator() ( index );
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
inline friend AccelerationTwist operator*(const AccelerationTwist& lhs,double rhs);
|
| 836 |
+
inline friend AccelerationTwist operator*(double lhs,const AccelerationTwist& rhs);
|
| 837 |
+
inline friend AccelerationTwist operator/(const AccelerationTwist& lhs,double rhs);
|
| 838 |
+
inline friend AccelerationTwist operator+(const AccelerationTwist& lhs,const AccelerationTwist& rhs);
|
| 839 |
+
inline friend AccelerationTwist operator-(const AccelerationTwist& lhs,const AccelerationTwist& rhs);
|
| 840 |
+
inline friend AccelerationTwist operator-(const AccelerationTwist& arg);
|
| 841 |
+
//inline friend double dot(const AccelerationTwist& lhs,const Wrench& rhs);
|
| 842 |
+
//inline friend double dot(const Wrench& rhs,const AccelerationTwist& lhs);
|
| 843 |
+
inline friend void SetToZero(AccelerationTwist& v);
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
//! @return a zero AccelerationTwist : AccelerationTwist(Vector::Zero(),Vector::Zero())
|
| 847 |
+
static inline AccelerationTwist Zero();
|
| 848 |
+
|
| 849 |
+
//! Reverses the sign of the AccelerationTwist
|
| 850 |
+
inline void ReverseSign();
|
| 851 |
+
|
| 852 |
+
//! Changes the reference point of the AccelerationTwist.
|
| 853 |
+
//! The vector v_base_AB is expressed in the same base as the AccelerationTwist
|
| 854 |
+
//! The vector v_base_AB is a vector from the old point to
|
| 855 |
+
//! the new point.
|
| 856 |
+
//!
|
| 857 |
+
//! Complexity : 6M+6A
|
| 858 |
+
inline AccelerationTwist RefPoint(const Vector& v_base_AB) const;
|
| 859 |
+
|
| 860 |
+
|
| 861 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 862 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 863 |
+
inline friend bool Equal(const AccelerationTwist& a,const AccelerationTwist& b,double eps=epsilon);
|
| 864 |
+
|
| 865 |
+
//! The literal equality operator==(), also identical.
|
| 866 |
+
inline friend bool operator==(const AccelerationTwist& a,const AccelerationTwist& b);
|
| 867 |
+
//! The literal inequality operator!=().
|
| 868 |
+
inline friend bool operator!=(const AccelerationTwist& a,const AccelerationTwist& b);
|
| 869 |
+
|
| 870 |
+
// = Friends
|
| 871 |
+
friend class Rotation;
|
| 872 |
+
friend class Frame;
|
| 873 |
+
|
| 874 |
+
};
|
| 875 |
+
*/
|
| 876 |
+
/**
|
| 877 |
+
* \brief represents the combination of a force and a torque.
|
| 878 |
+
*
|
| 879 |
+
* This class represents a Wrench. A Wrench is the force and torque applied at a point
|
| 880 |
+
*/
|
| 881 |
+
class Wrench
|
| 882 |
+
{
|
| 883 |
+
public:
|
| 884 |
+
Vector force; //!< Force that is applied at the origin of the current ref frame
|
| 885 |
+
Vector torque; //!< Torque that is applied at the origin of the current ref frame
|
| 886 |
+
public:
|
| 887 |
+
|
| 888 |
+
//! Does initialise force and torque to zero via the underlying constructor of Vector
|
| 889 |
+
Wrench():force(),torque() {};
|
| 890 |
+
Wrench(const Vector& _force,const Vector& _torque):force(_force),torque(_torque) {};
|
| 891 |
+
|
| 892 |
+
// = Operators
|
| 893 |
+
inline Wrench& operator-=(const Wrench& arg);
|
| 894 |
+
inline Wrench& operator+=(const Wrench& arg);
|
| 895 |
+
|
| 896 |
+
//! index-based access to components, first force(0..2), then torque(3..5)
|
| 897 |
+
inline double& operator()(int i);
|
| 898 |
+
|
| 899 |
+
//! index-based access to components, first force(0..2), then torque(3..5)
|
| 900 |
+
//! for use with a const Wrench
|
| 901 |
+
inline double operator()(int i) const;
|
| 902 |
+
|
| 903 |
+
double operator[] ( int index ) const
|
| 904 |
+
{
|
| 905 |
+
return this->operator() ( index );
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
double& operator[] ( int index )
|
| 909 |
+
{
|
| 910 |
+
return this->operator() ( index );
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
//! Scalar multiplication
|
| 914 |
+
inline friend Wrench operator*(const Wrench& lhs,double rhs);
|
| 915 |
+
//! Scalar multiplication
|
| 916 |
+
inline friend Wrench operator*(double lhs,const Wrench& rhs);
|
| 917 |
+
//! Scalar division
|
| 918 |
+
inline friend Wrench operator/(const Wrench& lhs,double rhs);
|
| 919 |
+
|
| 920 |
+
inline friend Wrench operator+(const Wrench& lhs,const Wrench& rhs);
|
| 921 |
+
inline friend Wrench operator-(const Wrench& lhs,const Wrench& rhs);
|
| 922 |
+
|
| 923 |
+
//! An unary - operator
|
| 924 |
+
inline friend Wrench operator-(const Wrench& arg);
|
| 925 |
+
|
| 926 |
+
//! Sets the Wrench to Zero, to have a uniform function that sets an object or
|
| 927 |
+
//! double to zero.
|
| 928 |
+
inline friend void SetToZero(Wrench& v);
|
| 929 |
+
|
| 930 |
+
//! @return a zero Wrench
|
| 931 |
+
static inline Wrench Zero();
|
| 932 |
+
|
| 933 |
+
//! Reverses the sign of the current Wrench
|
| 934 |
+
inline void ReverseSign();
|
| 935 |
+
|
| 936 |
+
//! Changes the reference point of the wrench.
|
| 937 |
+
//! The vector v_base_AB is expressed in the same base as the twist
|
| 938 |
+
//! The vector v_base_AB is a vector from the old point to
|
| 939 |
+
//! the new point.
|
| 940 |
+
//!
|
| 941 |
+
//! Complexity : 6M+6A
|
| 942 |
+
inline Wrench RefPoint(const Vector& v_base_AB) const;
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 946 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 947 |
+
inline friend bool Equal(const Wrench& a,const Wrench& b,double eps);
|
| 948 |
+
|
| 949 |
+
//! The literal equality operator==(), also identical.
|
| 950 |
+
inline friend bool operator==(const Wrench& a,const Wrench& b);
|
| 951 |
+
//! The literal inequality operator!=().
|
| 952 |
+
inline friend bool operator!=(const Wrench& a,const Wrench& b);
|
| 953 |
+
|
| 954 |
+
friend class Rotation;
|
| 955 |
+
friend class Frame;
|
| 956 |
+
};
|
| 957 |
+
|
| 958 |
+
|
| 959 |
+
//! 2D version of Vector
|
| 960 |
+
class Vector2
|
| 961 |
+
{
|
| 962 |
+
double data[2];
|
| 963 |
+
public:
|
| 964 |
+
//! Does not initialise to Zero().
|
| 965 |
+
Vector2() {data[0]=data[1] = 0.0;}
|
| 966 |
+
inline Vector2(double x,double y);
|
| 967 |
+
inline Vector2(const Vector2& arg);
|
| 968 |
+
|
| 969 |
+
inline Vector2& operator = ( const Vector2& arg);
|
| 970 |
+
|
| 971 |
+
//! Access to elements, range checked when NDEBUG is not set, from 0..1
|
| 972 |
+
inline double operator()(int index) const;
|
| 973 |
+
|
| 974 |
+
//! Access to elements, range checked when NDEBUG is not set, from 0..1
|
| 975 |
+
inline double& operator() (int index);
|
| 976 |
+
|
| 977 |
+
//! Equivalent to double operator()(int index) const
|
| 978 |
+
double operator[] ( int index ) const
|
| 979 |
+
{
|
| 980 |
+
return this->operator() ( index );
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
//! Equivalent to double& operator()(int index)
|
| 984 |
+
double& operator[] ( int index )
|
| 985 |
+
{
|
| 986 |
+
return this->operator() ( index );
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
inline double x() const;
|
| 990 |
+
inline double y() const;
|
| 991 |
+
inline void x(double);
|
| 992 |
+
inline void y(double);
|
| 993 |
+
|
| 994 |
+
inline void ReverseSign();
|
| 995 |
+
inline Vector2& operator-=(const Vector2& arg);
|
| 996 |
+
inline Vector2& operator +=(const Vector2& arg);
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
inline friend Vector2 operator*(const Vector2& lhs,double rhs);
|
| 1000 |
+
inline friend Vector2 operator*(double lhs,const Vector2& rhs);
|
| 1001 |
+
inline friend Vector2 operator/(const Vector2& lhs,double rhs);
|
| 1002 |
+
inline friend Vector2 operator+(const Vector2& lhs,const Vector2& rhs);
|
| 1003 |
+
inline friend Vector2 operator-(const Vector2& lhs,const Vector2& rhs);
|
| 1004 |
+
inline friend Vector2 operator*(const Vector2& lhs,const Vector2& rhs);
|
| 1005 |
+
inline friend Vector2 operator-(const Vector2& arg);
|
| 1006 |
+
inline friend void SetToZero(Vector2& v);
|
| 1007 |
+
|
| 1008 |
+
//! @return a zero 2D vector.
|
| 1009 |
+
inline static Vector2 Zero();
|
| 1010 |
+
|
| 1011 |
+
/** Normalizes this vector and returns it norm
|
| 1012 |
+
* makes v a unitvector and returns the norm of v.
|
| 1013 |
+
* if v is smaller than eps, Vector(1,0,0) is returned with norm 0.
|
| 1014 |
+
* if this is not good, check the return value of this method.
|
| 1015 |
+
*/
|
| 1016 |
+
double Normalize(double eps=epsilon);
|
| 1017 |
+
|
| 1018 |
+
//! @return the norm of the vector
|
| 1019 |
+
double Norm(double eps=epsilon) const;
|
| 1020 |
+
|
| 1021 |
+
//! projects v in its XY plane, and sets *this to these values
|
| 1022 |
+
inline void Set3DXY(const Vector& v);
|
| 1023 |
+
|
| 1024 |
+
//! projects v in its YZ plane, and sets *this to these values
|
| 1025 |
+
inline void Set3DYZ(const Vector& v);
|
| 1026 |
+
|
| 1027 |
+
//! projects v in its ZX plane, and sets *this to these values
|
| 1028 |
+
inline void Set3DZX(const Vector& v);
|
| 1029 |
+
|
| 1030 |
+
//! projects v_someframe in the XY plane of F_someframe_XY,
|
| 1031 |
+
//! and sets *this to these values
|
| 1032 |
+
//! expressed wrt someframe.
|
| 1033 |
+
inline void Set3DPlane(const Frame& F_someframe_XY,const Vector& v_someframe);
|
| 1034 |
+
|
| 1035 |
+
|
| 1036 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 1037 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 1038 |
+
inline friend bool Equal(const Vector2& a,const Vector2& b,double eps);
|
| 1039 |
+
|
| 1040 |
+
//! The literal equality operator==(), also identical.
|
| 1041 |
+
inline friend bool operator==(const Vector2& a,const Vector2& b);
|
| 1042 |
+
//! The literal inequality operator!=().
|
| 1043 |
+
inline friend bool operator!=(const Vector2& a,const Vector2& b);
|
| 1044 |
+
|
| 1045 |
+
friend class Rotation2;
|
| 1046 |
+
};
|
| 1047 |
+
|
| 1048 |
+
|
| 1049 |
+
//! A 2D Rotation class, for conventions see Rotation. For further documentation
|
| 1050 |
+
//! of the methods see Rotation class.
|
| 1051 |
+
class Rotation2
|
| 1052 |
+
{
|
| 1053 |
+
double s,c;
|
| 1054 |
+
//! c,s represent cos(angle), sin(angle), this also represents first col. of rot matrix
|
| 1055 |
+
//! from outside, this class behaves as if it would store the complete 2x2 matrix.
|
| 1056 |
+
public:
|
| 1057 |
+
//! Default constructor does NOT initialise to Zero().
|
| 1058 |
+
Rotation2() {c=1.0;s=0.0;}
|
| 1059 |
+
|
| 1060 |
+
explicit Rotation2(double angle_rad):s(sin(angle_rad)),c(cos(angle_rad)) {}
|
| 1061 |
+
|
| 1062 |
+
Rotation2(double ca,double sa):s(sa),c(ca){}
|
| 1063 |
+
|
| 1064 |
+
Rotation2(const Rotation2& arg);
|
| 1065 |
+
|
| 1066 |
+
inline Rotation2& operator=(const Rotation2& arg);
|
| 1067 |
+
inline Vector2 operator*(const Vector2& v) const;
|
| 1068 |
+
//! Access to elements 0..1,0..1, bounds are checked when NDEBUG is not set
|
| 1069 |
+
inline double operator() (int i,int j) const;
|
| 1070 |
+
|
| 1071 |
+
inline friend Rotation2 operator *(const Rotation2& lhs,const Rotation2& rhs);
|
| 1072 |
+
|
| 1073 |
+
inline void SetInverse();
|
| 1074 |
+
inline Rotation2 Inverse() const;
|
| 1075 |
+
inline Vector2 Inverse(const Vector2& v) const;
|
| 1076 |
+
|
| 1077 |
+
inline void SetIdentity();
|
| 1078 |
+
inline static Rotation2 Identity();
|
| 1079 |
+
|
| 1080 |
+
|
| 1081 |
+
//! The SetRot.. functions set the value of *this to the appropriate rotation matrix.
|
| 1082 |
+
inline void SetRot(double angle);
|
| 1083 |
+
|
| 1084 |
+
//! The Rot... static functions give the value of the appropriate rotation matrix bac
|
| 1085 |
+
inline static Rotation2 Rot(double angle);
|
| 1086 |
+
|
| 1087 |
+
//! Gets the angle (in radians)
|
| 1088 |
+
inline double GetRot() const;
|
| 1089 |
+
|
| 1090 |
+
//! do not use operator == because the definition of Equal(.,.) is slightly
|
| 1091 |
+
//! different. It compares whether the 2 arguments are equal in an eps-interval
|
| 1092 |
+
inline friend bool Equal(const Rotation2& a,const Rotation2& b,double eps);
|
| 1093 |
+
};
|
| 1094 |
+
|
| 1095 |
+
|
| 1096 |
+
//! A 2D frame class, for further documentation see the Frames class
|
| 1097 |
+
//! for methods with unchanged semantics.
|
| 1098 |
+
class Frame2
|
| 1099 |
+
{
|
| 1100 |
+
public:
|
| 1101 |
+
Vector2 p; //!< origine of the Frame
|
| 1102 |
+
Rotation2 M; //!< Orientation of the Frame
|
| 1103 |
+
|
| 1104 |
+
public:
|
| 1105 |
+
|
| 1106 |
+
inline Frame2(const Rotation2& R,const Vector2& V);
|
| 1107 |
+
explicit inline Frame2(const Vector2& V);
|
| 1108 |
+
explicit inline Frame2(const Rotation2& R);
|
| 1109 |
+
inline Frame2(void);
|
| 1110 |
+
inline Frame2(const Frame2& arg);
|
| 1111 |
+
inline void Make4x4(double* d);
|
| 1112 |
+
|
| 1113 |
+
//! Treats a frame as a 3x3 matrix and returns element i,j
|
| 1114 |
+
//! Access to elements 0..2,0..2, bounds are checked when NDEBUG is not set
|
| 1115 |
+
inline double operator()(int i,int j);
|
| 1116 |
+
|
| 1117 |
+
//! Treats a frame as a 4x4 matrix and returns element i,j
|
| 1118 |
+
//! Access to elements 0..3,0..3, bounds are checked when NDEBUG is not set
|
| 1119 |
+
inline double operator() (int i,int j) const;
|
| 1120 |
+
|
| 1121 |
+
inline void SetInverse();
|
| 1122 |
+
inline Frame2 Inverse() const;
|
| 1123 |
+
inline Vector2 Inverse(const Vector2& arg) const;
|
| 1124 |
+
inline Frame2& operator = (const Frame2& arg);
|
| 1125 |
+
inline Vector2 operator * (const Vector2& arg) const;
|
| 1126 |
+
inline friend Frame2 operator *(const Frame2& lhs,const Frame2& rhs);
|
| 1127 |
+
inline void SetIdentity();
|
| 1128 |
+
inline void Integrate(const Twist& t_this,double frequency);
|
| 1129 |
+
inline static Frame2 Identity() {
|
| 1130 |
+
Frame2 tmp;
|
| 1131 |
+
tmp.SetIdentity();
|
| 1132 |
+
return tmp;
|
| 1133 |
+
}
|
| 1134 |
+
inline friend bool Equal(const Frame2& a,const Frame2& b,double eps);
|
| 1135 |
+
};
|
| 1136 |
+
|
| 1137 |
+
/**
|
| 1138 |
+
* determines the difference of vector b with vector a.
|
| 1139 |
+
*
|
| 1140 |
+
* see diff for Rotation matrices for further background information.
|
| 1141 |
+
*
|
| 1142 |
+
* \param p_w_a start vector a expressed to some frame w
|
| 1143 |
+
* \param p_w_b end vector b expressed to some frame w .
|
| 1144 |
+
* \param dt [optional][obsolete] time interval over which the numerical differentiation takes place.
|
| 1145 |
+
* \return the difference (b-a) expressed to the frame w.
|
| 1146 |
+
*/
|
| 1147 |
+
IMETHOD Vector diff(const Vector& p_w_a,const Vector& p_w_b,double dt=1);
|
| 1148 |
+
|
| 1149 |
+
|
| 1150 |
+
/**
|
| 1151 |
+
* determines the (scaled) rotation axis necessary to rotate from b1 to b2.
|
| 1152 |
+
*
|
| 1153 |
+
* This rotation axis is expressed w.r.t. frame a. The rotation axis is scaled
|
| 1154 |
+
* by the necessary rotation angle. The rotation angle is always in the
|
| 1155 |
+
* (inclusive) interval \f$ [0 , \pi] \f$.
|
| 1156 |
+
*
|
| 1157 |
+
* This definition is chosen in this way to facilitate numerical differentiation.
|
| 1158 |
+
* With this definition diff(a,b) == -diff(b,a).
|
| 1159 |
+
*
|
| 1160 |
+
* The diff() function is overloaded for all classes in frames.hpp and framesvel.hpp, such that
|
| 1161 |
+
* numerical differentiation, equality checks with tolerances, etc. can be performed
|
| 1162 |
+
* without caring exactly on which type the operation is performed.
|
| 1163 |
+
*
|
| 1164 |
+
* \param R_a_b1: The rotation matrix \f$ _a^{b1} R \f$ of b1 with respect to frame a.
|
| 1165 |
+
* \param R_a_b2: The Rotation matrix \f$ _a^{b2} R \f$ of b2 with respect to frame a.
|
| 1166 |
+
* \param dt [optional][obsolete] time interval over which the numerical differentiation takes place. By default this is set to 1.0.
|
| 1167 |
+
* \return rotation axis to rotate from b1 to b2, scaled by the rotation angle, expressed in frame a.
|
| 1168 |
+
* \warning - The result is not a rotational vector, i.e. it is not a mathematical vector.
|
| 1169 |
+
* (no communitative addition).
|
| 1170 |
+
*
|
| 1171 |
+
* \warning - When used in the context of numerical differentiation, with the frames b1 and b2 very
|
| 1172 |
+
* close to each other, the semantics correspond to the twist, scaled by the time.
|
| 1173 |
+
*
|
| 1174 |
+
* \warning - For angles equal to \f$ \pi \f$, The negative of the
|
| 1175 |
+
* return value is equally valid.
|
| 1176 |
+
*/
|
| 1177 |
+
IMETHOD Vector diff(const Rotation& R_a_b1,const Rotation& R_a_b2,double dt=1);
|
| 1178 |
+
|
| 1179 |
+
/**
|
| 1180 |
+
* determines the rotation axis necessary to rotate the frame b1 to the same orientation as frame b2 and the vector
|
| 1181 |
+
* necessary to translate the origin of b1 to the origin of b2, and stores the result in a Twist datastructure.
|
| 1182 |
+
* \param F_a_b1 frame b1 expressed with respect to some frame a.
|
| 1183 |
+
* \param F_a_b2 frame b2 expressed with respect to some frame a.
|
| 1184 |
+
* \warning The result is not a Twist!
|
| 1185 |
+
* see diff() for Rotation and Vector arguments for further detail on the semantics.
|
| 1186 |
+
*/
|
| 1187 |
+
IMETHOD Twist diff(const Frame& F_a_b1,const Frame& F_a_b2,double dt=1);
|
| 1188 |
+
|
| 1189 |
+
/**
|
| 1190 |
+
* determines the difference between two twists i.e. the difference between
|
| 1191 |
+
* the underlying velocity vectors and rotational velocity vectors.
|
| 1192 |
+
*/
|
| 1193 |
+
IMETHOD Twist diff(const Twist& a,const Twist& b,double dt=1);
|
| 1194 |
+
|
| 1195 |
+
/**
|
| 1196 |
+
* determines the difference between two wrenches i.e. the difference between
|
| 1197 |
+
* the underlying torque vectors and force vectors.
|
| 1198 |
+
*/
|
| 1199 |
+
IMETHOD Wrench diff(const Wrench& W_a_p1,const Wrench& W_a_p2,double dt=1);
|
| 1200 |
+
|
| 1201 |
+
/**
|
| 1202 |
+
* \brief adds vector da to vector a.
|
| 1203 |
+
* see also the corresponding diff() routine.
|
| 1204 |
+
* \param p_w_a vector a expressed to some frame w.
|
| 1205 |
+
* \param p_w_da vector da expressed to some frame w.
|
| 1206 |
+
* \returns the vector resulting from the displacement of vector a by vector da, expressed in the frame w.
|
| 1207 |
+
*/
|
| 1208 |
+
IMETHOD Vector addDelta(const Vector& p_w_a,const Vector& p_w_da,double dt=1);
|
| 1209 |
+
|
| 1210 |
+
/**
|
| 1211 |
+
* returns the rotation matrix resulting from the rotation of frame a by the axis and angle
|
| 1212 |
+
* specified with da_w.
|
| 1213 |
+
*
|
| 1214 |
+
* see also the corresponding diff() routine.
|
| 1215 |
+
*
|
| 1216 |
+
* \param R_w_a Rotation matrix of frame a expressed to some frame w.
|
| 1217 |
+
* \param da_w axis and angle of the rotation expressed to some frame w.
|
| 1218 |
+
* \returns the rotation matrix resulting from the rotation of frame a by the axis and angle
|
| 1219 |
+
* specified with da. The resulting rotation matrix is expressed with respect to
|
| 1220 |
+
* frame w.
|
| 1221 |
+
*/
|
| 1222 |
+
IMETHOD Rotation addDelta(const Rotation& R_w_a,const Vector& da_w,double dt=1);
|
| 1223 |
+
|
| 1224 |
+
/**
|
| 1225 |
+
* returns the frame resulting from the rotation of frame a by the axis and angle
|
| 1226 |
+
* specified in da_w and the translation of the origin (also specified in da_w).
|
| 1227 |
+
*
|
| 1228 |
+
* see also the corresponding diff() routine.
|
| 1229 |
+
* \param R_w_a Rotation matrix of frame a expressed to some frame w.
|
| 1230 |
+
* \param da_w axis and angle of the rotation (da_w.rot), together with a displacement vector for the origin (da_w.vel), expressed to some frame w.
|
| 1231 |
+
* \returns the frame resulting from the rotation of frame a by the axis and angle
|
| 1232 |
+
* specified with da.rot, and the translation of the origin da_w.vel . The resulting frame is expressed with respect to frame w.
|
| 1233 |
+
*/
|
| 1234 |
+
IMETHOD Frame addDelta(const Frame& F_w_a,const Twist& da_w,double dt=1);
|
| 1235 |
+
|
| 1236 |
+
/**
|
| 1237 |
+
* \brief adds the twist da to the twist a.
|
| 1238 |
+
* see also the corresponding diff() routine.
|
| 1239 |
+
* \param a a twist wrt some frame
|
| 1240 |
+
* \param da a twist difference wrt some frame
|
| 1241 |
+
* \returns The twist (a+da) wrt the corresponding frame.
|
| 1242 |
+
*/
|
| 1243 |
+
IMETHOD Twist addDelta(const Twist& a,const Twist&da,double dt=1);
|
| 1244 |
+
|
| 1245 |
+
|
| 1246 |
+
/**
|
| 1247 |
+
* \brief adds the wrench da to the wrench w.
|
| 1248 |
+
* see also the corresponding diff() routine.
|
| 1249 |
+
* see also the corresponding diff() routine.
|
| 1250 |
+
* \param a a wrench wrt some frame
|
| 1251 |
+
* \param da a wrench difference wrt some frame
|
| 1252 |
+
* \returns the wrench (a+da) wrt the corresponding frame.
|
| 1253 |
+
*/
|
| 1254 |
+
IMETHOD Wrench addDelta(const Wrench& a,const Wrench&da,double dt=1);
|
| 1255 |
+
|
| 1256 |
+
#ifdef KDL_INLINE
|
| 1257 |
+
#include "frames.inl"
|
| 1258 |
+
#endif
|
| 1259 |
+
|
| 1260 |
+
}
|
| 1261 |
+
|
| 1262 |
+
template<> struct std::hash<KDL::Vector>
|
| 1263 |
+
{
|
| 1264 |
+
std::size_t operator()(KDL::Vector const& v) const noexcept
|
| 1265 |
+
{
|
| 1266 |
+
size_t seed = 0;
|
| 1267 |
+
KDL::hash_combine(seed, v.x());
|
| 1268 |
+
KDL::hash_combine(seed, v.y());
|
| 1269 |
+
KDL::hash_combine(seed, v.z());
|
| 1270 |
+
return seed;
|
| 1271 |
+
}
|
| 1272 |
+
};
|
| 1273 |
+
|
| 1274 |
+
template<> struct std::hash<KDL::Rotation>
|
| 1275 |
+
{
|
| 1276 |
+
std::size_t operator()(KDL::Rotation const& r) const noexcept
|
| 1277 |
+
{
|
| 1278 |
+
size_t seed = 0;
|
| 1279 |
+
double x, y, z, w;
|
| 1280 |
+
r.GetQuaternion(x, y, z, w);
|
| 1281 |
+
KDL::hash_combine(seed, x);
|
| 1282 |
+
KDL::hash_combine(seed, y);
|
| 1283 |
+
KDL::hash_combine(seed, z);
|
| 1284 |
+
KDL::hash_combine(seed, w);
|
| 1285 |
+
return seed;
|
| 1286 |
+
}
|
| 1287 |
+
};
|
| 1288 |
+
|
| 1289 |
+
template<> struct std::hash<KDL::Frame>
|
| 1290 |
+
{
|
| 1291 |
+
std::size_t operator()(KDL::Frame const& f) const noexcept
|
| 1292 |
+
{
|
| 1293 |
+
size_t seed = 0;
|
| 1294 |
+
KDL::hash_combine(seed, f.p);
|
| 1295 |
+
KDL::hash_combine(seed, f.M);
|
| 1296 |
+
return seed;
|
| 1297 |
+
}
|
| 1298 |
+
};
|
| 1299 |
+
|
| 1300 |
+
template<> struct std::hash<KDL::Wrench>
|
| 1301 |
+
{
|
| 1302 |
+
std::size_t operator()(KDL::Wrench const& w) const noexcept
|
| 1303 |
+
{
|
| 1304 |
+
size_t seed = 0;
|
| 1305 |
+
KDL::hash_combine(seed, w.force);
|
| 1306 |
+
KDL::hash_combine(seed, w.torque);
|
| 1307 |
+
return seed;
|
| 1308 |
+
}
|
| 1309 |
+
};
|
| 1310 |
+
|
| 1311 |
+
template<> struct std::hash<KDL::Twist>
|
| 1312 |
+
{
|
| 1313 |
+
std::size_t operator()(KDL::Twist const& t) const noexcept
|
| 1314 |
+
{
|
| 1315 |
+
size_t seed = 0;
|
| 1316 |
+
KDL::hash_combine(seed, t.vel);
|
| 1317 |
+
KDL::hash_combine(seed, t.rot);
|
| 1318 |
+
return seed;
|
| 1319 |
+
}
|
| 1320 |
+
};
|
| 1321 |
+
|
| 1322 |
+
template<> struct std::hash<KDL::Vector2>
|
| 1323 |
+
{
|
| 1324 |
+
std::size_t operator()(KDL::Vector2 const& v) const noexcept
|
| 1325 |
+
{
|
| 1326 |
+
size_t seed = 0;
|
| 1327 |
+
KDL::hash_combine(seed, v.x());
|
| 1328 |
+
KDL::hash_combine(seed, v.y());
|
| 1329 |
+
return seed;
|
| 1330 |
+
}
|
| 1331 |
+
};
|
| 1332 |
+
|
| 1333 |
+
template<> struct std::hash<KDL::Rotation2>
|
| 1334 |
+
{
|
| 1335 |
+
std::size_t operator()(KDL::Rotation2 const& r) const noexcept
|
| 1336 |
+
{
|
| 1337 |
+
size_t seed = 0;
|
| 1338 |
+
KDL::hash_combine(seed, r.GetRot());
|
| 1339 |
+
return seed;
|
| 1340 |
+
}
|
| 1341 |
+
};
|
| 1342 |
+
|
| 1343 |
+
template<> struct std::hash<KDL::Frame2>
|
| 1344 |
+
{
|
| 1345 |
+
std::size_t operator()(KDL::Frame2 const& f) const noexcept
|
| 1346 |
+
{
|
| 1347 |
+
size_t seed = 0;
|
| 1348 |
+
KDL::hash_combine(seed, f.p);
|
| 1349 |
+
KDL::hash_combine(seed, f.M);
|
| 1350 |
+
return seed;
|
| 1351 |
+
}
|
| 1352 |
+
};
|
| 1353 |
+
|
| 1354 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames.inl
ADDED
|
@@ -0,0 +1,1343 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
frames.inl - description
|
| 3 |
+
-------------------------
|
| 4 |
+
begin : June 2006
|
| 5 |
+
copyright : (C) 2006 Erwin Aertbelien
|
| 6 |
+
email : firstname.lastname@mech.kuleuven.ac.be
|
| 7 |
+
|
| 8 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 9 |
+
|
| 10 |
+
***************************************************************************
|
| 11 |
+
* This library is free software; you can redistribute it and/or *
|
| 12 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 13 |
+
* License as published by the Free Software Foundation; either *
|
| 14 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 15 |
+
* *
|
| 16 |
+
* This library is distributed in the hope that it will be useful, *
|
| 17 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 18 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 19 |
+
* Lesser General Public License for more details. *
|
| 20 |
+
* *
|
| 21 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 22 |
+
* License along with this library; if not, write to the Free Software *
|
| 23 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 24 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 25 |
+
* *
|
| 26 |
+
***************************************************************************/
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* \file frames.inl
|
| 30 |
+
* Inlined member functions and global functions that relate to the classes in frames.cpp
|
| 31 |
+
*
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
IMETHOD Vector::Vector(const Vector & arg)
|
| 37 |
+
{
|
| 38 |
+
data[0] = arg.data[0];
|
| 39 |
+
data[1] = arg.data[1];
|
| 40 |
+
data[2] = arg.data[2];
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
IMETHOD Vector::Vector(double x,double y, double z)
|
| 44 |
+
{
|
| 45 |
+
data[0]=x;data[1]=y;data[2]=z;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
IMETHOD Vector& Vector::operator =(const Vector & arg)
|
| 50 |
+
{
|
| 51 |
+
data[0] = arg.data[0];
|
| 52 |
+
data[1] = arg.data[1];
|
| 53 |
+
data[2] = arg.data[2];
|
| 54 |
+
return *this;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
IMETHOD Vector operator +(const Vector & lhs,const Vector& rhs)
|
| 58 |
+
{
|
| 59 |
+
Vector tmp;
|
| 60 |
+
tmp.data[0] = lhs.data[0]+rhs.data[0];
|
| 61 |
+
tmp.data[1] = lhs.data[1]+rhs.data[1];
|
| 62 |
+
tmp.data[2] = lhs.data[2]+rhs.data[2];
|
| 63 |
+
return tmp;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
IMETHOD Vector operator -(const Vector & lhs,const Vector& rhs)
|
| 67 |
+
{
|
| 68 |
+
Vector tmp;
|
| 69 |
+
tmp.data[0] = lhs.data[0]-rhs.data[0];
|
| 70 |
+
tmp.data[1] = lhs.data[1]-rhs.data[1];
|
| 71 |
+
tmp.data[2] = lhs.data[2]-rhs.data[2];
|
| 72 |
+
return tmp;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
IMETHOD double Vector::x() const { return data[0]; }
|
| 76 |
+
IMETHOD double Vector::y() const { return data[1]; }
|
| 77 |
+
IMETHOD double Vector::z() const { return data[2]; }
|
| 78 |
+
|
| 79 |
+
IMETHOD void Vector::x( double _x ) { data[0] = _x; }
|
| 80 |
+
IMETHOD void Vector::y( double _y ) { data[1] = _y; }
|
| 81 |
+
IMETHOD void Vector::z( double _z ) { data[2] = _z; }
|
| 82 |
+
|
| 83 |
+
Vector operator *(const Vector& lhs,double rhs)
|
| 84 |
+
{
|
| 85 |
+
Vector tmp;
|
| 86 |
+
tmp.data[0] = lhs.data[0]*rhs;
|
| 87 |
+
tmp.data[1] = lhs.data[1]*rhs;
|
| 88 |
+
tmp.data[2] = lhs.data[2]*rhs;
|
| 89 |
+
return tmp;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
Vector operator *(double lhs,const Vector& rhs)
|
| 93 |
+
{
|
| 94 |
+
Vector tmp;
|
| 95 |
+
tmp.data[0] = lhs*rhs.data[0];
|
| 96 |
+
tmp.data[1] = lhs*rhs.data[1];
|
| 97 |
+
tmp.data[2] = lhs*rhs.data[2];
|
| 98 |
+
return tmp;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
Vector operator /(const Vector& lhs,double rhs)
|
| 102 |
+
{
|
| 103 |
+
Vector tmp;
|
| 104 |
+
tmp.data[0] = lhs.data[0]/rhs;
|
| 105 |
+
tmp.data[1] = lhs.data[1]/rhs;
|
| 106 |
+
tmp.data[2] = lhs.data[2]/rhs;
|
| 107 |
+
return tmp;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
Vector operator *(const Vector & lhs,const Vector& rhs)
|
| 111 |
+
// Complexity : 6M+3A
|
| 112 |
+
{
|
| 113 |
+
Vector tmp;
|
| 114 |
+
tmp.data[0] = lhs.data[1]*rhs.data[2]-lhs.data[2]*rhs.data[1];
|
| 115 |
+
tmp.data[1] = lhs.data[2]*rhs.data[0]-lhs.data[0]*rhs.data[2];
|
| 116 |
+
tmp.data[2] = lhs.data[0]*rhs.data[1]-lhs.data[1]*rhs.data[0];
|
| 117 |
+
return tmp;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
Vector& Vector::operator +=(const Vector & arg)
|
| 121 |
+
// Complexity : 3A
|
| 122 |
+
{
|
| 123 |
+
data[0]+=arg.data[0];
|
| 124 |
+
data[1]+=arg.data[1];
|
| 125 |
+
data[2]+=arg.data[2];
|
| 126 |
+
return *this;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
Vector& Vector::operator -=(const Vector & arg)
|
| 130 |
+
// Complexity : 3A
|
| 131 |
+
{
|
| 132 |
+
data[0]-=arg.data[0];
|
| 133 |
+
data[1]-=arg.data[1];
|
| 134 |
+
data[2]-=arg.data[2];
|
| 135 |
+
return *this;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
Vector Vector::Zero()
|
| 139 |
+
{
|
| 140 |
+
return Vector(0,0,0);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
double Vector::operator()(int index) const {
|
| 144 |
+
FRAMES_CHECKI((0<=index)&&(index<=2));
|
| 145 |
+
return data[index];
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
double& Vector::operator () (int index)
|
| 149 |
+
{
|
| 150 |
+
FRAMES_CHECKI((0<=index)&&(index<=2));
|
| 151 |
+
return data[index];
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
Wrench Frame::operator * (const Wrench& arg) const
|
| 157 |
+
// Complexity : 24M+18A
|
| 158 |
+
{
|
| 159 |
+
Wrench tmp;
|
| 160 |
+
tmp.force = M*arg.force;
|
| 161 |
+
tmp.torque = M*arg.torque + p*tmp.force;
|
| 162 |
+
return tmp;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
Wrench Frame::Inverse(const Wrench& arg) const
|
| 166 |
+
{
|
| 167 |
+
Wrench tmp;
|
| 168 |
+
tmp.force = M.Inverse(arg.force);
|
| 169 |
+
tmp.torque = M.Inverse(arg.torque-p*arg.force);
|
| 170 |
+
return tmp;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
Wrench Rotation::Inverse(const Wrench& arg) const
|
| 176 |
+
{
|
| 177 |
+
return Wrench(Inverse(arg.force),Inverse(arg.torque));
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
Twist Rotation::Inverse(const Twist& arg) const
|
| 181 |
+
{
|
| 182 |
+
return Twist(Inverse(arg.vel),Inverse(arg.rot));
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
Wrench Wrench::Zero()
|
| 186 |
+
{
|
| 187 |
+
return Wrench(Vector::Zero(),Vector::Zero());
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
void Wrench::ReverseSign()
|
| 192 |
+
{
|
| 193 |
+
torque.ReverseSign();
|
| 194 |
+
force.ReverseSign();
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
Wrench Wrench::RefPoint(const Vector& v_base_AB) const
|
| 198 |
+
// Changes the reference point of the Wrench.
|
| 199 |
+
// The vector v_base_AB is expressed in the same base as the twist
|
| 200 |
+
// The vector v_base_AB is a vector from the old point to
|
| 201 |
+
// the new point.
|
| 202 |
+
{
|
| 203 |
+
return Wrench(this->force,
|
| 204 |
+
this->torque+this->force*v_base_AB
|
| 205 |
+
);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
Wrench& Wrench::operator-=(const Wrench& arg)
|
| 210 |
+
{
|
| 211 |
+
torque-=arg.torque;
|
| 212 |
+
force -=arg.force;
|
| 213 |
+
return *this;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
Wrench& Wrench::operator+=(const Wrench& arg)
|
| 217 |
+
{
|
| 218 |
+
torque+=arg.torque;
|
| 219 |
+
force +=arg.force;
|
| 220 |
+
return *this;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
double& Wrench::operator()(int i)
|
| 224 |
+
{
|
| 225 |
+
// assert((0<=i)&&(i<6)); done by underlying routines
|
| 226 |
+
if (i<3)
|
| 227 |
+
return force(i);
|
| 228 |
+
else
|
| 229 |
+
return torque(i-3);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
double Wrench::operator()(int i) const
|
| 233 |
+
{
|
| 234 |
+
// assert((0<=i)&&(i<6)); done by underlying routines
|
| 235 |
+
if (i<3)
|
| 236 |
+
return force(i);
|
| 237 |
+
else
|
| 238 |
+
return torque(i-3);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
Wrench operator*(const Wrench& lhs,double rhs)
|
| 243 |
+
{
|
| 244 |
+
return Wrench(lhs.force*rhs,lhs.torque*rhs);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
Wrench operator*(double lhs,const Wrench& rhs)
|
| 248 |
+
{
|
| 249 |
+
return Wrench(lhs*rhs.force,lhs*rhs.torque);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
Wrench operator/(const Wrench& lhs,double rhs)
|
| 253 |
+
{
|
| 254 |
+
return Wrench(lhs.force/rhs,lhs.torque/rhs);
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
// addition of Wrench's
|
| 258 |
+
Wrench operator+(const Wrench& lhs,const Wrench& rhs)
|
| 259 |
+
{
|
| 260 |
+
return Wrench(lhs.force+rhs.force,lhs.torque+rhs.torque);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
Wrench operator-(const Wrench& lhs,const Wrench& rhs)
|
| 264 |
+
{
|
| 265 |
+
return Wrench(lhs.force-rhs.force,lhs.torque-rhs.torque);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
// unary -
|
| 269 |
+
Wrench operator-(const Wrench& arg)
|
| 270 |
+
{
|
| 271 |
+
return Wrench(-arg.force,-arg.torque);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
Twist Frame::operator * (const Twist& arg) const
|
| 275 |
+
// Complexity : 24M+18A
|
| 276 |
+
{
|
| 277 |
+
Twist tmp;
|
| 278 |
+
tmp.rot = M*arg.rot;
|
| 279 |
+
tmp.vel = M*arg.vel+p*tmp.rot;
|
| 280 |
+
return tmp;
|
| 281 |
+
}
|
| 282 |
+
Twist Frame::Inverse(const Twist& arg) const
|
| 283 |
+
{
|
| 284 |
+
Twist tmp;
|
| 285 |
+
tmp.rot = M.Inverse(arg.rot);
|
| 286 |
+
tmp.vel = M.Inverse(arg.vel-p*arg.rot);
|
| 287 |
+
return tmp;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
Twist Twist::Zero()
|
| 291 |
+
{
|
| 292 |
+
return Twist(Vector::Zero(),Vector::Zero());
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
void Twist::ReverseSign()
|
| 297 |
+
{
|
| 298 |
+
vel.ReverseSign();
|
| 299 |
+
rot.ReverseSign();
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
Twist Twist::RefPoint(const Vector& v_base_AB) const
|
| 303 |
+
// Changes the reference point of the twist.
|
| 304 |
+
// The vector v_base_AB is expressed in the same base as the twist
|
| 305 |
+
// The vector v_base_AB is a vector from the old point to
|
| 306 |
+
// the new point.
|
| 307 |
+
// Complexity : 6M+6A
|
| 308 |
+
{
|
| 309 |
+
return Twist(this->vel+this->rot*v_base_AB,this->rot);
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
Twist& Twist::operator-=(const Twist& arg)
|
| 313 |
+
{
|
| 314 |
+
vel-=arg.vel;
|
| 315 |
+
rot -=arg.rot;
|
| 316 |
+
return *this;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
Twist& Twist::operator+=(const Twist& arg)
|
| 320 |
+
{
|
| 321 |
+
vel+=arg.vel;
|
| 322 |
+
rot +=arg.rot;
|
| 323 |
+
return *this;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
double& Twist::operator()(int i)
|
| 327 |
+
{
|
| 328 |
+
// assert((0<=i)&&(i<6)); done by underlying routines
|
| 329 |
+
if (i<3)
|
| 330 |
+
return vel(i);
|
| 331 |
+
else
|
| 332 |
+
return rot(i-3);
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
double Twist::operator()(int i) const
|
| 336 |
+
{
|
| 337 |
+
// assert((0<=i)&&(i<6)); done by underlying routines
|
| 338 |
+
if (i<3)
|
| 339 |
+
return vel(i);
|
| 340 |
+
else
|
| 341 |
+
return rot(i-3);
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
Twist operator*(const Twist& lhs,double rhs)
|
| 346 |
+
{
|
| 347 |
+
return Twist(lhs.vel*rhs,lhs.rot*rhs);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
Twist operator*(double lhs,const Twist& rhs)
|
| 351 |
+
{
|
| 352 |
+
return Twist(lhs*rhs.vel,lhs*rhs.rot);
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
Twist operator/(const Twist& lhs,double rhs)
|
| 356 |
+
{
|
| 357 |
+
return Twist(lhs.vel/rhs,lhs.rot/rhs);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
// addition of Twist's
|
| 361 |
+
Twist operator+(const Twist& lhs,const Twist& rhs)
|
| 362 |
+
{
|
| 363 |
+
return Twist(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
Twist operator-(const Twist& lhs,const Twist& rhs)
|
| 367 |
+
{
|
| 368 |
+
return Twist(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
// unary -
|
| 372 |
+
Twist operator-(const Twist& arg)
|
| 373 |
+
{
|
| 374 |
+
return Twist(-arg.vel,-arg.rot);
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
//Spatial products for twists
|
| 379 |
+
Twist operator*(const Twist& lhs,const Twist& rhs)
|
| 380 |
+
{
|
| 381 |
+
return Twist(lhs.rot*rhs.vel+lhs.vel*rhs.rot,lhs.rot*rhs.rot);
|
| 382 |
+
}
|
| 383 |
+
Wrench operator*(const Twist& lhs,const Wrench& rhs)
|
| 384 |
+
{
|
| 385 |
+
return Wrench(lhs.rot*rhs.force,lhs.rot*rhs.torque+lhs.vel*rhs.force);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
Frame::Frame(const Rotation & R)
|
| 389 |
+
{
|
| 390 |
+
M=R;
|
| 391 |
+
p=Vector::Zero();
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
Frame::Frame(const Vector & V)
|
| 395 |
+
{
|
| 396 |
+
M = Rotation::Identity();
|
| 397 |
+
p = V;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
Frame::Frame(const Rotation & R, const Vector & V)
|
| 401 |
+
{
|
| 402 |
+
M = R;
|
| 403 |
+
p = V;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
Frame operator *(const Frame& lhs,const Frame& rhs)
|
| 407 |
+
// Complexity : 36M+36A
|
| 408 |
+
{
|
| 409 |
+
return Frame(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
Vector Frame::operator *(const Vector & arg) const
|
| 413 |
+
{
|
| 414 |
+
return M*arg+p;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
Vector Frame::Inverse(const Vector& arg) const
|
| 418 |
+
{
|
| 419 |
+
return M.Inverse(arg-p);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
Frame Frame::Inverse() const
|
| 423 |
+
{
|
| 424 |
+
return Frame(M.Inverse(),-M.Inverse(p));
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
Frame& Frame::operator =(const Frame & arg)
|
| 429 |
+
{
|
| 430 |
+
M = arg.M;
|
| 431 |
+
p = arg.p;
|
| 432 |
+
return *this;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
Frame::Frame(const Frame & arg) :
|
| 436 |
+
p(arg.p),M(arg.M)
|
| 437 |
+
{}
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
void Vector::ReverseSign()
|
| 441 |
+
{
|
| 442 |
+
data[0] = -data[0];
|
| 443 |
+
data[1] = -data[1];
|
| 444 |
+
data[2] = -data[2];
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
Vector operator-(const Vector & arg)
|
| 450 |
+
{
|
| 451 |
+
Vector tmp;
|
| 452 |
+
tmp.data[0]=-arg.data[0];
|
| 453 |
+
tmp.data[1]=-arg.data[1];
|
| 454 |
+
tmp.data[2]=-arg.data[2];
|
| 455 |
+
return tmp;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
void Vector::Set2DXY(const Vector2& v)
|
| 459 |
+
// a 3D vector where the 2D vector v is put in the XY plane
|
| 460 |
+
{
|
| 461 |
+
data[0]=v(0);
|
| 462 |
+
data[1]=v(1);
|
| 463 |
+
data[2]=0;
|
| 464 |
+
|
| 465 |
+
}
|
| 466 |
+
void Vector::Set2DYZ(const Vector2& v)
|
| 467 |
+
// a 3D vector where the 2D vector v is put in the YZ plane
|
| 468 |
+
{
|
| 469 |
+
data[1]=v(0);
|
| 470 |
+
data[2]=v(1);
|
| 471 |
+
data[0]=0;
|
| 472 |
+
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
void Vector::Set2DZX(const Vector2& v)
|
| 476 |
+
// a 3D vector where the 2D vector v is put in the ZX plane
|
| 477 |
+
{
|
| 478 |
+
data[2]=v(0);
|
| 479 |
+
data[0]=v(1);
|
| 480 |
+
data[1]=0;
|
| 481 |
+
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
double& Rotation::operator()(int i,int j) {
|
| 489 |
+
FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
|
| 490 |
+
return data[i*3+j];
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
double Rotation::operator()(int i,int j) const {
|
| 494 |
+
FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
|
| 495 |
+
return data[i*3+j];
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
Rotation::Rotation( double Xx,double Yx,double Zx,
|
| 499 |
+
double Xy,double Yy,double Zy,
|
| 500 |
+
double Xz,double Yz,double Zz)
|
| 501 |
+
{
|
| 502 |
+
data[0] = Xx;data[1]=Yx;data[2]=Zx;
|
| 503 |
+
data[3] = Xy;data[4]=Yy;data[5]=Zy;
|
| 504 |
+
data[6] = Xz;data[7]=Yz;data[8]=Zz;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
Rotation::Rotation(const Vector& x,const Vector& y,const Vector& z)
|
| 509 |
+
{
|
| 510 |
+
data[0] = x.data[0];data[3] = x.data[1];data[6] = x.data[2];
|
| 511 |
+
data[1] = y.data[0];data[4] = y.data[1];data[7] = y.data[2];
|
| 512 |
+
data[2] = z.data[0];data[5] = z.data[1];data[8] = z.data[2];
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
Rotation::Rotation(const Rotation& arg) {
|
| 516 |
+
int count=9;
|
| 517 |
+
while (count--) data[count] = arg.data[count];
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
Rotation& Rotation::operator=(const Rotation& arg) {
|
| 521 |
+
int count=9;
|
| 522 |
+
while (count--) data[count] = arg.data[count];
|
| 523 |
+
return *this;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
Vector Rotation::operator*(const Vector& v) const {
|
| 527 |
+
// Complexity : 9M+6A
|
| 528 |
+
return Vector(
|
| 529 |
+
data[0]*v.data[0] + data[1]*v.data[1] + data[2]*v.data[2],
|
| 530 |
+
data[3]*v.data[0] + data[4]*v.data[1] + data[5]*v.data[2],
|
| 531 |
+
data[6]*v.data[0] + data[7]*v.data[1] + data[8]*v.data[2]
|
| 532 |
+
);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
Twist Rotation::operator * (const Twist& arg) const
|
| 536 |
+
// Transformation of the base to which the twist is expressed.
|
| 537 |
+
// look at Frame*Twist for a transformation that also transforms
|
| 538 |
+
// the velocity reference point.
|
| 539 |
+
// Complexity : 18M+12A
|
| 540 |
+
{
|
| 541 |
+
return Twist((*this)*arg.vel,(*this)*arg.rot);
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
Wrench Rotation::operator * (const Wrench& arg) const
|
| 545 |
+
// Transformation of the base to which the wrench is expressed.
|
| 546 |
+
// look at Frame*Twist for a transformation that also transforms
|
| 547 |
+
// the force reference point.
|
| 548 |
+
{
|
| 549 |
+
return Wrench((*this)*arg.force,(*this)*arg.torque);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
Rotation Rotation::Identity() {
|
| 553 |
+
return Rotation(1,0,0,0,1,0,0,0,1);
|
| 554 |
+
}
|
| 555 |
+
// *this = *this * ROT(X,angle)
|
| 556 |
+
void Rotation::DoRotX(double angle)
|
| 557 |
+
{
|
| 558 |
+
double cs = cos(angle);
|
| 559 |
+
double sn = sin(angle);
|
| 560 |
+
double x1,x2,x3;
|
| 561 |
+
x1 = cs* (*this)(0,1) + sn* (*this)(0,2);
|
| 562 |
+
x2 = cs* (*this)(1,1) + sn* (*this)(1,2);
|
| 563 |
+
x3 = cs* (*this)(2,1) + sn* (*this)(2,2);
|
| 564 |
+
(*this)(0,2) = -sn* (*this)(0,1) + cs* (*this)(0,2);
|
| 565 |
+
(*this)(1,2) = -sn* (*this)(1,1) + cs* (*this)(1,2);
|
| 566 |
+
(*this)(2,2) = -sn* (*this)(2,1) + cs* (*this)(2,2);
|
| 567 |
+
(*this)(0,1) = x1;
|
| 568 |
+
(*this)(1,1) = x2;
|
| 569 |
+
(*this)(2,1) = x3;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
void Rotation::DoRotY(double angle)
|
| 573 |
+
{
|
| 574 |
+
double cs = cos(angle);
|
| 575 |
+
double sn = sin(angle);
|
| 576 |
+
double x1,x2,x3;
|
| 577 |
+
x1 = cs* (*this)(0,0) - sn* (*this)(0,2);
|
| 578 |
+
x2 = cs* (*this)(1,0) - sn* (*this)(1,2);
|
| 579 |
+
x3 = cs* (*this)(2,0) - sn* (*this)(2,2);
|
| 580 |
+
(*this)(0,2) = sn* (*this)(0,0) + cs* (*this)(0,2);
|
| 581 |
+
(*this)(1,2) = sn* (*this)(1,0) + cs* (*this)(1,2);
|
| 582 |
+
(*this)(2,2) = sn* (*this)(2,0) + cs* (*this)(2,2);
|
| 583 |
+
(*this)(0,0) = x1;
|
| 584 |
+
(*this)(1,0) = x2;
|
| 585 |
+
(*this)(2,0) = x3;
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
void Rotation::DoRotZ(double angle)
|
| 589 |
+
{
|
| 590 |
+
double cs = cos(angle);
|
| 591 |
+
double sn = sin(angle);
|
| 592 |
+
double x1,x2,x3;
|
| 593 |
+
x1 = cs* (*this)(0,0) + sn* (*this)(0,1);
|
| 594 |
+
x2 = cs* (*this)(1,0) + sn* (*this)(1,1);
|
| 595 |
+
x3 = cs* (*this)(2,0) + sn* (*this)(2,1);
|
| 596 |
+
(*this)(0,1) = -sn* (*this)(0,0) + cs* (*this)(0,1);
|
| 597 |
+
(*this)(1,1) = -sn* (*this)(1,0) + cs* (*this)(1,1);
|
| 598 |
+
(*this)(2,1) = -sn* (*this)(2,0) + cs* (*this)(2,1);
|
| 599 |
+
(*this)(0,0) = x1;
|
| 600 |
+
(*this)(1,0) = x2;
|
| 601 |
+
(*this)(2,0) = x3;
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
Rotation Rotation::RotX(double angle) {
|
| 606 |
+
double cs=cos(angle);
|
| 607 |
+
double sn=sin(angle);
|
| 608 |
+
return Rotation(1,0,0,0,cs,-sn,0,sn,cs);
|
| 609 |
+
}
|
| 610 |
+
Rotation Rotation::RotY(double angle) {
|
| 611 |
+
double cs=cos(angle);
|
| 612 |
+
double sn=sin(angle);
|
| 613 |
+
return Rotation(cs,0,sn,0,1,0,-sn,0,cs);
|
| 614 |
+
}
|
| 615 |
+
Rotation Rotation::RotZ(double angle) {
|
| 616 |
+
double cs=cos(angle);
|
| 617 |
+
double sn=sin(angle);
|
| 618 |
+
return Rotation(cs,-sn,0,sn,cs,0,0,0,1);
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
void Frame::Integrate(const Twist& t_this,double samplefrequency)
|
| 625 |
+
{
|
| 626 |
+
double n = t_this.rot.Norm()/samplefrequency;
|
| 627 |
+
if (n<epsilon) {
|
| 628 |
+
p += M*(t_this.vel/samplefrequency);
|
| 629 |
+
} else {
|
| 630 |
+
(*this) = (*this) *
|
| 631 |
+
Frame ( Rotation::Rot( t_this.rot, n ),
|
| 632 |
+
t_this.vel/samplefrequency
|
| 633 |
+
);
|
| 634 |
+
}
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
Rotation Rotation::Inverse() const
|
| 638 |
+
{
|
| 639 |
+
Rotation tmp(*this);
|
| 640 |
+
tmp.SetInverse();
|
| 641 |
+
return tmp;
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
Vector Rotation::Inverse(const Vector& v) const {
|
| 645 |
+
return Vector(
|
| 646 |
+
data[0]*v.data[0] + data[3]*v.data[1] + data[6]*v.data[2],
|
| 647 |
+
data[1]*v.data[0] + data[4]*v.data[1] + data[7]*v.data[2],
|
| 648 |
+
data[2]*v.data[0] + data[5]*v.data[1] + data[8]*v.data[2]
|
| 649 |
+
);
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
void Rotation::SetInverse()
|
| 654 |
+
{
|
| 655 |
+
double tmp;
|
| 656 |
+
tmp = data[1];data[1]=data[3];data[3]=tmp;
|
| 657 |
+
tmp = data[2];data[2]=data[6];data[6]=tmp;
|
| 658 |
+
tmp = data[5];data[5]=data[7];data[7]=tmp;
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
double Frame::operator()(int i,int j) {
|
| 668 |
+
FRAMES_CHECKI((0<=i)&&(i<=3)&&(0<=j)&&(j<=3));
|
| 669 |
+
if (i==3) {
|
| 670 |
+
if (j==3)
|
| 671 |
+
return 1.0;
|
| 672 |
+
else
|
| 673 |
+
return 0.0;
|
| 674 |
+
} else {
|
| 675 |
+
if (j==3)
|
| 676 |
+
return p(i);
|
| 677 |
+
else
|
| 678 |
+
return M(i,j);
|
| 679 |
+
|
| 680 |
+
}
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
double Frame::operator()(int i,int j) const {
|
| 684 |
+
FRAMES_CHECKI((0<=i)&&(i<=3)&&(0<=j)&&(j<=3));
|
| 685 |
+
if (i==3) {
|
| 686 |
+
if (j==3)
|
| 687 |
+
return 1;
|
| 688 |
+
else
|
| 689 |
+
return 0;
|
| 690 |
+
} else {
|
| 691 |
+
if (j==3)
|
| 692 |
+
return p(i);
|
| 693 |
+
else
|
| 694 |
+
return M(i,j);
|
| 695 |
+
|
| 696 |
+
}
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
Frame Frame::Identity() {
|
| 701 |
+
return Frame(Rotation::Identity(),Vector::Zero());
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
void Vector::Set2DPlane(const Frame& F_someframe_XY,const Vector2& v_XY)
|
| 708 |
+
// a 3D vector where the 2D vector v is put in the XY plane of the frame
|
| 709 |
+
// F_someframe_XY.
|
| 710 |
+
{
|
| 711 |
+
Vector tmp_XY;
|
| 712 |
+
tmp_XY.Set2DXY(v_XY);
|
| 713 |
+
tmp_XY = F_someframe_XY*(tmp_XY);
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
|
| 723 |
+
|
| 724 |
+
//============ 2 dimensional version of the frames objects =============
|
| 725 |
+
IMETHOD Vector2::Vector2(const Vector2 & arg)
|
| 726 |
+
{
|
| 727 |
+
data[0] = arg.data[0];
|
| 728 |
+
data[1] = arg.data[1];
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
IMETHOD Vector2::Vector2(double x,double y)
|
| 732 |
+
{
|
| 733 |
+
data[0]=x;data[1]=y;
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
IMETHOD Vector2& Vector2::operator =(const Vector2 & arg)
|
| 738 |
+
{
|
| 739 |
+
data[0] = arg.data[0];
|
| 740 |
+
data[1] = arg.data[1];
|
| 741 |
+
return *this;
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
IMETHOD Vector2 operator +(const Vector2 & lhs,const Vector2& rhs)
|
| 746 |
+
{
|
| 747 |
+
return Vector2(lhs.data[0]+rhs.data[0],lhs.data[1]+rhs.data[1]);
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
IMETHOD Vector2 operator -(const Vector2 & lhs,const Vector2& rhs)
|
| 751 |
+
{
|
| 752 |
+
return Vector2(lhs.data[0]-rhs.data[0],lhs.data[1]-rhs.data[1]);
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
IMETHOD Vector2 operator *(const Vector2& lhs,double rhs)
|
| 756 |
+
{
|
| 757 |
+
return Vector2(lhs.data[0]*rhs,lhs.data[1]*rhs);
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
IMETHOD Vector2 operator *(double lhs,const Vector2& rhs)
|
| 761 |
+
{
|
| 762 |
+
return Vector2(lhs*rhs.data[0],lhs*rhs.data[1]);
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
IMETHOD Vector2 operator /(const Vector2& lhs,double rhs)
|
| 766 |
+
{
|
| 767 |
+
return Vector2(lhs.data[0]/rhs,lhs.data[1]/rhs);
|
| 768 |
+
}
|
| 769 |
+
|
| 770 |
+
IMETHOD Vector2& Vector2::operator +=(const Vector2 & arg)
|
| 771 |
+
{
|
| 772 |
+
data[0]+=arg.data[0];
|
| 773 |
+
data[1]+=arg.data[1];
|
| 774 |
+
return *this;
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
IMETHOD Vector2& Vector2::operator -=(const Vector2 & arg)
|
| 778 |
+
{
|
| 779 |
+
data[0]-=arg.data[0];
|
| 780 |
+
data[1]-=arg.data[1];
|
| 781 |
+
return *this;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
IMETHOD Vector2 Vector2::Zero() {
|
| 785 |
+
return Vector2(0,0);
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
IMETHOD double Vector2::operator()(int index) const {
|
| 789 |
+
FRAMES_CHECKI((0<=index)&&(index<=1));
|
| 790 |
+
return data[index];
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
IMETHOD double& Vector2::operator () (int index)
|
| 794 |
+
{
|
| 795 |
+
FRAMES_CHECKI((0<=index)&&(index<=1));
|
| 796 |
+
return data[index];
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
IMETHOD double Vector2::x() const { return data[0]; }
|
| 800 |
+
IMETHOD double Vector2::y() const { return data[1]; }
|
| 801 |
+
|
| 802 |
+
IMETHOD void Vector2::x( double _x ) { data[0] = _x; }
|
| 803 |
+
IMETHOD void Vector2::y( double _y ) { data[1] = _y; }
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
IMETHOD void Vector2::ReverseSign()
|
| 807 |
+
{
|
| 808 |
+
data[0] = -data[0];
|
| 809 |
+
data[1] = -data[1];
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
IMETHOD Vector2 operator-(const Vector2 & arg)
|
| 814 |
+
{
|
| 815 |
+
return Vector2(-arg.data[0],-arg.data[1]);
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
IMETHOD void Vector2::Set3DXY(const Vector& v)
|
| 820 |
+
// projects v in its XY plane, and sets *this to these values
|
| 821 |
+
{
|
| 822 |
+
data[0]=v(0);
|
| 823 |
+
data[1]=v(1);
|
| 824 |
+
}
|
| 825 |
+
IMETHOD void Vector2::Set3DYZ(const Vector& v)
|
| 826 |
+
// projects v in its XY plane, and sets *this to these values
|
| 827 |
+
{
|
| 828 |
+
data[0]=v(1);
|
| 829 |
+
data[1]=v(2);
|
| 830 |
+
}
|
| 831 |
+
IMETHOD void Vector2::Set3DZX(const Vector& v)
|
| 832 |
+
// projects v in its XY plane, and sets *this to these values
|
| 833 |
+
{
|
| 834 |
+
data[0]=v(2);
|
| 835 |
+
data[1]=v(0);
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
IMETHOD void Vector2::Set3DPlane(const Frame& F_someframe_XY,const Vector& v_someframe)
|
| 839 |
+
// projects v in the XY plane of F_someframe_XY, and sets *this to these values
|
| 840 |
+
// expressed wrt someframe.
|
| 841 |
+
{
|
| 842 |
+
Vector tmp = F_someframe_XY.Inverse(v_someframe);
|
| 843 |
+
data[0]=tmp(0);
|
| 844 |
+
data[1]=tmp(1);
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
IMETHOD Rotation2::Rotation2(const Rotation2& arg) {
|
| 848 |
+
c=arg.c;s=arg.s;
|
| 849 |
+
}
|
| 850 |
+
|
| 851 |
+
IMETHOD Rotation2& Rotation2::operator=(const Rotation2& arg) {
|
| 852 |
+
c=arg.c;s=arg.s;
|
| 853 |
+
return *this;
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
+
IMETHOD Vector2 Rotation2::operator*(const Vector2& v) const {
|
| 857 |
+
return Vector2(v.data[0]*c-v.data[1]*s,v.data[0]*s+v.data[1]*c);
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
IMETHOD double Rotation2::operator()(int i,int j) const {
|
| 861 |
+
FRAMES_CHECKI((0<=i)&&(i<=1)&&(0<=j)&&(j<=1));
|
| 862 |
+
if (i==j) return c;
|
| 863 |
+
if (i==0)
|
| 864 |
+
return s;
|
| 865 |
+
else
|
| 866 |
+
return -s;
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
|
| 870 |
+
IMETHOD Rotation2 operator *(const Rotation2& lhs,const Rotation2& rhs) {
|
| 871 |
+
return Rotation2(lhs.c*rhs.c-lhs.s*rhs.s,lhs.s*rhs.c+lhs.c*rhs.s);
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
IMETHOD void Rotation2::SetInverse() {
|
| 875 |
+
s=-s;
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
IMETHOD Rotation2 Rotation2::Inverse() const {
|
| 879 |
+
return Rotation2(c,-s);
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
IMETHOD Vector2 Rotation2::Inverse(const Vector2& v) const {
|
| 883 |
+
return Vector2(v.data[0]*c+v.data[1]*s,-v.data[0]*s+v.data[1]*c);
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
IMETHOD Rotation2 Rotation2::Identity() {
|
| 887 |
+
return Rotation2(1,0);
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
IMETHOD void Rotation2::SetIdentity()
|
| 891 |
+
{
|
| 892 |
+
c = 1;
|
| 893 |
+
s = 0;
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
IMETHOD void Rotation2::SetRot(double angle) {
|
| 897 |
+
c=cos(angle);s=sin(angle);
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
IMETHOD Rotation2 Rotation2::Rot(double angle) {
|
| 901 |
+
return Rotation2(cos(angle),sin(angle));
|
| 902 |
+
}
|
| 903 |
+
|
| 904 |
+
IMETHOD double Rotation2::GetRot() const {
|
| 905 |
+
return atan2(s,c);
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
|
| 909 |
+
IMETHOD Frame2::Frame2() {
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
IMETHOD Frame2::Frame2(const Rotation2 & R)
|
| 913 |
+
{
|
| 914 |
+
M=R;
|
| 915 |
+
p=Vector2::Zero();
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
IMETHOD Frame2::Frame2(const Vector2 & V)
|
| 919 |
+
{
|
| 920 |
+
M = Rotation2::Identity();
|
| 921 |
+
p = V;
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
IMETHOD Frame2::Frame2(const Rotation2 & R, const Vector2 & V)
|
| 925 |
+
{
|
| 926 |
+
M = R;
|
| 927 |
+
p = V;
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
+
IMETHOD Frame2 operator *(const Frame2& lhs,const Frame2& rhs)
|
| 931 |
+
{
|
| 932 |
+
return Frame2(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
IMETHOD Vector2 Frame2::operator *(const Vector2 & arg) const
|
| 936 |
+
{
|
| 937 |
+
return M*arg+p;
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
IMETHOD Vector2 Frame2::Inverse(const Vector2& arg) const
|
| 941 |
+
{
|
| 942 |
+
return M.Inverse(arg-p);
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
IMETHOD void Frame2::SetIdentity()
|
| 946 |
+
{
|
| 947 |
+
M.SetIdentity();
|
| 948 |
+
p = Vector2::Zero();
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
IMETHOD void Frame2::SetInverse()
|
| 952 |
+
{
|
| 953 |
+
M.SetInverse();
|
| 954 |
+
p = M*p;
|
| 955 |
+
p.ReverseSign();
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
|
| 959 |
+
IMETHOD Frame2 Frame2::Inverse() const
|
| 960 |
+
{
|
| 961 |
+
Frame2 tmp(*this);
|
| 962 |
+
tmp.SetInverse();
|
| 963 |
+
return tmp;
|
| 964 |
+
}
|
| 965 |
+
|
| 966 |
+
IMETHOD Frame2& Frame2::operator =(const Frame2 & arg)
|
| 967 |
+
{
|
| 968 |
+
M = arg.M;
|
| 969 |
+
p = arg.p;
|
| 970 |
+
return *this;
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
IMETHOD Frame2::Frame2(const Frame2 & arg) :
|
| 974 |
+
p(arg.p), M(arg.M)
|
| 975 |
+
{}
|
| 976 |
+
|
| 977 |
+
|
| 978 |
+
IMETHOD double Frame2::operator()(int i,int j) {
|
| 979 |
+
FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
|
| 980 |
+
if (i==2) {
|
| 981 |
+
if (j==2)
|
| 982 |
+
return 1;
|
| 983 |
+
else
|
| 984 |
+
return 0;
|
| 985 |
+
} else {
|
| 986 |
+
if (j==2)
|
| 987 |
+
return p(i);
|
| 988 |
+
else
|
| 989 |
+
return M(i,j);
|
| 990 |
+
|
| 991 |
+
}
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
IMETHOD double Frame2::operator()(int i,int j) const {
|
| 995 |
+
FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
|
| 996 |
+
if (i==2) {
|
| 997 |
+
if (j==2)
|
| 998 |
+
return 1;
|
| 999 |
+
else
|
| 1000 |
+
return 0;
|
| 1001 |
+
} else {
|
| 1002 |
+
if (j==2)
|
| 1003 |
+
return p(i);
|
| 1004 |
+
else
|
| 1005 |
+
return M(i,j);
|
| 1006 |
+
|
| 1007 |
+
}
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
// Scalar products.
|
| 1011 |
+
|
| 1012 |
+
IMETHOD double dot(const Vector& lhs,const Vector& rhs) {
|
| 1013 |
+
return rhs(0)*lhs(0)+rhs(1)*lhs(1)+rhs(2)*lhs(2);
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
IMETHOD double dot(const Twist& lhs,const Wrench& rhs) {
|
| 1017 |
+
return dot(lhs.vel,rhs.force)+dot(lhs.rot,rhs.torque);
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
IMETHOD double dot(const Wrench& rhs,const Twist& lhs) {
|
| 1021 |
+
return dot(lhs.vel,rhs.force)+dot(lhs.rot,rhs.torque);
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
|
| 1025 |
+
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
// Equality operators
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
IMETHOD bool Equal(const Vector& a,const Vector& b,double eps) {
|
| 1033 |
+
return (Equal(a.data[0],b.data[0],eps)&&
|
| 1034 |
+
Equal(a.data[1],b.data[1],eps)&&
|
| 1035 |
+
Equal(a.data[2],b.data[2],eps) );
|
| 1036 |
+
}
|
| 1037 |
+
|
| 1038 |
+
|
| 1039 |
+
IMETHOD bool Equal(const Frame& a,const Frame& b,double eps) {
|
| 1040 |
+
return (Equal(a.p,b.p,eps)&&
|
| 1041 |
+
Equal(a.M,b.M,eps) );
|
| 1042 |
+
}
|
| 1043 |
+
|
| 1044 |
+
IMETHOD bool Equal(const Wrench& a,const Wrench& b,double eps) {
|
| 1045 |
+
return (Equal(a.force,b.force,eps)&&
|
| 1046 |
+
Equal(a.torque,b.torque,eps) );
|
| 1047 |
+
}
|
| 1048 |
+
|
| 1049 |
+
IMETHOD bool Equal(const Twist& a,const Twist& b,double eps) {
|
| 1050 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 1051 |
+
Equal(a.vel,b.vel,eps) );
|
| 1052 |
+
}
|
| 1053 |
+
|
| 1054 |
+
IMETHOD bool Equal(const Vector2& a,const Vector2& b,double eps) {
|
| 1055 |
+
return (Equal(a.data[0],b.data[0],eps)&&
|
| 1056 |
+
Equal(a.data[1],b.data[1],eps) );
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
IMETHOD bool Equal(const Rotation2& a,const Rotation2& b,double eps) {
|
| 1060 |
+
return ( Equal(a.c,b.c,eps) && Equal(a.s,b.s,eps) );
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
IMETHOD bool Equal(const Frame2& a,const Frame2& b,double eps) {
|
| 1064 |
+
return (Equal(a.p,b.p,eps)&&
|
| 1065 |
+
Equal(a.M,b.M,eps) );
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
IMETHOD void SetToZero(Vector& v) {
|
| 1069 |
+
v=Vector::Zero();
|
| 1070 |
+
}
|
| 1071 |
+
IMETHOD void SetToZero(Twist& v) {
|
| 1072 |
+
SetToZero(v.rot);
|
| 1073 |
+
SetToZero(v.vel);
|
| 1074 |
+
}
|
| 1075 |
+
IMETHOD void SetToZero(Wrench& v) {
|
| 1076 |
+
SetToZero(v.force);
|
| 1077 |
+
SetToZero(v.torque);
|
| 1078 |
+
}
|
| 1079 |
+
|
| 1080 |
+
IMETHOD void SetToZero(Vector2& v) {
|
| 1081 |
+
v = Vector2::Zero();
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
|
| 1085 |
+
////////////////////////////////////////////////////////////////
|
| 1086 |
+
// The following defines the operations
|
| 1087 |
+
// diff
|
| 1088 |
+
// addDelta
|
| 1089 |
+
// random
|
| 1090 |
+
// posrandom
|
| 1091 |
+
// on all the types defined in this library.
|
| 1092 |
+
// (mostly for uniform integration, differentiation and testing).
|
| 1093 |
+
// Defined as functions because double is not a class and a method
|
| 1094 |
+
// would brake uniformity when defined for a double.
|
| 1095 |
+
////////////////////////////////////////////////////////////////
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
|
| 1102 |
+
/**
|
| 1103 |
+
* axis_a_b is a rotation vector, its norm is a rotation angle
|
| 1104 |
+
* axis_a_b rotates the a frame towards the b frame.
|
| 1105 |
+
* This routine returns the rotation matrix R_a_b
|
| 1106 |
+
*/
|
| 1107 |
+
IMETHOD Rotation Rot(const Vector& axis_a_b) {
|
| 1108 |
+
// The formula is
|
| 1109 |
+
// V.(V.tr) + st*[V x] + ct*(I-V.(V.tr))
|
| 1110 |
+
// can be found by multiplying it with an arbitrary vector p
|
| 1111 |
+
// and noting that this vector is rotated.
|
| 1112 |
+
Vector rotvec = axis_a_b;
|
| 1113 |
+
double angle = rotvec.Normalize(1E-10);
|
| 1114 |
+
double ct = ::cos(angle);
|
| 1115 |
+
double st = ::sin(angle);
|
| 1116 |
+
double vt = 1-ct;
|
| 1117 |
+
return Rotation(
|
| 1118 |
+
ct + vt*rotvec(0)*rotvec(0),
|
| 1119 |
+
-rotvec(2)*st + vt*rotvec(0)*rotvec(1),
|
| 1120 |
+
rotvec(1)*st + vt*rotvec(0)*rotvec(2),
|
| 1121 |
+
rotvec(2)*st + vt*rotvec(1)*rotvec(0),
|
| 1122 |
+
ct + vt*rotvec(1)*rotvec(1),
|
| 1123 |
+
-rotvec(0)*st + vt*rotvec(1)*rotvec(2),
|
| 1124 |
+
-rotvec(1)*st + vt*rotvec(2)*rotvec(0),
|
| 1125 |
+
rotvec(0)*st + vt*rotvec(2)*rotvec(1),
|
| 1126 |
+
ct + vt*rotvec(2)*rotvec(2)
|
| 1127 |
+
);
|
| 1128 |
+
}
|
| 1129 |
+
IMETHOD Vector diff(const Vector& a,const Vector& b,double dt) {
|
| 1130 |
+
return (b-a)/dt;
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
IMETHOD Vector diff(const Rotation& R_a_b1,const Rotation& R_a_b2,double dt) {
|
| 1134 |
+
Rotation R_b1_b2(R_a_b1.Inverse()*R_a_b2);
|
| 1135 |
+
return R_a_b1 * R_b1_b2.GetRot() / dt;
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
IMETHOD Twist diff(const Frame& F_a_b1,const Frame& F_a_b2,double dt) {
|
| 1139 |
+
return Twist(
|
| 1140 |
+
diff(F_a_b1.p,F_a_b2.p,dt),
|
| 1141 |
+
diff(F_a_b1.M,F_a_b2.M,dt)
|
| 1142 |
+
);
|
| 1143 |
+
}
|
| 1144 |
+
IMETHOD Twist diff(const Twist& a,const Twist& b,double dt) {
|
| 1145 |
+
return Twist(diff(a.vel,b.vel,dt),diff(a.rot,b.rot,dt));
|
| 1146 |
+
}
|
| 1147 |
+
|
| 1148 |
+
IMETHOD Wrench diff(const Wrench& a,const Wrench& b,double dt) {
|
| 1149 |
+
return Wrench(
|
| 1150 |
+
diff(a.force,b.force,dt),
|
| 1151 |
+
diff(a.torque,b.torque,dt)
|
| 1152 |
+
);
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
+
|
| 1156 |
+
IMETHOD Vector addDelta(const Vector& a,const Vector&da,double dt) {
|
| 1157 |
+
return a+da*dt;
|
| 1158 |
+
}
|
| 1159 |
+
|
| 1160 |
+
IMETHOD Rotation addDelta(const Rotation& a,const Vector&da,double dt) {
|
| 1161 |
+
return Rot(da*dt)*a;
|
| 1162 |
+
}
|
| 1163 |
+
IMETHOD Frame addDelta(const Frame& a,const Twist& da,double dt) {
|
| 1164 |
+
return Frame(
|
| 1165 |
+
addDelta(a.M,da.rot,dt),
|
| 1166 |
+
addDelta(a.p,da.vel,dt)
|
| 1167 |
+
);
|
| 1168 |
+
}
|
| 1169 |
+
IMETHOD Twist addDelta(const Twist& a,const Twist&da,double dt) {
|
| 1170 |
+
return Twist(addDelta(a.vel,da.vel,dt),addDelta(a.rot,da.rot,dt));
|
| 1171 |
+
}
|
| 1172 |
+
IMETHOD Wrench addDelta(const Wrench& a,const Wrench&da,double dt) {
|
| 1173 |
+
return Wrench(addDelta(a.force,da.force,dt),addDelta(a.torque,da.torque,dt));
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
|
| 1177 |
+
/**
|
| 1178 |
+
* \brief addDelta operator for displacement rotational velocity.
|
| 1179 |
+
*
|
| 1180 |
+
* The Vector arguments here represent a displacement rotational velocity. i.e. a rotation
|
| 1181 |
+
* around a fixed axis for a certain angle. For this representation you cannot use diff() but
|
| 1182 |
+
* have to use diff_displ().
|
| 1183 |
+
*
|
| 1184 |
+
* \param a : displacement rotational velocity
|
| 1185 |
+
* \param da : rotational velocity
|
| 1186 |
+
* \return displacement rotational velocity
|
| 1187 |
+
*
|
| 1188 |
+
* \warning do not confuse displacement rotational velocities and velocities
|
| 1189 |
+
* \warning do not confuse displacement twist and twist.
|
| 1190 |
+
*
|
| 1191 |
+
IMETHOD Vector addDelta_displ(const Vector& a,const Vector&da,double dt) {
|
| 1192 |
+
return getRot(addDelta(Rot(a),da,dt));
|
| 1193 |
+
}*/
|
| 1194 |
+
|
| 1195 |
+
/**
|
| 1196 |
+
* \brief addDelta operator for displacement twist.
|
| 1197 |
+
*
|
| 1198 |
+
* The Vector arguments here represent a displacement rotational velocity. i.e. a rotation
|
| 1199 |
+
* around a fixed axis for a certain angle. For this representation you cannot use diff() but
|
| 1200 |
+
* have to use diff_displ().
|
| 1201 |
+
*
|
| 1202 |
+
* \param a : displacement twist
|
| 1203 |
+
* \param da : twist
|
| 1204 |
+
* \return displacement twist
|
| 1205 |
+
*
|
| 1206 |
+
* \warning do not confuse displacement rotational velocities and velocities
|
| 1207 |
+
* \warning do not confuse displacement twist and twist.
|
| 1208 |
+
*
|
| 1209 |
+
IMETHOD Twist addDelta_displ(const Twist& a,const Twist&da,double dt) {
|
| 1210 |
+
return Twist(addDelta(a.vel,da.vel,dt),addDelta_displ(a.rot,da.rot,dt));
|
| 1211 |
+
}*/
|
| 1212 |
+
|
| 1213 |
+
|
| 1214 |
+
IMETHOD void random(Vector& a) {
|
| 1215 |
+
random(a[0]);
|
| 1216 |
+
random(a[1]);
|
| 1217 |
+
random(a[2]);
|
| 1218 |
+
}
|
| 1219 |
+
IMETHOD void random(Twist& a) {
|
| 1220 |
+
random(a.rot);
|
| 1221 |
+
random(a.vel);
|
| 1222 |
+
}
|
| 1223 |
+
IMETHOD void random(Wrench& a) {
|
| 1224 |
+
random(a.torque);
|
| 1225 |
+
random(a.force);
|
| 1226 |
+
}
|
| 1227 |
+
|
| 1228 |
+
IMETHOD void random(Rotation& R) {
|
| 1229 |
+
double alfa;
|
| 1230 |
+
double beta;
|
| 1231 |
+
double gamma;
|
| 1232 |
+
random(alfa);
|
| 1233 |
+
random(beta);
|
| 1234 |
+
random(gamma);
|
| 1235 |
+
R = Rotation::EulerZYX(alfa,beta,gamma);
|
| 1236 |
+
}
|
| 1237 |
+
|
| 1238 |
+
IMETHOD void random(Frame& F) {
|
| 1239 |
+
random(F.M);
|
| 1240 |
+
random(F.p);
|
| 1241 |
+
}
|
| 1242 |
+
|
| 1243 |
+
IMETHOD void posrandom(Vector& a) {
|
| 1244 |
+
posrandom(a[0]);
|
| 1245 |
+
posrandom(a[1]);
|
| 1246 |
+
posrandom(a[2]);
|
| 1247 |
+
}
|
| 1248 |
+
IMETHOD void posrandom(Twist& a) {
|
| 1249 |
+
posrandom(a.rot);
|
| 1250 |
+
posrandom(a.vel);
|
| 1251 |
+
}
|
| 1252 |
+
IMETHOD void posrandom(Wrench& a) {
|
| 1253 |
+
posrandom(a.torque);
|
| 1254 |
+
posrandom(a.force);
|
| 1255 |
+
}
|
| 1256 |
+
|
| 1257 |
+
IMETHOD void posrandom(Rotation& R) {
|
| 1258 |
+
double alfa;
|
| 1259 |
+
double beta;
|
| 1260 |
+
double gamma;
|
| 1261 |
+
posrandom(alfa);
|
| 1262 |
+
posrandom(beta);
|
| 1263 |
+
posrandom(gamma);
|
| 1264 |
+
R = Rotation::EulerZYX(alfa,beta,gamma);
|
| 1265 |
+
}
|
| 1266 |
+
|
| 1267 |
+
IMETHOD void posrandom(Frame& F) {
|
| 1268 |
+
random(F.M);
|
| 1269 |
+
random(F.p);
|
| 1270 |
+
}
|
| 1271 |
+
|
| 1272 |
+
|
| 1273 |
+
|
| 1274 |
+
|
| 1275 |
+
IMETHOD bool operator==(const Frame& a,const Frame& b ) {
|
| 1276 |
+
#ifdef KDL_USE_EQUAL
|
| 1277 |
+
return Equal(a,b);
|
| 1278 |
+
#else
|
| 1279 |
+
return (a.p == b.p &&
|
| 1280 |
+
a.M == b.M );
|
| 1281 |
+
#endif
|
| 1282 |
+
}
|
| 1283 |
+
|
| 1284 |
+
IMETHOD bool operator!=(const Frame& a,const Frame& b) {
|
| 1285 |
+
return !operator==(a,b);
|
| 1286 |
+
}
|
| 1287 |
+
|
| 1288 |
+
IMETHOD bool operator==(const Vector& a,const Vector& b) {
|
| 1289 |
+
#ifdef KDL_USE_EQUAL
|
| 1290 |
+
return Equal(a,b);
|
| 1291 |
+
#else
|
| 1292 |
+
return (a.data[0]==b.data[0]&&
|
| 1293 |
+
a.data[1]==b.data[1]&&
|
| 1294 |
+
a.data[2]==b.data[2] );
|
| 1295 |
+
#endif
|
| 1296 |
+
}
|
| 1297 |
+
|
| 1298 |
+
IMETHOD bool operator!=(const Vector& a,const Vector& b) {
|
| 1299 |
+
return !operator==(a,b);
|
| 1300 |
+
}
|
| 1301 |
+
|
| 1302 |
+
IMETHOD bool operator==(const Twist& a,const Twist& b) {
|
| 1303 |
+
#ifdef KDL_USE_EQUAL
|
| 1304 |
+
return Equal(a,b);
|
| 1305 |
+
#else
|
| 1306 |
+
return (a.rot==b.rot &&
|
| 1307 |
+
a.vel==b.vel );
|
| 1308 |
+
#endif
|
| 1309 |
+
}
|
| 1310 |
+
|
| 1311 |
+
IMETHOD bool operator!=(const Twist& a,const Twist& b) {
|
| 1312 |
+
return !operator==(a,b);
|
| 1313 |
+
}
|
| 1314 |
+
|
| 1315 |
+
IMETHOD bool operator==(const Wrench& a,const Wrench& b ) {
|
| 1316 |
+
#ifdef KDL_USE_EQUAL
|
| 1317 |
+
return Equal(a,b);
|
| 1318 |
+
#else
|
| 1319 |
+
return (a.force==b.force &&
|
| 1320 |
+
a.torque==b.torque );
|
| 1321 |
+
#endif
|
| 1322 |
+
}
|
| 1323 |
+
|
| 1324 |
+
IMETHOD bool operator!=(const Wrench& a,const Wrench& b) {
|
| 1325 |
+
return !operator==(a,b);
|
| 1326 |
+
}
|
| 1327 |
+
IMETHOD bool operator!=(const Rotation& a,const Rotation& b) {
|
| 1328 |
+
return !operator==(a,b);
|
| 1329 |
+
}
|
| 1330 |
+
|
| 1331 |
+
IMETHOD bool operator==(const Vector2& a,const Vector2& b) {
|
| 1332 |
+
#ifdef KDL_USE_EQUAL
|
| 1333 |
+
return Equal(a,b);
|
| 1334 |
+
#else
|
| 1335 |
+
return (a.data[0]==b.data[0]&&
|
| 1336 |
+
a.data[1]==b.data[1] );
|
| 1337 |
+
#endif
|
| 1338 |
+
}
|
| 1339 |
+
|
| 1340 |
+
IMETHOD bool operator!=(const Vector2& a,const Vector2& b) {
|
| 1341 |
+
return !operator==(a,b);
|
| 1342 |
+
}
|
| 1343 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames_io.cpp
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/***************************************************************************
|
| 3 |
+
frames_io.h - description
|
| 4 |
+
-------------------------
|
| 5 |
+
begin : June 2006
|
| 6 |
+
copyright : (C) 2006 Erwin Aertbelien
|
| 7 |
+
email : firstname.lastname@mech.kuleuven.ac.be
|
| 8 |
+
|
| 9 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 10 |
+
|
| 11 |
+
***************************************************************************
|
| 12 |
+
* This library is free software; you can redistribute it and/or *
|
| 13 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 14 |
+
* License as published by the Free Software Foundation; either *
|
| 15 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 16 |
+
* *
|
| 17 |
+
* This library is distributed in the hope that it will be useful, *
|
| 18 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 19 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 20 |
+
* Lesser General Public License for more details. *
|
| 21 |
+
* *
|
| 22 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 23 |
+
* License along with this library; if not, write to the Free Software *
|
| 24 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 25 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 26 |
+
* *
|
| 27 |
+
***************************************************************************/
|
| 28 |
+
|
| 29 |
+
#include "utilities/error.h"
|
| 30 |
+
#include "utilities/error_stack.h"
|
| 31 |
+
#include "frames.hpp"
|
| 32 |
+
#include "frames_io.hpp"
|
| 33 |
+
|
| 34 |
+
#include <stdlib.h>
|
| 35 |
+
#include <ctype.h>
|
| 36 |
+
#include <string.h>
|
| 37 |
+
#include <iostream>
|
| 38 |
+
|
| 39 |
+
namespace KDL {
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
std::ostream& operator << (std::ostream& os,const Vector& v) {
|
| 43 |
+
os << "[" << std::setw(KDL_FRAME_WIDTH) << v(0) << "," << std::setw(KDL_FRAME_WIDTH)<<v(1)
|
| 44 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v(2) << "]";
|
| 45 |
+
return os;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
std::ostream& operator << (std::ostream& os,const Twist& v) {
|
| 49 |
+
os << "[" << std::setw(KDL_FRAME_WIDTH) << v.vel(0)
|
| 50 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.vel(1)
|
| 51 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.vel(2)
|
| 52 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.rot(0)
|
| 53 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.rot(1)
|
| 54 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.rot(2)
|
| 55 |
+
<< "]";
|
| 56 |
+
return os;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
std::ostream& operator << (std::ostream& os,const Wrench& v) {
|
| 60 |
+
os << "[" << std::setw(KDL_FRAME_WIDTH) << v.force(0)
|
| 61 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.force(1)
|
| 62 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.force(2)
|
| 63 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.torque(0)
|
| 64 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.torque(1)
|
| 65 |
+
<< "," << std::setw(KDL_FRAME_WIDTH) << v.torque(2)
|
| 66 |
+
<< "]";
|
| 67 |
+
return os;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
std::ostream& operator << (std::ostream& os,const Rotation& R) {
|
| 72 |
+
#ifdef KDL_ROTATION_PROPERTIES_RPY
|
| 73 |
+
double r,p,y;
|
| 74 |
+
R.GetRPY(r,p,y);
|
| 75 |
+
os << "[RPY]"<<endl;
|
| 76 |
+
os << "[";
|
| 77 |
+
os << std::setw(KDL_FRAME_WIDTH) << r << ",";
|
| 78 |
+
os << std::setw(KDL_FRAME_WIDTH) << p << ",";
|
| 79 |
+
os << std::setw(KDL_FRAME_WIDTH) << y << "]";
|
| 80 |
+
#else
|
| 81 |
+
# ifdef KDL_ROTATION_PROPERTIES_EULER
|
| 82 |
+
double z,y,x;
|
| 83 |
+
R.GetEulerZYX(z,y,x);
|
| 84 |
+
os << "[EULERZYX]"<<endl;
|
| 85 |
+
os << "[";
|
| 86 |
+
os << std::setw(KDL_FRAME_WIDTH) << z << ",";
|
| 87 |
+
os << std::setw(KDL_FRAME_WIDTH) << y << ",";
|
| 88 |
+
os << std::setw(KDL_FRAME_WIDTH) << x << "]";
|
| 89 |
+
# else
|
| 90 |
+
os << "[";
|
| 91 |
+
for (int i=0;i<=2;i++) {
|
| 92 |
+
os << std::setw(KDL_FRAME_WIDTH) << R(i,0) << "," <<
|
| 93 |
+
std::setw(KDL_FRAME_WIDTH) << R(i,1) << "," <<
|
| 94 |
+
std::setw(KDL_FRAME_WIDTH) << R(i,2);
|
| 95 |
+
if (i<2)
|
| 96 |
+
os << ";"<< std::endl << " ";
|
| 97 |
+
else
|
| 98 |
+
os << "]";
|
| 99 |
+
}
|
| 100 |
+
# endif
|
| 101 |
+
#endif
|
| 102 |
+
return os;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
std::ostream& operator << (std::ostream& os, const Frame& T)
|
| 106 |
+
{
|
| 107 |
+
os << "[" << T.M << std::endl<< T.p << "]";
|
| 108 |
+
return os;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
std::ostream& operator << (std::ostream& os,const Vector2& v) {
|
| 112 |
+
os << "[" << std::setw(KDL_FRAME_WIDTH) << v(0) << "," << std::setw(KDL_FRAME_WIDTH)<<v(1)
|
| 113 |
+
<< "]";
|
| 114 |
+
return os;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// Rotation2 gives back an angle in degrees with the << and >> operators.
|
| 118 |
+
std::ostream& operator << (std::ostream& os,const Rotation2& R) {
|
| 119 |
+
os << "[" << R.GetRot()*rad2deg << "]";
|
| 120 |
+
return os;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
std::ostream& operator << (std::ostream& os, const Frame2& T)
|
| 124 |
+
{
|
| 125 |
+
os << T.M << T.p;
|
| 126 |
+
return os;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
std::istream& operator >> (std::istream& is,Vector& v)
|
| 130 |
+
{ IOTrace("Stream input Vector (vector or ZERO)");
|
| 131 |
+
char storage[10];
|
| 132 |
+
EatWord(is,"[]",storage,10);
|
| 133 |
+
if (strlen(storage)==0) {
|
| 134 |
+
Eat(is,'[');
|
| 135 |
+
is >> v(0);
|
| 136 |
+
Eat(is,',');
|
| 137 |
+
is >> v(1);
|
| 138 |
+
Eat(is,',');
|
| 139 |
+
is >> v(2);
|
| 140 |
+
EatEnd(is,']');
|
| 141 |
+
IOTracePop();
|
| 142 |
+
return is;
|
| 143 |
+
}
|
| 144 |
+
if (strcmp(storage,"ZERO")==0) {
|
| 145 |
+
v = Vector::Zero();
|
| 146 |
+
IOTracePop();
|
| 147 |
+
return is;
|
| 148 |
+
}
|
| 149 |
+
throw Error_Frame_Vector_Unexpected_id();
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
std::istream& operator >> (std::istream& is,Twist& v)
|
| 153 |
+
{ IOTrace("Stream input Twist");
|
| 154 |
+
Eat(is,'[');
|
| 155 |
+
is >> v.vel(0);
|
| 156 |
+
Eat(is,',');
|
| 157 |
+
is >> v.vel(1);
|
| 158 |
+
Eat(is,',');
|
| 159 |
+
is >> v.vel(2);
|
| 160 |
+
Eat(is,',');
|
| 161 |
+
is >> v.rot(0);
|
| 162 |
+
Eat(is,',');
|
| 163 |
+
is >> v.rot(1);
|
| 164 |
+
Eat(is,',');
|
| 165 |
+
is >> v.rot(2);
|
| 166 |
+
EatEnd(is,']');
|
| 167 |
+
IOTracePop();
|
| 168 |
+
return is;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
std::istream& operator >> (std::istream& is,Wrench& v)
|
| 172 |
+
{ IOTrace("Stream input Wrench");
|
| 173 |
+
Eat(is,'[');
|
| 174 |
+
is >> v.force(0);
|
| 175 |
+
Eat(is,',');
|
| 176 |
+
is >> v.force(1);
|
| 177 |
+
Eat(is,',');
|
| 178 |
+
is >> v.force(2);
|
| 179 |
+
Eat(is,',');
|
| 180 |
+
is >> v.torque(0);
|
| 181 |
+
Eat(is,',');
|
| 182 |
+
is >> v.torque(1);
|
| 183 |
+
Eat(is,',');
|
| 184 |
+
is >> v.torque(2);
|
| 185 |
+
EatEnd(is,']');
|
| 186 |
+
IOTracePop();
|
| 187 |
+
return is;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
std::istream& operator >> (std::istream& is,Rotation& r)
|
| 191 |
+
{ IOTrace("Stream input Rotation (Matrix or EULERZYX, EULERZYZ,RPY, ROT, IDENTITY)");
|
| 192 |
+
char storage[10];
|
| 193 |
+
EatWord(is,"[]",storage,10);
|
| 194 |
+
if (strlen(storage)==0) {
|
| 195 |
+
Eat(is,'[');
|
| 196 |
+
for (int i=0;i<3;i++) {
|
| 197 |
+
is >> r(i,0);
|
| 198 |
+
Eat(is,',') ;
|
| 199 |
+
is >> r(i,1);
|
| 200 |
+
Eat(is,',');
|
| 201 |
+
is >> r(i,2);
|
| 202 |
+
if (i<2)
|
| 203 |
+
Eat(is,';');
|
| 204 |
+
else
|
| 205 |
+
EatEnd(is,']');
|
| 206 |
+
}
|
| 207 |
+
IOTracePop();
|
| 208 |
+
return is;
|
| 209 |
+
}
|
| 210 |
+
Vector v;
|
| 211 |
+
if (strcmp(storage,"EULERZYX")==0) {
|
| 212 |
+
is >> v;
|
| 213 |
+
v=v*deg2rad;
|
| 214 |
+
r = Rotation::EulerZYX(v(0),v(1),v(2));
|
| 215 |
+
IOTracePop();
|
| 216 |
+
return is;
|
| 217 |
+
}
|
| 218 |
+
if (strcmp(storage,"EULERZYZ")==0) {
|
| 219 |
+
is >> v;
|
| 220 |
+
v=v*deg2rad;
|
| 221 |
+
r = Rotation::EulerZYZ(v(0),v(1),v(2));
|
| 222 |
+
IOTracePop();
|
| 223 |
+
return is;
|
| 224 |
+
}
|
| 225 |
+
if (strcmp(storage,"RPY")==0) {
|
| 226 |
+
is >> v;
|
| 227 |
+
v=v*deg2rad;
|
| 228 |
+
r = Rotation::RPY(v(0),v(1),v(2));
|
| 229 |
+
IOTracePop();
|
| 230 |
+
return is;
|
| 231 |
+
}
|
| 232 |
+
if (strcmp(storage,"ROT")==0) {
|
| 233 |
+
is >> v;
|
| 234 |
+
double angle;
|
| 235 |
+
Eat(is,'[');
|
| 236 |
+
is >> angle;
|
| 237 |
+
EatEnd(is,']');
|
| 238 |
+
r = Rotation::Rot(v,angle*deg2rad);
|
| 239 |
+
IOTracePop();
|
| 240 |
+
return is;
|
| 241 |
+
}
|
| 242 |
+
if (strcmp(storage,"IDENTITY")==0) {
|
| 243 |
+
r = Rotation::Identity();
|
| 244 |
+
IOTracePop();
|
| 245 |
+
return is;
|
| 246 |
+
}
|
| 247 |
+
throw Error_Frame_Rotation_Unexpected_id();
|
| 248 |
+
return is;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
std::istream& operator >> (std::istream& is,Frame& T)
|
| 252 |
+
{ IOTrace("Stream input Frame (Rotation,Vector) or DH[...]");
|
| 253 |
+
char storage[10];
|
| 254 |
+
EatWord(is,"[",storage,10);
|
| 255 |
+
if (strlen(storage)==0) {
|
| 256 |
+
Eat(is,'[');
|
| 257 |
+
is >> T.M;
|
| 258 |
+
is >> T.p;
|
| 259 |
+
EatEnd(is,']');
|
| 260 |
+
IOTracePop();
|
| 261 |
+
return is;
|
| 262 |
+
}
|
| 263 |
+
if (strcmp(storage,"DH")==0) {
|
| 264 |
+
double a,alpha,d,theta;
|
| 265 |
+
Eat(is,'[');
|
| 266 |
+
is >> a;
|
| 267 |
+
Eat(is,',');
|
| 268 |
+
is >> alpha;
|
| 269 |
+
Eat(is,',');
|
| 270 |
+
is >> d;
|
| 271 |
+
Eat(is,',');
|
| 272 |
+
is >> theta;
|
| 273 |
+
EatEnd(is,']');
|
| 274 |
+
T = Frame::DH(a,alpha*deg2rad,d,theta*deg2rad);
|
| 275 |
+
IOTracePop();
|
| 276 |
+
return is;
|
| 277 |
+
}
|
| 278 |
+
throw Error_Frame_Frame_Unexpected_id();
|
| 279 |
+
return is;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
std::istream& operator >> (std::istream& is,Vector2& v)
|
| 283 |
+
{ IOTrace("Stream input Vector2");
|
| 284 |
+
Eat(is,'[');
|
| 285 |
+
is >> v(0);
|
| 286 |
+
Eat(is,',');
|
| 287 |
+
is >> v(1);
|
| 288 |
+
EatEnd(is,']');
|
| 289 |
+
IOTracePop();
|
| 290 |
+
return is;
|
| 291 |
+
}
|
| 292 |
+
std::istream& operator >> (std::istream& is,Rotation2& r)
|
| 293 |
+
{ IOTrace("Stream input Rotation2");
|
| 294 |
+
Eat(is,'[');
|
| 295 |
+
double val;
|
| 296 |
+
is >> val;
|
| 297 |
+
r.Rot(val*deg2rad);
|
| 298 |
+
EatEnd(is,']');
|
| 299 |
+
IOTracePop();
|
| 300 |
+
return is;
|
| 301 |
+
}
|
| 302 |
+
std::istream& operator >> (std::istream& is,Frame2& T)
|
| 303 |
+
{ IOTrace("Stream input Frame2");
|
| 304 |
+
is >> T.M;
|
| 305 |
+
is >> T.p;
|
| 306 |
+
IOTracePop();
|
| 307 |
+
return is;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
} // namespace Frame
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/frames_io.hpp
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
frames_io.h - description
|
| 3 |
+
-------------------------
|
| 4 |
+
begin : June 2006
|
| 5 |
+
copyright : (C) 2006 Erwin Aertbelien
|
| 6 |
+
email : firstname.lastname@mech.kuleuven.ac.be
|
| 7 |
+
|
| 8 |
+
History (only major changes)( AUTHOR-Description ) :
|
| 9 |
+
|
| 10 |
+
Ruben Smits - Added output for jacobian and jntarray 06/2007
|
| 11 |
+
|
| 12 |
+
***************************************************************************
|
| 13 |
+
* This library is free software; you can redistribute it and/or *
|
| 14 |
+
* modify it under the terms of the GNU Lesser General Public *
|
| 15 |
+
* License as published by the Free Software Foundation; either *
|
| 16 |
+
* version 2.1 of the License, or (at your option) any later version. *
|
| 17 |
+
* *
|
| 18 |
+
* This library is distributed in the hope that it will be useful, *
|
| 19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
| 21 |
+
* Lesser General Public License for more details. *
|
| 22 |
+
* *
|
| 23 |
+
* You should have received a copy of the GNU Lesser General Public *
|
| 24 |
+
* License along with this library; if not, write to the Free Software *
|
| 25 |
+
* Foundation, Inc., 59 Temple Place, *
|
| 26 |
+
* Suite 330, Boston, MA 02111-1307 USA *
|
| 27 |
+
* *
|
| 28 |
+
***************************************************************************/
|
| 29 |
+
/**
|
| 30 |
+
//
|
| 31 |
+
// \file
|
| 32 |
+
// Defines routines for I/O of Frame and related objects.
|
| 33 |
+
// \verbatim
|
| 34 |
+
// Spaces, tabs and newlines do not have any importance.
|
| 35 |
+
// Comments are allowed C-style,C++-style, make/perl/csh -style
|
| 36 |
+
// Description of the I/O :
|
| 37 |
+
// Vector : OUTPUT : e.g. [10,20,30]
|
| 38 |
+
// INPUT :
|
| 39 |
+
// 1) [10,20,30]
|
| 40 |
+
// 2) Zero
|
| 41 |
+
// Twist : e.g. [1,2,3,4,5,6]
|
| 42 |
+
// where [1,2,3] is velocity vector
|
| 43 |
+
// where [4,5,6] is rotational velocity vector
|
| 44 |
+
// Wrench : e.g. [1,2,3,4,5,6]
|
| 45 |
+
// where [1,2,3] represents a force vector
|
| 46 |
+
// where [4,5,6] represents a torque vector
|
| 47 |
+
// Rotation : output :
|
| 48 |
+
// [1,2,3;
|
| 49 |
+
// 4,5,6;
|
| 50 |
+
// 7,8,9] cfr definition of Rotation object.
|
| 51 |
+
// input :
|
| 52 |
+
// 1) like the output
|
| 53 |
+
// 2) EulerZYX,EulerZYZ,RPY word followed by a vector, e.g. :
|
| 54 |
+
// Eulerzyx[10,20,30]
|
| 55 |
+
// (ANGLES are always expressed in DEGREES for I/O)
|
| 56 |
+
// (ANGELS are always expressed in RADIANS for internal representation)
|
| 57 |
+
// 3) Rot [1,2,3] [20] Rotates around axis [1,2,3] with an angle
|
| 58 |
+
// of 20 degrees.
|
| 59 |
+
// 4) Identity returns identity rotation matrix.
|
| 60 |
+
// Frames : output : [ Rotationmatrix positionvector ]
|
| 61 |
+
// e.g. [ [1,0,0;0,1,0;0,0,1] [1,2,3] ]
|
| 62 |
+
// Input :
|
| 63 |
+
// 1) [ Rotationmatrix positionvector ]
|
| 64 |
+
// 2) DH [ 10,10,50,30] Denavit-Hartenberg representation
|
| 65 |
+
// ( is in fact not the representation of a Frame, but more
|
| 66 |
+
// limited, cfr. documentation of Frame object.)
|
| 67 |
+
// \endverbatim
|
| 68 |
+
//
|
| 69 |
+
// \warning
|
| 70 |
+
// You can use iostream.h or iostream header files for file I/O,
|
| 71 |
+
// if one declares the define WANT_STD_IOSTREAM then the standard C++
|
| 72 |
+
// iostreams headers are included instead of the compiler-dependent version
|
| 73 |
+
//
|
| 74 |
+
*
|
| 75 |
+
****************************************************************************/
|
| 76 |
+
#ifndef FRAMES_IO_H
|
| 77 |
+
#define FRAMES_IO_H
|
| 78 |
+
|
| 79 |
+
#include "utilities/utility_io.h"
|
| 80 |
+
#include "frames.hpp"
|
| 81 |
+
#include "jntarray.hpp"
|
| 82 |
+
#include "jacobian.hpp"
|
| 83 |
+
|
| 84 |
+
namespace KDL {
|
| 85 |
+
|
| 86 |
+
//! width to be used when printing variables out with frames_io.h
|
| 87 |
+
//! global variable, can be changed.
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
// I/O to C++ stream.
|
| 91 |
+
std::ostream& operator << (std::ostream& os,const Vector& v);
|
| 92 |
+
std::ostream& operator << (std::ostream& os,const Rotation& R);
|
| 93 |
+
std::ostream& operator << (std::ostream& os,const Frame& T);
|
| 94 |
+
std::ostream& operator << (std::ostream& os,const Twist& T);
|
| 95 |
+
std::ostream& operator << (std::ostream& os,const Wrench& T);
|
| 96 |
+
std::ostream& operator << (std::ostream& os,const Vector2& v);
|
| 97 |
+
std::ostream& operator << (std::ostream& os,const Rotation2& R);
|
| 98 |
+
std::ostream& operator << (std::ostream& os,const Frame2& T);
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
std::istream& operator >> (std::istream& is,Vector& v);
|
| 103 |
+
std::istream& operator >> (std::istream& is,Rotation& R);
|
| 104 |
+
std::istream& operator >> (std::istream& is,Frame& T);
|
| 105 |
+
std::istream& operator >> (std::istream& os,Twist& T);
|
| 106 |
+
std::istream& operator >> (std::istream& os,Wrench& T);
|
| 107 |
+
std::istream& operator >> (std::istream& is,Vector2& v);
|
| 108 |
+
std::istream& operator >> (std::istream& is,Rotation2& R);
|
| 109 |
+
std::istream& operator >> (std::istream& is,Frame2& T);
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
} // namespace Frame
|
| 113 |
+
|
| 114 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/framevel.cpp
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \author
|
| 3 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 4 |
+
*
|
| 5 |
+
* \version
|
| 6 |
+
* ORO_Geometry V0.2
|
| 7 |
+
*
|
| 8 |
+
* \par History
|
| 9 |
+
* - $log$
|
| 10 |
+
*
|
| 11 |
+
* \par Release
|
| 12 |
+
* $Id: rframes.cpp,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 13 |
+
* $Name: $
|
| 14 |
+
****************************************************************************/
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#include "framevel.hpp"
|
| 18 |
+
|
| 19 |
+
namespace KDL {
|
| 20 |
+
|
| 21 |
+
#ifndef KDL_INLINE
|
| 22 |
+
#include "framevel.inl"
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \file
|
| 3 |
+
* This file contains the definition of classes for a
|
| 4 |
+
* Rall Algebra of (subset of) the classes defined in frames,
|
| 5 |
+
* i.e. classes that contain a pair (value,derivative) and define operations on that pair
|
| 6 |
+
* this classes are useful for automatic differentiation ( <-> symbolic diff , <-> numeric diff)
|
| 7 |
+
* Defines VectorVel, RotationVel, FrameVel. Look at Frames.h for details on how to work
|
| 8 |
+
* with Frame objects.
|
| 9 |
+
* \author
|
| 10 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 11 |
+
*
|
| 12 |
+
* \version
|
| 13 |
+
* ORO_Geometry V0.2
|
| 14 |
+
*
|
| 15 |
+
* \par History
|
| 16 |
+
* - $log$
|
| 17 |
+
*
|
| 18 |
+
* \par Release
|
| 19 |
+
* $Id: rframes.h,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 20 |
+
* $Name: $
|
| 21 |
+
****************************************************************************/
|
| 22 |
+
|
| 23 |
+
#ifndef KDL_FRAMEVEL_H
|
| 24 |
+
#define KDL_FRAMEVEL_H
|
| 25 |
+
|
| 26 |
+
#include "utilities/utility.h"
|
| 27 |
+
#include "utilities/rall1d.h"
|
| 28 |
+
#include "utilities/traits.h"
|
| 29 |
+
|
| 30 |
+
#include "frames.hpp"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
namespace KDL {
|
| 34 |
+
|
| 35 |
+
typedef Rall1d<double> doubleVel;
|
| 36 |
+
|
| 37 |
+
IMETHOD doubleVel diff(const doubleVel& a,const doubleVel& b,double dt=1.0) {
|
| 38 |
+
return doubleVel((b.t-a.t)/dt,(b.grad-a.grad)/dt);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
IMETHOD doubleVel addDelta(const doubleVel& a,const doubleVel&da,double dt=1.0) {
|
| 42 |
+
return doubleVel(a.t+da.t*dt,a.grad+da.grad*dt);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
IMETHOD void random(doubleVel& F) {
|
| 46 |
+
random(F.t);
|
| 47 |
+
random(F.grad);
|
| 48 |
+
}
|
| 49 |
+
IMETHOD void posrandom(doubleVel& F) {
|
| 50 |
+
posrandom(F.t);
|
| 51 |
+
posrandom(F.grad);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
template <>
|
| 57 |
+
struct Traits<KDL::doubleVel> {
|
| 58 |
+
typedef double valueType;
|
| 59 |
+
typedef KDL::doubleVel derivType;
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
namespace KDL {
|
| 63 |
+
|
| 64 |
+
class TwistVel;
|
| 65 |
+
class VectorVel;
|
| 66 |
+
class FrameVel;
|
| 67 |
+
class RotationVel;
|
| 68 |
+
|
| 69 |
+
// Equal is friend function, but default arguments for friends are forbidden (§8.3.6.4)
|
| 70 |
+
IMETHOD bool Equal(const VectorVel& r1,const VectorVel& r2,double eps=epsilon);
|
| 71 |
+
IMETHOD bool Equal(const Vector& r1,const VectorVel& r2,double eps=epsilon);
|
| 72 |
+
IMETHOD bool Equal(const VectorVel& r1,const Vector& r2,double eps=epsilon);
|
| 73 |
+
IMETHOD bool Equal(const RotationVel& r1,const RotationVel& r2,double eps=epsilon);
|
| 74 |
+
IMETHOD bool Equal(const Rotation& r1,const RotationVel& r2,double eps=epsilon);
|
| 75 |
+
IMETHOD bool Equal(const RotationVel& r1,const Rotation& r2,double eps=epsilon);
|
| 76 |
+
IMETHOD bool Equal(const FrameVel& r1,const FrameVel& r2,double eps=epsilon);
|
| 77 |
+
IMETHOD bool Equal(const Frame& r1,const FrameVel& r2,double eps=epsilon);
|
| 78 |
+
IMETHOD bool Equal(const FrameVel& r1,const Frame& r2,double eps=epsilon);
|
| 79 |
+
IMETHOD bool Equal(const TwistVel& a,const TwistVel& b,double eps=epsilon);
|
| 80 |
+
IMETHOD bool Equal(const Twist& a,const TwistVel& b,double eps=epsilon);
|
| 81 |
+
IMETHOD bool Equal(const TwistVel& a,const Twist& b,double eps=epsilon);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class VectorVel
|
| 85 |
+
// = TITLE
|
| 86 |
+
// An VectorVel is a Vector and its first derivative
|
| 87 |
+
// = CLASS TYPE
|
| 88 |
+
// Concrete
|
| 89 |
+
{
|
| 90 |
+
public:
|
| 91 |
+
Vector p; // position vector
|
| 92 |
+
Vector v; // velocity vector
|
| 93 |
+
public:
|
| 94 |
+
VectorVel():p(),v(){}
|
| 95 |
+
VectorVel(const Vector& _p,const Vector& _v):p(_p),v(_v) {}
|
| 96 |
+
explicit VectorVel(const Vector& _p):p(_p),v(Vector::Zero()) {}
|
| 97 |
+
|
| 98 |
+
Vector value() const { return p;}
|
| 99 |
+
Vector deriv() const { return v;}
|
| 100 |
+
|
| 101 |
+
IMETHOD VectorVel& operator = (const VectorVel& arg);
|
| 102 |
+
IMETHOD VectorVel& operator = (const Vector& arg);
|
| 103 |
+
IMETHOD VectorVel& operator += (const VectorVel& arg);
|
| 104 |
+
IMETHOD VectorVel& operator -= (const VectorVel& arg);
|
| 105 |
+
IMETHOD static VectorVel Zero();
|
| 106 |
+
IMETHOD void ReverseSign();
|
| 107 |
+
IMETHOD doubleVel Norm(double eps=epsilon) const;
|
| 108 |
+
IMETHOD friend VectorVel operator + (const VectorVel& r1,const VectorVel& r2);
|
| 109 |
+
IMETHOD friend VectorVel operator - (const VectorVel& r1,const VectorVel& r2);
|
| 110 |
+
IMETHOD friend VectorVel operator + (const Vector& r1,const VectorVel& r2);
|
| 111 |
+
IMETHOD friend VectorVel operator - (const Vector& r1,const VectorVel& r2);
|
| 112 |
+
IMETHOD friend VectorVel operator + (const VectorVel& r1,const Vector& r2);
|
| 113 |
+
IMETHOD friend VectorVel operator - (const VectorVel& r1,const Vector& r2);
|
| 114 |
+
IMETHOD friend VectorVel operator * (const VectorVel& r1,const VectorVel& r2);
|
| 115 |
+
IMETHOD friend VectorVel operator * (const VectorVel& r1,const Vector& r2);
|
| 116 |
+
IMETHOD friend VectorVel operator * (const Vector& r1,const VectorVel& r2);
|
| 117 |
+
IMETHOD friend VectorVel operator * (const VectorVel& r1,double r2);
|
| 118 |
+
IMETHOD friend VectorVel operator * (double r1,const VectorVel& r2);
|
| 119 |
+
IMETHOD friend VectorVel operator * (const doubleVel& r1,const VectorVel& r2);
|
| 120 |
+
IMETHOD friend VectorVel operator * (const VectorVel& r2,const doubleVel& r1);
|
| 121 |
+
IMETHOD friend VectorVel operator*(const Rotation& R,const VectorVel& x);
|
| 122 |
+
|
| 123 |
+
IMETHOD friend VectorVel operator / (const VectorVel& r1,double r2);
|
| 124 |
+
IMETHOD friend VectorVel operator / (const VectorVel& r2,const doubleVel& r1);
|
| 125 |
+
IMETHOD friend void SetToZero(VectorVel& v);
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
IMETHOD friend bool Equal(const VectorVel& r1,const VectorVel& r2,double eps);
|
| 129 |
+
IMETHOD friend bool Equal(const Vector& r1,const VectorVel& r2,double eps);
|
| 130 |
+
IMETHOD friend bool Equal(const VectorVel& r1,const Vector& r2,double eps);
|
| 131 |
+
|
| 132 |
+
IMETHOD friend bool operator==(const VectorVel& r1,const VectorVel& r2);
|
| 133 |
+
IMETHOD friend bool operator!=(const VectorVel& r1,const VectorVel& r2);
|
| 134 |
+
IMETHOD friend bool operator==(const Vector& r1,const VectorVel& r2);
|
| 135 |
+
IMETHOD friend bool operator!=(const Vector& r1,const VectorVel& r2);
|
| 136 |
+
IMETHOD friend bool operator==(const VectorVel& r1,const Vector& r2);
|
| 137 |
+
IMETHOD friend bool operator!=(const VectorVel& r1,const Vector& r2);
|
| 138 |
+
|
| 139 |
+
IMETHOD friend VectorVel operator - (const VectorVel& r);
|
| 140 |
+
IMETHOD friend doubleVel dot(const VectorVel& lhs,const VectorVel& rhs);
|
| 141 |
+
IMETHOD friend doubleVel dot(const VectorVel& lhs,const Vector& rhs);
|
| 142 |
+
IMETHOD friend doubleVel dot(const Vector& lhs,const VectorVel& rhs);
|
| 143 |
+
};
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class RotationVel
|
| 147 |
+
// = TITLE
|
| 148 |
+
// An RotationVel is a Rotation and its first derivative, a rotation vector
|
| 149 |
+
// = CLASS TYPE
|
| 150 |
+
// Concrete
|
| 151 |
+
{
|
| 152 |
+
public:
|
| 153 |
+
Rotation R; // Rotation matrix
|
| 154 |
+
Vector w; // rotation vector
|
| 155 |
+
public:
|
| 156 |
+
RotationVel():R(),w() {}
|
| 157 |
+
explicit RotationVel(const Rotation& _R):R(_R),w(Vector::Zero()){}
|
| 158 |
+
RotationVel(const Rotation& _R,const Vector& _w):R(_R),w(_w){}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
Rotation value() const { return R;}
|
| 162 |
+
Vector deriv() const { return w;}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
IMETHOD RotationVel& operator = (const RotationVel& arg);
|
| 166 |
+
IMETHOD RotationVel& operator = (const Rotation& arg);
|
| 167 |
+
IMETHOD VectorVel UnitX() const;
|
| 168 |
+
IMETHOD VectorVel UnitY() const;
|
| 169 |
+
IMETHOD VectorVel UnitZ() const;
|
| 170 |
+
IMETHOD static RotationVel Identity();
|
| 171 |
+
IMETHOD RotationVel Inverse() const;
|
| 172 |
+
IMETHOD VectorVel Inverse(const VectorVel& arg) const;
|
| 173 |
+
IMETHOD VectorVel Inverse(const Vector& arg) const;
|
| 174 |
+
IMETHOD VectorVel operator*(const VectorVel& arg) const;
|
| 175 |
+
IMETHOD VectorVel operator*(const Vector& arg) const;
|
| 176 |
+
IMETHOD void DoRotX(const doubleVel& angle);
|
| 177 |
+
IMETHOD void DoRotY(const doubleVel& angle);
|
| 178 |
+
IMETHOD void DoRotZ(const doubleVel& angle);
|
| 179 |
+
IMETHOD static RotationVel RotX(const doubleVel& angle);
|
| 180 |
+
IMETHOD static RotationVel RotY(const doubleVel& angle);
|
| 181 |
+
IMETHOD static RotationVel RotZ(const doubleVel& angle);
|
| 182 |
+
IMETHOD static RotationVel Rot(const Vector& rotvec,const doubleVel& angle);
|
| 183 |
+
// rotvec has arbitrary norm
|
| 184 |
+
// rotation around a constant vector !
|
| 185 |
+
IMETHOD static RotationVel Rot2(const Vector& rotvec,const doubleVel& angle);
|
| 186 |
+
// rotvec is normalized.
|
| 187 |
+
// rotation around a constant vector !
|
| 188 |
+
IMETHOD friend RotationVel operator* (const RotationVel& r1,const RotationVel& r2);
|
| 189 |
+
IMETHOD friend RotationVel operator* (const Rotation& r1,const RotationVel& r2);
|
| 190 |
+
IMETHOD friend RotationVel operator* (const RotationVel& r1,const Rotation& r2);
|
| 191 |
+
IMETHOD friend bool Equal(const RotationVel& r1,const RotationVel& r2,double eps);
|
| 192 |
+
IMETHOD friend bool Equal(const Rotation& r1,const RotationVel& r2,double eps);
|
| 193 |
+
IMETHOD friend bool Equal(const RotationVel& r1,const Rotation& r2,double eps);
|
| 194 |
+
|
| 195 |
+
IMETHOD friend bool operator==(const RotationVel& r1,const RotationVel& r2);
|
| 196 |
+
IMETHOD friend bool operator!=(const RotationVel& r1,const RotationVel& r2);
|
| 197 |
+
IMETHOD friend bool operator==(const Rotation& r1,const RotationVel& r2);
|
| 198 |
+
IMETHOD friend bool operator!=(const Rotation& r1,const RotationVel& r2);
|
| 199 |
+
IMETHOD friend bool operator==(const RotationVel& r1,const Rotation& r2);
|
| 200 |
+
IMETHOD friend bool operator!=(const RotationVel& r1,const Rotation& r2);
|
| 201 |
+
|
| 202 |
+
IMETHOD TwistVel Inverse(const TwistVel& arg) const;
|
| 203 |
+
IMETHOD TwistVel Inverse(const Twist& arg) const;
|
| 204 |
+
IMETHOD TwistVel operator * (const TwistVel& arg) const;
|
| 205 |
+
IMETHOD TwistVel operator * (const Twist& arg) const;
|
| 206 |
+
};
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
class FrameVel
|
| 210 |
+
// = TITLE
|
| 211 |
+
// An FrameVel is a Frame and its first derivative, a Twist vector
|
| 212 |
+
// = CLASS TYPE
|
| 213 |
+
// Concrete
|
| 214 |
+
// = CAVEATS
|
| 215 |
+
//
|
| 216 |
+
{
|
| 217 |
+
public:
|
| 218 |
+
RotationVel M;
|
| 219 |
+
VectorVel p;
|
| 220 |
+
public:
|
| 221 |
+
FrameVel(){}
|
| 222 |
+
|
| 223 |
+
explicit FrameVel(const Frame& _T):
|
| 224 |
+
M(_T.M),p(_T.p) {}
|
| 225 |
+
|
| 226 |
+
FrameVel(const Frame& _T,const Twist& _t):
|
| 227 |
+
M(_T.M,_t.rot),p(_T.p,_t.vel) {}
|
| 228 |
+
|
| 229 |
+
FrameVel(const RotationVel& _M,const VectorVel& _p):
|
| 230 |
+
M(_M),p(_p) {}
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
Frame value() const { return Frame(M.value(),p.value());}
|
| 234 |
+
Twist deriv() const { return Twist(p.deriv(),M.deriv());}
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
IMETHOD FrameVel& operator = (const Frame& arg);
|
| 238 |
+
IMETHOD FrameVel& operator = (const FrameVel& arg);
|
| 239 |
+
IMETHOD static FrameVel Identity();
|
| 240 |
+
IMETHOD FrameVel Inverse() const;
|
| 241 |
+
IMETHOD VectorVel Inverse(const VectorVel& arg) const;
|
| 242 |
+
IMETHOD VectorVel operator*(const VectorVel& arg) const;
|
| 243 |
+
IMETHOD VectorVel operator*(const Vector& arg) const;
|
| 244 |
+
IMETHOD VectorVel Inverse(const Vector& arg) const;
|
| 245 |
+
IMETHOD Frame GetFrame() const;
|
| 246 |
+
IMETHOD Twist GetTwist() const;
|
| 247 |
+
IMETHOD friend FrameVel operator * (const FrameVel& f1,const FrameVel& f2);
|
| 248 |
+
IMETHOD friend FrameVel operator * (const Frame& f1,const FrameVel& f2);
|
| 249 |
+
IMETHOD friend FrameVel operator * (const FrameVel& f1,const Frame& f2);
|
| 250 |
+
IMETHOD friend bool Equal(const FrameVel& r1,const FrameVel& r2,double eps);
|
| 251 |
+
IMETHOD friend bool Equal(const Frame& r1,const FrameVel& r2,double eps);
|
| 252 |
+
IMETHOD friend bool Equal(const FrameVel& r1,const Frame& r2,double eps);
|
| 253 |
+
|
| 254 |
+
IMETHOD friend bool operator==(const FrameVel& a,const FrameVel& b);
|
| 255 |
+
IMETHOD friend bool operator!=(const FrameVel& a,const FrameVel& b);
|
| 256 |
+
IMETHOD friend bool operator==(const Frame& a,const FrameVel& b);
|
| 257 |
+
IMETHOD friend bool operator!=(const Frame& a,const FrameVel& b);
|
| 258 |
+
IMETHOD friend bool operator==(const FrameVel& a,const Frame& b);
|
| 259 |
+
IMETHOD friend bool operator!=(const FrameVel& a,const Frame& b);
|
| 260 |
+
|
| 261 |
+
IMETHOD TwistVel Inverse(const TwistVel& arg) const;
|
| 262 |
+
IMETHOD TwistVel Inverse(const Twist& arg) const;
|
| 263 |
+
IMETHOD TwistVel operator * (const TwistVel& arg) const;
|
| 264 |
+
IMETHOD TwistVel operator * (const Twist& arg) const;
|
| 265 |
+
};
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
//very similar to Wrench class.
|
| 269 |
+
class TwistVel
|
| 270 |
+
// = TITLE
|
| 271 |
+
// This class represents a TwistVel. This is a velocity and rotational velocity together
|
| 272 |
+
{
|
| 273 |
+
public:
|
| 274 |
+
VectorVel vel;
|
| 275 |
+
VectorVel rot;
|
| 276 |
+
public:
|
| 277 |
+
|
| 278 |
+
// = Constructors
|
| 279 |
+
TwistVel():vel(),rot() {};
|
| 280 |
+
TwistVel(const VectorVel& _vel,const VectorVel& _rot):vel(_vel),rot(_rot) {};
|
| 281 |
+
TwistVel(const Twist& p,const Twist& v):vel(p.vel, v.vel), rot( p.rot, v.rot) {};
|
| 282 |
+
TwistVel(const Twist& p):vel(p.vel), rot( p.rot) {};
|
| 283 |
+
|
| 284 |
+
Twist value() const {
|
| 285 |
+
return Twist(vel.value(),rot.value());
|
| 286 |
+
}
|
| 287 |
+
Twist deriv() const {
|
| 288 |
+
return Twist(vel.deriv(),rot.deriv());
|
| 289 |
+
}
|
| 290 |
+
// = Operators
|
| 291 |
+
IMETHOD TwistVel& operator-=(const TwistVel& arg);
|
| 292 |
+
IMETHOD TwistVel& operator+=(const TwistVel& arg);
|
| 293 |
+
|
| 294 |
+
// = External operators
|
| 295 |
+
IMETHOD friend TwistVel operator*(const TwistVel& lhs,double rhs);
|
| 296 |
+
IMETHOD friend TwistVel operator*(double lhs,const TwistVel& rhs);
|
| 297 |
+
IMETHOD friend TwistVel operator/(const TwistVel& lhs,double rhs);
|
| 298 |
+
|
| 299 |
+
IMETHOD friend TwistVel operator*(const TwistVel& lhs,const doubleVel& rhs);
|
| 300 |
+
IMETHOD friend TwistVel operator*(const doubleVel& lhs,const TwistVel& rhs);
|
| 301 |
+
IMETHOD friend TwistVel operator/(const TwistVel& lhs,const doubleVel& rhs);
|
| 302 |
+
|
| 303 |
+
IMETHOD friend TwistVel operator+(const TwistVel& lhs,const TwistVel& rhs);
|
| 304 |
+
IMETHOD friend TwistVel operator-(const TwistVel& lhs,const TwistVel& rhs);
|
| 305 |
+
IMETHOD friend TwistVel operator-(const TwistVel& arg);
|
| 306 |
+
IMETHOD friend void SetToZero(TwistVel& v);
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
// = Zero
|
| 310 |
+
static IMETHOD TwistVel Zero();
|
| 311 |
+
|
| 312 |
+
// = Reverse Sign
|
| 313 |
+
IMETHOD void ReverseSign();
|
| 314 |
+
|
| 315 |
+
// = Change Reference point
|
| 316 |
+
IMETHOD TwistVel RefPoint(const VectorVel& v_base_AB);
|
| 317 |
+
// Changes the reference point of the TwistVel.
|
| 318 |
+
// The VectorVel v_base_AB is expressed in the same base as the TwistVel
|
| 319 |
+
// The VectorVel v_base_AB is a VectorVel from the old point to
|
| 320 |
+
// the new point.
|
| 321 |
+
// Complexity : 6M+6A
|
| 322 |
+
|
| 323 |
+
// = Equality operators
|
| 324 |
+
// do not use operator == because the definition of Equal(.,.) is slightly
|
| 325 |
+
// different. It compares whether the 2 arguments are equal in an eps-interval
|
| 326 |
+
IMETHOD friend bool Equal(const TwistVel& a,const TwistVel& b,double eps);
|
| 327 |
+
IMETHOD friend bool Equal(const Twist& a,const TwistVel& b,double eps);
|
| 328 |
+
IMETHOD friend bool Equal(const TwistVel& a,const Twist& b,double eps);
|
| 329 |
+
|
| 330 |
+
IMETHOD friend bool operator==(const TwistVel& a,const TwistVel& b);
|
| 331 |
+
IMETHOD friend bool operator!=(const TwistVel& a,const TwistVel& b);
|
| 332 |
+
IMETHOD friend bool operator==(const Twist& a,const TwistVel& b);
|
| 333 |
+
IMETHOD friend bool operator!=(const Twist& a,const TwistVel& b);
|
| 334 |
+
IMETHOD friend bool operator==(const TwistVel& a,const Twist& b);
|
| 335 |
+
IMETHOD friend bool operator!=(const TwistVel& a,const Twist& b);
|
| 336 |
+
|
| 337 |
+
// = Conversion to other entities
|
| 338 |
+
IMETHOD Twist GetTwist() const;
|
| 339 |
+
IMETHOD Twist GetTwistDot() const;
|
| 340 |
+
// = Friends
|
| 341 |
+
friend class RotationVel;
|
| 342 |
+
friend class FrameVel;
|
| 343 |
+
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
IMETHOD VectorVel diff(const VectorVel& a,const VectorVel& b,double dt=1.0) {
|
| 347 |
+
return VectorVel(diff(a.p,b.p,dt),diff(a.v,b.v,dt));
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
IMETHOD VectorVel addDelta(const VectorVel& a,const VectorVel&da,double dt=1.0) {
|
| 351 |
+
return VectorVel(addDelta(a.p,da.p,dt),addDelta(a.v,da.v,dt));
|
| 352 |
+
}
|
| 353 |
+
IMETHOD VectorVel diff(const RotationVel& a,const RotationVel& b,double dt = 1.0) {
|
| 354 |
+
return VectorVel(diff(a.R,b.R,dt),diff(a.w,b.w,dt));
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
IMETHOD RotationVel addDelta(const RotationVel& a,const VectorVel&da,double dt=1.0) {
|
| 358 |
+
return RotationVel(addDelta(a.R,da.p,dt),addDelta(a.w,da.v,dt));
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
IMETHOD TwistVel diff(const FrameVel& a,const FrameVel& b,double dt=1.0) {
|
| 362 |
+
return TwistVel(diff(a.M,b.M,dt),diff(a.p,b.p,dt));
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
IMETHOD FrameVel addDelta(const FrameVel& a,const TwistVel& da,double dt=1.0) {
|
| 366 |
+
return FrameVel(
|
| 367 |
+
addDelta(a.M,da.rot,dt),
|
| 368 |
+
addDelta(a.p,da.vel,dt)
|
| 369 |
+
);
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
IMETHOD void random(VectorVel& a) {
|
| 373 |
+
random(a.p);
|
| 374 |
+
random(a.v);
|
| 375 |
+
}
|
| 376 |
+
IMETHOD void random(TwistVel& a) {
|
| 377 |
+
random(a.vel);
|
| 378 |
+
random(a.rot);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
IMETHOD void random(RotationVel& R) {
|
| 382 |
+
random(R.R);
|
| 383 |
+
random(R.w);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
IMETHOD void random(FrameVel& F) {
|
| 387 |
+
random(F.M);
|
| 388 |
+
random(F.p);
|
| 389 |
+
}
|
| 390 |
+
IMETHOD void posrandom(VectorVel& a) {
|
| 391 |
+
posrandom(a.p);
|
| 392 |
+
posrandom(a.v);
|
| 393 |
+
}
|
| 394 |
+
IMETHOD void posrandom(TwistVel& a) {
|
| 395 |
+
posrandom(a.vel);
|
| 396 |
+
posrandom(a.rot);
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
IMETHOD void posrandom(RotationVel& R) {
|
| 400 |
+
posrandom(R.R);
|
| 401 |
+
posrandom(R.w);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
IMETHOD void posrandom(FrameVel& F) {
|
| 405 |
+
posrandom(F.M);
|
| 406 |
+
posrandom(F.p);
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
#ifdef KDL_INLINE
|
| 410 |
+
#include "framevel.inl"
|
| 411 |
+
#endif
|
| 412 |
+
|
| 413 |
+
} // namespace KDL
|
| 414 |
+
|
| 415 |
+
template<> struct std::hash<KDL::doubleVel>
|
| 416 |
+
{
|
| 417 |
+
std::size_t operator()(KDL::doubleVel const& dv) const noexcept
|
| 418 |
+
{
|
| 419 |
+
size_t seed = 0;
|
| 420 |
+
KDL::hash_combine(seed, dv.value());
|
| 421 |
+
KDL::hash_combine(seed, dv.deriv());
|
| 422 |
+
return seed;
|
| 423 |
+
}
|
| 424 |
+
};
|
| 425 |
+
|
| 426 |
+
template<> struct std::hash<KDL::VectorVel>
|
| 427 |
+
{
|
| 428 |
+
std::size_t operator()(KDL::VectorVel const& vv) const noexcept
|
| 429 |
+
{
|
| 430 |
+
size_t seed = 0;
|
| 431 |
+
KDL::hash_combine(seed, vv.p);
|
| 432 |
+
KDL::hash_combine(seed, vv.v);
|
| 433 |
+
return seed;
|
| 434 |
+
}
|
| 435 |
+
};
|
| 436 |
+
|
| 437 |
+
template<> struct std::hash<KDL::RotationVel>
|
| 438 |
+
{
|
| 439 |
+
std::size_t operator()(KDL::RotationVel const& rv) const noexcept
|
| 440 |
+
{
|
| 441 |
+
size_t seed = 0;
|
| 442 |
+
KDL::hash_combine(seed, rv.R);
|
| 443 |
+
KDL::hash_combine(seed, rv.w);
|
| 444 |
+
return seed;
|
| 445 |
+
}
|
| 446 |
+
};
|
| 447 |
+
|
| 448 |
+
template<> struct std::hash<KDL::FrameVel>
|
| 449 |
+
{
|
| 450 |
+
std::size_t operator()(KDL::FrameVel const& fv) const noexcept
|
| 451 |
+
{
|
| 452 |
+
size_t seed = 0;
|
| 453 |
+
KDL::hash_combine(seed, fv.M);
|
| 454 |
+
KDL::hash_combine(seed, fv.p);
|
| 455 |
+
return seed;
|
| 456 |
+
}
|
| 457 |
+
};
|
| 458 |
+
|
| 459 |
+
template<> struct std::hash<KDL::TwistVel>
|
| 460 |
+
{
|
| 461 |
+
std::size_t operator()(KDL::TwistVel const& tv) const noexcept
|
| 462 |
+
{
|
| 463 |
+
size_t seed = 0;
|
| 464 |
+
KDL::hash_combine(seed, tv.vel);
|
| 465 |
+
KDL::hash_combine(seed, tv.rot);
|
| 466 |
+
return seed;
|
| 467 |
+
}
|
| 468 |
+
};
|
| 469 |
+
|
| 470 |
+
#end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4 |
+
*
|
| 5 |
+
* \author
|
| 6 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 7 |
+
*
|
| 8 |
+
* \version
|
| 9 |
+
* ORO_Geometry V0.2
|
| 10 |
+
*
|
| 11 |
+
* \par History
|
| 12 |
+
* - $log$
|
| 13 |
+
*
|
| 14 |
+
* \par Release
|
| 15 |
+
* $Id: rframes.inl,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 16 |
+
* $Name: $
|
| 17 |
+
****************************************************************************/
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
// Methods and operators related to FrameVelVel
|
| 21 |
+
// They all delegate most of the work to RotationVelVel and VectorVelVel
|
| 22 |
+
FrameVel& FrameVel::operator = (const FrameVel& arg) {
|
| 23 |
+
M=arg.M;
|
| 24 |
+
p=arg.p;
|
| 25 |
+
return *this;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
FrameVel FrameVel::Identity() {
|
| 29 |
+
return FrameVel(RotationVel::Identity(),VectorVel::Zero());
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
FrameVel operator *(const FrameVel& lhs,const FrameVel& rhs)
|
| 34 |
+
{
|
| 35 |
+
return FrameVel(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 36 |
+
}
|
| 37 |
+
FrameVel operator *(const FrameVel& lhs,const Frame& rhs)
|
| 38 |
+
{
|
| 39 |
+
return FrameVel(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
|
| 40 |
+
}
|
| 41 |
+
FrameVel operator *(const Frame& lhs,const FrameVel& rhs)
|
| 42 |
+
{
|
| 43 |
+
return FrameVel(lhs.M*rhs.M , lhs.M*rhs.p+lhs.p );
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
VectorVel FrameVel::operator *(const VectorVel & arg) const
|
| 47 |
+
{
|
| 48 |
+
return M*arg+p;
|
| 49 |
+
}
|
| 50 |
+
VectorVel FrameVel::operator *(const Vector & arg) const
|
| 51 |
+
{
|
| 52 |
+
return M*arg+p;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
VectorVel FrameVel::Inverse(const VectorVel& arg) const
|
| 56 |
+
{
|
| 57 |
+
return M.Inverse(arg-p);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
VectorVel FrameVel::Inverse(const Vector& arg) const
|
| 61 |
+
{
|
| 62 |
+
return M.Inverse(arg-p);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
FrameVel FrameVel::Inverse() const
|
| 66 |
+
{
|
| 67 |
+
return FrameVel(M.Inverse(),-M.Inverse(p));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
FrameVel& FrameVel::operator = (const Frame& arg) {
|
| 71 |
+
M = arg.M;
|
| 72 |
+
p = arg.p;
|
| 73 |
+
return *this;
|
| 74 |
+
}
|
| 75 |
+
bool Equal(const FrameVel& r1,const FrameVel& r2,double eps) {
|
| 76 |
+
return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
|
| 77 |
+
}
|
| 78 |
+
bool Equal(const Frame& r1,const FrameVel& r2,double eps) {
|
| 79 |
+
return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
|
| 80 |
+
}
|
| 81 |
+
bool Equal(const FrameVel& r1,const Frame& r2,double eps) {
|
| 82 |
+
return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
|
| 83 |
+
}
|
| 84 |
+
bool operator==(const FrameVel& r1,const FrameVel& r2) {
|
| 85 |
+
#ifdef KDL_USE_EQUAL
|
| 86 |
+
return Equal(r1, r2);
|
| 87 |
+
#else
|
| 88 |
+
return (r1.p == r2.p &&
|
| 89 |
+
r1.M == r2.M );
|
| 90 |
+
#endif
|
| 91 |
+
}
|
| 92 |
+
bool operator!=(const FrameVel& r1,const FrameVel& r2) {
|
| 93 |
+
return !operator==(r1,r2);
|
| 94 |
+
}
|
| 95 |
+
bool operator==(const Frame& r1,const FrameVel& r2) {
|
| 96 |
+
#ifdef KDL_USE_EQUAL
|
| 97 |
+
return Equal(r1, r2);
|
| 98 |
+
#else
|
| 99 |
+
return (r1.p == r2.p &&
|
| 100 |
+
r1.M == r2.M );
|
| 101 |
+
#endif
|
| 102 |
+
}
|
| 103 |
+
bool operator!=(const Frame& r1,const FrameVel& r2) {
|
| 104 |
+
return !operator==(r1,r2);
|
| 105 |
+
}
|
| 106 |
+
bool operator==(const FrameVel& r1,const Frame& r2) {
|
| 107 |
+
#ifdef KDL_USE_EQUAL
|
| 108 |
+
return Equal(r1, r2);
|
| 109 |
+
#else
|
| 110 |
+
return (r1.p == r2.p &&
|
| 111 |
+
r1.M == r2.M );
|
| 112 |
+
#endif
|
| 113 |
+
}
|
| 114 |
+
bool operator!=(const FrameVel& r1,const Frame& r2) {
|
| 115 |
+
return !operator==(r1,r2);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
Frame FrameVel::GetFrame() const {
|
| 121 |
+
return Frame(M.R,p.p);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
Twist FrameVel::GetTwist() const {
|
| 125 |
+
return Twist(p.v,M.w);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
RotationVel operator* (const RotationVel& r1,const RotationVel& r2) {
|
| 130 |
+
return RotationVel( r1.R*r2.R, r1.w + r1.R*r2.w );
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
RotationVel operator* (const Rotation& r1,const RotationVel& r2) {
|
| 134 |
+
return RotationVel( r1*r2.R, r1*r2.w );
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
RotationVel operator* (const RotationVel& r1,const Rotation& r2) {
|
| 138 |
+
return RotationVel( r1.R*r2, r1.w );
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
RotationVel& RotationVel::operator = (const RotationVel& arg) {
|
| 142 |
+
R=arg.R;
|
| 143 |
+
w=arg.w;
|
| 144 |
+
return *this;
|
| 145 |
+
}
|
| 146 |
+
RotationVel& RotationVel::operator = (const Rotation& arg) {
|
| 147 |
+
R=arg;
|
| 148 |
+
w=Vector::Zero();
|
| 149 |
+
return *this;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
VectorVel RotationVel::UnitX() const {
|
| 153 |
+
return VectorVel(R.UnitX(),w*R.UnitX());
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
VectorVel RotationVel::UnitY() const {
|
| 157 |
+
return VectorVel(R.UnitY(),w*R.UnitY());
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
VectorVel RotationVel::UnitZ() const {
|
| 161 |
+
return VectorVel(R.UnitZ(),w*R.UnitZ());
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
RotationVel RotationVel::Identity() {
|
| 167 |
+
return RotationVel(Rotation::Identity(),Vector::Zero());
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
RotationVel RotationVel::Inverse() const {
|
| 171 |
+
return RotationVel(R.Inverse(),-R.Inverse(w));
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
VectorVel RotationVel::Inverse(const VectorVel& arg) const {
|
| 175 |
+
Vector tmp=R.Inverse(arg.p);
|
| 176 |
+
return VectorVel(tmp,
|
| 177 |
+
R.Inverse(arg.v-w*arg.p)
|
| 178 |
+
);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
VectorVel RotationVel::Inverse(const Vector& arg) const {
|
| 182 |
+
Vector tmp=R.Inverse(arg);
|
| 183 |
+
return VectorVel(tmp,
|
| 184 |
+
R.Inverse(-w*arg)
|
| 185 |
+
);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
VectorVel RotationVel::operator*(const VectorVel& arg) const {
|
| 190 |
+
Vector tmp=R*arg.p;
|
| 191 |
+
return VectorVel(tmp,w*tmp+R*arg.v);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
VectorVel RotationVel::operator*(const Vector& arg) const {
|
| 195 |
+
Vector tmp=R*arg;
|
| 196 |
+
return VectorVel(tmp,w*tmp);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
// = Rotations
|
| 201 |
+
// The Rot... static functions give the value of the appropriate rotation matrix back.
|
| 202 |
+
// The DoRot... functions apply a rotation R to *this,such that *this = *this * R.
|
| 203 |
+
|
| 204 |
+
void RotationVel::DoRotX(const doubleVel& angle) {
|
| 205 |
+
w+=R*Vector(angle.grad,0,0);
|
| 206 |
+
R.DoRotX(angle.t);
|
| 207 |
+
}
|
| 208 |
+
RotationVel RotationVel::RotX(const doubleVel& angle) {
|
| 209 |
+
return RotationVel(Rotation::RotX(angle.t),Vector(angle.grad,0,0));
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
void RotationVel::DoRotY(const doubleVel& angle) {
|
| 213 |
+
w+=R*Vector(0,angle.grad,0);
|
| 214 |
+
R.DoRotY(angle.t);
|
| 215 |
+
}
|
| 216 |
+
RotationVel RotationVel::RotY(const doubleVel& angle) {
|
| 217 |
+
return RotationVel(Rotation::RotX(angle.t),Vector(0,angle.grad,0));
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
void RotationVel::DoRotZ(const doubleVel& angle) {
|
| 221 |
+
w+=R*Vector(0,0,angle.grad);
|
| 222 |
+
R.DoRotZ(angle.t);
|
| 223 |
+
}
|
| 224 |
+
RotationVel RotationVel::RotZ(const doubleVel& angle) {
|
| 225 |
+
return RotationVel(Rotation::RotZ(angle.t),Vector(0,0,angle.grad));
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
RotationVel RotationVel::Rot(const Vector& rotvec,const doubleVel& angle)
|
| 230 |
+
// rotvec has arbitrary norm
|
| 231 |
+
// rotation around a constant vector !
|
| 232 |
+
{
|
| 233 |
+
Vector v(rotvec);
|
| 234 |
+
v.Normalize();
|
| 235 |
+
return RotationVel(Rotation::Rot2(v,angle.t),v*angle.grad);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
RotationVel RotationVel::Rot2(const Vector& rotvec,const doubleVel& angle)
|
| 239 |
+
// rotvec is normalized.
|
| 240 |
+
{
|
| 241 |
+
return RotationVel(Rotation::Rot2(rotvec,angle.t),rotvec*angle.grad);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
VectorVel operator + (const VectorVel& r1,const VectorVel& r2) {
|
| 246 |
+
return VectorVel(r1.p+r2.p,r1.v+r2.v);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
VectorVel operator - (const VectorVel& r1,const VectorVel& r2) {
|
| 250 |
+
return VectorVel(r1.p-r2.p,r1.v-r2.v);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
VectorVel operator + (const VectorVel& r1,const Vector& r2) {
|
| 254 |
+
return VectorVel(r1.p+r2,r1.v);
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
VectorVel operator - (const VectorVel& r1,const Vector& r2) {
|
| 258 |
+
return VectorVel(r1.p-r2,r1.v);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
VectorVel operator + (const Vector& r1,const VectorVel& r2) {
|
| 262 |
+
return VectorVel(r1+r2.p,r2.v);
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
VectorVel operator - (const Vector& r1,const VectorVel& r2) {
|
| 266 |
+
return VectorVel(r1-r2.p,-r2.v);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
// unary -
|
| 270 |
+
VectorVel operator - (const VectorVel& r) {
|
| 271 |
+
return VectorVel(-r.p,-r.v);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
void SetToZero(VectorVel& v){
|
| 275 |
+
SetToZero(v.p);
|
| 276 |
+
SetToZero(v.v);
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// cross prod.
|
| 280 |
+
VectorVel operator * (const VectorVel& r1,const VectorVel& r2) {
|
| 281 |
+
return VectorVel(r1.p*r2.p, r1.p*r2.v+r1.v*r2.p);
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
VectorVel operator * (const VectorVel& r1,const Vector& r2) {
|
| 285 |
+
return VectorVel(r1.p*r2, r1.v*r2);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
VectorVel operator * (const Vector& r1,const VectorVel& r2) {
|
| 289 |
+
return VectorVel(r1*r2.p, r1*r2.v);
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
// scalar mult.
|
| 295 |
+
VectorVel operator * (double r1,const VectorVel& r2) {
|
| 296 |
+
return VectorVel(r1*r2.p, r1*r2.v);
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
VectorVel operator * (const VectorVel& r1,double r2) {
|
| 300 |
+
return VectorVel(r1.p*r2, r1.v*r2);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
VectorVel operator * (const doubleVel& r1,const VectorVel& r2) {
|
| 306 |
+
return VectorVel(r1.t*r2.p, r1.t*r2.v + r1.grad*r2.p);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
VectorVel operator * (const VectorVel& r2,const doubleVel& r1) {
|
| 310 |
+
return VectorVel(r1.t*r2.p, r1.t*r2.v + r1.grad*r2.p);
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
VectorVel operator / (const VectorVel& r1,double r2) {
|
| 314 |
+
return VectorVel(r1.p/r2, r1.v/r2);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
VectorVel operator / (const VectorVel& r2,const doubleVel& r1) {
|
| 318 |
+
return VectorVel(r2.p/r1.t, r2.v/r1.t - r2.p*r1.grad/r1.t/r1.t);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
VectorVel operator*(const Rotation& R,const VectorVel& x) {
|
| 322 |
+
return VectorVel(R*x.p,R*x.v);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
VectorVel& VectorVel::operator = (const VectorVel& arg) {
|
| 326 |
+
p=arg.p;
|
| 327 |
+
v=arg.v;
|
| 328 |
+
return *this;
|
| 329 |
+
}
|
| 330 |
+
VectorVel& VectorVel::operator = (const Vector& arg) {
|
| 331 |
+
p=arg;
|
| 332 |
+
v=Vector::Zero();
|
| 333 |
+
return *this;
|
| 334 |
+
}
|
| 335 |
+
VectorVel& VectorVel::operator += (const VectorVel& arg) {
|
| 336 |
+
p+=arg.p;
|
| 337 |
+
v+=arg.v;
|
| 338 |
+
return *this;
|
| 339 |
+
}
|
| 340 |
+
VectorVel& VectorVel::operator -= (const VectorVel& arg) {
|
| 341 |
+
p-=arg.p;
|
| 342 |
+
v-=arg.v;
|
| 343 |
+
return *this;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
VectorVel VectorVel::Zero() {
|
| 347 |
+
return VectorVel(Vector::Zero(),Vector::Zero());
|
| 348 |
+
}
|
| 349 |
+
void VectorVel::ReverseSign() {
|
| 350 |
+
p.ReverseSign();
|
| 351 |
+
v.ReverseSign();
|
| 352 |
+
}
|
| 353 |
+
doubleVel VectorVel::Norm(double eps) const {
|
| 354 |
+
double n = p.Norm(eps);
|
| 355 |
+
if (n < eps) // Setting norm of p and v to 0 in case norm of p is smaller than eps
|
| 356 |
+
return doubleVel(0, 0);
|
| 357 |
+
return doubleVel(n, dot(p,v)/n);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
bool Equal(const VectorVel& r1,const VectorVel& r2,double eps) {
|
| 361 |
+
return (Equal(r1.p,r2.p,eps) && Equal(r1.v,r2.v,eps));
|
| 362 |
+
}
|
| 363 |
+
bool Equal(const Vector& r1,const VectorVel& r2,double eps) {
|
| 364 |
+
return (Equal(r1,r2.p,eps) && Equal(Vector::Zero(),r2.v,eps));
|
| 365 |
+
}
|
| 366 |
+
bool Equal(const VectorVel& r1,const Vector& r2,double eps) {
|
| 367 |
+
return (Equal(r1.p,r2,eps) && Equal(r1.v,Vector::Zero(),eps));
|
| 368 |
+
}
|
| 369 |
+
bool operator==(const VectorVel& r1,const VectorVel& r2) {
|
| 370 |
+
#ifdef KDL_USE_EQUAL
|
| 371 |
+
return Equal(r1, r2);
|
| 372 |
+
#else
|
| 373 |
+
return (r1.p == r2.p &&
|
| 374 |
+
r1.v == r2.v );
|
| 375 |
+
#endif
|
| 376 |
+
}
|
| 377 |
+
bool operator!=(const VectorVel& r1,const VectorVel& r2) {
|
| 378 |
+
return !operator==(r1,r2);
|
| 379 |
+
}
|
| 380 |
+
bool operator==(const Vector& r1,const VectorVel& r2) {
|
| 381 |
+
#ifdef KDL_USE_EQUAL
|
| 382 |
+
return Equal(r1, r2);
|
| 383 |
+
#else
|
| 384 |
+
return (r1 == r2.p &&
|
| 385 |
+
Vector::Zero() == r2.v);
|
| 386 |
+
#endif
|
| 387 |
+
}
|
| 388 |
+
bool operator!=(const Vector& r1,const VectorVel& r2) {
|
| 389 |
+
return !operator==(r1,r2);
|
| 390 |
+
}
|
| 391 |
+
bool operator==(const VectorVel& r1,const Vector& r2) {
|
| 392 |
+
#ifdef KDL_USE_EQUAL
|
| 393 |
+
return Equal(r1, r2);
|
| 394 |
+
#else
|
| 395 |
+
return (r1.p == r2 &&
|
| 396 |
+
r1.v == Vector::Zero() );
|
| 397 |
+
#endif
|
| 398 |
+
}
|
| 399 |
+
bool operator!=(const VectorVel& r1,const Vector& r2) {
|
| 400 |
+
return !operator==(r1,r2);
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
bool Equal(const RotationVel& r1,const RotationVel& r2,double eps) {
|
| 405 |
+
return (Equal(r1.w,r2.w,eps) && Equal(r1.R,r2.R,eps));
|
| 406 |
+
}
|
| 407 |
+
bool Equal(const Rotation& r1,const RotationVel& r2,double eps) {
|
| 408 |
+
return (Equal(Vector::Zero(),r2.w,eps) && Equal(r1,r2.R,eps));
|
| 409 |
+
}
|
| 410 |
+
bool Equal(const RotationVel& r1,const Rotation& r2,double eps) {
|
| 411 |
+
return (Equal(r1.w,Vector::Zero(),eps) && Equal(r1.R,r2,eps));
|
| 412 |
+
}
|
| 413 |
+
bool operator==(const RotationVel& r1,const RotationVel& r2) {
|
| 414 |
+
#ifdef KDL_USE_EQUAL
|
| 415 |
+
return Equal(r1, r2);
|
| 416 |
+
#else
|
| 417 |
+
return (r1.w == r2.w &&
|
| 418 |
+
r1.R == r2.R );
|
| 419 |
+
#endif
|
| 420 |
+
}
|
| 421 |
+
bool operator!=(const RotationVel& r1,const RotationVel& r2) {
|
| 422 |
+
return !operator==(r1,r2);
|
| 423 |
+
}
|
| 424 |
+
bool operator==(const Rotation& r1,const RotationVel& r2) {
|
| 425 |
+
#ifdef KDL_USE_EQUAL
|
| 426 |
+
return Equal(r1, r2);
|
| 427 |
+
#else
|
| 428 |
+
return (Vector::Zero() == r2.w &&
|
| 429 |
+
r1 == r2.R);
|
| 430 |
+
#endif
|
| 431 |
+
}
|
| 432 |
+
bool operator!=(const Rotation& r1,const RotationVel& r2) {
|
| 433 |
+
return !operator==(r1,r2);
|
| 434 |
+
}
|
| 435 |
+
bool operator==(const RotationVel& r1,const Rotation& r2) {
|
| 436 |
+
#ifdef KDL_USE_EQUAL
|
| 437 |
+
return Equal(r1, r2);
|
| 438 |
+
#else
|
| 439 |
+
return (r1.w == Vector::Zero() &&
|
| 440 |
+
r1.R == r2);
|
| 441 |
+
#endif
|
| 442 |
+
}
|
| 443 |
+
bool operator!=(const RotationVel& r1,const Rotation& r2) {
|
| 444 |
+
return !operator==(r1,r2);
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
bool Equal(const TwistVel& a,const TwistVel& b,double eps) {
|
| 449 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 450 |
+
Equal(a.vel,b.vel,eps) );
|
| 451 |
+
}
|
| 452 |
+
bool Equal(const Twist& a,const TwistVel& b,double eps) {
|
| 453 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 454 |
+
Equal(a.vel,b.vel,eps) );
|
| 455 |
+
}
|
| 456 |
+
bool Equal(const TwistVel& a,const Twist& b,double eps) {
|
| 457 |
+
return (Equal(a.rot,b.rot,eps)&&
|
| 458 |
+
Equal(a.vel,b.vel,eps) );
|
| 459 |
+
}
|
| 460 |
+
bool operator==(const TwistVel& a,const TwistVel& b) {
|
| 461 |
+
#ifdef KDL_USE_EQUAL
|
| 462 |
+
return Equal(a, b);
|
| 463 |
+
#else
|
| 464 |
+
return (a.rot == b.rot &&
|
| 465 |
+
a.vel == b.vel );
|
| 466 |
+
#endif
|
| 467 |
+
}
|
| 468 |
+
bool operator!=(const TwistVel& a,const TwistVel& b) {
|
| 469 |
+
return !operator==(a,b);
|
| 470 |
+
}
|
| 471 |
+
bool operator==(const Twist& a,const TwistVel& b) {
|
| 472 |
+
#ifdef KDL_USE_EQUAL
|
| 473 |
+
return Equal(a, b);
|
| 474 |
+
#else
|
| 475 |
+
return (a.rot == b.rot &&
|
| 476 |
+
a.vel == b.vel );
|
| 477 |
+
#endif
|
| 478 |
+
}
|
| 479 |
+
bool operator!=(const Twist& r1,const TwistVel& r2) {
|
| 480 |
+
return !operator==(r1,r2);
|
| 481 |
+
}
|
| 482 |
+
bool operator==(const TwistVel& r1,const Twist& r2) {
|
| 483 |
+
#ifdef KDL_USE_EQUAL
|
| 484 |
+
return Equal(r1, r2);
|
| 485 |
+
#else
|
| 486 |
+
return (a.rot == b.rot &&
|
| 487 |
+
a.vel == b.vel );
|
| 488 |
+
#endif
|
| 489 |
+
}
|
| 490 |
+
bool operator!=(const TwistVel& r1,const Twist& r2) {
|
| 491 |
+
return !operator==(r1,r2);
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
IMETHOD doubleVel dot(const VectorVel& lhs,const VectorVel& rhs) {
|
| 496 |
+
return doubleVel(dot(lhs.p,rhs.p),dot(lhs.p,rhs.v)+dot(lhs.v,rhs.p));
|
| 497 |
+
}
|
| 498 |
+
IMETHOD doubleVel dot(const VectorVel& lhs,const Vector& rhs) {
|
| 499 |
+
return doubleVel(dot(lhs.p,rhs),dot(lhs.v,rhs));
|
| 500 |
+
}
|
| 501 |
+
IMETHOD doubleVel dot(const Vector& lhs,const VectorVel& rhs) {
|
| 502 |
+
return doubleVel(dot(lhs,rhs.p),dot(lhs,rhs.v));
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
TwistVel TwistVel::Zero()
|
| 506 |
+
{
|
| 507 |
+
return TwistVel(VectorVel::Zero(),VectorVel::Zero());
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
void TwistVel::ReverseSign()
|
| 512 |
+
{
|
| 513 |
+
vel.ReverseSign();
|
| 514 |
+
rot.ReverseSign();
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
TwistVel TwistVel::RefPoint(const VectorVel& v_base_AB)
|
| 518 |
+
// Changes the reference point of the TwistVel.
|
| 519 |
+
// The VectorVel v_base_AB is expressed in the same base as the TwistVel
|
| 520 |
+
// The VectorVel v_base_AB is a VectorVel from the old point to
|
| 521 |
+
// the new point.
|
| 522 |
+
// Complexity : 6M+6A
|
| 523 |
+
{
|
| 524 |
+
return TwistVel(this->vel+this->rot*v_base_AB,this->rot);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
TwistVel& TwistVel::operator-=(const TwistVel& arg)
|
| 528 |
+
{
|
| 529 |
+
vel-=arg.vel;
|
| 530 |
+
rot -=arg.rot;
|
| 531 |
+
return *this;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
TwistVel& TwistVel::operator+=(const TwistVel& arg)
|
| 535 |
+
{
|
| 536 |
+
vel+=arg.vel;
|
| 537 |
+
rot +=arg.rot;
|
| 538 |
+
return *this;
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
TwistVel operator*(const TwistVel& lhs,double rhs)
|
| 543 |
+
{
|
| 544 |
+
return TwistVel(lhs.vel*rhs,lhs.rot*rhs);
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
TwistVel operator*(double lhs,const TwistVel& rhs)
|
| 548 |
+
{
|
| 549 |
+
return TwistVel(lhs*rhs.vel,lhs*rhs.rot);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
TwistVel operator/(const TwistVel& lhs,double rhs)
|
| 553 |
+
{
|
| 554 |
+
return TwistVel(lhs.vel/rhs,lhs.rot/rhs);
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
TwistVel operator*(const TwistVel& lhs,const doubleVel& rhs)
|
| 559 |
+
{
|
| 560 |
+
return TwistVel(lhs.vel*rhs,lhs.rot*rhs);
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
TwistVel operator*(const doubleVel& lhs,const TwistVel& rhs)
|
| 564 |
+
{
|
| 565 |
+
return TwistVel(lhs*rhs.vel,lhs*rhs.rot);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
TwistVel operator/(const TwistVel& lhs,const doubleVel& rhs)
|
| 569 |
+
{
|
| 570 |
+
return TwistVel(lhs.vel/rhs,lhs.rot/rhs);
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
// addition of TwistVel's
|
| 576 |
+
TwistVel operator+(const TwistVel& lhs,const TwistVel& rhs)
|
| 577 |
+
{
|
| 578 |
+
return TwistVel(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
TwistVel operator-(const TwistVel& lhs,const TwistVel& rhs)
|
| 582 |
+
{
|
| 583 |
+
return TwistVel(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
// unary -
|
| 587 |
+
TwistVel operator-(const TwistVel& arg)
|
| 588 |
+
{
|
| 589 |
+
return TwistVel(-arg.vel,-arg.rot);
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
void SetToZero(TwistVel& v)
|
| 593 |
+
{
|
| 594 |
+
SetToZero(v.vel);
|
| 595 |
+
SetToZero(v.rot);
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
TwistVel RotationVel::Inverse(const TwistVel& arg) const
|
| 603 |
+
{
|
| 604 |
+
return TwistVel(Inverse(arg.vel),Inverse(arg.rot));
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
TwistVel RotationVel::operator * (const TwistVel& arg) const
|
| 608 |
+
{
|
| 609 |
+
return TwistVel((*this)*arg.vel,(*this)*arg.rot);
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
TwistVel RotationVel::Inverse(const Twist& arg) const
|
| 613 |
+
{
|
| 614 |
+
return TwistVel(Inverse(arg.vel),Inverse(arg.rot));
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
TwistVel RotationVel::operator * (const Twist& arg) const
|
| 618 |
+
{
|
| 619 |
+
return TwistVel((*this)*arg.vel,(*this)*arg.rot);
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
TwistVel FrameVel::operator * (const TwistVel& arg) const
|
| 624 |
+
{
|
| 625 |
+
TwistVel tmp;
|
| 626 |
+
tmp.rot = M*arg.rot;
|
| 627 |
+
tmp.vel = M*arg.vel+p*tmp.rot;
|
| 628 |
+
return tmp;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
TwistVel FrameVel::operator * (const Twist& arg) const
|
| 632 |
+
{
|
| 633 |
+
TwistVel tmp;
|
| 634 |
+
tmp.rot = M*arg.rot;
|
| 635 |
+
tmp.vel = M*arg.vel+p*tmp.rot;
|
| 636 |
+
return tmp;
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
TwistVel FrameVel::Inverse(const TwistVel& arg) const
|
| 640 |
+
{
|
| 641 |
+
TwistVel tmp;
|
| 642 |
+
tmp.rot = M.Inverse(arg.rot);
|
| 643 |
+
tmp.vel = M.Inverse(arg.vel-p*arg.rot);
|
| 644 |
+
return tmp;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
TwistVel FrameVel::Inverse(const Twist& arg) const
|
| 648 |
+
{
|
| 649 |
+
TwistVel tmp;
|
| 650 |
+
tmp.rot = M.Inverse(arg.rot);
|
| 651 |
+
tmp.vel = M.Inverse(arg.vel-p*arg.rot);
|
| 652 |
+
return tmp;
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
Twist TwistVel::GetTwist() const {
|
| 656 |
+
return Twist(vel.p,rot.p);
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
Twist TwistVel::GetTwistDot() const {
|
| 660 |
+
return Twist(vel.v,rot.v);
|
| 661 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/framevel_io.hpp
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* \file
|
| 3 |
+
* provides I/O operations on FrameVels classes
|
| 4 |
+
*
|
| 5 |
+
* \author
|
| 6 |
+
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
|
| 7 |
+
*
|
| 8 |
+
* \version
|
| 9 |
+
* ORO_Geometry V2
|
| 10 |
+
*
|
| 11 |
+
* \par History
|
| 12 |
+
* - $log$
|
| 13 |
+
*
|
| 14 |
+
* \par Release
|
| 15 |
+
* $Id: rframes_io.h,v 1.1.1.1 2002/08/26 14:14:21 rmoreas Exp $
|
| 16 |
+
* $Name: $
|
| 17 |
+
****************************************************************************/
|
| 18 |
+
#ifndef KDL_FRAMESVEL_IO
|
| 19 |
+
#define KDL_FRAMESVEL_IO
|
| 20 |
+
|
| 21 |
+
#include "utilities/utility_io.h"
|
| 22 |
+
#include "utilities/rall1d_io.h"
|
| 23 |
+
|
| 24 |
+
#include "frames_io.hpp"
|
| 25 |
+
|
| 26 |
+
namespace KDL {
|
| 27 |
+
|
| 28 |
+
// Output...
|
| 29 |
+
inline std::ostream& operator << (std::ostream& os,const VectorVel& r) {
|
| 30 |
+
os << "{" << r.p << "," << r.v << "}" << std::endl;
|
| 31 |
+
return os;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
inline std::ostream& operator << (std::ostream& os,const RotationVel& r) {
|
| 35 |
+
os << "{" << std::endl << r.R << "," <<std::endl << r.w << std::endl << "}" << std::endl;
|
| 36 |
+
return os;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
inline std::ostream& operator << (std::ostream& os,const FrameVel& r) {
|
| 41 |
+
os << "{" << std::endl << r.M << "," << std::endl << r.p << std::endl << "}" << std::endl;
|
| 42 |
+
return os;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
inline std::ostream& operator << (std::ostream& os,const TwistVel& r) {
|
| 46 |
+
os << "{" << std::endl << r.vel << "," << std::endl << r.rot << std::endl << "}" << std::endl;
|
| 47 |
+
return os;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
} // namespace Frame
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/jacobian.cpp
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at intermodalics dot eu>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "jacobian.hpp"
|
| 23 |
+
|
| 24 |
+
namespace KDL
|
| 25 |
+
{
|
| 26 |
+
Jacobian::Jacobian()
|
| 27 |
+
{
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Jacobian::Jacobian(unsigned int nr_of_columns):
|
| 32 |
+
data(6,nr_of_columns)
|
| 33 |
+
{
|
| 34 |
+
data.setZero();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
Jacobian::Jacobian(const Jacobian& arg):
|
| 38 |
+
data(arg.data)
|
| 39 |
+
{
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
Jacobian& Jacobian::operator = (const Jacobian& arg)
|
| 43 |
+
{
|
| 44 |
+
this->data=arg.data;
|
| 45 |
+
return *this;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Jacobian::~Jacobian()
|
| 50 |
+
{
|
| 51 |
+
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void Jacobian::resize(unsigned int new_nr_of_columns)
|
| 55 |
+
{
|
| 56 |
+
data.conservativeResize(Eigen::NoChange,new_nr_of_columns);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
double Jacobian::operator()(unsigned int i,unsigned int j)const
|
| 60 |
+
{
|
| 61 |
+
return data(i,j);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
double& Jacobian::operator()(unsigned int i,unsigned int j)
|
| 65 |
+
{
|
| 66 |
+
return data(i,j);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
unsigned int Jacobian::rows()const
|
| 70 |
+
{
|
| 71 |
+
return static_cast<unsigned int>(data.rows());
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
unsigned int Jacobian::columns()const
|
| 75 |
+
{
|
| 76 |
+
return static_cast<unsigned int>(data.cols());
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
void SetToZero(Jacobian& jac)
|
| 80 |
+
{
|
| 81 |
+
jac.data.setZero();
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void Jacobian::changeRefPoint(const Vector& base_AB){
|
| 85 |
+
for(unsigned int i=0;i<data.cols();i++)
|
| 86 |
+
this->setColumn(i,this->getColumn(i).RefPoint(base_AB));
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
bool changeRefPoint(const Jacobian& src1, const Vector& base_AB, Jacobian& dest)
|
| 90 |
+
{
|
| 91 |
+
if(src1.columns()!=dest.columns())
|
| 92 |
+
return false;
|
| 93 |
+
for(unsigned int i=0;i<src1.columns();i++)
|
| 94 |
+
dest.setColumn(i,src1.getColumn(i).RefPoint(base_AB));
|
| 95 |
+
return true;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void Jacobian::changeBase(const Rotation& rot){
|
| 99 |
+
for(unsigned int i=0;i<data.cols();i++)
|
| 100 |
+
this->setColumn(i,rot*this->getColumn(i));;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
bool changeBase(const Jacobian& src1, const Rotation& rot, Jacobian& dest)
|
| 104 |
+
{
|
| 105 |
+
if(src1.columns()!=dest.columns())
|
| 106 |
+
return false;
|
| 107 |
+
for(unsigned int i=0;i<src1.columns();i++)
|
| 108 |
+
dest.setColumn(i,rot*src1.getColumn(i));;
|
| 109 |
+
return true;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void Jacobian::changeRefFrame(const Frame& frame){
|
| 113 |
+
for(unsigned int i=0;i<data.cols();i++)
|
| 114 |
+
this->setColumn(i,frame*this->getColumn(i));
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
bool changeRefFrame(const Jacobian& src1,const Frame& frame, Jacobian& dest)
|
| 118 |
+
{
|
| 119 |
+
if(src1.columns()!=dest.columns())
|
| 120 |
+
return false;
|
| 121 |
+
for(unsigned int i=0;i<src1.columns();i++)
|
| 122 |
+
dest.setColumn(i,frame*src1.getColumn(i));
|
| 123 |
+
return true;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
bool Jacobian::operator ==(const Jacobian& arg)const
|
| 127 |
+
{
|
| 128 |
+
return Equal((*this),arg);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
bool Jacobian::operator!=(const Jacobian& arg)const
|
| 132 |
+
{
|
| 133 |
+
return !Equal((*this),arg);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
bool Equal(const Jacobian& a,const Jacobian& b,double eps)
|
| 137 |
+
{
|
| 138 |
+
if(a.rows()==b.rows()&&a.columns()==b.columns()){
|
| 139 |
+
return (a.data-b.data).isZero(eps);
|
| 140 |
+
}else
|
| 141 |
+
return false;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
Twist Jacobian::getColumn(unsigned int i) const{
|
| 145 |
+
return Twist(Vector(data(0,i),data(1,i),data(2,i)),Vector(data(3,i),data(4,i),data(5,i)));
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void Jacobian::setColumn(unsigned int i,const Twist& t){
|
| 149 |
+
data.col(i).head<3>()=Eigen::Map<const Eigen::Vector3d>(t.vel.data);
|
| 150 |
+
data.col(i).tail<3>()=Eigen::Map<const Eigen::Vector3d>(t.rot.data);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
}
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/jacobian.hpp
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_JACOBIAN_HPP
|
| 23 |
+
#define KDL_JACOBIAN_HPP
|
| 24 |
+
|
| 25 |
+
#include "frames.hpp"
|
| 26 |
+
#include <Eigen/Core>
|
| 27 |
+
|
| 28 |
+
namespace KDL
|
| 29 |
+
{
|
| 30 |
+
// Equal is friend function, but default arguments for friends are forbidden (§8.3.6.4)
|
| 31 |
+
class Jacobian;
|
| 32 |
+
bool Equal(const Jacobian& a,const Jacobian& b,double eps=epsilon);
|
| 33 |
+
void SetToZero(Jacobian& jac);
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class Jacobian
|
| 37 |
+
{
|
| 38 |
+
public:
|
| 39 |
+
|
| 40 |
+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
| 41 |
+
Eigen::Matrix<double,6,Eigen::Dynamic> data;
|
| 42 |
+
Jacobian();
|
| 43 |
+
explicit Jacobian(unsigned int nr_of_columns);
|
| 44 |
+
Jacobian(const Jacobian& arg);
|
| 45 |
+
|
| 46 |
+
///Allocates memory for new size (can break realtime behavior)
|
| 47 |
+
void resize(unsigned int newNrOfColumns);
|
| 48 |
+
|
| 49 |
+
///Allocates memory if size of this and argument is different
|
| 50 |
+
Jacobian& operator=(const Jacobian& arg);
|
| 51 |
+
|
| 52 |
+
bool operator ==(const Jacobian& arg)const;
|
| 53 |
+
bool operator !=(const Jacobian& arg)const;
|
| 54 |
+
|
| 55 |
+
friend bool Equal(const Jacobian& a,const Jacobian& b,double eps);
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
~Jacobian();
|
| 59 |
+
|
| 60 |
+
double operator()(unsigned int i,unsigned int j)const;
|
| 61 |
+
double& operator()(unsigned int i,unsigned int j);
|
| 62 |
+
unsigned int rows()const;
|
| 63 |
+
unsigned int columns()const;
|
| 64 |
+
|
| 65 |
+
friend void SetToZero(Jacobian& jac);
|
| 66 |
+
|
| 67 |
+
friend bool changeRefPoint(const Jacobian& src1, const Vector& base_AB, Jacobian& dest);
|
| 68 |
+
friend bool changeBase(const Jacobian& src1, const Rotation& rot, Jacobian& dest);
|
| 69 |
+
friend bool changeRefFrame(const Jacobian& src1,const Frame& frame, Jacobian& dest);
|
| 70 |
+
|
| 71 |
+
Twist getColumn(unsigned int i) const;
|
| 72 |
+
void setColumn(unsigned int i,const Twist& t);
|
| 73 |
+
|
| 74 |
+
void changeRefPoint(const Vector& base_AB);
|
| 75 |
+
void changeBase(const Rotation& rot);
|
| 76 |
+
void changeRefFrame(const Frame& frame);
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
bool changeRefPoint(const Jacobian& src1, const Vector& base_AB, Jacobian& dest);
|
| 82 |
+
bool changeBase(const Jacobian& src1, const Rotation& rot, Jacobian& dest);
|
| 83 |
+
bool changeRefFrame(const Jacobian& src1,const Frame& frame, Jacobian& dest);
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/jntarray.cpp
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "jntarray.hpp"
|
| 23 |
+
|
| 24 |
+
namespace KDL
|
| 25 |
+
{
|
| 26 |
+
JntArray::JntArray()
|
| 27 |
+
{
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
JntArray::JntArray(unsigned int _size):
|
| 31 |
+
data(_size)
|
| 32 |
+
{
|
| 33 |
+
data.setZero();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
JntArray::JntArray(const JntArray& arg):
|
| 38 |
+
data(arg.data)
|
| 39 |
+
{
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
JntArray& JntArray::operator = (const JntArray& arg)
|
| 43 |
+
{
|
| 44 |
+
data=arg.data;
|
| 45 |
+
return *this;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
JntArray::~JntArray()
|
| 50 |
+
{
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
void JntArray::resize(unsigned int newSize)
|
| 54 |
+
{
|
| 55 |
+
data.conservativeResizeLike(Eigen::VectorXd::Zero(newSize));
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
double JntArray::operator()(unsigned int i,unsigned int j)const
|
| 59 |
+
{
|
| 60 |
+
assert(j==0);
|
| 61 |
+
return data(i);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
double& JntArray::operator()(unsigned int i,unsigned int j)
|
| 65 |
+
{
|
| 66 |
+
assert(j==0);
|
| 67 |
+
return data(i);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
unsigned int JntArray::rows()const
|
| 71 |
+
{
|
| 72 |
+
return static_cast<unsigned int>(data.rows());
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
unsigned int JntArray::columns()const
|
| 76 |
+
{
|
| 77 |
+
return static_cast<unsigned int>(data.cols());
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void Add(const JntArray& src1,const JntArray& src2,JntArray& dest)
|
| 81 |
+
{
|
| 82 |
+
dest.data=src1.data+src2.data;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void Subtract(const JntArray& src1,const JntArray& src2,JntArray& dest)
|
| 86 |
+
{
|
| 87 |
+
dest.data=src1.data-src2.data;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void Multiply(const JntArray& src,const double& factor,JntArray& dest)
|
| 91 |
+
{
|
| 92 |
+
dest.data=factor*src.data;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void Divide(const JntArray& src,const double& factor,JntArray& dest)
|
| 96 |
+
{
|
| 97 |
+
dest.data=src.data/factor;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void MultiplyJacobian(const Jacobian& jac, const JntArray& src, Twist& dest)
|
| 101 |
+
{
|
| 102 |
+
Eigen::Matrix<double,6,1> t=jac.data.lazyProduct(src.data);
|
| 103 |
+
dest=Twist(Vector(t(0),t(1),t(2)),Vector(t(3),t(4),t(5)));
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
void SetToZero(JntArray& array)
|
| 107 |
+
{
|
| 108 |
+
array.data.setZero();
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
bool Equal(const JntArray& src1, const JntArray& src2,double eps)
|
| 112 |
+
{
|
| 113 |
+
if(src1.rows()!=src2.rows())
|
| 114 |
+
return false;
|
| 115 |
+
return (src1.data-src2.data).isZero(eps);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
bool operator==(const JntArray& src1,const JntArray& src2){return Equal(src1,src2);}
|
| 119 |
+
//bool operator!=(const JntArray& src1,const JntArray& src2){return Equal(src1,src2);}
|
| 120 |
+
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/jntarray.hpp
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#ifndef KDL_JNTARRAY_HPP
|
| 23 |
+
#define KDL_JNTARRAY_HPP
|
| 24 |
+
|
| 25 |
+
#include "frames.hpp"
|
| 26 |
+
#include "jacobian.hpp"
|
| 27 |
+
|
| 28 |
+
#include <Eigen/Core>
|
| 29 |
+
|
| 30 |
+
namespace KDL
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* @brief This class represents an fixed size array containing
|
| 34 |
+
* joint values of a KDL::Chain.
|
| 35 |
+
*
|
| 36 |
+
* \warning An object constructed with the default constructor provides
|
| 37 |
+
* a valid, but inert, object. Many of the member functions will do
|
| 38 |
+
* the correct thing and have no affect on this object, but some
|
| 39 |
+
* member functions can _NOT_ deal with an inert/empty object. These
|
| 40 |
+
* functions will assert() and exit the program instead. The intended use
|
| 41 |
+
* case for the default constructor (in an RTT/OCL setting) is outlined in
|
| 42 |
+
* code below - the default constructor plus the resize() function allow
|
| 43 |
+
* use of JntArray objects whose size is set within a configureHook() call
|
| 44 |
+
* (typically based on a size determined from a property).
|
| 45 |
+
|
| 46 |
+
\code
|
| 47 |
+
class MyTask : public RTT::TaskContext
|
| 48 |
+
{
|
| 49 |
+
JntArray j;
|
| 50 |
+
MyTask()
|
| 51 |
+
{} // invokes j's default constructor
|
| 52 |
+
|
| 53 |
+
bool configureHook()
|
| 54 |
+
{
|
| 55 |
+
unsigned int size = some_property.rvalue();
|
| 56 |
+
j.resize(size)
|
| 57 |
+
...
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void updateHook()
|
| 61 |
+
{
|
| 62 |
+
** use j here
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
\endcode
|
| 66 |
+
|
| 67 |
+
*/
|
| 68 |
+
|
| 69 |
+
class JntArray
|
| 70 |
+
{
|
| 71 |
+
public:
|
| 72 |
+
Eigen::VectorXd data;
|
| 73 |
+
|
| 74 |
+
/** Construct with _no_ data array
|
| 75 |
+
* @post NULL == data
|
| 76 |
+
* @post 0 == rows()
|
| 77 |
+
* @warning use of an object constructed like this, without
|
| 78 |
+
* a resize() first, may result in program exit! See class
|
| 79 |
+
* documentation.
|
| 80 |
+
*/
|
| 81 |
+
JntArray();
|
| 82 |
+
/**
|
| 83 |
+
* Constructor of the joint array
|
| 84 |
+
*
|
| 85 |
+
* @param size size of the array, this cannot be changed
|
| 86 |
+
* afterwards.
|
| 87 |
+
* @pre 0 < size
|
| 88 |
+
* @post NULL != data
|
| 89 |
+
* @post 0 < rows()
|
| 90 |
+
* @post all elements in data have 0 value
|
| 91 |
+
*/
|
| 92 |
+
explicit JntArray(unsigned int size);
|
| 93 |
+
|
| 94 |
+
/** Copy constructor
|
| 95 |
+
* @note Will correctly copy an empty object
|
| 96 |
+
*/
|
| 97 |
+
JntArray(const JntArray& arg);
|
| 98 |
+
~JntArray();
|
| 99 |
+
/** Resize the array
|
| 100 |
+
* @warning This causes a dynamic allocation (and potentially
|
| 101 |
+
* also a dynamic deallocation). This _will_ negatively affect
|
| 102 |
+
* real-time performance!
|
| 103 |
+
*
|
| 104 |
+
* @post newSize == rows()
|
| 105 |
+
* @post NULL != data
|
| 106 |
+
* @post all elements in data have 0 value
|
| 107 |
+
*/
|
| 108 |
+
void resize(unsigned int newSize);
|
| 109 |
+
|
| 110 |
+
JntArray& operator = ( const JntArray& arg);
|
| 111 |
+
/**
|
| 112 |
+
* get_item operator for the joint array, if a second value is
|
| 113 |
+
* given it should be zero, since a JntArray resembles a column.
|
| 114 |
+
*
|
| 115 |
+
*
|
| 116 |
+
* @return the joint value at position i, starting from 0
|
| 117 |
+
* @pre 0 != size (ie non-default constructor or resize() called)
|
| 118 |
+
*/
|
| 119 |
+
double operator()(unsigned int i,unsigned int j=0)const;
|
| 120 |
+
/**
|
| 121 |
+
* set_item operator, again if a second value is given it
|
| 122 |
+
*should be zero.
|
| 123 |
+
*
|
| 124 |
+
* @return reference to the joint value at position i,starting
|
| 125 |
+
*from zero.
|
| 126 |
+
* @pre 0 != size (ie non-default constructor or resize() called)
|
| 127 |
+
*/
|
| 128 |
+
double& operator()(unsigned int i,unsigned int j=0);
|
| 129 |
+
/**
|
| 130 |
+
* Returns the number of rows (size) of the array
|
| 131 |
+
*
|
| 132 |
+
*/
|
| 133 |
+
unsigned int rows()const;
|
| 134 |
+
/**
|
| 135 |
+
* Returns the number of columns of the array, always 1.
|
| 136 |
+
*/
|
| 137 |
+
unsigned int columns()const;
|
| 138 |
+
|
| 139 |
+
friend void Add(const JntArray& src1,const JntArray& src2,JntArray& dest);
|
| 140 |
+
friend void Subtract(const JntArray& src1,const JntArray& src2,JntArray& dest);
|
| 141 |
+
friend void Multiply(const JntArray& src,const double& factor,JntArray& dest);
|
| 142 |
+
friend void Divide(const JntArray& src,const double& factor,JntArray& dest);
|
| 143 |
+
friend void MultiplyJacobian(const Jacobian& jac, const JntArray& src, Twist& dest);
|
| 144 |
+
friend void SetToZero(JntArray& array);
|
| 145 |
+
friend bool Equal(const JntArray& src1,const JntArray& src2,double eps);
|
| 146 |
+
|
| 147 |
+
friend bool operator==(const JntArray& src1,const JntArray& src2);
|
| 148 |
+
//friend bool operator!=(const JntArray& src1,const JntArray& src2);
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
bool operator==(const JntArray& src1,const JntArray& src2);
|
| 152 |
+
//bool operator!=(const JntArray& src1,const JntArray& src2);
|
| 153 |
+
|
| 154 |
+
/**
|
| 155 |
+
* Function to add two joint arrays, all the arguments must
|
| 156 |
+
* have the same size: A + B = C. This function is
|
| 157 |
+
* aliasing-safe, A or B can be the same array as C.
|
| 158 |
+
*
|
| 159 |
+
* @param src1 A
|
| 160 |
+
* @param src2 B
|
| 161 |
+
* @param dest C
|
| 162 |
+
*/
|
| 163 |
+
void Add(const JntArray& src1,const JntArray& src2,JntArray& dest);
|
| 164 |
+
/**
|
| 165 |
+
* Function to subtract two joint arrays, all the arguments must
|
| 166 |
+
* have the same size: A - B = C. This function is
|
| 167 |
+
* aliasing-safe, A or B can be the same array as C.
|
| 168 |
+
*
|
| 169 |
+
* @param src1 A
|
| 170 |
+
* @param src2 B
|
| 171 |
+
* @param dest C
|
| 172 |
+
*/
|
| 173 |
+
void Subtract(const JntArray& src1,const JntArray& src2,JntArray& dest);
|
| 174 |
+
/**
|
| 175 |
+
* Function to multiply all the array values with a scalar
|
| 176 |
+
* factor: A*b=C. This function is aliasing-safe, A can be the
|
| 177 |
+
* same array as C.
|
| 178 |
+
*
|
| 179 |
+
* @param src A
|
| 180 |
+
* @param factor b
|
| 181 |
+
* @param dest C
|
| 182 |
+
*/
|
| 183 |
+
void Multiply(const JntArray& src,const double& factor,JntArray& dest);
|
| 184 |
+
/**
|
| 185 |
+
* Function to divide all the array values with a scalar
|
| 186 |
+
* factor: A/b=C. This function is aliasing-safe, A can be the
|
| 187 |
+
* same array as C.
|
| 188 |
+
*
|
| 189 |
+
* @param src A
|
| 190 |
+
* @param factor b
|
| 191 |
+
* @param dest C
|
| 192 |
+
*/
|
| 193 |
+
void Divide(const JntArray& src,const double& factor,JntArray& dest);
|
| 194 |
+
/**
|
| 195 |
+
* Function to multiply a KDL::Jacobian with a KDL::JntArray
|
| 196 |
+
* to get a KDL::Twist, it should not be used to calculate the
|
| 197 |
+
* forward velocity kinematics, the solver classes are built
|
| 198 |
+
* for this purpose.
|
| 199 |
+
* J*q = t
|
| 200 |
+
*
|
| 201 |
+
* @param jac J
|
| 202 |
+
* @param src q
|
| 203 |
+
* @param dest t
|
| 204 |
+
* @post dest==Twist::Zero() if 0==src.rows() (ie src is empty)
|
| 205 |
+
*/
|
| 206 |
+
void MultiplyJacobian(const Jacobian& jac, const JntArray& src, Twist& dest);
|
| 207 |
+
/**
|
| 208 |
+
* Function to set all the values of the array to 0
|
| 209 |
+
*
|
| 210 |
+
* @param array
|
| 211 |
+
*/
|
| 212 |
+
void SetToZero(JntArray& array);
|
| 213 |
+
/**
|
| 214 |
+
* Function to check if two arrays are the same with a
|
| 215 |
+
*precision of eps
|
| 216 |
+
*
|
| 217 |
+
* @param src1
|
| 218 |
+
* @param src2
|
| 219 |
+
* @param eps default: epsilon
|
| 220 |
+
* @return true if each element of src1 is within eps of the same
|
| 221 |
+
* element in src2, or if both src1 and src2 have no data (ie 0==rows())
|
| 222 |
+
*/
|
| 223 |
+
bool Equal(const JntArray& src1,const JntArray& src2,double eps=epsilon);
|
| 224 |
+
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
#endif
|
third_party/orocos_kinematics_dynamics/orocos_kdl/src/jntarrayacc.cpp
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 2 |
+
|
| 3 |
+
// Version: 1.0
|
| 4 |
+
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 5 |
+
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
|
| 6 |
+
// URL: http://www.orocos.org/kdl
|
| 7 |
+
|
| 8 |
+
// This library is free software; you can redistribute it and/or
|
| 9 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
// License as published by the Free Software Foundation; either
|
| 11 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
|
| 13 |
+
// This library is distributed in the hope that it will be useful,
|
| 14 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
// Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
// License along with this library; if not, write to the Free Software
|
| 20 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
|
| 22 |
+
#include "jntarrayacc.hpp"
|
| 23 |
+
|
| 24 |
+
namespace KDL
|
| 25 |
+
{
|
| 26 |
+
JntArrayAcc::JntArrayAcc(unsigned int size):
|
| 27 |
+
q(size),qdot(size),qdotdot(size)
|
| 28 |
+
{
|
| 29 |
+
}
|
| 30 |
+
JntArrayAcc::JntArrayAcc(const JntArray& qin, const JntArray& qdotin,const JntArray& qdotdotin):
|
| 31 |
+
q(qin),qdot(qdotin),qdotdot(qdotdotin)
|
| 32 |
+
{
|
| 33 |
+
assert(q.rows()==qdot.rows()&&qdot.rows()==qdotdot.rows());
|
| 34 |
+
}
|
| 35 |
+
JntArrayAcc::JntArrayAcc(const JntArray& qin, const JntArray& qdotin):
|
| 36 |
+
q(qin),qdot(qdotin),qdotdot(q.rows())
|
| 37 |
+
{
|
| 38 |
+
assert(q.rows()==qdot.rows());
|
| 39 |
+
}
|
| 40 |
+
JntArrayAcc::JntArrayAcc(const JntArray& qin):
|
| 41 |
+
q(qin),qdot(q.rows()),qdotdot(q.rows())
|
| 42 |
+
{
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void JntArrayAcc::resize(unsigned int newSize)
|
| 46 |
+
{
|
| 47 |
+
q.resize(newSize);
|
| 48 |
+
qdot.resize(newSize);
|
| 49 |
+
qdotdot.resize(newSize);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
JntArray JntArrayAcc::value()const
|
| 53 |
+
{
|
| 54 |
+
return q;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
JntArray JntArrayAcc::deriv()const
|
| 58 |
+
{
|
| 59 |
+
return qdot;
|
| 60 |
+
}
|
| 61 |
+
JntArray JntArrayAcc::dderiv()const
|
| 62 |
+
{
|
| 63 |
+
return qdotdot;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
void Add(const JntArrayAcc& src1,const JntArrayAcc& src2,JntArrayAcc& dest)
|
| 67 |
+
{
|
| 68 |
+
Add(src1.q,src2.q,dest.q);
|
| 69 |
+
Add(src1.qdot,src2.qdot,dest.qdot);
|
| 70 |
+
Add(src1.qdotdot,src2.qdotdot,dest.qdotdot);
|
| 71 |
+
}
|
| 72 |
+
void Add(const JntArrayAcc& src1,const JntArrayVel& src2,JntArrayAcc& dest)
|
| 73 |
+
{
|
| 74 |
+
Add(src1.q,src2.q,dest.q);
|
| 75 |
+
Add(src1.qdot,src2.qdot,dest.qdot);
|
| 76 |
+
dest.qdotdot=src1.qdotdot;
|
| 77 |
+
}
|
| 78 |
+
void Add(const JntArrayAcc& src1,const JntArray& src2,JntArrayAcc& dest)
|
| 79 |
+
{
|
| 80 |
+
Add(src1.q,src2,dest.q);
|
| 81 |
+
dest.qdot=src1.qdot;
|
| 82 |
+
dest.qdotdot=src1.qdotdot;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void Subtract(const JntArrayAcc& src1,const JntArrayAcc& src2,JntArrayAcc& dest)
|
| 86 |
+
{
|
| 87 |
+
Subtract(src1.q,src2.q,dest.q);
|
| 88 |
+
Subtract(src1.qdot,src2.qdot,dest.qdot);
|
| 89 |
+
Subtract(src1.qdotdot,src2.qdotdot,dest.qdotdot);
|
| 90 |
+
}
|
| 91 |
+
void Subtract(const JntArrayAcc& src1,const JntArrayVel& src2,JntArrayAcc& dest)
|
| 92 |
+
{
|
| 93 |
+
Subtract(src1.q,src2.q,dest.q);
|
| 94 |
+
Subtract(src1.qdot,src2.qdot,dest.qdot);
|
| 95 |
+
dest.qdotdot=src1.qdotdot;
|
| 96 |
+
}
|
| 97 |
+
void Subtract(const JntArrayAcc& src1,const JntArray& src2,JntArrayAcc& dest)
|
| 98 |
+
{
|
| 99 |
+
Subtract(src1.q,src2,dest.q);
|
| 100 |
+
dest.qdot=src1.qdot;
|
| 101 |
+
dest.qdotdot=src1.qdotdot;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
void Multiply(const JntArrayAcc& src,const double& factor,JntArrayAcc& dest)
|
| 105 |
+
{
|
| 106 |
+
Multiply(src.q,factor,dest.q);
|
| 107 |
+
Multiply(src.qdot,factor,dest.qdot);
|
| 108 |
+
Multiply(src.qdotdot,factor,dest.qdotdot);
|
| 109 |
+
}
|
| 110 |
+
void Multiply(const JntArrayAcc& src,const doubleVel& factor,JntArrayAcc& dest)
|
| 111 |
+
{
|
| 112 |
+
Multiply(src.qdot,factor.grad*2,dest.qdot);
|
| 113 |
+
Multiply(src.qdotdot,factor.t,dest.qdotdot);
|
| 114 |
+
Add(dest.qdot,dest.qdotdot,dest.qdotdot);
|
| 115 |
+
Multiply(src.q,factor.grad,dest.q);
|
| 116 |
+
Multiply(src.qdot,factor.t,dest.qdot);
|
| 117 |
+
Add(dest.qdot,dest.q,dest.qdot);
|
| 118 |
+
Multiply(src.q,factor.t,dest.q);
|
| 119 |
+
}
|
| 120 |
+
void Multiply(const JntArrayAcc& src,const doubleAcc& factor,JntArrayAcc& dest)
|
| 121 |
+
{
|
| 122 |
+
Multiply(src.q,factor.dd,dest.q);
|
| 123 |
+
Multiply(src.qdot,factor.d*2,dest.qdot);
|
| 124 |
+
Multiply(src.qdotdot,factor.t,dest.qdotdot);
|
| 125 |
+
Add(dest.qdotdot,dest.qdot,dest.qdotdot);
|
| 126 |
+
Add(dest.qdotdot,dest.q,dest.qdotdot);
|
| 127 |
+
Multiply(src.q,factor.d,dest.q);
|
| 128 |
+
Multiply(src.qdot,factor.t,dest.qdot);
|
| 129 |
+
Add(dest.qdot,dest.q,dest.qdot);
|
| 130 |
+
Multiply(src.q,factor.t,dest.q);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
void Divide(const JntArrayAcc& src,const double& factor,JntArrayAcc& dest)
|
| 134 |
+
{
|
| 135 |
+
Divide(src.q,factor,dest.q);
|
| 136 |
+
Divide(src.qdot,factor,dest.qdot);
|
| 137 |
+
Divide(src.qdotdot,factor,dest.qdotdot);
|
| 138 |
+
}
|
| 139 |
+
void Divide(const JntArrayAcc& src,const doubleVel& factor,JntArrayAcc& dest)
|
| 140 |
+
{
|
| 141 |
+
Multiply(src.q,(2*factor.grad*factor.grad)/(factor.t*factor.t*factor.t),dest.q);
|
| 142 |
+
Multiply(src.qdot,(2*factor.grad)/(factor.t*factor.t),dest.qdot);
|
| 143 |
+
Divide(src.qdotdot,factor.t,dest.qdotdot);
|
| 144 |
+
Subtract(dest.qdotdot,dest.qdot,dest.qdotdot);
|
| 145 |
+
Add(dest.qdotdot,dest.q,dest.qdotdot);
|
| 146 |
+
Multiply(src.q,factor.grad/(factor.t*factor.t),dest.q);
|
| 147 |
+
Divide(src.qdot,factor.t,dest.qdot);
|
| 148 |
+
Subtract(dest.qdot,dest.q,dest.qdot);
|
| 149 |
+
Divide(src.q,factor.t,dest.q);
|
| 150 |
+
}
|
| 151 |
+
void Divide(const JntArrayAcc& src,const doubleAcc& factor,JntArrayAcc& dest)
|
| 152 |
+
{
|
| 153 |
+
Multiply(src.q,(2*factor.d*factor.d)/(factor.t*factor.t*factor.t)-factor.dd/(factor.t*factor.t),dest.q);
|
| 154 |
+
Multiply(src.qdot,(2*factor.d)/(factor.t*factor.t),dest.qdot);
|
| 155 |
+
Divide(src.qdotdot,factor.t,dest.qdotdot);
|
| 156 |
+
Subtract(dest.qdotdot,dest.qdot,dest.qdotdot);
|
| 157 |
+
Add(dest.qdotdot,dest.q,dest.qdotdot);
|
| 158 |
+
Multiply(src.q,factor.d/(factor.t*factor.t),dest.q);
|
| 159 |
+
Divide(src.qdot,factor.t,dest.qdot);
|
| 160 |
+
Subtract(dest.qdot,dest.q,dest.qdot);
|
| 161 |
+
Divide(src.q,factor.t,dest.q);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
void SetToZero(JntArrayAcc& array)
|
| 165 |
+
{
|
| 166 |
+
SetToZero(array.q);
|
| 167 |
+
SetToZero(array.qdot);
|
| 168 |
+
SetToZero(array.qdotdot);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
bool Equal(const JntArrayAcc& src1,const JntArrayAcc& src2,double eps)
|
| 172 |
+
{
|
| 173 |
+
return (Equal(src1.q,src2.q,eps)&&Equal(src1.qdot,src2.qdot,eps)&&Equal(src1.qdotdot,src2.qdotdot,eps));
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|