Cheetah Software  1.0
test_footswing.cpp
Go to the documentation of this file.
2 #include "cppTypes.h"
3 #include "Math/MathUtilities.h"
4 #include "gmock/gmock.h"
5 #include "gtest/gtest.h"
6 
7 
8 TEST(FootSwing, fstest) {
10  Vec3<double> p0(1,1,1);
11  traj.setInitialPosition(p0);
12  Vec3<double> pf(2,2,1.2);
13  traj.setFinalPosition(pf);
14  traj.setHeight(1);
15 
16  // initial
17  traj.computeSwingTrajectoryBezier(0, 0.5);
18  EXPECT_TRUE(almostEqual(p0, traj.getPosition(), 0.001));
19 
20  // midpoint
21  traj.computeSwingTrajectoryBezier(0.5, 0.5);
22  Vec3<double> pMid = (p0 + pf)/2;
23  pMid[2] = 2;
24  EXPECT_TRUE(almostEqual(pMid, traj.getPosition(), 0.0001));
25 
26  // final
27  traj.computeSwingTrajectoryBezier(1, 0.5);
28  EXPECT_TRUE(almostEqual(pf, traj.getPosition(), 0.00001));
29 
30 
31 
32 
33 }
34 
35 TEST(FootSwing, fsderiv) {
37  Vec3<double> _p0(1,1,1);
38  traj.setInitialPosition(_p0);
39  Vec3<double> pf(2,2,1.2);
40  traj.setFinalPosition(pf);
41  traj.setHeight(1);
42 
43 
44  // velocity/acceleration:
45  double phasePerSecond = 2.; // 0.5 second swing.
46  double t0 = 0.27;
47  double dt = 0.001;
48  double t1 = t0 + dt;
49  double ph0 = t0 * phasePerSecond;
50  double ph1 = t1 * phasePerSecond;
51 
52  traj.computeSwingTrajectoryBezier(ph0, 0.5);
53  auto p0 = traj.getPosition();
54  auto v0 = traj.getVelocity();
55  auto a0 = traj.getAcceleration();
56 
57 
58  traj.computeSwingTrajectoryBezier(ph1, 0.5);
59  auto p1 = traj.getPosition();
60  auto v1 = traj.getVelocity();
61  auto a1 = traj.getAcceleration();
62 
63  Vec3<double> vdiff = (p1 - p0) / dt;
64  Vec3<double> vref = (v0 + v1) / 2;
65  Vec3<double> adiff = (v1 - v0) / dt;
66  Vec3<double> aref = (a0 + a1) / 2;
67 
68  EXPECT_TRUE(almostEqual(adiff, aref, 0.001));
69  EXPECT_TRUE(almostEqual(vdiff, vref, 0.001));
70 }
void setInitialPosition(Vec3< T > p0)
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
void computeSwingTrajectoryBezier(T phase, T swingTime)
Utility functions for math.
TEST(FootSwing, fstest)
void setFinalPosition(Vec3< T > pf)