test_integrator.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2020 Northwestern University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *********************************************************************/
39 #include <gtest/gtest.h>
43 
44 TEST(IntegratorTest, RungeKutta)
45 {
46  const ergodic_exploration::models::Cart cart(0.1, 2.0);
47  const auto horizon = 0.4;
48  const auto dt = 0.1;
49  const auto N = static_cast<unsigned int>(horizon / dt);
50  arma::mat ut(2, N);
51  ut.row(0).fill(1.0);
52  ut.row(1).fill(1.0);
53 
54  const arma::vec x0 = { 0.0, 0.0, 0.0 };
55  const ergodic_exploration::RungeKutta rk4(0.1);
56  const arma::mat xt = rk4.solve(cart, x0, ut, horizon);
57 
58  // Expected to drive in straight line along the x-axis
59  ASSERT_DOUBLE_EQ(xt(0, 0), 0.01);
60  ASSERT_DOUBLE_EQ(xt(0, 1), 0.02);
61  ASSERT_DOUBLE_EQ(xt(0, 2), 0.03);
62  ASSERT_DOUBLE_EQ(xt(0, 3), 0.04);
63 
64  ASSERT_DOUBLE_EQ(xt(1, 0), 0.0);
65  ASSERT_DOUBLE_EQ(xt(1, 1), 0.0);
66  ASSERT_DOUBLE_EQ(xt(1, 2), 0.0);
67  ASSERT_DOUBLE_EQ(xt(1, 3), 0.0);
68 
69  ASSERT_DOUBLE_EQ(xt(2, 0), 0.0);
70  ASSERT_DOUBLE_EQ(xt(2, 1), 0.0);
71  ASSERT_DOUBLE_EQ(xt(2, 2), 0.0);
72  ASSERT_DOUBLE_EQ(xt(2, 3), 0.0);
73 }
74 
75 TEST(IntegratorTest, OmniPoseChange)
76 {
77  const auto dt = 0.1;
78  const arma::vec vb = { 1.0, 0.5, 0.5 };
79  const arma::vec x0(3, arma::fill::zeros);
80 
82  const ergodic_exploration::RungeKutta rk4(dt);
83 
84  const arma::vec pose = ergodic_exploration::integrate_twist(x0, vb, dt);
85  // pose.print("integrate twist");
86  //
87  // const arma::vec pose2 = rk4.step(omni, x0, vb);
88  // pose2.print("rk4");
89 
90  ASSERT_NEAR(pose(0), 0.0987, 1e-4);
91  ASSERT_NEAR(pose(1), 0.0525, 1e-4);
92  ASSERT_NEAR(pose(2), 0.0500, 1e-4);
93 }
94 
95 TEST(IntegratorTest, OmniTrajectory)
96 {
97  const auto horizon = 0.5;
98  const auto dt = 0.1;
99  const auto steps = static_cast<unsigned int>(horizon / dt);
100  const arma::vec vb = { 1.0, 0.5, 0.5 };
101  const arma::vec x0 = { 1.0, 0.0, 0.0 };
102 
104  const ergodic_exploration::RungeKutta rk4(dt);
105 
106  arma::mat traj(3, steps, arma::fill::zeros);
107  arma::vec x = x0;
108 
109  for (unsigned int i = 0; i < steps; i++)
110  {
112  traj.col(i) = x;
113  }
114 
115  // arma::mat ut(3, steps);
116  // ut.row(0).fill(vb(0));
117  // ut.row(1).fill(vb(1));
118  // ut.row(2).fill(vb(2));
119  //
120  // arma::mat traj2 = rk4.solve(omni, x0, ut, horizon);
121  //
122  // traj.print("integrate twist");
123  // traj2.print("rk4");
124 
125  ASSERT_NEAR(traj(0, 0), 1.0987, 1e-4);
126  ASSERT_NEAR(traj(0, 1), 1.1947, 1e-4);
127  ASSERT_NEAR(traj(0, 2), 1.2876, 1e-4);
128  ASSERT_NEAR(traj(0, 3), 1.3774, 1e-4);
129  ASSERT_NEAR(traj(0, 4), 1.4637, 1e-4);
130 
131  ASSERT_NEAR(traj(1, 0), 0.0525, 1e-4);
132  ASSERT_NEAR(traj(1, 1), 0.1098, 1e-4);
133  ASSERT_NEAR(traj(1, 2), 0.1719, 1e-4);
134  ASSERT_NEAR(traj(1, 3), 0.2385, 1e-4);
135  ASSERT_NEAR(traj(1, 4), 0.3096, 1e-4);
136 
137  ASSERT_NEAR(traj(2, 0), 0.0500, 1e-4);
138  ASSERT_NEAR(traj(2, 1), 0.1000, 1e-4);
139  ASSERT_NEAR(traj(2, 2), 0.1500, 1e-4);
140  ASSERT_NEAR(traj(2, 3), 0.2000, 1e-4);
141  ASSERT_NEAR(traj(2, 4), 0.2500, 1e-4);
142 }
ergodic_exploration::RungeKutta::solve
mat solve(const ModelT &model, const vec &x0, const mat &ut, double horizon) const
Simulate the dynamics forward in time.
Definition: integrator.hpp:136
integrator.hpp
Numerical integration methods.
cart.hpp
Kinematic cart models control wheel velocities or body twist.
ergodic_exploration::integrate_twist
vec integrate_twist(const vec &x, const vec &u, double dt)
Integrate a constant twist.
Definition: numerics.hpp:273
ergodic_exploration::models::Cart
Kinematic model of 2 wheel differential drive robot.
Definition: cart.hpp:60
omni.hpp
Kinematic omni directional models control wheel velocities or body twist.
ergodic_exploration::RungeKutta
4th order Runge-Kutta integration
Definition: integrator.hpp:63
ergodic_exploration::models::Omni
Kinematic model of omni directonal robot.
Definition: omni.hpp:164
TEST
TEST(IntegratorTest, RungeKutta)
Definition: test_integrator.cpp:44


ergodic_exploration
Author(s): bostoncleek
autogenerated on Wed Mar 2 2022 00:17:13