File: jacobian.cpp

package info (click to toggle)
freecad 0.14.3702+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 162,288 kB
  • ctags: 78,057
  • sloc: cpp: 360,157; python: 199,755; xml: 7,653; fortran: 3,878; ansic: 702; lex: 204; yacc: 91; sh: 41; makefile: 18
file content (154 lines) | stat: -rw-r--r-- 4,264 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>

// Version: 1.0
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
// URL: http://www.orocos.org/kdl

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#include "jacobian.hpp"

namespace KDL
{
    USING_PART_OF_NAMESPACE_EIGEN

    Jacobian::Jacobian()
    {
    }


    Jacobian::Jacobian(unsigned int nr_of_columns):
        data(6,nr_of_columns)
    {
    }
    
    Jacobian::Jacobian(const Jacobian& arg):
        data(arg.data)
    {
    }

    Jacobian& Jacobian::operator = (const Jacobian& arg)
    { 
        this->data=arg.data;
        return *this;
    }


    Jacobian::~Jacobian()
    {
        
    }

    void Jacobian::resize(unsigned int new_nr_of_columns)
    {
        data.resize(6,new_nr_of_columns);
    }

    double Jacobian::operator()(unsigned int i,unsigned int j)const
    {
        return data(i,j);
    }

    double& Jacobian::operator()(unsigned int i,unsigned int j)
    {
        return data(i,j);
    }

    unsigned int Jacobian::rows()const
    {
        return data.rows();
    }

    unsigned int Jacobian::columns()const
    {
        return data.cols();
    }

    void SetToZero(Jacobian& jac)
    {
        jac.data.setZero();
    }

    void Jacobian::changeRefPoint(const Vector& base_AB){
        for(unsigned int i=0;i<data.cols();i++)
            this->setColumn(i,this->getColumn(i).RefPoint(base_AB));
    }

    bool changeRefPoint(const Jacobian& src1, const Vector& base_AB, Jacobian& dest)
    {
        if(src1.columns()!=dest.columns())
            return false;
        for(unsigned int i=0;i<src1.columns();i++)
            dest.setColumn(i,src1.getColumn(i).RefPoint(base_AB));
        return true;
    }
    
    void Jacobian::changeBase(const Rotation& rot){
        for(unsigned int i=0;i<data.cols();i++)
            this->setColumn(i,rot*this->getColumn(i));;
    }

    bool changeBase(const Jacobian& src1, const Rotation& rot, Jacobian& dest)
    {
        if(src1.columns()!=dest.columns())
            return false;
        for(unsigned int i=0;i<src1.columns();i++)
            dest.setColumn(i,rot*src1.getColumn(i));;
        return true;
    }

    void Jacobian::changeRefFrame(const Frame& frame){
        for(unsigned int i=0;i<data.cols();i++)
            this->setColumn(i,frame*this->getColumn(i));
    }
    
    bool changeRefFrame(const Jacobian& src1,const Frame& frame, Jacobian& dest)
    {
        if(src1.columns()!=dest.columns())
            return false;
        for(unsigned int i=0;i<src1.columns();i++)
            dest.setColumn(i,frame*src1.getColumn(i));
        return true;
    }

    bool Jacobian::operator ==(const Jacobian& arg)const
    {
        return Equal((*this),arg, epsilon);
    }
    
    bool Jacobian::operator!=(const Jacobian& arg)const
    {
        return !Equal((*this),arg, epsilon);
    }
    
    bool Equal(const Jacobian& a,const Jacobian& b,double eps)
    {
        if(a.rows()==b.rows()&&a.columns()==b.columns()){
            return a.data.isApprox(b.data,eps);
        }else
            return false;
    }
    
    Twist Jacobian::getColumn(unsigned int i) const{
        return Twist(Vector(data(0,i),data(1,i),data(2,i)),Vector(data(3,i),data(4,i),data(5,i)));
    }
    
    void Jacobian::setColumn(unsigned int i,const Twist& t){
        data.col(i).start<3>()=Eigen::Map<Vector3d>(t.vel.data);
        data.col(i).end<3>()=Eigen::Map<Vector3d>(t.rot.data);
    }

}