30 if (mat_motion_sensor_.rows() == 3 && mat_motion_sensor_.cols() == 3) {
31 is_3d_motion_ =
false;
32 }
else if (mat_motion_sensor_.rows() == 4 && mat_motion_sensor_.cols() == 4) {
35 AERROR <<
"Unknow motion matrix size : " << mat_motion_sensor_.rows() <<
" "
36 << mat_motion_sensor_.cols();
41 if (mot_buffer_ !=
nullptr) {
43 mot_buffer_ =
nullptr;
49 float time_d =
static_cast<float>(vehicledata->
time_d);
52 float theta = time_d * vehicledata->
yaw_rate;
53 Eigen::Rotation2Df rot2d(theta);
54 Eigen::Vector2f trans;
55 float velocity =
static_cast<float>(
58 float displacement = time_d * velocity;
59 trans(0) =
static_cast<float>(displacement * cos(theta));
60 trans(1) =
static_cast<float>(displacement * sin(theta));
64 motion_2d.block(0, 0, 2, 2) = rot2d.toRotationMatrix().transpose();
65 motion_2d.block(0, 2, 2, 1) = -rot2d.toRotationMatrix().transpose() * trans;
68 vehicledata->
motion = motion_2d;
71 float roll_delta = time_d * vehicledata->
roll_rate;
72 float pitch_delta = time_d * vehicledata->
pitch_rate;
73 float yaw_delta = time_d * vehicledata->
yaw_rate;
75 Eigen::AngleAxisf roll_angle(roll_delta, Eigen::Vector3f::UnitX());
76 Eigen::AngleAxisf pitch_angle(pitch_delta, Eigen::Vector3f::UnitY());
77 Eigen::AngleAxisf yaw_angle(yaw_delta, Eigen::Vector3f::UnitZ());
79 Eigen::Quaternion<float> q = roll_angle * pitch_angle * yaw_angle;
80 Eigen::Matrix3f rot3d = q.matrix();
82 float displacement = time_d * vehicledata->
velocity;
83 Eigen::Vector3f trans;
85 static_cast<float>(sqrt(displacement * displacement /
86 (tan(yaw_delta) * tan(yaw_delta) +
87 tan(pitch_delta) * tan(pitch_delta) + 1)));
88 trans(1) =
static_cast<float>(tan(yaw_delta) * trans(0));
89 trans(2) =
static_cast<float>(tan(pitch_delta) * trans(0));
91 motion_3d.block(0, 0, 3, 3) = rot3d.transpose();
92 motion_3d.block(0, 3, 3, 1) = -rot3d.transpose() * trans;
95 vehicledata->
motion = motion_3d;
99void PlaneMotion::accumulate_motion(
const double start_time,
100 const double end_time) {
102 auto iter = raw_motion_queue_.begin();
103 for (; iter != raw_motion_queue_.end() && iter->time_ts <= end_time; ++iter) {
104 if (iter->time_ts < start_time) {
107 mat_motion_sensor_ *= iter->motion;
108 time_difference_ +=
static_cast<float>(iter->time_d);
111 while (raw_motion_queue_.begin() != iter) {
112 raw_motion_queue_.pop_front();
116void PlaneMotion::update_motion_buffer(
const base::VehicleStatus &vehicledata,
117 const double pre_image_timestamp,
118 const double image_timestamp) {
119 std::lock_guard<std::mutex> lock(mutex_);
121 for (
size_t k = 0; k < mot_buffer_->size(); ++k) {
122 mot_buffer_->at(k).motion *= mat_motion_sensor_;
126 time_difference_ =
static_cast<float>(image_timestamp - pre_image_timestamp);
129 mot_buffer_->push_back(vehicledata);
130 mot_buffer_->back().time_d = time_difference_;
132 mot_buffer_->back().motion = mat_motion_sensor_;
133 mot_buffer_->back().time_ts = image_timestamp;
136 base::MotionType::Identity();
137 time_difference_ = 0.0f;
142 std::lock_guard<std::mutex> lock(mutex_);
143 ADEBUG <<
"mot_buffer_->size(): " << mot_buffer_->size();
145 for (
auto rit = mot_buffer_->rbegin(); rit != mot_buffer_->rend(); ++rit) {
146 if (std::abs(rit->time_ts - timestamp) <
147 std::numeric_limits<double>::epsilon()) {
156 std::lock_guard<std::mutex> lock(mutex_);
161 double image_timestamp,
162 int motion_operation_flag,
164 while (!raw_motion_queue_.empty() &&
165 vehicledata->
time_ts < raw_motion_queue_.back().time_ts) {
166 raw_motion_queue_.pop_back();
168 << raw_motion_queue_.back().time_ts <<
" "
169 << raw_motion_queue_.size();
172 if (motion_operation_flag !=
RESET) {
173 generate_motion_matrix(vehicledata);
174 raw_motion_queue_.push_back(*vehicledata);
175 if (
static_cast<int>(raw_motion_queue_.size()) > buffer_size_ * 10) {
176 AWARN <<
"MotionQueue is too large, try sync motion/image timestep";
179 switch (motion_operation_flag) {
184 accumulate_motion(pre_image_timestamp, image_timestamp);
185 update_motion_buffer(*vehicledata, pre_image_timestamp,
189 AERROR <<
"motion operation flag:wrong type";
193 mot_buffer_->clear();
195 vehicledata->
time_ts = image_timestamp;
196 vehicledata->
motion = base::MotionType::Identity();
197 mot_buffer_->push_back(*vehicledata);
198 ADEBUG <<
"pop and rest raw_buffer, mot_buffer: "
199 << raw_motion_queue_.size();
void set_buffer_size(int s)
bool find_motion_with_timestamp(double timestamp, base::VehicleStatus *vs)
base::MotionBuffer get_buffer()
void add_new_motion(double pre_image_timestamp, double image_timestamp, int motion_operation_flag, base::VehicleStatus *vehicledata)
boost::circular_buffer< VehicleStatus > MotionBuffer
Eigen::Matrix4f MotionType