-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOdometry.h
201 lines (156 loc) · 5.03 KB
/
Odometry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/******************************************************************************
*** Odometry.h
******************************************************************************/
/*
This class provides a generic odometry mode based on wheel movement for a
differential drive robot. A differential drive robot travels in circular arcs
with the special case of a straight line being an arc of infinite radius. The
equations are exact for constant velocity and over small movements acceleration
should be negligible.
Author: Tim Craig (Druai Robotics) 2018
*/
#ifndef ODOMETRY_H
#define ODOMETRY_H
#pragma once
/*****************************************************************************
****************************** I N C L U D E ******************************
****************************************************************************/
#include <cmath>
#include <math.h>
/*****************************************************************************
*
*** class DPose
*
* General pose for at robot operating on a 2D plane.
*
*****************************************************************************/
class DPose
{
public:
DPose(double dX = 0.0, double dY = 0.0, double dTheta = 0.0)
: m_dX{dX}, m_dY{dY}
{
SetTheta(dTheta);
return;
}
DPose(const DPose& src) = default;
DPose(DPose&& src) = default;
~DPose() = default;
DPose& operator=(const DPose& rhs) = default;
DPose& operator=(DPose&& rhs) = default;
void Reset(double dX, double dY, double dTheta)
{
m_dX = dX;
m_dY = dY;
SetTheta(dTheta);
return;
}
void SetX(double dX)
{
m_dX = dX;
return;
}
double GetX() const
{
return(m_dX);
}
void SetY(double dY)
{
m_dY = dY;
return;
}
double GetY() const
{
return (m_dY);
}
double GetTheta() const
{
return (m_dTheta);
}
void GetHeadingVector(double& dHeadingX, double& dHeadingY) const
{
dHeadingX = m_dHeadingX;
dHeadingY = m_dHeadingY;
return;
}
void SetTheta(double dTheta)
{
m_dTheta = dTheta;
m_dHeadingX = std::cos(m_dTheta);
m_dHeadingY = std::sin(m_dTheta);
return;
}
void Update(double dDeltaX, double dDeltaY)
{
m_dX += dDeltaX;
m_dY += dDeltaY;
\
return;
}
void Update(double dDeltaX, double dDeltaY, double dDeltaTheta)
{
m_dX += dDeltaX;
m_dY += dDeltaY;
SetTheta(m_dTheta + dDeltaTheta);
\
return;
}
protected:
// Position in world units
double m_dX;
double m_dY;
// Heading angle in radians
double m_dTheta;
// Heading unit vector (sin and cos of Theta)
double m_dHeadingY;
double m_dHeadingX;
private:
}; // end of class DPose
/*****************************************************************************
*
*** class DOdometry
*
* Provide updating pose for a differential drive robot using wheel rotation
* measurements. Motion of the robot is always along a circular arc (an arc of
* infinite radius is also known as a straight line which is treated as a separate
* case). This assumes motion at constant wheel speeds so the equations are exact
* neglecting noise and encoder quantization errors. Wheel accelerataions are
* not accounted for and assumed to be negligible over short sampling times.
*
*****************************************************************************/
class DOdometry
{
public:
DOdometry(double dX = 0.0, double dY = 0.0, double dTheta = 0.0, double dTrack = 1.0)
: m_Pose{dX, dY, dTheta}, m_dTrack{dTrack}
{
return;
}
DOdometry(const DPose& Pose, double dTrack = 1.0)
: m_Pose{Pose}, m_dTrack{dTrack}
{
return;
}
DOdometry(const DOdometry& src) = default;
DOdometry(DOdometry&& src) = default;
~DOdometry() = default;
DOdometry& operator=(const DOdometry& rhs) = default;
DOdometry& operator=(DOdometry&& rhs) = default;
const DPose& GetPose() const
{
return (m_Pose);
}
double GetTrack() const
{
return (m_dTrack);
}
// Primary function. Update the pose given wheel travel.
void UpdatePose(double dLeft, double dRight);
protected:
// Pose of the robot X, Y, and Heading (Rotation relative to the world system)
DPose m_Pose;
// Distance between wheel centers. Same units as robot positions.
const double m_dTrack;
private:
}; // end of class DOdometry
#endif // ODOMETRY_H