cart.hpp
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  *********************************************************************/
38 #ifndef CART_HPP
39 #define CART_HPP
40 
41 #include <cmath>
42 #include <stdexcept>
43 
44 #include <armadillo>
45 
47 
48 namespace ergodic_exploration
49 {
50 namespace models
51 {
52 using arma::mat;
53 using arma::vec;
54 
60 struct Cart
61 {
68  Cart(double wheel_radius, double wheel_base)
70  {
71  }
72 
78  vec wheels2Twist(const vec u) const
79  {
80  const double vx = wheel_radius / 2.0 * (u(0) + u(1));
81  const double w = wheel_radius / (2.0 * wheel_base) * (u(1) - u(0));
82 
83  return { vx, 0.0, w };
84  }
85 
92  vec operator()(const vec x, const vec u) const
93  {
94  vec xdot(3);
95  xdot(0) = (u(0) + u(1)) * std::cos(x(2));
96  xdot(1) = (u(0) + u(1)) * std::sin(x(2));
97  xdot(2) = (u(1) - u(0)) / wheel_base;
98 
99  return (wheel_radius / 2.0) * xdot;
100  }
101 
108  mat fdx(const vec x, const vec u) const
109  {
110  mat A(3, 3, arma::fill::zeros);
111 
112  const auto df0dth = -(wheel_radius / 2.0) * (u(0) + u(1)) * std::sin(x(2));
113  const auto df1dth = (wheel_radius / 2.0) * (u(0) + u(1)) * std::cos(x(2));
114 
115  A(0, 2) = df0dth;
116  A(1, 2) = df1dth;
117 
118  return A;
119  }
120 
126  mat fdu(const vec x) const
127  {
128  mat B(3, 2);
129 
130  B(0, 0) = std::cos(x(2));
131  B(0, 1) = std::cos(x(2));
132 
133  B(1, 0) = std::sin(x(2));
134  B(1, 1) = std::sin(x(2));
135 
136  B(2, 0) = -1.0 / wheel_base;
137  B(2, 1) = 1.0 / wheel_base;
138 
139  return (wheel_radius / 2.0) * B;
140  }
141 
142  double wheel_radius; // radius of wheel
143  double wheel_base; // distance from robot center to wheel center
144  unsigned int state_space; // states space dimension
145 };
146 
153 {
156  {
157  }
158 
165  vec operator()(const vec x, const vec u) const
166  {
167  if (!almost_equal(u(1), 0.0))
168  {
169  throw std::invalid_argument("Invalid twist y-velocity must be 0.");
170  }
171 
172  return { u(0) * std::cos(x(2)), u(0) * std::sin(x(2)), u(2) };
173  }
174 
181  mat fdx(const vec x, const vec u) const
182  {
183  mat A(3, 3, arma::fill::zeros);
184  A(0, 2) = -u(0) * std::sin(x(2));
185  A(1, 2) = u(0) * std::cos(x(2));
186  return A;
187  }
188 
194  mat fdu(const vec x) const
195  {
196  mat B(3, 3, arma::fill::zeros);
197 
198  B(0, 0) = std::cos(x(2));
199  B(1, 0) = std::sin(x(2));
200  B(2, 2) = 1.0;
201 
202  return B;
203  }
204 
205  unsigned int state_space; // states space dimension
206 };
207 } // namespace models
208 } // namespace ergodic_exploration
209 #endif
ergodic_exploration::models::Cart::state_space
unsigned int state_space
Definition: cart.hpp:144
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
ergodic_exploration::models::Cart::Cart
Cart(double wheel_radius, double wheel_base)
Constructor.
Definition: cart.hpp:68
ergodic_exploration::models::Cart::fdu
mat fdu(const vec x) const
Jacobian of the model with respect to the control.
Definition: cart.hpp:126
ergodic_exploration::models::Cart::wheel_base
double wheel_base
Definition: cart.hpp:143
A
ergodic_exploration
Definition: basis.hpp:43
ergodic_exploration::models::SimpleCart::state_space
unsigned int state_space
Definition: cart.hpp:205
ergodic_exploration::models::Cart
Kinematic model of 2 wheel differential drive robot.
Definition: cart.hpp:60
ergodic_exploration::almost_equal
bool almost_equal(double d1, double d2, double epsilon=1.0e-12)
approximately compare two floating-point numbers
Definition: numerics.hpp:67
numerics.hpp
Useful numerical utilities.
ergodic_exploration::models::Cart::operator()
vec operator()(const vec x, const vec u) const
Kinematic model of a 2 wheel differential drive robot.
Definition: cart.hpp:92
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::models::SimpleCart::operator()
vec operator()(const vec x, const vec u) const
Kinematic model of a 2 wheel differential drive robot.
Definition: cart.hpp:165
ergodic_exploration::models::Cart::wheel_radius
double wheel_radius
Definition: cart.hpp:142
ergodic_exploration::models::SimpleCart::SimpleCart
SimpleCart()
Constructor.
Definition: cart.hpp:155


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