MIRA
DifferentialRobotModel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_DIFFERENTIALROBOTMODEL_H_
48 #define _MIRA_DIFFERENTIALROBOTMODEL_H_
49 
50 #include <math/Random.h>
53 
54 namespace mira { namespace robot {
55 
57 
71 {
73 
74 public:
77 
79 
80  template<typename Reflector>
81  void reflect(Reflector& r)
82  {
84  r.property("WheelDistance", wheelDist,
85  "Distance of the main drive wheels [m]. Must be greater than zero.");
86 
88  }
89 
91 
92 public:
95 
96  virtual Pose2 localKinematics(const Velocity2& v, float dt) const;
97 
98  virtual float predictStandstillDistance(const Velocity2& v) const;
99 
100  virtual float predictStandstillRotation(const Velocity2& v) const;
101 
103 
104 public:
107 
115  SignedAnglef angleFromTotalDistance(float totalLeft, float totalRight) const;
116 
117 
124  Velocity2 convert2Velocity(float vLeft, float vRight) const;
125 
131  std::pair<float, float> convert2LRWheelSpeed(const Velocity2& v) const;
132 
137  float getMaxVelocity() const;
138 
140 
141 public:
142 
144  float wheelDist;
145 };
146 
148 typedef boost::shared_ptr<DifferentialRobotModel> DifferentialRobotModelPtr;
149 
151 
152 // KEEP THE FOLLOWING CODE INLINE FOR PERFORMANCE REASONS !!!
153 
155  float dt) const
156 {
157  assert(dt >= 0.0f);
158 
159  float dx,dy;
160  float dphi = dt * v.r.angle();
161 
162  if(std::abs(dphi)>0.001f) {
163  // compute curvature of arc, and assume circular movement
164  float R = v.x() / v.r.angle();
165  dx = sinf(dphi) * R;
166  dy = (1-cosf(dphi)) * R;
167  } else {
168  // assume translational movement, only
169  float s = dt * v.t.x();
170  dx = cosf(0.5f*dphi) * s;
171  dy = sinf(0.5f*dphi) * s;
172  }
173  return Pose2(dx,dy,dphi);
174 }
175 
177 {
178  assert(maxEmergencyDeceleration > 0.0f);
179 
180  // v = a*t
181  // t = v/a
182  // s = 0.5 * a * t^2
183  // s = 0.5 * v^2 / a
184  float a = maxEmergencyDeceleration;
185  return 0.5f * (v.x()*v.x()) / a;
186 }
187 
189 {
190  assert(maxRotDeceleration > 0.0f);
191 
192  float a = maxRotDeceleration;
193  float rot = 0.5f * (v.phi()*v.phi()) / a;
194  return (v.phi() > 0 ? rot : -rot);
195 }
196 
198 
200  float totalRight) const
201 {
202  assert(wheelDist > 0.0f);
203 
204  float outlineLength = two_pi<float>() * wheelDist;
205  return SignedAnglef(fmod((totalRight - totalLeft)/wheelDist, outlineLength));
206 }
207 
209  float vRight) const
210 {
211  assert(wheelDist > 0.0f);
212  return Velocity2((vRight + vLeft)*0.5f, 0.0f, (vRight-vLeft)/wheelDist);
213 }
214 
215 inline std::pair<float, float> DifferentialRobotModel::convert2LRWheelSpeed(const Velocity2& v) const
216 {
217  float vTrans = v.x();
218  float vRot = v.r.angle();
219  vRot *= 0.5f*wheelDist;
220  return std::make_pair(vTrans-vRot, vTrans+vRot);
221 }
222 
224 {
226 }
227 
229 
230 }}
231 
232 #endif
float maxEmergencyDeceleration
Max. deceleration in case of an emergency. Must be greater than zero.
Definition: UnicycleBasedRobotModel.h:148
float getMaxVelocity() const
Returns the absolute max.
Definition: DifferentialRobotModel.h:223
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Definition: UnicycleBasedRobotModel.h:58
float maxBackwardVelocity
The maximum velocity for driving backward (both wheels) [m/s].
Definition: UnicycleBasedRobotModel.h:128
RigidTransform< float, 2 > Velocity2
float maxRotDeceleration
Max. deceleration. Must be greater than zero.
Definition: UnicycleBasedRobotModel.h:153
RigidTransform< float, 2 > Pose2
float maxForwardVelocity
The maximum velocity for driving forward (both wheels) [m/s].
Definition: UnicycleBasedRobotModel.h:131
Duration abs(const Duration &duration)
SignedAngle< float > SignedAnglef
boost::shared_ptr< DifferentialRobotModel > DifferentialRobotModelPtr
Typedef for DifferentialRobotModel pointer.
Definition: DifferentialRobotModel.h:148
void reflect(Reflector &r)
Definition: DifferentialRobotModel.h:81
virtual Pose2 localKinematics(const Velocity2 &v, float dt) const
Computes the local movement of the robot if it moves with the specified velocity v for the specified ...
Definition: DifferentialRobotModel.h:154
Velocity2 convert2Velocity(float vLeft, float vRight) const
Convert wheel speeds of left and right wheel to velocity (trans, rot)
Definition: DifferentialRobotModel.h:208
SignedAnglef angleFromTotalDistance(float totalLeft, float totalRight) const
Calculates the view direction of the robot from given traveled distance of left and right wheel and t...
Definition: DifferentialRobotModel.h:199
#define MIRA_OBJECT(classIdentifier)
virtual float predictStandstillDistance(const Velocity2 &v) const
Calculate the distance that is needed for braking to stand still, if the robot moves with the specifi...
Definition: DifferentialRobotModel.h:176
Probabilistic motion model for a robot with differential drive.
float wheelDist
The distance of both wheels. Must be greater than zero.
Definition: DifferentialRobotModel.h:144
Probabilistic motion model for a robot with differential drive.
Definition: DifferentialProbabilisticMotionModel.h:70
virtual float predictStandstillRotation(const Velocity2 &v) const
Calculate the rotation that is needed for braking to stand still, if the robot moves with the specifi...
Definition: DifferentialRobotModel.h:188
A robot model for robot with a differential drive (2 wheels on an axis, fixed orientation).
Definition: DifferentialRobotModel.h:68
std::pair< float, float > convert2LRWheelSpeed(const Velocity2 &v) const
Converts velocity into left and right wheel speeds.
Definition: DifferentialRobotModel.h:215
A robot model class for unicycle based motion models (differential drive, tricycle) ...
#define MIRA_ROBOT_DATATYPES_EXPORT
Definition: RobotDataTypesExports.h:61