06_RMLVelocitySampleApplication.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 <RMLVelocityFlags.h>
48 
49 
50 //*************************************************************************
51 // defines
52 
53 #define CYCLE_TIME_IN_SECONDS 0.001
54 #define NUMBER_OF_DOFS 3
55 
56 
57 //*************************************************************************
58 // Main function to run the process that contains the test application
59 //
60 // This function contains source code to get started with the Type II
61 // Reflexxes Motion Library. Only a minimum amount of functionality is
62 // contained in this program: a simple trajectory for a
63 // three-degree-of-freedom system is executed. This code snippet
64 // directly corresponds to the example trajectories shown in the
65 // documentation.
66 //*************************************************************************
67 int main()
68 {
69  // ********************************************************************
70  // Variable declarations and definitions
71 
72  int ResultValue = 0 ;
73 
74  ReflexxesAPI *RML = NULL ;
75 
76  RMLVelocityInputParameters *IP = NULL ;
77 
78  RMLVelocityOutputParameters *OP = NULL ;
79 
80  RMLVelocityFlags Flags ;
81 
82  // ********************************************************************
83  // Creating all relevant objects of the Type II Reflexxes Motion Library
84 
85  RML = new ReflexxesAPI( NUMBER_OF_DOFS
87 
89 
91 
92  // ********************************************************************
93  // Set-up a timer with a period of one millisecond
94  // (not implemented in this example in order to keep it simple)
95  // ********************************************************************
96 
97  printf("-------------------------------------------------------\n" );
98  printf("Reflexxes Motion Libraries \n" );
99  printf("Example: 06_RMLVelocitySampleApplication.cpp \n\n");
100  printf("This example demonstrates the most basic use of the \n" );
101  printf("Reflexxes API (class ReflexxesAPI) using the velocity- \n" );
102  printf("based Type II Online Trajectory Generation algorithm. \n\n");
103  printf("Copyright (C) 2014 Google, Inc. \n" );
104  printf("-------------------------------------------------------\n" );
105 
106  // ********************************************************************
107  // Set-up the input parameters
108 
109  // In this test program, arbitrary values are chosen. If executed on a
110  // real robot or mechanical system, the position is read and stored in
111  // an RMLVelocityInputParameters::CurrentPositionVector vector object.
112  // For the very first motion after starting the controller, velocities
113  // and acceleration are commonly set to zero. The desired target state
114  // of motion and the motion constraints depend on the robot and the
115  // current task/application.
116  // The internal data structures make use of native C data types
117  // (e.g., IP->CurrentPositionVector->VecData is a pointer to
118  // an array of NUMBER_OF_DOFS double values), such that the Reflexxes
119  // Library can be used in a universal way.
120 
121  IP->CurrentPositionVector->VecData [0] = 100.0 ;
122  IP->CurrentPositionVector->VecData [1] = 50.0 ;
123  IP->CurrentPositionVector->VecData [2] = -100.0 ;
124 
125  IP->CurrentVelocityVector->VecData [0] = 80.0 ;
126  IP->CurrentVelocityVector->VecData [1] = 25.0 ;
127  IP->CurrentVelocityVector->VecData [2] = -50.0 ;
128 
129  IP->CurrentAccelerationVector->VecData [0] = -50.0 ;
130  IP->CurrentAccelerationVector->VecData [1] = -150.0 ;
131  IP->CurrentAccelerationVector->VecData [2] = 80.0 ;
132 
133  IP->MaxAccelerationVector->VecData [0] = 400.0 ;
134  IP->MaxAccelerationVector->VecData [1] = 300.0 ;
135  IP->MaxAccelerationVector->VecData [2] = 500.0 ;
136 
137  IP->MaxJerkVector->VecData [0] = 500.0 ;
138  IP->MaxJerkVector->VecData [1] = 400.0 ;
139  IP->MaxJerkVector->VecData [2] = 300.0 ;
140 
141  IP->TargetVelocityVector->VecData [0] = 200.0 ;
142  IP->TargetVelocityVector->VecData [1] = -150.0 ;
143  IP->TargetVelocityVector->VecData [2] = -20.0 ;
144 
145  IP->SelectionVector->VecData [0] = true ;
146  IP->SelectionVector->VecData [1] = true ;
147  IP->SelectionVector->VecData [2] = true ;
148 
150 
151  // ********************************************************************
152  // Starting the control loop
153 
154  while (ResultValue != ReflexxesAPI::RML_FINAL_STATE_REACHED)
155  {
156 
157  // ****************************************************************
158  // Wait for the next timer tick
159  // (not implemented in this example in order to keep it simple)
160  // ****************************************************************
161 
162  // Calling the Reflexxes OTG algorithm
163  ResultValue = RML->RMLVelocity( *IP
164  , OP
165  , Flags );
166 
167  if (ResultValue < 0)
168  {
169  printf("An error occurred (%d).\n", ResultValue );
170  break;
171  }
172 
173  // ****************************************************************
174  // Here, the new state of motion, that is
175  //
176  // - OP->NewPositionVector
177  // - OP->NewVelocityVector
178  // - OP->NewAccelerationVector
179  //
180  // can be used as input values for lower level controllers. In the
181  // most simple case, a position controller in actuator space is
182  // used, but the computed state can be applied to many other
183  // controllers (e.g., Cartesian impedance controllers,
184  // operational space controllers).
185  // ****************************************************************
186 
187  // ****************************************************************
188  // Feed the output values of the current control cycle back to
189  // input values of the next control cycle
190 
194  }
195 
196  // ********************************************************************
197  // Deleting the objects of the Reflexxes Motion Library end terminating
198  // the process
199 
200  delete RML ;
201  delete IP ;
202  delete OP ;
203 
204  exit(EXIT_SUCCESS) ;
205 }
Header file for the class ReflexxesAPI (API of the Reflexxes Motion Libraries)
RMLDoubleVector * NewAccelerationVector
A pointer to the new acceleration vector .
Data structure containing flags to parameterize the execution of the velocity-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 RMLVelocityInputParameters.
Header file for the class RMLVelocityFlags.
unsigned char SynchronizationBehavior
This value specifies the desired synchronization behavior.
Definition: RMLFlags.h:192
RMLBoolVector * SelectionVector
A pointer to the selection vector .
Header file for the class RMLVelocityOutputParameters.
Class for the output parameters of the velocity-based On-Line Trajectory Generation algorithm...
#define CYCLE_TIME_IN_SECONDS
int RMLVelocity(const RMLVelocityInputParameters &InputValues, RMLVelocityOutputParameters *OutputValues, const RMLVelocityFlags &Flags)
This is the method for velocity-based On-Line Trajectory Generation.
Even if it is possible to calculate a phase-synchronized trajectory, only a time-synchronized traject...
Definition: RMLFlags.h:152
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 .
RMLDoubleVector * NewVelocityVector
A pointer to the new velocity vector .
Class for the input parameters of the velocity-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