TypeIIRMLStep2PhaseSynchronization.cpp
Go to the documentation of this file.
1 // ---------------------- Doxygen info ----------------------
37 // ----------------------------------------------------------
38 // For a convenient reading of this file's source code,
39 // please use a tab width of four characters.
40 // ----------------------------------------------------------
41 
42 
43 #include <TypeIIRMLPosition.h>
44 #include <TypeIIRMLMath.h>
45 #include <TypeIIRMLDecisionTree2.h>
46 
47 using namespace TypeIIRMLMath;
48 
49 
50 //****************************************************************************
51 // Step2PhaseSynchronization()
52 
54 {
55  unsigned int i = 0
56  , j = 0 ;
57 
58  double P_a0 = 0.0
59  , P_a1 = 0.0
60  , P_a2 = 0.0
61  , V_a0 = 0.0
62  , V_a1 = 0.0
63  , V_a2 = 0.0
64  , A_a0 = 0.0
65  , A_a1 = 0.0
66  , A_a2 = 0.0
67  , DeltaT = 0.0
68  , ScalingValueFromReferenceVector = 0.0
69  , V_ErrorAtBeginning = 0.0
70  , P_ErrorAtEnd = 0.0
71  , V_ErrorAtEnd = 0.0 ;
72 
73  // Calculate the trajectory of the reference DOF
74 
75  TypeIIRMLDecisionTree2( (this->CurrentInputParameters->CurrentPositionVector->VecData )[this->GreatestDOFForPhaseSynchronization]
76  , (this->CurrentInputParameters->CurrentVelocityVector->VecData )[this->GreatestDOFForPhaseSynchronization]
77  , (this->CurrentInputParameters->TargetPositionVector->VecData )[this->GreatestDOFForPhaseSynchronization]
78  , (this->CurrentInputParameters->TargetVelocityVector->VecData )[this->GreatestDOFForPhaseSynchronization]
79  , (this->CurrentInputParameters->MaxVelocityVector->VecData )[this->GreatestDOFForPhaseSynchronization]
80  , (this->CurrentInputParameters->MaxAccelerationVector->VecData )[this->GreatestDOFForPhaseSynchronization]
81  , this->SynchronizationTime
82  , &((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]) );
83 
84 
85 
86  // Adapt the synchronization time value to the time value, at which the reference DOF reaches
87  // its final state of motion. Although, this should not differ from the originally calculated
88  // synchronization time value, it differs due to numerical inaccuracies. In oder to compensate
89  // these inaccuracies, we use the Step 2 result value of the reference DOF.
90  this->SynchronizationTime = (((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).PolynomialTimes)[((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).ValidPolynomials - 2];
91 
92  // Calculate the trajectory of all other selected DOFs
93 
94  for (i = 0; i < this->NumberOfDOFs; i++)
95  {
96  if ( (this->ModifiedSelectionVector->VecData)[i] && (i != this->GreatestDOFForPhaseSynchronization) )
97  {
98  ScalingValueFromReferenceVector = (this->PhaseSynchronizationReferenceVector->VecData)[i]
99  / (this->PhaseSynchronizationReferenceVector->VecData)[this->GreatestDOFForPhaseSynchronization];
100 
101  for (j = 0; j < ((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).ValidPolynomials; j++)
102  {
103  ((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).PositionPolynomial[j].GetCoefficients (&P_a2, &P_a1, &P_a0, &DeltaT);
104  ((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).VelocityPolynomial[j].GetCoefficients (&V_a2, &V_a1, &V_a0, &DeltaT);
105  ((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).AccelerationPolynomial[j].GetCoefficients (&A_a2, &A_a1, &A_a0, &DeltaT);
106 
107  P_a2 *= ScalingValueFromReferenceVector;
108  P_a1 *= ScalingValueFromReferenceVector;
109  P_a0 = ((this->CurrentInputParameters->CurrentPositionVector->VecData)[i]
110  + (P_a0
111  - (this->CurrentInputParameters->CurrentPositionVector->VecData)[this->GreatestDOFForPhaseSynchronization])
112  * ScalingValueFromReferenceVector);
113 
114  V_a2 *= ScalingValueFromReferenceVector;
115  V_a1 *= ScalingValueFromReferenceVector;
116  V_a0 *= ScalingValueFromReferenceVector;
117 
118  A_a2 *= ScalingValueFromReferenceVector;
119  A_a1 *= ScalingValueFromReferenceVector;
120  A_a0 *= ScalingValueFromReferenceVector;
121 
122  ((this->Polynomials)[i]).PositionPolynomial[j].SetCoefficients (P_a2, P_a1, P_a0, DeltaT);
123  ((this->Polynomials)[i]).VelocityPolynomial[j].SetCoefficients (V_a2, V_a1, V_a0, DeltaT);
124  ((this->Polynomials)[i]).AccelerationPolynomial[j].SetCoefficients (A_a2, A_a1, A_a0, DeltaT);
125 
126  ((this->Polynomials)[i]).PolynomialTimes[j] = ((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).PolynomialTimes[j];
127  }
128 
129  ((this->Polynomials)[i]).ValidPolynomials = ((this->Polynomials)[this->GreatestDOFForPhaseSynchronization]).ValidPolynomials;
130 
131  // ----------------------------------------------------------
132  // Correcting numerical errors by adding a polynomial of degree one to the existing polynomials
133  // ----------------------------------------------------------
134 
135  if (this->SynchronizationTime > this->CycleTime)
136  {
137  V_ErrorAtBeginning = (this->CurrentInputParameters->CurrentVelocityVector->VecData)[i]
138  - ((this->Polynomials)[i]).VelocityPolynomial[0].CalculateValue(0.0);
139 
140  V_ErrorAtEnd = (this->CurrentInputParameters->TargetVelocityVector->VecData)[i]
141  - ((this->Polynomials)[i]).VelocityPolynomial[((this->Polynomials)[i]).ValidPolynomials - 1].CalculateValue(this->SynchronizationTime);
142 
143  for (j = 0; j < ((this->Polynomials)[i]).ValidPolynomials; j++)
144  {
145  ((this->Polynomials)[i]).PositionPolynomial[j].GetCoefficients (&P_a2, &P_a1, &P_a0, &DeltaT);
146  ((this->Polynomials)[i]).VelocityPolynomial[j].GetCoefficients (&V_a2, &V_a1, &V_a0, &DeltaT);
147 
148  V_a1 += (V_ErrorAtEnd - V_ErrorAtBeginning) / this->SynchronizationTime;
149  V_a0 += V_ErrorAtBeginning - DeltaT * (V_ErrorAtEnd - V_ErrorAtBeginning) / this->SynchronizationTime;
150 
151  P_a1 = V_a0;
152 
153  ((this->Polynomials)[i]).PositionPolynomial[j].SetCoefficients (P_a2, P_a1, P_a0, DeltaT);
154  ((this->Polynomials)[i]).VelocityPolynomial[j].SetCoefficients (V_a2, V_a1, V_a0, DeltaT);
155  }
156 
157  P_ErrorAtEnd = (this->CurrentInputParameters->TargetPositionVector->VecData)[i]
158  - ((this->Polynomials)[i]).PositionPolynomial[((this->Polynomials)[i]).ValidPolynomials - 1].CalculateValue(this->SynchronizationTime);
159 
160  for (j = 0; j < ((this->Polynomials)[i]).ValidPolynomials; j++)
161  {
162  ((this->Polynomials)[i]).PositionPolynomial[j].GetCoefficients (&P_a2, &P_a1, &P_a0, &DeltaT);
163 
164  P_a1 += P_ErrorAtEnd / this->SynchronizationTime;
165  P_a0 -= DeltaT * P_ErrorAtEnd / this->SynchronizationTime;
166 
167  ((this->Polynomials)[i]).PositionPolynomial[j].SetCoefficients (P_a2, P_a1, P_a0, DeltaT);
168  }
169  }
170  // ----------------------------------------------------------
171  }
172  }
173 
174 }
void Step2PhaseSynchronization(void)
Executes Step 2 for phase-synchronized motion trajectories.
void TypeIIRMLDecisionTree2(const double &CurrentPosition, const double &CurrentVelocity, const double &TargetPosition, const double &TargetVelocity, const double &MaxVelocity, const double &MaxAcceleration, const double &SynchronizationTime, MotionPolynomials *PolynomialsInternal)
This function contains the decision tree of the Step 2 of the Type II On-Line Trajectory Generation a...
Header file for functions and definitions of constant values and macros.
Header file for the class TypeIIRMLPosition, which constitutes the actual interface of the Type II Re...
Header file for the Step 2 decision tree of the Type II On-Line Trajectory Generation algorithm (time...


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