trajectories.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <fstream>
13 #include <iostream>
14 #include <string>
15 #include <gtest/gtest.h>
16 #include <ecl/containers/array.hpp>
21 #include "../../include/ecl/manipulators/waypoint.hpp"
22 #include "../../include/ecl/manipulators/trajectory.hpp"
23 
24 
25 /*****************************************************************************
26 ** Using
27 *****************************************************************************/
28 
29 using std::cout;
30 using std::endl;
31 using std::string;
32 using ecl::Array;
33 using ecl::RightAlign;
34 using ecl::Format;
38 using ecl::JointAngles;
39 using ecl::Trajectory;
40 using ecl::WayPoint;
41 
42 /*****************************************************************************
43 ** Tests
44 *****************************************************************************/
45 
46 TEST(TrajectoryTests,allEggsInOneBasket) {
47  // Haven't got around to running this properly through gtests yet.
48  SUCCEED();
49 }
50 
51 /*****************************************************************************
52 ** Main program
53 *****************************************************************************/
54 
55 int main(int argc, char **argv) {
56 
57  Format<string> string_format; string_format.width(8); string_format.align(RightAlign);
58  Format<double> format; format.width(8); format.precision(2); format.align(RightAlign);
59  int n = 200;
60 
61  std::ofstream tension_file_output, linear_file_output;
62  tension_file_output.open("tension_interpolation.dat");
63  linear_file_output.open("linear_interpolation.dat");
64  tension_file_output << "# Created by trajectories_output_to_file test." << endl;
65  tension_file_output << "# name: tension_interpolation" << endl;
66  tension_file_output << "# type: matrix" << endl;
67  tension_file_output << "# rows: " << (n + 1) * 3 << endl;
68  tension_file_output << "# columns: " << 1 + 2 * 3 << endl;
69  tension_file_output << endl;
70  linear_file_output << "# Created by trajectories_output_to_file test." << endl;
71  linear_file_output << "# name: linear_interpolation" << endl;
72  linear_file_output << "# type: matrix" << endl;
73  linear_file_output << "# rows: " << (n + 1) * 3 << endl;
74  linear_file_output << "# columns: " << 1 + 2 * 3 << endl;
75  linear_file_output << endl;
76 
77  std::cout << std::endl;
78  std::cout << "***********************************************************" << std::endl;
79  std::cout << " Constructor" << std::endl;
80  std::cout << "***********************************************************" << std::endl;
81  std::cout << std::endl;
82 
83  Trajectory<JointAngles> trajectory(2,"Crash Test Dummy");
84 
85  /******************************************
86  ** Common Waypoint Parameters
87  *******************************************/
88  WayPoint<JointAngles> initial_waypoint(2), waypoint(2), final_waypoint(2);
89 
90  initial_waypoint.name("Initial Position");
91  initial_waypoint.angles() << 1.0, 1.0;
92  initial_waypoint.rates() << 0.0, 2.0;
93  initial_waypoint.nominalRates(0.5);
94  trajectory.append(initial_waypoint);
95 
96  waypoint.name("Second Waypoint");
97  waypoint.angles() << 2.0, 0.0;
98  waypoint.nominalRates(1.0);
99  trajectory.append(waypoint);
100 
101  waypoint.name("Mid Waypoint");
102  waypoint.angles() << 1.0, 5.0;
103  waypoint.nominalRates(1.2);
104  trajectory.append(waypoint);
105 
106  waypoint.name("Fourth Waypoint");
107  waypoint.angles() << 3.0, 3.0;
108  waypoint.nominalRates(0.5);
109  trajectory.append(waypoint);
110 
111  final_waypoint.name("End Position");
112  final_waypoint.angles() << 4.0, 2.0;
113  final_waypoint.nominalRates(0.5);
114  final_waypoint.rates() << 0.0, 1.0;
115  trajectory.append(final_waypoint);
116 
117  std::cout << trajectory << std::endl;
118 
119  trajectory.maxAccelerations(5);
120 
121  std::cout << std::endl;
122  std::cout << "***********************************************************" << std::endl;
123  std::cout << " Tension Spline Interpolation" << std::endl;
124  std::cout << "***********************************************************" << std::endl;
125  std::cout << std::endl;
126 
127  trajectory.tensionSplineInterpolation(4.0); // Tension arg
128 
129 // cout << string_format("t ");
130 // cout << string_format("y ");
131 // cout << string_format("y' ");
132 // cout << string_format("y''");
133 // cout << string_format("y ");
134 // cout << string_format("y' ");
135 // cout << string_format("y''");
136 // cout << endl;
137  for ( int i = 0; i <= n; ++i ) {
138  double x;
139  if ( i != n ) {
140  x = i*(trajectory.duration())/n;
141  } else {
142  x = trajectory.duration();
143  }
144 // cout << format(x);
145 // cout << format(trajectory(0,x));
146 // cout << format(trajectory.derivative(0,x));
147 // cout << format(trajectory.dderivative(0,x));
148 // cout << format(trajectory(1,x));
149 // cout << format(trajectory.derivative(1,x));
150 // cout << format(trajectory.dderivative(1,x));
151 // cout << endl;
152 
153  tension_file_output << format(x);
154  tension_file_output << format(trajectory(0,x));
155  tension_file_output << format(trajectory.derivative(0,x));
156  tension_file_output << format(trajectory.dderivative(0,x));
157  tension_file_output << format(trajectory(1,x));
158  tension_file_output << format(trajectory.derivative(1,x));
159  tension_file_output << format(trajectory.dderivative(1,x));
160  tension_file_output << endl;
161  }
162 
163 
164  std::cout << std::endl;
165  std::cout << "***********************************************************" << std::endl;
166  std::cout << " Smooth Linear Spline Interpolation" << std::endl;
167  std::cout << "***********************************************************" << std::endl;
168  std::cout << std::endl;
169 
170  trajectory.maxAccelerations(5);
171  trajectory.linearSplineInterpolation();
172 
173 // cout << string_format("t ");
174 // cout << string_format("y ");
175 // cout << string_format("y' ");
176 // cout << string_format("y''");
177 // cout << string_format("y ");
178 // cout << string_format("y' ");
179 // cout << string_format("y''");
180 // cout << endl;
181  for ( int i = 0; i <= n; ++i ) {
182  double x;
183  if ( i != n ) {
184  x = i*(trajectory.duration())/n;
185  } else {
186  x = trajectory.duration();
187  }
188 // cout << format(x);
189 // cout << format(trajectory(0,x));
190 // cout << format(trajectory.derivative(0,x));
191 // cout << format(trajectory.dderivative(0,x));
192 // cout << format(trajectory(1,x));
193 // cout << format(trajectory.derivative(1,x));
194 // cout << format(trajectory.dderivative(1,x));
195 // cout << endl;
196 
197  linear_file_output << format(x);
198  linear_file_output << format(trajectory(0,x));
199  linear_file_output << format(trajectory.derivative(0,x));
200  linear_file_output << format(trajectory.dderivative(0,x));
201  linear_file_output << format(trajectory(1,x));
202  linear_file_output << format(trajectory.derivative(1,x));
203  linear_file_output << format(trajectory.dderivative(1,x));
204  linear_file_output << endl;
205  }
206 
207 
208  std::cout << std::endl;
209  std::cout << "***********************************************************" << std::endl;
210  std::cout << " Passed" << std::endl;
211  std::cout << "***********************************************************" << std::endl;
212  std::cout << std::endl;
213 
214  tension_file_output.close();
215  linear_file_output.close();
216  std::cout << "Trajectories written to files 'linear_interpolation.dat', 'tension_interpolation.dat'." << std::endl;
217 
218  testing::InitGoogleTest(&argc,argv);
219  return RUN_ALL_TESTS();
220 }
221 
Primary template for waypoints.
Definition: waypoint.hpp:46
int main(int argc, char **argv)
TEST(TrajectoryTests, allEggsInOneBasket)
RightAlign
Primary template for manipulator trajectories.
Definition: trajectory.hpp:57
Joint angle representations are being used.
Definition: types.hpp:33
Polynomial< 3 > CubicPolynomial


ecl_manipulators
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:09:10