39 const char help[]={
"***************************************************************************+\n\
40 ------------------------------ |\n\
41 | PHUA HAPTIC INTERFACE HELP | |\n\
42 ------------------------------ |\n\
44 This program uses RS232 comunication over an USB adapter to send |\n\
45 commands to the humanoid robot. |\n\
46 If you're having trouble connecting, use the path to your USB port |\n\
47 as an argument when you call the application. |\n\
49 example: >> ./phua_haptic_interface /dev/ttyUSB* |\n\
50 [where * is the number of your port] |\n\
52 ---------------------------------------------------------------------------+\n\
54 The PHANToM OMNI joystick functions require a FireWire port active |\n\
55 and superuser permissions to access it. |\n\
56 If you are having trouble with this, open a terminal and run: |\n\
58 >> sudo modprobe raw1394 |\n\
60 This will probe the FireWire port the joystick connection. If it is |\n\
61 sucessful, module raw1394 should appear in your ´/dev/´ system folder. |\n\
63 For the program to have permission to communicate with the device, call |\n\
64 this application with superuser rights using ´sudo´ or run within |\n\
67 >> sudo chmod 777 /dev/raw1394 |\n\
69 This should allow normal execution of the program. |\n\
71 ---------------------------------------------------------------------------+\n\
73 To run aplication in debug mode, use argument ´--debug´. |\n\
74 In this mode, application will execute even if connections are |\n\
75 not established. Keep in mind that the application may not |\n\
76 properly control the robot or retrieve data from the PHANToM OMNI |\n\
77 joystick in this mode, and a restart is required in order to |\n\
78 use the program's full funcionalities. |\n\
80 example: >> ./phua_haptic_interface --debug |\n\
82 ---------------------------------------------------------------------------+\n\
85 Happy Haptics! :-) |\n\
86 ***************************************************************************+"
93 char servo_comm_on[15]=
" ";
94 if(RobotVars->
servo->IsActive())
95 strcat(servo_comm_on,
"ONLINE");
97 strcat(servo_comm_on,
"OFFLINE");
99 char phant_on[15]=
" ";
101 strcat(phant_on,
"ONLINE");
103 strcat(phant_on,
"OFFLINE");
105 printf(
"***************************************************************************\n\
106 ------------------------------------- \n\
107 | PHUA HAPTIC INTERFACE APPLICATION | \n\
108 ------------------------------------- \n\
111 ***************************************************************************\n\
113 REQUIRED COMUNICATION STATUS \n\
114 ---------------------------------- \n\
115 > Servomotor COMM: |%s | \n\
116 > PHANToM OMNI COMM: |%s | \n\
117 ---------------------------------- \n",
118 servo_comm_on,phant_on);
123 static const uint array_size=20;
125 static std::vector<double> accumulationXdiff;
126 static std::vector<double> accumulationYdiff;
127 static std::vector<double> accumulationZdiff;
128 static std::vector<long double> accumulation_time;
130 accumulationXdiff.push_back(diffX);
131 accumulationYdiff.push_back(diffY);
132 accumulationZdiff.push_back(diffZ);
133 accumulation_time.push_back(time_interval);
135 if(accumulationXdiff.size()>array_size)
136 accumulationXdiff.erase(accumulationXdiff.begin());
138 if(accumulationYdiff.size()>array_size)
139 accumulationYdiff.erase(accumulationYdiff.begin());
141 if(accumulationZdiff.size()>array_size)
142 accumulationZdiff.erase(accumulationZdiff.begin());
144 if(accumulation_time.size()>array_size)
145 accumulation_time.erase(accumulation_time.begin());
147 double x_mean=pc_mean<double>(accumulationXdiff);
148 double y_mean=pc_mean<double>(accumulationYdiff);
149 double z_mean=pc_mean<double>(accumulationZdiff);
150 long double time_mean=pc_mean<long double>(accumulation_time);
152 return_vector[0]=round(x_mean/time_mean);
153 return_vector[1]=round(y_mean/time_mean);
154 return_vector[2]=round(z_mean/time_mean);
157 Eigen::Matrix3d
rotx(
double angle_in_degrees)
159 static Eigen::Matrix3d rotation_matrix;
160 static double angle_in_radians;
162 angle_in_radians =
DegToRad(angle_in_degrees);
164 for(
int i=0; i<3; i++)
166 for(
int j=0; j<3; j++)
169 rotation_matrix(i,j) = 1;
170 else if((i==1 && j==1) || (i==2 && j==2))
171 rotation_matrix(i,j) = cos(angle_in_radians);
172 else if((i==1 && j==2))
173 rotation_matrix(i,j) = -1 * sin(angle_in_radians);
174 else if((i==2 && j==1))
175 rotation_matrix(i,j) = sin(angle_in_radians);
177 rotation_matrix(i,j) = 0;
180 return rotation_matrix;
183 Eigen::Matrix3d
roty(
double angle_in_degrees)
185 static Eigen::Matrix3d rotation_matrix;
186 static double angle_in_radians;
188 angle_in_radians =
DegToRad(angle_in_degrees);
190 for(
int i=0; i<3; i++)
192 for(
int j=0; j<3; j++)
195 rotation_matrix(i,j) = 1;
196 else if((i==0 && j==0) || (i==2 && j==2))
197 rotation_matrix(i,j) = cos(angle_in_radians);
198 else if((i==0 && j==2))
199 rotation_matrix(i,j) = sin(angle_in_radians);
200 else if((i==2 && j==0))
201 rotation_matrix(i,j) = -1. * sin(angle_in_radians);
203 rotation_matrix(i,j) = 0;
206 return rotation_matrix;
209 Eigen::Matrix3d
rotz(
double angle_in_degrees)
211 static Eigen::Matrix3d rotation_matrix;
212 static double angle_in_radians;
214 angle_in_radians =
DegToRad(angle_in_degrees);
216 for(
int i=0; i<3; i++)
218 for(
int j=0; j<3; j++)
221 rotation_matrix(i,j) = 1;
222 else if((i==0 && j==0) || (i==1 && j==1))
223 rotation_matrix(i,j) = cos(angle_in_radians);
224 else if((i==1 && j==0))
225 rotation_matrix(i,j) = sin(angle_in_radians);
226 else if((i==0 && j==1))
227 rotation_matrix(i,j) = -1. * sin(angle_in_radians);
229 rotation_matrix(i,j) = 0;
232 return rotation_matrix;
239 for (i = 0; i < len; i++)
246 if (s == NULL || *s ==
'\0' || isspace(*s))
249 int r=strtod (s, &p);
256 return ((x >= 0.) ? 1. : -1.);
262 int ret=scanf(
"%d",&s);
270 int ret=scanf(
"%s",&s);
278 int ret=scanf(
"%f",&s);
291 printf(
"%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
void ScreenClear(void)
Sends equivalent shell command "clean" to stdout.
void CalculateAverageCartesianSpeed(double diffX, double diffY, double diffZ, long double time_interval, double *return_vector)
Function acumulate position differences and calculate average speed.
char GetStrFromKeyboard(void)
Gets a character from keyboard input.
Shared struture that holds robot/device information.
double pc_mean(double *v, int len)
Function to calculate mean value of an array [Taken from http://rosettacode.org/].
Eigen::Matrix3d rotz(double angle_in_degrees)
Function to calculate rotation matrix over the Z axis.
void PrintRedLine(void)
Printf of an horizontal separator red line.
void textcolor(int attr, int fg, int bg)
FUNCTIONS CREATED BY VITOR SANTOS(vitor@ua.pt) | ALL CREDITS GO TO HIM... :-)
int isNumeric(const char *s)
Function to check if string is numeric.
void ResetTextColors(void)
Reset color text.
Eigen::Matrix3d roty(double angle_in_degrees)
Function to calculate rotation matrix over the Y axis.
double GetDblFromKeyboard(void)
Gets a double number from keyboard input.
int GetNbrFromKeyboard(void)
Gets a number from keyboard input.
void HighLightText(void)
Make somesort of highlight text.
void print_help(void)
Prints to stdout the program help tips.
double get_sign(double x)
Function to determine sign of a given number.
Eigen::Matrix3d rotx(double angle_in_degrees)
Function to calculate rotation matrix over the X axis.
miscellaneous.h file for this module. Contains prototypes, includes and defines.
Type DegToRad(Type deg)
Templated degree to radian conversion function.
void print_greeting(shared_vars_t *RobotVars)
Prints to stdout the program greeting.