01_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 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  RMLPositionInputParameters *IP = NULL ;
77 
78  RMLPositionOutputParameters *OP = NULL ;
79 
80  RMLPositionFlags 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: 01_RMLPositionSampleApplication \n\n");
100  printf("This example demonstrates the most basic use of the \n" );
101  printf("Reflexxes API (class ReflexxesAPI) using the position- \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 RMLPositionInputParameters::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] = 0.0 ;
123  IP->CurrentPositionVector->VecData [2] = 50.0 ;
124 
125  IP->CurrentVelocityVector->VecData [0] = 100.0 ;
126  IP->CurrentVelocityVector->VecData [1] = -220.0 ;
127  IP->CurrentVelocityVector->VecData [2] = -50.0 ;
128 
129  IP->CurrentAccelerationVector->VecData [0] = -150.0 ;
130  IP->CurrentAccelerationVector->VecData [1] = 250.0 ;
131  IP->CurrentAccelerationVector->VecData [2] = -50.0 ;
132 
133  IP->MaxVelocityVector->VecData [0] = 300.0 ;
134  IP->MaxVelocityVector->VecData [1] = 100.0 ;
135  IP->MaxVelocityVector->VecData [2] = 300.0 ;
136 
137  IP->MaxAccelerationVector->VecData [0] = 300.0 ;
138  IP->MaxAccelerationVector->VecData [1] = 200.0 ;
139  IP->MaxAccelerationVector->VecData [2] = 100.0 ;
140 
141  IP->MaxJerkVector->VecData [0] = 400.0 ;
142  IP->MaxJerkVector->VecData [1] = 300.0 ;
143  IP->MaxJerkVector->VecData [2] = 200.0 ;
144 
145  IP->TargetPositionVector->VecData [0] = -600.0 ;
146  IP->TargetPositionVector->VecData [1] = -200.0 ;
147  IP->TargetPositionVector->VecData [2] = -350.0 ;
148 
149  IP->TargetVelocityVector->VecData [0] = 50.0 ;
150  IP->TargetVelocityVector->VecData [1] = -50.0 ;
151  IP->TargetVelocityVector->VecData [2] = -200.0 ;
152 
153  IP->SelectionVector->VecData [0] = true ;
154  IP->SelectionVector->VecData [1] = true ;
155  IP->SelectionVector->VecData [2] = true ;
156 
157  // ********************************************************************
158  // Starting the control loop
159 
160  while (ResultValue != ReflexxesAPI::RML_FINAL_STATE_REACHED)
161  {
162 
163  // ****************************************************************
164  // Wait for the next timer tick
165  // (not implemented in this example in order to keep it simple)
166  // ****************************************************************
167 
168  // Calling the Reflexxes OTG algorithm
169  ResultValue = RML->RMLPosition( *IP
170  , OP
171  , Flags );
172 
173  if (ResultValue < 0)
174  {
175  printf("An error occurred (%d).\n", ResultValue );
176  break;
177  }
178 
179  // ****************************************************************
180  // Here, the new state of motion, that is
181  //
182  // - OP->NewPositionVector
183  // - OP->NewVelocityVector
184  // - OP->NewAccelerationVector
185  //
186  // can be used as input values for lower level controllers. In the
187  // most simple case, a position controller in actuator space is
188  // used, but the computed state can be applied to many other
189  // controllers (e.g., Cartesian impedance controllers,
190  // operational space controllers).
191  // ****************************************************************
192 
193  // ****************************************************************
194  // Feed the output values of the current control cycle back to
195  // input values of the next control cycle
196 
200  }
201 
202  // ********************************************************************
203  // Deleting the objects of the Reflexxes Motion Library end terminating
204  // the process
205 
206  delete RML ;
207  delete IP ;
208  delete OP ;
209 
210  exit(EXIT_SUCCESS) ;
211 }
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 .
#define CYCLE_TIME_IN_SECONDS
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 .
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 .
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