-
Notifications
You must be signed in to change notification settings - Fork 9
/
compensator.h
executable file
·159 lines (139 loc) · 4.05 KB
/
compensator.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
//
// The MIT License (MIT)
//
// Copyright (c) 2019-2020 EAIBOT. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
/** @mainpage Compensator
* Compensator API
<table>
<tr><th>Library <td>Compensator
<tr><th>File <td>compensator.h
<tr><th>Author <td>Tony [code at ydlidar com]
<tr><th>Source <td>https://github.com/ydlidar/Compensator
<tr><th>Version <td>1.0.0
</table>
* @copyright Copyright (c) 2018-2020 EAIBOT
Jump to the @link ::ydlidar::drivers::Compensator @endlink interface documentation.
*/
#pragma once
#include <memory>
#include <string>
#include <deque>
#include <src/CYdLidar.h>
#include <core/math/angles.h>
#include "matrix/math.hpp"
namespace ydlidar {
namespace drivers {
struct odometry_t {
uint64_t stamp; ///< timestamp
double x; ///< x position
double y; ///< y position
double phi; ///< yaw angle
odometry_t &operator=(const odometry_t &o) { //operator=
this->stamp = o.stamp;
this->x = o.x;
this->y = o.y;
this->phi = o.phi;
return *this;
}
void clear() {
this->stamp = 0;
this->x = 0;
this->y = 0;
this->phi = 0;
}
};
class Compensator {
public:
Compensator();
virtual ~Compensator();
/**
* @brief insert odometry
*
*/
void InsertOdomMsg(const odometry_t &odom);
/**
* @brief motion compensation for LaserScan
*/
bool MotionCompensation(const LaserScan &msg, LaserScan &msg_compensated);
private:
/**
* @brief motion compensation for LaserScan
*/
void MotionCompensation(const LaserScan &msg, LaserScan &msg_compensated,
const matrix::SquareMatrix<double, 3> &pose_min_time);
/**
* @brief Query last odometry msg
*/
void QueryOdomMsg();
/**
* @brief waitForOdomAvailable
* @param time
* @param threshold_in_sec
* @return
*/
bool waitForOdomAvailable(const uint64_t time,
double threshold_in_sec = 10.e-3);
/**
* @brief QueryOdomCache
* @return
*/
bool QueryOdomCache();
/**
* @brief canAvailable
* @param time
* @return
*/
bool canAvailable(const uint16_t time);
/**
* @brief get odometry pose by time
* @param time
* @param odom
* @param threshold_in_sec
* @return
*/
bool GetOdomAtTime(const uint64_t time, odometry_t &odom,
double threshold_in_sec = 8.e-3);//8ms
/**
* @brief TrimOdometryData
*/
void TrimOdometryData();
/**
* @brief TrimTimedData
*/
void TrimTimedData(const uint64_t time);
private:
//time odom queue
std::deque< odometry_t > odom_queue;
//query odom msg
std::deque< odometry_t > odom_msgs_;
core::base::Locker _odom_lock;
//scan time queue
std::deque<uint64_t> timed_scan_queue_;
const uint32_t scan_queue_duration_ = 5 * 1e8;//0.5s
int m_warn_throttle;
int first_indices;
//lidar
matrix::Vector<double, 3> lidar_sensor_vector;
matrix::Vector<double, 3> current_sensor_vector;
};
} // namespace drivers
} // namespace ydlidar