omni.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 OMNI_HPP
39 #define OMNI_HPP
40 
41 #include <cmath>
42 #include <armadillo>
43 
45 
46 namespace ergodic_exploration
47 {
48 namespace models
49 {
50 using arma::mat;
51 using arma::vec;
52 
59 struct Mecanum
60 {
71  , state_space(3)
72  {
73  }
74 
80  vec wheels2Twist(const vec u) const
81  {
82  const auto l = 1.0 / (wheel_base_x + wheel_base_y);
83 
84  // pseudo inverse of jacobian matrix
85  const mat Hp = { { 1.0, 1.0, 1.0, 1.0 }, { -1.0, 1.0, -1.0, 1.0 }, { -l, l, l, -l } };
86 
87  const vec vb = (wheel_radius / 4.0) * Hp * u;
88 
89  return { vb(0), vb(1), vb(2) };
90  }
91 
98  vec operator()(const vec x, const vec u) const
99  {
100  vec xdot(3);
101  const auto s = (wheel_radius / 4.0) * std::sin(x(2));
102  const auto c = (wheel_radius / 4.0) * std::cos(x(2));
103  const auto l = wheel_radius / (4.0 * (wheel_base_x + wheel_base_y));
104 
105  xdot(0) = u(0) * (s + c) + u(1) * (-s + c) + u(2) * (s + c) + u(3) * (-s + c);
106  xdot(1) = u(0) * (s - c) + u(1) * (s + c) + u(2) * (s - c) + u(3) * (s + c);
107  xdot(2) = -u(0) * l + u(1) * l + u(2) * l - u(3) * l;
108 
109  return xdot;
110  }
111 
118  mat fdx(const vec x, const vec u) const
119  {
120  mat A(3, 3, arma::fill::zeros);
121 
122  const auto s = (wheel_radius / 4.0) * std::sin(x(2));
123  const auto c = (wheel_radius / 4.0) * std::cos(x(2));
124 
125  const auto df0dth =
126  u(0) * (-s + c) + u(1) * (-s - c) + u(2) * (-s + c) + u(3) * (-s - c);
127  const auto df1dth =
128  u(0) * (s + c) + u(1) * (-s + c) + u(2) * (s + c) + u(3) * (-s + c);
129 
130  A(0, 2) = df0dth;
131  A(1, 2) = df1dth;
132 
133  return A;
134  }
135 
141  mat fdu(const vec x) const
142  {
143  const auto s = (wheel_radius / 4.0) * std::sin(x(2));
144  const auto c = (wheel_radius / 4.0) * std::cos(x(2));
145  const auto l = wheel_radius / (4.0 * (wheel_base_x + wheel_base_y));
146 
147  const mat B = { { s + c, -s + c, s + c, -s + c },
148  { s - c, s + c, s - c, s + c },
149  { -l, l, l, -l } };
150  return B;
151  }
152 
153  double wheel_radius; // radius of wheel
154  double wheel_base_x; // distance from chassis center to wheel center along x-axis
155  double wheel_base_y; // distance from chassis center to wheel center along y-axis
156  unsigned int state_space; // states space dimension
157 };
158 
164 struct Omni
165 {
168  {
169  }
170 
177  vec operator()(const vec x, const vec u) const
178  {
179  const auto xdot = u(0) * std::cos(x(2)) - u(1) * std::sin(x(2));
180  const auto ydot = u(0) * std::sin(x(2)) + u(1) * std::cos(x(2));
181  return { xdot, ydot, u(2) };
182  // return { xdot, ydot, 0.0 };
183  // return { u(0), u(1), u(2) };
184  }
185 
192  mat fdx(const vec x, const vec u) const
193  {
194  mat A(3, 3, arma::fill::zeros);
195  A(0, 2) = -u(0) * std::sin(x(2)) - u(1) * std::cos(x(2));
196  A(1, 2) = u(0) * std::cos(x(2)) - u(1) * std::sin(x(2));
197  return A;
198  }
199 
205  mat fdu(const vec x) const
206  {
207  // mat B(3,3, arma::fill::eye);
208  const mat B = { { std::cos(x(2)), -std::sin(x(2)), 0.0 },
209  { std::sin(x(2)), std::cos(x(2)), 0.0 },
210  { 0.0, 0.0, 1.0 } };
211  return B;
212  }
213 
214  unsigned int state_space; // states space dimension
215 };
216 } // namespace models
217 } // namespace ergodic_exploration
218 #endif
ergodic_exploration::models::Mecanum::wheel_radius
double wheel_radius
Definition: omni.hpp:153
ergodic_exploration::models::Mecanum::operator()
vec operator()(const vec x, const vec u) const
Kinematic model of 4 mecanum wheel robot.
Definition: omni.hpp:98
ergodic_exploration::models::Omni::state_space
unsigned int state_space
Definition: omni.hpp:214
s
XmlRpcServer s
ergodic_exploration::models::Mecanum::fdx
mat fdx(const vec x, const vec u) const
Jacobian of the model with respect to the state.
Definition: omni.hpp:118
A
ergodic_exploration::models::Mecanum::fdu
mat fdu(const vec x) const
Jacobian of the model with respect to the control.
Definition: omni.hpp:141
ergodic_exploration
Definition: basis.hpp:43
numerics.hpp
Useful numerical utilities.
ergodic_exploration::models::Mecanum::wheels2Twist
vec wheels2Twist(const vec u) const
Convert wheel velocities to a body frame twist.
Definition: omni.hpp:80
ergodic_exploration::models::Mecanum::Mecanum
Mecanum(double wheel_radius, double wheel_base_x, double wheel_base_y)
Constructor.
Definition: omni.hpp:67
ergodic_exploration::models::Mecanum::wheel_base_x
double wheel_base_x
Definition: omni.hpp:154
ergodic_exploration::models::Omni::fdx
mat fdx(const vec x, const vec u) const
Jacobian of the model with respect to the state.
Definition: omni.hpp:192
ergodic_exploration::models::Omni::Omni
Omni()
Constructor.
Definition: omni.hpp:167
ergodic_exploration::models::Mecanum::wheel_base_y
double wheel_base_y
Definition: omni.hpp:155
ergodic_exploration::models::Mecanum
Kinematic model of 4 mecanum wheel robot.
Definition: omni.hpp:59
ergodic_exploration::models::Omni::operator()
vec operator()(const vec x, const vec u) const
Kinematic model of 4 mecanum wheel robot.
Definition: omni.hpp:177
ergodic_exploration::models::Omni::fdu
mat fdu(const vec x) const
Jacobian of the model with respect to the control.
Definition: omni.hpp:205
ergodic_exploration::models::Mecanum::state_space
unsigned int state_space
Definition: omni.hpp:156
ergodic_exploration::models::Omni
Kinematic model of omni directonal robot.
Definition: omni.hpp:164


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