ROBOOP, A Robotics Object Oriented Package in C++
utils.h
Go to the documentation of this file.
1 /*
2 ROBOOP -- A robotics object oriented package in C++
3 Copyright (C) 1996-2004 Richard Gourdeau
4 
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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
13 GNU 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 
19 
20 Report problems and direct all questions to:
21 
22 Richard Gourdeau, Professeur
23 Departement de genie electrique
24 Ecole Polytechnique de Montreal
25 C.P. 6079, Succ. Centre-Ville
26 Montreal, Quebec, H3C 3A7
27 
28 email: richard.gourdeau@polymtl.ca
29 
30 -------------------------------------------------------------------------------
31 Revision_history:
32 
33 2004/07/01: Etienne Lachance
34  -Added doxygen documentation.
35 
36 2004/07/01: Ethan Tira-Thompson
37  -Added support for newmat's use_namespace #define, using ROBOOP namespace
38 
39 2004/09/18: Etienne Lachance
40  -Added deg2rad rad2deg
41 
42 2005/06/10: Carmine Lia
43  -Added pinv
44 -------------------------------------------------------------------------------
45 */
46 
47 #ifndef __cplusplus
48 #error Must use C++ for the type Robot
49 #endif
50 #ifndef UTILS_H
51 #define UTILS_H
52 
58 #ifdef _MSC_VER // Microsoft
59 #pragma warning (disable:4786) /* Disable decorated name truncation warnings */
60 #endif
61 #include <stdio.h>
62 #include <limits>
63 #define WANT_STRING /* include.h will get string fns */
64 #define WANT_STREAM /* include.h will get stream fns */
65 #define WANT_FSTREAM /* include.h will get fstream fns */
66 #define WANT_MATH /* include.h will get math fns */
67  /* newmatap.h will get include.h */
68 
69 #include "newmatap.h" /* need matrix applications */
70 
71 #include "newmatio.h" /* need matrix output routines */
72 
73 #ifdef use_namespace
74 namespace ROBOOP {
75  using namespace NEWMAT;
76 #endif
77 
78 #ifndef M_PI
79 #define M_PI 3.14159265358979
80 #endif
81 
82 #define GRAVITY 9.81
83 
84 // global variables
85 extern Real fourbyfourident[];
86 extern Real threebythreeident[];
87 
88 // angle conversion
89 inline double deg2rad(const double angle_deg){ return angle_deg*M_PI/180; }
90 inline double rad2deg(const double angle_rad){ return angle_rad*180/M_PI; }
91 
92 // vector operation
93 
94 ReturnMatrix x_prod_matrix(const ColumnVector & x);
95 
96 ReturnMatrix pinv(const Matrix & M);
97 
98 // numerical analysis tools
99 
100 ReturnMatrix Integ_Trap(const ColumnVector & present, ColumnVector & past, const Real dt);
101 
102 void Runge_Kutta4(ReturnMatrix (*xdot)(Real time, const Matrix & xin),
103  const Matrix & xo, Real to, Real tf, int nsteps,
104  RowVector & tout, Matrix & xout);
105 
106 void Runge_Kutta4_Real_time(ReturnMatrix (*xdot)(Real time, const Matrix & xin),
107  const Matrix & xo, Real to, Real tf, int nsteps);
108 
109 void Runge_Kutta4_Real_time(ReturnMatrix (*xdot)(Real time, const Matrix & xin,
110  bool & exit, bool & init),
111  const Matrix & xo, Real to, Real tf, int nsteps);
112 
113 void odeint(ReturnMatrix (*xdot)(Real time, const Matrix & xin),
114  Matrix & xo, Real to, Real tf, Real eps, Real h1, Real hmin,
115  int & nok, int & nbad,
116  RowVector & tout, Matrix & xout, Real dtsav);
117 
118 ReturnMatrix sign(const Matrix & x);
119 
120 short sign(const Real x);
121 
122 const double epsilon = 0.0000001;
123 
124 inline bool isZero(const double x)
125 {
126  if ( fabs(x) < epsilon)
127  {
128  return true;
129  }
130  return false;
131 }
132 
133 
134 // translation
135 ReturnMatrix trans(const ColumnVector & a);
136 
137 // rotation matrices
138 ReturnMatrix rotx(const Real alpha);
139 ReturnMatrix roty(const Real beta);
140 ReturnMatrix rotz(const Real gamma);
141 ReturnMatrix rotk(const Real theta, const ColumnVector & k);
142 
143 ReturnMatrix rpy(const ColumnVector & a);
144 ReturnMatrix eulzxz(const ColumnVector & a);
145 ReturnMatrix rotd(const Real theta, const ColumnVector & k1, const ColumnVector & k2);
146 
147 
148 // inverse on rotation matrices
149 ReturnMatrix irotk(const Matrix & R);
150 ReturnMatrix irpy(const Matrix & R);
151 ReturnMatrix ieulzxz(const Matrix & R);
152 
153 #ifdef use_namespace
154 }
155 #endif
156 
157 #endif
158