03_RMLPositionSampleApplication.cpp
Go to the documentation of this file.
1 // ---------------------- Doxygen info ----------------------
35 // ----------------------------------------------------------
36 // For a convenient reading of this file's source code,
37 // please use a tab width of four characters.
38 // ----------------------------------------------------------
39 
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 
44 #include <ReflexxesAPI.h>
45 #include <RMLPositionFlags.h>
48 
49 
50 //*************************************************************************
51 // defines
52 
53 #define CYCLE_TIME_IN_SECONDS 0.001
54 #define NUMBER_OF_DOFS 2
55 
56 
57 //*************************************************************************
58 // Main function to run the process that contains the test application
59 //
60 // This function is based on the sample program of
61 // 01_RMLPositionSampleApplication.cpp and contains a simple example to use
62 // and distinguish between time- and phase-synchronized motion trajectories
63 // that are generated by the Type II Reflexxes Motion Library. This code
64 // snippet directly corresponds to the example trajectories shown in the
65 // documentation.
66 //*************************************************************************
67 int main()
68 {
69  // ********************************************************************
70  // Variable declarations and definitions
71 
72  bool IntermediateTargetStateSet = false
73  , IntermediateStateReached = false ;
74 
75  int ResultValue = 0 ;
76 
77  double Time = 0.0 ;
78 
79  ReflexxesAPI *RML = NULL ;
80 
81  RMLPositionInputParameters *IP = NULL ;
82 
83  RMLPositionOutputParameters *OP = NULL ;
84 
85  RMLPositionFlags Flags ;
86 
87  // ********************************************************************
88  // Creating all relevant objects of the Type II Reflexxes Motion Library
89 
90  RML = new ReflexxesAPI( NUMBER_OF_DOFS
92 
94 
96 
97  // ********************************************************************
98  // Set-up a timer with a period of one millisecond
99  // (not implemented in this example in order to keep it simple)
100  // ********************************************************************
101 
102  printf("-------------------------------------------------------\n" );
103  printf("Reflexxes Motion Libraries \n" );
104  printf("Example: 03_RMLPositionSampleApplication \n\n");
105  printf("This example demonstrates how to set-up the \n" );
106  printf("generation of time- and phase-synchronized motion \n" );
107  printf("trajectories using the position-based Online \n" );
108  printf("Trajectory Generation algorithm of the Type II \n" );
109  printf("Reflexxes Motion Library. \n\n");
110  printf("Copyright (C) 2014 Google, Inc. \n" );
111  printf("-------------------------------------------------------\n" );
112 
113  // ********************************************************************
114  // Set-up the input parameters
115 
116  // In this test program, arbitrary values are chosen. If executed on a
117  // real robot or mechanical system, the position is read and stored in
118  // an RMLPositionInputParameters::CurrentPositionVector vector object.
119  // For the very first motion after starting the controller, velocities
120  // and acceleration are commonly set to zero. The desired target state
121  // of motion and the motion constraints depend on the robot and the
122  // current task/application.
123  // The internal data structures make use of native C data types
124  // (e.g., IP->CurrentPositionVector->VecData is a pointer to
125  // an array of NUMBER_OF_DOFS double values), such that the Reflexxes
126  // Library can be used in a universal way.
127 
128  IP->CurrentPositionVector->VecData [0] = 100.0 ;
129  IP->CurrentPositionVector->VecData [1] = 100.0 ;
130 
131  IP->CurrentVelocityVector->VecData [0] = 0.0 ;
132  IP->CurrentVelocityVector->VecData [1] = 0.0 ;
133 
134  IP->CurrentAccelerationVector->VecData [0] = 0.0 ;
135  IP->CurrentAccelerationVector->VecData [1] = 0.0 ;
136 
137  IP->MaxVelocityVector->VecData [0] = 300.0 ;
138  IP->MaxVelocityVector->VecData [1] = 300.0 ;
139 
140  IP->MaxAccelerationVector->VecData [0] = 400.0 ;
141  IP->MaxAccelerationVector->VecData [1] = 400.0 ;
142 
143  IP->MaxJerkVector->VecData [0] = 500.0 ;
144  IP->MaxJerkVector->VecData [1] = 500.0 ;
145 
146  IP->TargetPositionVector->VecData [0] = 700.0 ;
147  IP->TargetPositionVector->VecData [1] = 300.0 ;
148 
149  IP->TargetVelocityVector->VecData [0] = 0.0 ;
150  IP->TargetVelocityVector->VecData [1] = 0.0 ;
151 
152  IP->SelectionVector->VecData [0] = true ;
153  IP->SelectionVector->VecData [1] = true ;
154 
155  // ********************************************************************
156  // Setting the flag for time- and phase-synchronization:
157  //
158  // - RMLPositionFlags::ONLY_TIME_SYNCHRONIZATION for
159  // time-synchronization
160  // - RMLPositionFlags::PHASE_SYNCHRONIZATION_IF_POSSIBLE for
161  // phase-synchronization
162  //
163  // Please feel free to change this flag to see the difference in the
164  // behavior of the algorithm.
165 
167 
168  // ********************************************************************
169  // Starting the control loop
170 
171  for(;;)
172  {
173 
174  // ****************************************************************
175  // Wait for the next timer tick
176  // (not implemented in this example in order to keep it simple)
177  // ****************************************************************
178 
179  // Calling the Reflexxes OTG algorithm
180  ResultValue = RML->RMLPosition( *IP
181  , OP
182  , Flags );
183 
184  if (ResultValue < 0)
185  {
186  printf("An error occurred (%d).\n", ResultValue );
187  break;
188  }
189 
190  // ****************************************************************
191  // Here, the new state of motion, that is
192  //
193  // - OP->NewPositionVector
194  // - OP->NewVelocityVector
195  // - OP->NewAccelerationVector
196  //
197  // can be used as input values for lower level controllers. In the
198  // most simple case, a position controller in actuator space is
199  // used, but the computed state can be applied to many other
200  // controllers (e.g., Cartesian impedance controllers,
201  // operational space controllers).
202  // ****************************************************************
203 
204  // ****************************************************************
205  // Feed the output values of the current control cycle back to
206  // input values of the next control cycle
207 
211 
212  Time += CYCLE_TIME_IN_SECONDS;
213 
214  // ****************************************************************
215  // In this introductory example, we simple trigger a sensor event
216  // after one second. On a real-world system, trigger signal are
217  // commonly generated based on (unforeseen) sensor signals. This
218  // event changes the input parameters and specifies a
219  // intermediate state of motion, that is, a new desired target
220  // state of motion for the Reflexxes algorithm.
221 
222 
223  if ( ( Time >= 1.0 )
224  && ( !IntermediateTargetStateSet ) )
225  {
226  IP->TargetPositionVector->VecData [0] = 550.0 ;
227  IP->TargetPositionVector->VecData [1] = 250.0 ;
228 
229  IP->TargetVelocityVector->VecData [0] = -150.0 ;
230  IP->TargetVelocityVector->VecData [1] = -50.0 ;
231  }
232 
233  // ****************************************************************
234  // After reaching the intermediate state of motion define above
235  // we switch the values of the desired target state of motion
236  // back to the original one. In the documentation and the
237  // description of time- and phase-synchronized motion trajectories,
238  // this switching happens at 3873 milliseconds.
239 
240  if ( ( ResultValue == ReflexxesAPI::RML_FINAL_STATE_REACHED )
241  && ( !IntermediateStateReached ) )
242  {
243  IntermediateStateReached = true;
244 
245  IP->TargetPositionVector->VecData [0] = 700.0 ;
246  IP->TargetPositionVector->VecData [1] = 300.0 ;
247 
248  IP->TargetVelocityVector->VecData [0] = 0.0 ;
249  IP->TargetVelocityVector->VecData [1] = 0.0 ;
250 
251  continue;
252  }
253 
254  // ****************************************************************
255  // After the final state of motion is reached, we leave the loop
256  // and terminate the program.
257 
258  if (ResultValue == ReflexxesAPI::RML_FINAL_STATE_REACHED)
259  {
260  break;
261  }
262  }
263 
264  // ********************************************************************
265  // Deleting the objects of the Reflexxes Motion Library end terminating
266  // the process
267 
268  delete RML ;
269  delete IP ;
270  delete OP ;
271 
272  exit(EXIT_SUCCESS) ;
273 }
Header file for the class RMLPositionOutputParameters.
Header file for the class ReflexxesAPI (API of the Reflexxes Motion Libraries)
Header file for the class RMLPositionFlags.
RMLDoubleVector * NewAccelerationVector
A pointer to the new acceleration vector .
Data structure containing flags to parameterize the execution of the position-based On-Line Trajector...
RMLDoubleVector * CurrentVelocityVector
A pointer to the current velocity vector .
RMLDoubleVector * MaxAccelerationVector
A pointer to the maximum acceleration vector .
T * VecData
Pointer to the actual vector data, that is, an array of type T objects.
Definition: RMLVector.h:524
RMLDoubleVector * NewPositionVector
A pointer to the new position vector .
Header file for the class RMLPositionInputParameters.
RMLDoubleVector * MaxVelocityVector
A pointer to the maximum velocity vector .
unsigned char SynchronizationBehavior
This value specifies the desired synchronization behavior.
Definition: RMLFlags.h:192
int RMLPosition(const RMLPositionInputParameters &InputValues, RMLPositionOutputParameters *OutputValues, const RMLPositionFlags &Flags)
This is the central method of each Reflexxes Type Motion Library.
RMLBoolVector * SelectionVector
A pointer to the selection vector .
RMLDoubleVector * TargetPositionVector
A pointer to the target position vector .
Even if it is possible to calculate a phase-synchronized trajectory, only a time-synchronized traject...
Definition: RMLFlags.h:152
#define CYCLE_TIME_IN_SECONDS
This class constitutes the API of the Reflexxes Motion Libraries
Definition: ReflexxesAPI.h:123
RMLDoubleVector * TargetVelocityVector
A pointer to the target velocity vector .
RMLDoubleVector * MaxJerkVector
A pointer to the maximum jerk vector .
Class for the output parameters of the position-based On-Line Trajectory Generation algorithm...
RMLDoubleVector * NewVelocityVector
A pointer to the new velocity vector .
Class for the input parameters of the position-based On-Line Trajectory Generation algorithm...
RMLDoubleVector * CurrentAccelerationVector
A pointer to the current acceleration vector .
RMLDoubleVector * CurrentPositionVector
A pointer to the current position vector .


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