Drake
lcmUtil.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Core>
4 #include <iostream>
6 #include "lcmtypes/drake/lcmt_polynomial.hpp"
7 #include "lcmtypes/drake/lcmt_polynomial_matrix.hpp"
8 #include "lcmtypes/drake/lcmt_piecewise_polynomial.hpp"
9 #include "lcmtypes/drake/lcmt_qp_controller_input.hpp"
10 #include "drake/drakeLCMUtil_export.h"
11 
12 DRAKELCMUTIL_EXPORT void encodePolynomial(const Polynomial<double>& polynomial,
13  drake::lcmt_polynomial& msg);
14 
15 DRAKELCMUTIL_EXPORT Polynomial<double> decodePolynomial(
16  const drake::lcmt_polynomial& msg);
17 
18 template <int RowsAtCompileTime, int ColsAtCompileTime>
20  const Eigen::Matrix<Polynomial<double>, RowsAtCompileTime,
21  ColsAtCompileTime>& polynomial_matrix,
22  drake::lcmt_polynomial_matrix& msg) {
23  msg.polynomials.clear();
24  msg.polynomials.resize(polynomial_matrix.rows());
25  for (int row = 0; row < polynomial_matrix.rows(); ++row) {
26  auto& polynomial_msg_row = msg.polynomials[row];
27  polynomial_msg_row.resize(polynomial_matrix.cols());
28  for (int col = 0; col < polynomial_matrix.cols(); ++col) {
29  encodePolynomial(polynomial_matrix(row, col), polynomial_msg_row[col]);
30  }
31  }
32  msg.rows = polynomial_matrix.rows();
33  msg.cols = polynomial_matrix.cols();
34 }
35 
36 template <int RowsAtCompileTime, int ColsAtCompileTime>
37 Eigen::Matrix<Polynomial<double>, RowsAtCompileTime, ColsAtCompileTime>
38 decodePolynomialMatrix(const drake::lcmt_polynomial_matrix& msg) {
39  Eigen::Matrix<Polynomial<double>, RowsAtCompileTime, ColsAtCompileTime> ret(
40  msg.rows, msg.cols);
41  for (int row = 0; row < msg.rows; ++row) {
42  for (int col = 0; col < msg.cols; ++col) {
43  ret(row, col) = decodePolynomial(msg.polynomials[row][col]);
44  }
45  }
46  return ret;
47 }
48 
49 DRAKELCMUTIL_EXPORT void encodePiecewisePolynomial(
50  const PiecewisePolynomial<double>& piecewise_polynomial,
51  drake::lcmt_piecewise_polynomial& msg);
52 
54  const drake::lcmt_piecewise_polynomial& msg);
55 
56 DRAKELCMUTIL_EXPORT void verifySubtypeSizes(
57  drake::lcmt_support_data& support_data);
58 DRAKELCMUTIL_EXPORT void verifySubtypeSizes(
59  drake::lcmt_qp_controller_input& qp_input);
DRAKELCMUTIL_EXPORT void encodePolynomial(const Polynomial< double > &polynomial, drake::lcmt_polynomial &msg)
Definition: lcmUtil.cpp:6
DRAKELCMUTIL_EXPORT void encodePiecewisePolynomial(const PiecewisePolynomial< double > &piecewise_polynomial, drake::lcmt_piecewise_polynomial &msg)
Definition: lcmUtil.cpp:18
DRAKELCMUTIL_EXPORT void verifySubtypeSizes(drake::lcmt_support_data &support_data)
Definition: lcmUtil.cpp:43
A scalar multi-variate polynomial, modeled after the msspoly in spotless.
Definition: Polynomial.h:42
DRAKELCMUTIL_EXPORT PiecewisePolynomial< double > decodePiecewisePolynomial(const drake::lcmt_piecewise_polynomial &msg)
Definition: lcmUtil.cpp:32
A scalar multi-variate piecewise polynomial.
Definition: PiecewisePolynomial.h:33
void encodePolynomialMatrix(const Eigen::Matrix< Polynomial< double >, RowsAtCompileTime, ColsAtCompileTime > &polynomial_matrix, drake::lcmt_polynomial_matrix &msg)
Definition: lcmUtil.h:19
DRAKELCMUTIL_EXPORT Polynomial< double > decodePolynomial(const drake::lcmt_polynomial &msg)
Definition: lcmUtil.cpp:12
Eigen::Matrix< Polynomial< double >, RowsAtCompileTime, ColsAtCompileTime > decodePolynomialMatrix(const drake::lcmt_polynomial_matrix &msg)
Definition: lcmUtil.h:38