Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include <fstream>
00013 #include <iostream>
00014 #include <string>
00015 #include <gtest/gtest.h>
00016 #include <ecl/containers/array.hpp>
00017 #include <ecl/formatters/floats.hpp>
00018 #include <ecl/formatters/strings.hpp>
00019 #include <ecl/geometry/polynomial.hpp>
00020 #include <ecl/geometry/spline_function.hpp>
00021 #include "../../include/ecl/manipulators/waypoint.hpp"
00022 #include "../../include/ecl/manipulators/trajectory.hpp"
00023
00024
00025
00026
00027
00028
00029 using std::cout;
00030 using std::endl;
00031 using std::string;
00032 using ecl::Array;
00033 using ecl::RightAlign;
00034 using ecl::Format;
00035 using ecl::CubicPolynomial;
00036 using ecl::GenericSplineFunction;
00037 using ecl::SplineFunction;
00038 using ecl::JointAngles;
00039 using ecl::Trajectory;
00040 using ecl::WayPoint;
00041
00042
00043
00044
00045
00046 TEST(TrajectoryTests,allEggsInOneBasket) {
00047
00048 SUCCEED();
00049 }
00050
00051
00052
00053
00054
00055 int main(int argc, char **argv) {
00056
00057 Format<string> string_format; string_format.width(8); string_format.align(RightAlign);
00058 Format<double> format; format.width(8); format.precision(2); format.align(RightAlign);
00059 int n = 200;
00060
00061 std::ofstream tension_file_output, linear_file_output;
00062 tension_file_output.open("tension_interpolation.dat");
00063 linear_file_output.open("linear_interpolation.dat");
00064 tension_file_output << "# Created by trajectories_output_to_file test." << endl;
00065 tension_file_output << "# name: tension_interpolation" << endl;
00066 tension_file_output << "# type: matrix" << endl;
00067 tension_file_output << "# rows: " << (n + 1) * 3 << endl;
00068 tension_file_output << "# columns: " << 1 + 2 * 3 << endl;
00069 tension_file_output << endl;
00070 linear_file_output << "# Created by trajectories_output_to_file test." << endl;
00071 linear_file_output << "# name: linear_interpolation" << endl;
00072 linear_file_output << "# type: matrix" << endl;
00073 linear_file_output << "# rows: " << (n + 1) * 3 << endl;
00074 linear_file_output << "# columns: " << 1 + 2 * 3 << endl;
00075 linear_file_output << endl;
00076
00077 std::cout << std::endl;
00078 std::cout << "***********************************************************" << std::endl;
00079 std::cout << " Constructor" << std::endl;
00080 std::cout << "***********************************************************" << std::endl;
00081 std::cout << std::endl;
00082
00083 Trajectory<JointAngles> trajectory(2,"Crash Test Dummy");
00084
00085
00086
00087
00088 WayPoint<JointAngles> initial_waypoint(2), waypoint(2), final_waypoint(2);
00089
00090 initial_waypoint.name("Initial Position");
00091 initial_waypoint.angles() << 1.0, 1.0;
00092 initial_waypoint.rates() << 0.0, 2.0;
00093 initial_waypoint.nominalRates(0.5);
00094 trajectory.append(initial_waypoint);
00095
00096 waypoint.name("Second Waypoint");
00097 waypoint.angles() << 2.0, 0.0;
00098 waypoint.nominalRates(1.0);
00099 trajectory.append(waypoint);
00100
00101 waypoint.name("Mid Waypoint");
00102 waypoint.angles() << 1.0, 5.0;
00103 waypoint.nominalRates(1.2);
00104 trajectory.append(waypoint);
00105
00106 waypoint.name("Fourth Waypoint");
00107 waypoint.angles() << 3.0, 3.0;
00108 waypoint.nominalRates(0.5);
00109 trajectory.append(waypoint);
00110
00111 final_waypoint.name("End Position");
00112 final_waypoint.angles() << 4.0, 2.0;
00113 final_waypoint.nominalRates(0.5);
00114 final_waypoint.rates() << 0.0, 1.0;
00115 trajectory.append(final_waypoint);
00116
00117 std::cout << trajectory << std::endl;
00118
00119 trajectory.maxAccelerations(5);
00120
00121 std::cout << std::endl;
00122 std::cout << "***********************************************************" << std::endl;
00123 std::cout << " Tension Spline Interpolation" << std::endl;
00124 std::cout << "***********************************************************" << std::endl;
00125 std::cout << std::endl;
00126
00127 trajectory.tensionSplineInterpolation(4.0);
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 for ( int i = 0; i <= n; ++i ) {
00138 double x;
00139 if ( i != n ) {
00140 x = i*(trajectory.duration())/n;
00141 } else {
00142 x = trajectory.duration();
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 tension_file_output << format(x);
00154 tension_file_output << format(trajectory(0,x));
00155 tension_file_output << format(trajectory.derivative(0,x));
00156 tension_file_output << format(trajectory.dderivative(0,x));
00157 tension_file_output << format(trajectory(1,x));
00158 tension_file_output << format(trajectory.derivative(1,x));
00159 tension_file_output << format(trajectory.dderivative(1,x));
00160 tension_file_output << endl;
00161 }
00162
00163
00164 std::cout << std::endl;
00165 std::cout << "***********************************************************" << std::endl;
00166 std::cout << " Smooth Linear Spline Interpolation" << std::endl;
00167 std::cout << "***********************************************************" << std::endl;
00168 std::cout << std::endl;
00169
00170 trajectory.maxAccelerations(5);
00171 trajectory.linearSplineInterpolation();
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 for ( int i = 0; i <= n; ++i ) {
00182 double x;
00183 if ( i != n ) {
00184 x = i*(trajectory.duration())/n;
00185 } else {
00186 x = trajectory.duration();
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 linear_file_output << format(x);
00198 linear_file_output << format(trajectory(0,x));
00199 linear_file_output << format(trajectory.derivative(0,x));
00200 linear_file_output << format(trajectory.dderivative(0,x));
00201 linear_file_output << format(trajectory(1,x));
00202 linear_file_output << format(trajectory.derivative(1,x));
00203 linear_file_output << format(trajectory.dderivative(1,x));
00204 linear_file_output << endl;
00205 }
00206
00207
00208 std::cout << std::endl;
00209 std::cout << "***********************************************************" << std::endl;
00210 std::cout << " Passed" << std::endl;
00211 std::cout << "***********************************************************" << std::endl;
00212 std::cout << std::endl;
00213
00214 tension_file_output.close();
00215 linear_file_output.close();
00216 std::cout << "Trajectories written to files 'linear_interpolation.dat', 'tension_interpolation.dat'." << std::endl;
00217
00218 testing::InitGoogleTest(&argc,argv);
00219 return RUN_ALL_TESTS();
00220 }
00221