Apollo 10.0
自动驾驶开放平台
matrix_operations.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22#include <cmath>
23#include <utility>
24
25#include "Eigen/Dense"
26#include "Eigen/SVD"
27
29
34namespace apollo {
35namespace common {
36namespace math {
37
38bool ContinuousToDiscrete(const Eigen::MatrixXd &m_a,
39 const Eigen::MatrixXd &m_b,
40 const Eigen::MatrixXd &m_c,
41 const Eigen::MatrixXd &m_d, const double ts,
42 Eigen::MatrixXd *ptr_a_d, Eigen::MatrixXd *ptr_b_d,
43 Eigen::MatrixXd *ptr_c_d, Eigen::MatrixXd *ptr_d_d) {
44 if (ts <= 0.0) {
45 AERROR << "ContinuousToDiscrete : ts is less than or equal to zero";
46 return false;
47 }
48
49 // Only matrix_a is mandatory to be non-zeros in matrix
50 // conversion.
51 if (m_a.rows() == 0) {
52 AERROR << "ContinuousToDiscrete: matrix_a size 0 ";
53 return false;
54 }
55
56 if (m_a.cols() != m_b.rows() || m_b.cols() != m_d.cols() ||
57 m_c.rows() != m_d.rows() || m_a.cols() != m_c.cols()) {
58 AERROR << "ContinuousToDiscrete: matrix dimensions mismatch";
59 return false;
60 }
61
62 Eigen::MatrixXd m_identity =
63 Eigen::MatrixXd::Identity(m_a.cols(), m_a.rows());
64
65 *ptr_a_d =
66 (m_identity - ts * 0.5 * m_a).inverse() * (m_identity + ts * 0.5 * m_a);
67
68 *ptr_b_d = std::sqrt(ts) * (m_identity - ts * 0.5 * m_a).inverse() * m_b;
69
70 *ptr_c_d = std::sqrt(ts) * m_c * (m_identity - ts * 0.5 * m_a).inverse();
71
72 *ptr_d_d = 0.5 * m_c * (m_identity - ts * 0.5 * m_a).inverse() * m_b + m_d;
73
74 return true;
75}
76
77} // namespace math
78} // namespace common
79} // namespace apollo
#define AERROR
Definition log.h:44
Defines some useful matrix operations.
bool ContinuousToDiscrete(const Eigen::MatrixXd &m_a, const Eigen::MatrixXd &m_b, const Eigen::MatrixXd &m_c, const Eigen::MatrixXd &m_d, const double ts, Eigen::MatrixXd *ptr_a_d, Eigen::MatrixXd *ptr_b_d, Eigen::MatrixXd *ptr_c_d, Eigen::MatrixXd *ptr_d_d)
class register implement
Definition arena_queue.h:37