TypeIIRMLVelocityIsPhaseSynchronizationPossible.cpp
Go to the documentation of this file.
1 // ---------------------- Doxygen info ----------------------
38 // ----------------------------------------------------------
39 // For a convenient reading of this file's source code,
40 // please use a tab width of four characters.
41 // ----------------------------------------------------------
42 
43 
44 #include <TypeIIRMLVelocity.h>
45 #include <TypeIIRMLMath.h>
48 #include <RMLVector.h>
49 #include <ReflexxesAPI.h>
50 #include <RMLVelocityFlags.h>
51 
52 
53 
54 
55 using namespace TypeIIRMLMath;
56 
57 
58 
59 //****************************************************************************
60 // IsPhaseSynchronizationPossible()
61 
63 {
64  bool Result = true
65  , SignSwitch = false;
66 
67  unsigned int i = 0;
68 
69  double LengthOfCurrentVelocityVector = 0.0
70  , LengthOfTargetVelocityVector = 0.0
71  , LengthOfReferenceVector = 0.0;
72 
73  for (i = 0; i < this->NumberOfDOFs; i++)
74  {
75  if ((this->PhaseSyncSelectionVector->VecData)[i])
76  {
77  (this->PhaseSynchronizationCurrentVelocityVector->VecData)[i]
78  = (this->CurrentInputParameters->CurrentVelocityVector->VecData)[i];
79  (this->PhaseSynchronizationTargetVelocityVector->VecData)[i]
80  = (this->CurrentInputParameters->TargetVelocityVector->VecData)[i];
81 
82  LengthOfCurrentVelocityVector += pow2((this->PhaseSynchronizationCurrentVelocityVector->VecData)[i]);
83  LengthOfTargetVelocityVector += pow2((this->PhaseSynchronizationTargetVelocityVector->VecData)[i]);
84  }
85  else
86  {
87  (this->PhaseSynchronizationCurrentVelocityVector->VecData) [i] = 0.0;
88  (this->PhaseSynchronizationTargetVelocityVector->VecData) [i] = 0.0;
89  }
90  }
91 
92  LengthOfCurrentVelocityVector = RMLSqrt(LengthOfCurrentVelocityVector);
93  LengthOfTargetVelocityVector = RMLSqrt(LengthOfTargetVelocityVector);
94 
95  if ( (LengthOfCurrentVelocityVector != POSITIVE_ZERO) && (LengthOfCurrentVelocityVector != 0.0) )
96  {
97  for (i = 0; i < this->NumberOfDOFs; i++)
98  {
99  if ((this->PhaseSyncSelectionVector->VecData)[i])
100  {
101  (this->PhaseSynchronizationCurrentVelocityVector->VecData)[i] /= LengthOfCurrentVelocityVector;
102  }
103  }
104  }
105  else
106  {
107  for (i = 0; i < this->NumberOfDOFs; i++)
108  {
109  if ((this->PhaseSyncSelectionVector->VecData)[i])
110  {
111  (this->PhaseSynchronizationCurrentVelocityVector->VecData)[i] = 0.0;
112  }
113  }
114  }
115 
116  if ( (LengthOfTargetVelocityVector != POSITIVE_ZERO) && (LengthOfTargetVelocityVector != 0.0) )
117  {
118  for (i = 0; i < this->NumberOfDOFs; i++)
119  {
120  if ((this->PhaseSyncSelectionVector->VecData)[i])
121  {
122  (this->PhaseSynchronizationTargetVelocityVector->VecData)[i] /= LengthOfTargetVelocityVector;
123  }
124  }
125  }
126  else
127  {
128  for (i = 0; i < this->NumberOfDOFs; i++)
129  {
130  if ((this->PhaseSyncSelectionVector->VecData)[i])
131  {
132  (this->PhaseSynchronizationTargetVelocityVector->VecData)[i] = 0.0;
133  }
134  }
135  }
136 
137  // Determine a reference vector.
138 
139  LengthOfReferenceVector = ABSOLUTE_PHASE_SYNC_EPSILON;
140 
141  if ( ( LengthOfCurrentVelocityVector >= LengthOfTargetVelocityVector )
142  && ( LengthOfCurrentVelocityVector >= ABSOLUTE_PHASE_SYNC_EPSILON ))
143  {
144  *(this->PhaseSynchronizationReferenceVector) = *(this->PhaseSynchronizationCurrentVelocityVector);
145  LengthOfReferenceVector = LengthOfCurrentVelocityVector;
146  }
147 
148  if ( ( LengthOfTargetVelocityVector >= LengthOfCurrentVelocityVector )
149  && ( LengthOfTargetVelocityVector >= ABSOLUTE_PHASE_SYNC_EPSILON ))
150  {
151  *(this->PhaseSynchronizationReferenceVector) = *(this->PhaseSynchronizationTargetVelocityVector);
152  LengthOfReferenceVector = LengthOfTargetVelocityVector;
153  }
154 
155  if (LengthOfReferenceVector > ABSOLUTE_PHASE_SYNC_EPSILON)
156  {
157  // Switch vector orientations
158 
159  SignSwitch = true;
160 
161  for (i = 0; i < this->NumberOfDOFs; i++)
162  {
163  if ((this->PhaseSyncSelectionVector->VecData)[i])
164  {
165  if ((Sign((this->PhaseSynchronizationCurrentVelocityVector->VecData)[i])
166  == Sign((this->PhaseSynchronizationReferenceVector->VecData)[i]))
167  && (fabs((this->PhaseSynchronizationCurrentVelocityVector->VecData)[i])
169  {
170  SignSwitch = false;
171  break;
172  }
173  }
174  }
175 
176  if (SignSwitch)
177  {
178  for (i = 0; i < this->NumberOfDOFs; i++)
179  {
180  if ((this->PhaseSyncSelectionVector->VecData)[i])
181  {
182  (this->PhaseSynchronizationCurrentVelocityVector->VecData)[i]
183  = -(this->PhaseSynchronizationCurrentVelocityVector->VecData)[i];
184  }
185  }
186  }
187 
188  SignSwitch = true;
189 
190  for (i = 0; i < this->NumberOfDOFs; i++)
191  {
192  if ((this->PhaseSyncSelectionVector->VecData)[i])
193  {
194  if ((Sign((this->PhaseSynchronizationTargetVelocityVector->VecData)[i])
195  == Sign((this->PhaseSynchronizationReferenceVector->VecData)[i]))
196  && (fabs((this->PhaseSynchronizationTargetVelocityVector->VecData)[i])
198  {
199  SignSwitch = false;
200  break;
201  }
202  }
203  }
204 
205  if (SignSwitch)
206  {
207  for (i = 0; i < this->NumberOfDOFs; i++)
208  {
209  if ((this->PhaseSyncSelectionVector->VecData)[i])
210  {
211  (this->PhaseSynchronizationTargetVelocityVector->VecData)[i]
212  = -(this->PhaseSynchronizationTargetVelocityVector->VecData)[i];
213  }
214  }
215  }
216 
217  // For the case that all (normalized) are colinear, they now also have the same orientation.
218 
219 
220  for (i = 0; i < this->NumberOfDOFs; i++)
221  {
222  if ( (this->PhaseSyncSelectionVector->VecData)[i] )
223  {
224  if ( ((fabs((this->PhaseSynchronizationReferenceVector->VecData)[i] - (this->PhaseSynchronizationCurrentVelocityVector->VecData)[i])
226  && (fabs((this->PhaseSynchronizationCurrentVelocityVector->VecData)[i]) > ABSOLUTE_PHASE_SYNC_EPSILON) )
227  || ((fabs((this->PhaseSynchronizationReferenceVector->VecData)[i] - (this->PhaseSynchronizationTargetVelocityVector->VecData)[i])
229  && (fabs((this->PhaseSynchronizationTargetVelocityVector->VecData)[i]) > ABSOLUTE_PHASE_SYNC_EPSILON) ) )
230  {
231  Result = false;
232  break;
233  }
234  }
235  }
236  }
237  else
238  {
239  Result = false;
240  }
241 
242  if (!Result)
243  {
244  this->PhaseSynchronizationReferenceVector->Set(0.0);
245  }
246 
247  return(Result);
248 }
Header file for the dynamic vector class used for the Reflexxes Motion Libraries. ...
#define ABSOLUTE_PHASE_SYNC_EPSILON
Absolute epsilon to check whether all required vectors are collinear.
Header file for the class ReflexxesAPI (API of the Reflexxes Motion Libraries)
Header file for the class TypeIIRMLVelocity.
Header file for functions and definitions of constant values and macros.
Header file for the class RMLVelocityInputParameters.
double RMLSqrt(const double &Value)
Calculates the real square root of a given value. If the value is negative a value of almost zero wil...
Header file for the class RMLVelocityFlags.
bool IsPhaseSynchronizationPossible(void)
Checks, whether the motion trajectory can be phase-synchronized.
Header file for the class RMLVelocityOutputParameters.
#define pow2(A)
A to the power of 2.
#define Sign(A)
Sign macro (integer)
#define POSITIVE_ZERO
To prevent from numerical errors, a value for a "positive" value of zero is required for deterministi...


libreflexxestype2
Author(s):
autogenerated on Sat Nov 21 2020 03:17:34