g2o
Loading...
Searching...
No Matches
odometry_measurement.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
28
29#include <Eigen/Core>
30#include <Eigen/Geometry>
31
32namespace g2o {
33
34VelocityMeasurement::VelocityMeasurement() : _measurement(0., 0.), _dt(0.) {}
35
36VelocityMeasurement::VelocityMeasurement(double vl, double vr, double dt)
37 : _measurement(vl, vr), _dt(dt) {}
38
39MotionMeasurement::MotionMeasurement() : _measurement(0., 0., 0.), _dt(0.) {}
40
41MotionMeasurement::MotionMeasurement(double x, double y, double theta,
42 double dt)
43 : _measurement(x, y, theta), _dt(dt) {}
44
46 : _measurement(m), _dt(dt) {}
47
49 if (fabs(m.theta()) > 1e-7) {
50 const double translation = std::hypot(m.x(), m.y());
51 const double R = translation / (2 * sin(m.theta() / 2));
52 double w = 0.;
53 if (fabs(m.dt()) > 1e-7) w = m.theta() / m.dt();
54
55 const double vl = (2. * R * w - w) / 2.;
56 const double vr = w + vl;
57
58 return VelocityMeasurement(vl, vr, m.dt());
59 } else {
60 double vl, vr;
61 if (fabs(m.dt()) > 1e-7)
62 vl = vr = std::hypot(m.x(), m.y()) / m.dt();
63 else
64 vl = vr = 0.;
65 return VelocityMeasurement(vl, vr, m.dt());
66 }
67}
68
70 double l) {
71 double x, y, theta;
72 if (fabs(v.vr() - v.vl()) > 1e-7) {
73 double R = l * 0.5 * ((v.vl() + v.vr()) / (v.vr() - v.vl()));
74 double w = (v.vr() - v.vl()) / l;
75
76 theta = w * v.dt();
77 Rotation2D rot(theta);
78 Vector2 icc(0, R);
79 Vector2 motion = (rot * (Vector2(-1. * icc))) + icc;
80 x = motion.x();
81 y = motion.y();
82 } else {
83 double tv = 0.5 * (v.vr() + v.vl());
84 theta = 0.;
85 x = tv * v.dt();
86 y = 0.;
87 }
88
89 return MotionMeasurement(x, y, theta, v.dt());
90}
91
92} // namespace g2o
A 2D odometry measurement expressed as a transformation.
static VelocityMeasurement convertToVelocity(const MotionMeasurement &m)
static MotionMeasurement convertToMotion(const VelocityMeasurement &vi, double l=1.0)
velocity measurement of a differential robot
VectorN< 3 > Vector3
Definition eigen_types.h:51
Eigen::Rotation2D< double > Rotation2D
Definition eigen_types.h:80
VectorN< 2 > Vector2
Definition eigen_types.h:50