miscellaneous.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
36 #ifndef __MISCELLANEOUS_H_
37 #define __MISCELLANEOUS_H_
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <ctype.h>
42 #include <string.h>
43 #include <math.h>
44 #include <time.h>
45 
46 #include <iostream>
47 #include <vector>
48 
49 #include <Eigen/Dense>
50 #include <armadillo>
51 
52 #include <phua_haptic/types.h>
53 
54 //PFLN DEFINITION (CREDITS TO MIKE :-))
55 #define PFLN {printf("Passing through File [%s] @ Line [%d].\n", __FILE__, __LINE__);}
56 
64 template <typename Type>
65 Type RetrievePrecisionFromDouble(Type original, Type precision)
66 {
67  int integer=(int)original;
68  Type sub1=(1.0/precision)*(original-(Type)integer);
69  return (Type)integer+precision*((Type)round(sub1));
70 }
71 
78 template <typename Type>
79 Type DegToRad(Type deg)
80 {
81 #if ROS_VERSION_MINIMUM(1, 8, 0) //At least FUERTE , V. Santos, 27-Mai-2013
82  return (deg * (Type)M_PI / (Type)180.0);
83 #else
84  return (deg * (Type)arma::datum::pi / (Type)180.0);
85 #endif
86 }
87 
94 template <typename Type>
95 Type RadToDeg(Type rad)
96 {
97 #if ROS_VERSION_MINIMUM(1, 8, 0) //At least FUERTE , V. Santos, 27-Mai-2013
98  return (rad * (Type)180.0 / (Type)M_PI);
99 #else
100  return (rad * (Type)180.0 / (Type)arma::datum::pi);
101 #endif
102 }
103 
115 void CalculateAverageCartesianSpeed(double diffX, double diffY, double diffZ, long double time_interval, double *return_vector);
116 
124 double pc_mean(double *v, int len);
125 
131 Eigen::Matrix3d rotx(double angle_in_degrees);
132 
138 Eigen::Matrix3d roty(double angle_in_degrees);
139 
145 Eigen::Matrix3d rotz(double angle_in_degrees);
146 
154 template <class T>
155 T pc_mean(std::vector<T> vect)
156 {
157  T sum = 0;
158 
159  for(uint i = 0; i < vect.size(); i++)
160  sum += vect[i];
161 
162  return sum / vect.size();
163 }
164 
172 template <typename Type>
173 bool IsWithinRange(Type value, Type lower_bound, Type upper_bound)
174 {
175  if(value >= lower_bound && value < upper_bound)
176  {
177  return TRUE;
178  }
179  else if(value > lower_bound && value <= upper_bound)
180  {
181  return TRUE;
182  }
183  else
184  {
185  return FALSE;
186  }
187 }
188 
189 #ifdef _cplusplus
190 extern "C" {
191 #endif // _cplusplus
192 
201 int isNumeric (const char * s);
202 
210 double get_sign(double x);
211 
212 //FUNCTIONS I CREATED
213 
214 //phua_haptic related
220 void print_help(void);
221 
228 void print_greeting(shared_vars_t*RobotVars);
229 
230 //other
237 int GetNbrFromKeyboard(void);
238 
245 char GetStrFromKeyboard(void);
246 
253 double GetDblFromKeyboard(void);
254 
260 void ScreenClear(void);
261 
262 //COLOR FUNCTIONS ATTRIBUTES
266 #define RESET 0
267 #define BRIGHT 1
268 #define DIM 2
269 #define UNDERLINE 3
270 #define BLINK 4
271 #define REVERSE 7
272 #define HIDDEN 8
273 
277 #define BLACK 0
278 #define RED 1
279 #define GREEN 2
280 #define YELLOW 3
281 #define BLUE 4
282 #define MAGENTA 5
283 #define CYAN 6
284 #define GRAY 7
285 #define WHITE 8
286 
287 
289 
297 void textcolor(int attr, int fg, int bg);
298 
304 void PrintRedLine(void);
305 
311 void ResetTextColors(void);
312 
318 void HighLightText(void);
319 
320 #ifdef _cplusplus
321 }
322 #endif // _cplusplus
323 
324 #endif
325 
void HighLightText(void)
Make somesort of highlight text.
int GetNbrFromKeyboard(void)
Gets a number from keyboard input.
void print_greeting(shared_vars_t *RobotVars)
Prints to stdout the program greeting.
double get_sign(double x)
Function to determine sign of a given number.
void textcolor(int attr, int fg, int bg)
FUNCTIONS CREATED BY VITOR SANTOS(vitor@ua.pt) | ALL CREDITS GO TO HIM... :-)
types.h file for this module. Contains types and structures used by the application.
bool IsWithinRange(Type value, Type lower_bound, Type upper_bound)
Template function to determine if a given value is within a give range.
Type RadToDeg(Type rad)
Templated radian to degree conversion function.
Definition: miscellaneous.h:95
Type RetrievePrecisionFromDouble(Type original, Type precision)
Retrieve a value cropped with the required precision.
Definition: miscellaneous.h:65
Eigen::Matrix3d rotx(double angle_in_degrees)
Function to calculate rotation matrix over the X axis.
Eigen::Matrix3d roty(double angle_in_degrees)
Function to calculate rotation matrix over the Y axis.
Shared struture that holds robot/device information.
Definition: types.h:279
Eigen::Matrix3d rotz(double angle_in_degrees)
Function to calculate rotation matrix over the Z axis.
double GetDblFromKeyboard(void)
Gets a double number from keyboard input.
void PrintRedLine(void)
Printf of an horizontal separator red line.
void print_help(void)
Prints to stdout the program help tips.
void ScreenClear(void)
Sends equivalent shell command "clean" to stdout.
double pc_mean(double *v, int len)
Function to calculate mean value of an array [Taken from http://rosettacode.org/].
void ResetTextColors(void)
Reset color text.
int isNumeric(const char *s)
Function to check if string is numeric.
char GetStrFromKeyboard(void)
Gets a character from keyboard input.
void CalculateAverageCartesianSpeed(double diffX, double diffY, double diffZ, long double time_interval, double *return_vector)
Function acumulate position differences and calculate average speed.
Type DegToRad(Type deg)
Templated degree to radian conversion function.
Definition: miscellaneous.h:79


phua_haptic
Author(s): Pedro Cruz
autogenerated on Mon Mar 2 2015 01:32:36