1 #include "gmock/gmock.h" 2 #include "gtest/gtest.h" 9 #include <Configuration.h> 10 #include "../user/WBC_Controller/WBC_States/Bounding/CtrlSet/ImpulseCurve.hpp" 15 TEST(Spline, BezierCurve_test) {
16 constexpr
int dim = 3;
17 constexpr
int num_ctrl_pt = 4;
20 double** ctrl_pt =
new double*[num_ctrl_pt];
22 for (
int i(0); i < 4; ++i) {
23 ctrl_pt[i] =
new double[dim];
34 ctrl_pt[1][2] = ctrl_pt[0][2] + gap * 0.3;
39 ctrl_pt[2][2] = ctrl_pt[1][2] + gap * 0.6;
44 ctrl_pt[3][2] = ctrl_pt[2][2] + gap * 1.0;
50 double curve_vel[dim];
55 for (
size_t i(0); i < dim; ++i) ctrl_pt[0][i] = curve_pt[i];
57 ctrl_pt[1][2] = ctrl_pt[0][2] + gap;
58 ctrl_pt[2][2] = ctrl_pt[1][2] + gap * 1.3;
59 ctrl_pt[3][2] = ctrl_pt[2][2] + gap * 1.7;
68 for (
int i(0); i < 1001; ++i) {
83 EXPECT_TRUE(
fpEqual(curve_pt[0], 0., .0001));
84 EXPECT_TRUE(
fpEqual(curve_pt[1], 0.0, .0001));
85 EXPECT_TRUE(
fpEqual(curve_pt[2], 0.4, .0001));
88 EXPECT_TRUE(
fpEqual(curve_pt[0], 4.2, .0001));
89 EXPECT_TRUE(
fpEqual(curve_pt[1], -1.0, .0001));
92 for (
int i(0); i < num_ctrl_pt; ++i) {
98 TEST(Spline, BSpline_test) {
99 constexpr
int dim_bs = 3;
100 constexpr
int degree = 3;
101 constexpr
int num_middle_pt = 3;
102 constexpr
int ini_cstr_level = 2;
103 constexpr
int fin_cstr_level = 2;
105 BS_Basic<double, dim_bs, degree, num_middle_pt, ini_cstr_level,
108 double ini_pt[dim_bs * (degree)];
109 double fin_pt[dim_bs * (degree)];
111 for (
int i(0); i < dim_bs * degree; ++i) {
115 double height_gap = 0.3;
120 double** middle_pt = NULL;
121 if (num_middle_pt > 1) {
122 middle_pt =
new double*[num_middle_pt];
123 for (
int i(0); i < num_middle_pt; ++i) {
124 middle_pt[i] =
new double[dim_bs];
127 middle_pt[0][0] = 0.4;
128 middle_pt[0][1] = -0.7;
129 middle_pt[0][2] = ini_pt[2] + height_gap * 0.25;
132 middle_pt[1][0] = 0.4;
133 middle_pt[1][1] = -0.7;
134 middle_pt[1][2] = ini_pt[2] + height_gap * 0.5;
137 middle_pt[2][0] = 2.5;
138 middle_pt[2][1] = 0.5;
139 middle_pt[2][2] = ini_pt[2] + height_gap * 0.75;
144 fin_pt[2] = ini_pt[2] + height_gap;
155 bs.SetParam(ini_pt, fin_pt, middle_pt, end_time);
157 double curve_pt[dim_bs];
158 double curve_vel[dim_bs];
159 double curve_acc[dim_bs];
160 double curve_d3[dim_bs];
164 bs.getCurvePoint(mid_time, curve_pt);
165 bs.getCurveDerPoint(mid_time, 1, curve_vel);
166 bs.getCurveDerPoint(mid_time, 2, curve_acc);
168 bs.getCurveDerPoint(mid_time, 3, curve_d3);
170 BS_Basic<double, dim_bs, degree, num_middle_pt, ini_cstr_level,
173 double ini_pt2[dim_bs * degree];
174 double fin_pt2[dim_bs * degree];
175 for (
int i(0); i < dim_bs * degree; ++i) {
179 for (
int i(0); i < 3; ++i) {
180 ini_pt2[i] = curve_pt[i];
181 ini_pt2[i + 3] = curve_vel[i];
182 ini_pt2[i + 6] = curve_acc[i];
184 if (degree > 3) ini_pt2[i + 9] = curve_d3[i];
187 double** middle_pt2 = NULL;
188 if (num_middle_pt > 0) {
189 middle_pt2 =
new double*[num_middle_pt];
190 for (
int i(0); i < num_middle_pt; ++i) {
191 middle_pt2[i] =
new double[dim_bs];
194 middle_pt2[0][0] = 0.4;
195 middle_pt2[0][1] = -0.7;
196 middle_pt2[0][2] = ini_pt2[2] + height_gap * 0.25;
199 middle_pt2[1][0] = 0.4;
200 middle_pt2[1][1] = -0.7;
201 middle_pt2[1][2] = ini_pt2[2] + height_gap * 0.5;
204 middle_pt2[2][0] = 2.5;
205 middle_pt2[2][1] = 0.5;
206 middle_pt2[2][2] = ini_pt2[2] + height_gap * 0.75;
212 fin_pt2[2] = ini_pt2[2] + height_gap;
214 bs_2.
SetParam(ini_pt2, fin_pt2, middle_pt2, end_time);
218 for (
int i(0); i < 1001; ++i) {
222 bs.getCurvePoint(t, curve_pt);
223 bs.getCurveDerPoint(t, 1, curve_vel);
224 bs.getCurveDerPoint(t, 2, curve_acc);
226 bs_2.getCurvePoint(t - mid_time, curve_pt);
227 bs_2.getCurveDerPoint(t - mid_time, 1, curve_vel);
228 bs_2.getCurveDerPoint(t - mid_time, 2, curve_acc);
237 bs.getCurvePoint(0., curve_pt);
238 EXPECT_TRUE(
fpEqual(curve_pt[0], 0., .0001));
239 EXPECT_TRUE(
fpEqual(curve_pt[1], 0.0, .0001));
240 EXPECT_TRUE(
fpEqual(curve_pt[2], 0.4, .0001));
242 bs.getCurvePoint(end_time, curve_pt);
243 EXPECT_TRUE(
fpEqual(curve_pt[0], 4.2, .0001));
244 EXPECT_TRUE(
fpEqual(curve_pt[1], -1.0, .0001));
247 bs.getCurveDerPoint(end_time, 2, curve_acc);
248 EXPECT_TRUE(
fpEqual(curve_acc[0], 0., .0001));
249 EXPECT_TRUE(
fpEqual(curve_acc[1], 0.0, .0001));
250 EXPECT_TRUE(
fpEqual(curve_acc[2], 0.0, .0001));
252 for (
int i(0); i < num_middle_pt; ++i) {
253 delete[] middle_pt[i];
258 TEST(Spline, BSpline_1D_test) {
259 constexpr
int dim_bs = 1;
260 constexpr
int degree = 3;
261 constexpr
int num_middle_pt = 3;
262 constexpr
int ini_cstr_level = 2;
263 constexpr
int fin_cstr_level = 2;
265 BS_Basic<double, dim_bs, degree, num_middle_pt, ini_cstr_level,
268 double ini_pt[dim_bs * (degree)];
269 double fin_pt[dim_bs * (degree)];
271 for (
int i(0); i < dim_bs * degree; ++i) {
275 double height_gap = 0.3;
280 double** middle_pt = NULL;
281 if (num_middle_pt > 1) {
282 middle_pt =
new double*[num_middle_pt];
283 for (
int i(0); i < num_middle_pt; ++i) {
284 middle_pt[i] =
new double[dim_bs];
287 middle_pt[0][0] = ini_pt[0] + height_gap * 0.25;
290 middle_pt[1][0] = ini_pt[0] + height_gap * 0.5;
293 middle_pt[2][0] = ini_pt[0] + height_gap * 0.75;
296 fin_pt[0] = ini_pt[0] + height_gap;
299 bs.SetParam(ini_pt, fin_pt, middle_pt, end_time);
301 double curve_pt[dim_bs];
303 double curve_vel[dim_bs];
305 double curve_acc[dim_bs];
311 for (
int i(0); i < 1001; ++i) {
314 bs.getCurvePoint(t, curve_pt);
315 bs.getCurveDerPoint(t, 1, curve_vel);
316 bs.getCurveDerPoint(t, 2, curve_acc);
318 bs_pva[0] = curve_pt[0];
319 bs_pva[1] = curve_vel[0];
320 bs_pva[2] = curve_acc[0];
325 for (
int i(0); i < num_middle_pt; ++i) {
326 delete[] middle_pt[i];
332 ImpulseCurve<double> curve;
334 double apex_value(2.9);
336 curve.setCurve(apex_value, time);
342 for (
int i(-10); i < 501; ++i) {
345 curve_pt = curve.getValue(t);
346 sum += (curve_pt * dt);
350 double integrated_value = 0.7 * apex_value * time;
354 EXPECT_TRUE(
fpEqual(curve.getValue(time / 2.), apex_value, .0001));
355 EXPECT_TRUE(
fpEqual(integrated_value, sum, .0001));
bool fpEqual(T a, T b, T tol)
bool SetParam(T **ctrl_pt, T fin_time)
typename Eigen::Matrix< T, 3, 1 > Vec3
TEST(Spline, BezierCurve_test)
bool getCurvePoint(T u, T *ret)
Timer for measuring how long things take.
bool SetParam(T *init, T *fin, T **middle_pt, T fin_time)
bool getCurveVelocity(T u, T *ret)