g2o
Loading...
Searching...
No Matches
g2o
types
sclam2d
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
27
#include "
odometry_measurement.h
"
28
29
#include <Eigen/Core>
30
#include <Eigen/Geometry>
31
32
namespace
g2o
{
33
34
VelocityMeasurement::VelocityMeasurement
() : _measurement(0., 0.), _dt(0.) {}
35
36
VelocityMeasurement::VelocityMeasurement
(
double
vl,
double
vr,
double
dt)
37
: _measurement(vl, vr), _dt(dt) {}
38
39
MotionMeasurement::MotionMeasurement
() : _measurement(0., 0., 0.), _dt(0.) {}
40
41
MotionMeasurement::MotionMeasurement
(
double
x,
double
y,
double
theta,
42
double
dt)
43
: _measurement(x, y, theta), _dt(dt) {}
44
45
MotionMeasurement::MotionMeasurement
(
const
Vector3
& m,
double
dt)
46
: _measurement(m), _dt(dt) {}
47
48
VelocityMeasurement
OdomConvert::convertToVelocity
(
const
MotionMeasurement
& m) {
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
69
MotionMeasurement
OdomConvert::convertToMotion
(
const
VelocityMeasurement
& v,
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
g2o::MotionMeasurement
A 2D odometry measurement expressed as a transformation.
Definition
odometry_measurement.h:65
g2o::MotionMeasurement::x
double x() const
Definition
odometry_measurement.h:72
g2o::MotionMeasurement::dt
double dt() const
Definition
odometry_measurement.h:81
g2o::MotionMeasurement::theta
double theta() const
Definition
odometry_measurement.h:78
g2o::MotionMeasurement::y
double y() const
Definition
odometry_measurement.h:75
g2o::MotionMeasurement::MotionMeasurement
MotionMeasurement()
Definition
odometry_measurement.cpp:39
g2o::OdomConvert::convertToVelocity
static VelocityMeasurement convertToVelocity(const MotionMeasurement &m)
Definition
odometry_measurement.cpp:48
g2o::OdomConvert::convertToMotion
static MotionMeasurement convertToMotion(const VelocityMeasurement &vi, double l=1.0)
Definition
odometry_measurement.cpp:69
g2o::VelocityMeasurement
velocity measurement of a differential robot
Definition
odometry_measurement.h:40
g2o::VelocityMeasurement::vr
double vr() const
Definition
odometry_measurement.h:49
g2o::VelocityMeasurement::dt
double dt() const
Definition
odometry_measurement.h:52
g2o::VelocityMeasurement::VelocityMeasurement
VelocityMeasurement()
Definition
odometry_measurement.cpp:34
g2o::VelocityMeasurement::vl
double vl() const
Definition
odometry_measurement.h:46
g2o
Definition
dl_wrapper.cpp:55
g2o::Vector3
VectorN< 3 > Vector3
Definition
eigen_types.h:51
g2o::Rotation2D
Eigen::Rotation2D< double > Rotation2D
Definition
eigen_types.h:80
g2o::Vector2
VectorN< 2 > Vector2
Definition
eigen_types.h:50
odometry_measurement.h
Generated on Tue Nov 11 2025 05:18:45 for g2o by
1.9.8