test_cart.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>
41 
42 TEST(CartTest, CartKinematics)
43 {
44  const auto wheel_radius = 0.033;
45  const auto wheel_base = 0.08;
46  const ergodic_exploration::models::Cart cart(wheel_radius, wheel_base);
47 
48  const arma::vec x = { 1.0, 2.0, 0.707 };
49  const arma::vec u = { 0.1, 0.2 };
50  const arma::vec xdot = cart(x, u);
51 
52  ASSERT_NEAR(xdot(0), 0.003763, 1e-6);
53  ASSERT_NEAR(xdot(1), 0.003215, 1e-6);
54  ASSERT_NEAR(xdot(2), 0.020625, 1e-6);
55 }
56 
57 TEST(CartTest, CartJacobianState)
58 {
59  const auto wheel_radius = 0.033;
60  const auto wheel_base = 0.08;
61  const ergodic_exploration::models::Cart cart(wheel_radius, wheel_base);
62 
63  const arma::vec x = { 1.0, 2.0, 0.707 };
64  const arma::vec u = { 0.1, 0.2 };
65  const arma::mat A = cart.fdx(x, u);
66 
67  ASSERT_NEAR(A(0, 2), -0.003215, 1e-6);
68  ASSERT_NEAR(A(1, 2), 0.003763, 1e-6);
69 }
70 
71 TEST(CartTest, CartJacobianControl)
72 {
73  const auto wheel_radius = 0.033;
74  const auto wheel_base = 0.08;
75  const ergodic_exploration::models::Cart cart(wheel_radius, wheel_base);
76 
77  const arma::vec x = { 1.0, 2.0, 0.707 };
78  const arma::mat B = cart.fdu(x);
79 
80  ASSERT_NEAR(B(0, 0), 0.012545, 1e-6);
81  ASSERT_NEAR(B(0, 1), 0.012545, 1e-6);
82 
83  ASSERT_NEAR(B(1, 0), 0.010717, 1e-6);
84  ASSERT_NEAR(B(1, 1), 0.010717, 1e-6);
85 
86  ASSERT_NEAR(B(2, 0), -0.20625, 1e-6);
87  ASSERT_NEAR(B(2, 1), 0.20625, 1e-6);
88 }
89 
90 TEST(CartTest, CartWheels2TwistStraight)
91 {
92  const auto wheel_radius = 0.033;
93  const auto wheel_base = 0.08;
94  const ergodic_exploration::models::Cart cart(wheel_radius, wheel_base);
95 
96  const arma::vec u = { 1.0, 1.0 };
97  const arma::vec vb = cart.wheels2Twist(u);
98 
99  ASSERT_NEAR(vb(0), 0.033, 1e-6);
100  ASSERT_NEAR(vb(1), 0.0, 1e-6);
101  ASSERT_NEAR(vb(2), 0.0, 1e-6);
102 }
103 
104 TEST(CartTest, CartWheels2LeftTurn)
105 {
106  const auto wheel_radius = 0.033;
107  const auto wheel_base = 0.08;
108  const ergodic_exploration::models::Cart cart(wheel_radius, wheel_base);
109 
110  const arma::vec u = { -1.0, 1.0 };
111  const arma::vec vb = cart.wheels2Twist(u);
112 
113  ASSERT_NEAR(vb(0), 0.0, 1e-6);
114  ASSERT_NEAR(vb(1), 0.0, 1e-6);
115  ASSERT_NEAR(vb(2), 0.4125, 1e-6);
116 }
117 
118 TEST(CartTest, CartWheels2RightTurn)
119 {
120  const auto wheel_radius = 0.033;
121  const auto wheel_base = 0.08;
122  const ergodic_exploration::models::Cart cart(wheel_radius, wheel_base);
123 
124  const arma::vec u = { 1.0, -1.0 };
125  const arma::vec vb = cart.wheels2Twist(u);
126 
127  ASSERT_NEAR(vb(0), 0.0, 1e-6);
128  ASSERT_NEAR(vb(1), 0.0, 1e-6);
129  ASSERT_NEAR(vb(2), -0.4125, 1e-6);
130 }
131 
132 TEST(CartTest, SimpleCartKinematics)
133 {
135 
136  const arma::vec x = { 1.0, 2.0, 0.707 };
137  const arma::vec u = { 0.5, 0.0, 0.01 };
138  const arma::vec xdot = cart(x, u);
139 
140  ASSERT_NEAR(xdot(0), 0.380156, 1e-6);
141  ASSERT_NEAR(xdot(1), 0.324777, 1e-6);
142  ASSERT_NEAR(xdot(2), 0.01, 1e-6);
143 }
144 
145 TEST(CartTest, SimpleCartJacobianState)
146 {
148 
149  const arma::vec x = { 1.0, 2.0, 0.707 };
150  const arma::vec u = { 0.5, 0.0, 0.01 };
151  const arma::mat A = cart.fdx(x, u);
152 
153  ASSERT_NEAR(A(0, 2), -0.324777, 1e-6);
154  ASSERT_NEAR(A(1, 2), 0.380156, 1e-6);
155 }
156 
157 TEST(CartTest, SimpleCartJacobianControl)
158 {
160 
161  const arma::vec x = { 1.0, 2.0, 0.707 };
162  const arma::vec u = { 0.5, 0.01 };
163  const arma::mat B = cart.fdu(x);
164 
165  ASSERT_NEAR(B(0, 0), 0.760313, 1e-6);
166  ASSERT_NEAR(B(1, 0), 0.649555, 1e-6);
167 }
TEST
TEST(CartTest, CartKinematics)
Definition: test_cart.cpp:42
ergodic_exploration::models::Cart::fdx
mat fdx(const vec x, const vec u) const
Jacobian of the model with respect to the state.
Definition: cart.hpp:108
cart.hpp
Kinematic cart models control wheel velocities or body twist.
ergodic_exploration::models::Cart::fdu
mat fdu(const vec x) const
Jacobian of the model with respect to the control.
Definition: cart.hpp:126
A
ergodic_exploration::models::Cart
Kinematic model of 2 wheel differential drive robot.
Definition: cart.hpp:60
ergodic_exploration::models::Cart::wheels2Twist
vec wheels2Twist(const vec u) const
Convert wheel velocities to a body frame twist.
Definition: cart.hpp:78
ergodic_exploration::models::SimpleCart
Kinematic model of a wheeled differential drive robot.
Definition: cart.hpp:152
ergodic_exploration::models::SimpleCart::fdu
mat fdu(const vec x) const
Jacobian of the model with respect to the control.
Definition: cart.hpp:194
ergodic_exploration::models::SimpleCart::fdx
mat fdx(const vec x, const vec u) const
Jacobian of the model with respect to the state.
Definition: cart.hpp:181


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