Welcome to mirror list, hosted at ThFree Co, Russian Federation.

frames_io.cpp « kdl « itasc « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3db0790cabfdac4d99115a1fe3f410f0eb72cf98 (plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/** \file itasc/kdl/frames_io.cpp
 *  \ingroup itasc
 */

/***************************************************************************
                        frames_io.h -  description
                       -------------------------
    begin                : June 2006
    copyright            : (C) 2006 Erwin Aertbelien
    email                : firstname.lastname@mech.kuleuven.ac.be

 History (only major changes)( AUTHOR-Description ) :

 ***************************************************************************
 *   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 Street,                                    *
 *   Fifth Floor, Boston, MA 02110-1301, USA.                               *
 *                                                                         *
 ***************************************************************************/

#include "utilities/error.h"
#include "utilities/error_stack.h"
#include "frames.hpp"
#include "frames_io.hpp"

#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <iostream>

namespace KDL {


std::ostream& operator << (std::ostream& os,const Vector& v) {
    os << "[" << std::setw(KDL_FRAME_WIDTH) << v(0) << "," << std::setw(KDL_FRAME_WIDTH)<<v(1)
       << "," << std::setw(KDL_FRAME_WIDTH) << v(2) << "]";
    return os;
}

std::ostream& operator << (std::ostream& os,const Twist& v) {
    os << "[" << std::setw(KDL_FRAME_WIDTH) << v.vel(0)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.vel(1)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.vel(2)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.rot(0)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.rot(1)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.rot(2)
       << "]";
    return os;
}

std::ostream& operator << (std::ostream& os,const Wrench& v) {
    os << "[" << std::setw(KDL_FRAME_WIDTH) << v.force(0)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.force(1)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.force(2)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.torque(0)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.torque(1)
       << "," << std::setw(KDL_FRAME_WIDTH) << v.torque(2)
       << "]";
    return os;
}


std::ostream& operator << (std::ostream& os,const Rotation& R) {
#ifdef KDL_ROTATION_PROPERTIES_RPY
    double r,p,y;
    R.GetRPY(r,p,y);
    os << "[RPY]"<<endl;
    os << "[";
    os << std::setw(KDL_FRAME_WIDTH) << r << ",";
    os << std::setw(KDL_FRAME_WIDTH) << p << ",";
    os << std::setw(KDL_FRAME_WIDTH) << y << "]";
#else
# ifdef KDL_ROTATION_PROPERTIES_EULER
    double z,y,x;
    R.GetEulerZYX(z,y,x);
    os << "[EULERZYX]"<<endl;
    os << "[";
    os << std::setw(KDL_FRAME_WIDTH) << z << ",";
    os << std::setw(KDL_FRAME_WIDTH) << y << ",";
    os << std::setw(KDL_FRAME_WIDTH) << x << "]";
# else
    os << "[";
    for (int i=0;i<=2;i++) {
        os << std::setw(KDL_FRAME_WIDTH) << R(i,0) << "," <<
                       std::setw(KDL_FRAME_WIDTH) << R(i,1) << "," <<
                       std::setw(KDL_FRAME_WIDTH) << R(i,2);
        if (i<2)
            os << ";"<< std::endl << " ";
        else
            os << "]";
    }
# endif
#endif
    return os;
}

std::ostream& operator << (std::ostream& os, const Frame& T)
{
    os << "[" << T.M << std::endl<< T.p << "]";
    return os;
}

std::ostream& operator << (std::ostream& os,const Vector2& v) {
    os << "[" << std::setw(KDL_FRAME_WIDTH) << v(0) << "," << std::setw(KDL_FRAME_WIDTH)<<v(1)
       << "]";
    return os;
}

// Rotation2 gives back an angle in degrees with the << and >> operators.
std::ostream& operator << (std::ostream& os,const Rotation2& R) {
    os << "[" << R.GetRot()*rad2deg << "]";
    return os;
}

std::ostream& operator << (std::ostream& os, const Frame2& T)
{
    os << T.M << T.p;
    return os;
}

std::istream& operator >> (std::istream& is,Vector& v)
{   IOTrace("Stream input Vector (vector or ZERO)");
    char storage[10];
    EatWord(is,"[]",storage,10);
    if (storage[0]=='\0') {
        Eat(is,'[');
        is >> v(0);
        Eat(is,',');
        is >> v(1);
        Eat(is,',');
        is >> v(2);
        EatEnd(is,']');
        IOTracePop();
        return is;
    }
    if (strcmp(storage,"ZERO")==0) {
        v = Vector::Zero();
        IOTracePop();
        return is;
    }
    throw Error_Frame_Vector_Unexpected_id();
}

std::istream& operator >> (std::istream& is,Twist& v)
{   IOTrace("Stream input Twist");
    Eat(is,'[');
    is >> v.vel(0);
    Eat(is,',');
    is >> v.vel(1);
    Eat(is,',');
    is >> v.vel(2);
    Eat(is,',');
    is >> v.rot(0);
    Eat(is,',');
    is >> v.rot(1);
    Eat(is,',');
    is >> v.rot(2);
    EatEnd(is,']');
    IOTracePop();
    return is;
}

std::istream& operator >> (std::istream& is,Wrench& v)
{   IOTrace("Stream input Wrench");
    Eat(is,'[');
    is >> v.force(0);
    Eat(is,',');
    is >> v.force(1);
    Eat(is,',');
    is >> v.force(2);
    Eat(is,',');
    is >> v.torque(0);
    Eat(is,',');
    is >> v.torque(1);
    Eat(is,',');
    is >> v.torque(2);
    EatEnd(is,']');
    IOTracePop();
    return is;
}

std::istream& operator >> (std::istream& is,Rotation& r)
{   IOTrace("Stream input Rotation (Matrix or EULERZYX, EULERZYZ,RPY, ROT, IDENTITY)");
    char storage[10];
    EatWord(is,"[]",storage,10);
    if (storage[0]=='\0') {
        Eat(is,'[');
        for (int i=0;i<3;i++) {
            is >> r(i,0);
            Eat(is,',') ;
            is >> r(i,1);
            Eat(is,',');
            is >> r(i,2);
            if (i<2)
                Eat(is,';');
            else
                EatEnd(is,']');
        }
        IOTracePop();
        return is;
    }
    Vector v;
    if (strcmp(storage,"EULERZYX")==0) {
        is >> v;
        v=v*deg2rad;
        r = Rotation::EulerZYX(v(0),v(1),v(2));
        IOTracePop();
        return is;
    }
    if (strcmp(storage,"EULERZYZ")==0) {
        is >> v;
        v=v*deg2rad;
        r = Rotation::EulerZYZ(v(0),v(1),v(2));
        IOTracePop();
        return is;
    }
    if (strcmp(storage,"RPY")==0) {
        is >> v;
        v=v*deg2rad;
        r = Rotation::RPY(v(0),v(1),v(2));
        IOTracePop();
        return is;
    }
    if (strcmp(storage,"ROT")==0) {
        is >> v;
        double angle;
        Eat(is,'[');
        is >> angle;
        EatEnd(is,']');
        r = Rotation::Rot(v,angle*deg2rad);
        IOTracePop();
        return is;
    }
    if (strcmp(storage,"IDENTITY")==0) {
        r = Rotation::Identity();
        IOTracePop();
        return is;
    }
    throw Error_Frame_Rotation_Unexpected_id();
    return is;
}

std::istream& operator >> (std::istream& is,Frame& T)
{   IOTrace("Stream input Frame (Rotation,Vector) or DH[...]");
    char storage[10];
    EatWord(is,"[",storage,10);
    if (storage[0]=='\0') {
        Eat(is,'[');
        is >> T.M;
        is >> T.p;
        EatEnd(is,']');
        IOTracePop();
        return is;
    }
    if (strcmp(storage,"DH")==0) {
        double a,alpha,d,theta;
        Eat(is,'[');
        is >> a;
        Eat(is,',');
        is >> alpha;
        Eat(is,',');
        is >> d;
        Eat(is,',');
        is >> theta;
        EatEnd(is,']');
        T = Frame::DH(a,alpha*deg2rad,d,theta*deg2rad);
        IOTracePop();
        return is;
    }
    throw Error_Frame_Frame_Unexpected_id();
    return is;
}

std::istream& operator >> (std::istream& is,Vector2& v)
{   IOTrace("Stream input Vector2");
    Eat(is,'[');
    is >> v(0);
    Eat(is,',');
    is >> v(1);
    EatEnd(is,']');
    IOTracePop();
    return is;
}
std::istream& operator >> (std::istream& is,Rotation2& r)
{   IOTrace("Stream input Rotation2");
    Eat(is,'[');
    double val;
    is >> val;
    r.Rot(val*deg2rad);
    EatEnd(is,']');
    IOTracePop();
    return is;
}
std::istream& operator >> (std::istream& is,Frame2& T)
{   IOTrace("Stream input Frame2");
    is >> T.M;
    is >> T.p;
    IOTracePop();
    return is;
}

} // namespace Frame