40 if (Q.isDiagonal(1e-10))
return setWeightQ(Q.diagonal().asDiagonal());
93 cost.noalias() = x_k.transpose() *
_Q_diag * x_k;
95 cost.noalias() = x_k.transpose() *
_Q * x_k;
101 cost.noalias() = xd.transpose() *
_Q_diag * xd;
103 cost.noalias() = xd.transpose() *
_Q * xd;
112 assert(cost.size() == 1);
119 cost[0] += x_k.transpose() *
_Q_diag * x_k;
121 cost[0] += x_k.transpose() *
_Q * x_k;
127 cost[0] += xd.transpose() *
_Q_diag * xd;
129 cost[0] += xd.transpose() *
_Q * xd;
142 *issues <<
"QuadraticStateCost: Diagonal matrix dimension of Q (" <<
_Q_diag.
diagonal().size()
143 <<
") does not match state vector dimension (" << state_dim <<
"); Please specify diagonal elements only." << std::endl;
149 if (
_Q.rows() != state_dim ||
_Q.cols() != state_dim)
152 *issues <<
"QuadraticStateCost: Matrix dimension of Q (" <<
_Q.rows() <<
"x" <<
_Q.cols()
153 <<
") does not match state vector dimension (" << state_dim <<
"); Please specify " << (state_dim * state_dim)
154 <<
" elements (Row-Major)." << std::endl;
162 #ifdef MESSAGE_SUPPORT
163 bool QuadraticStateCost::fromMessage(
const messages::QuadraticStateCost& message, std::stringstream* issues)
172 *issues <<
"QuadraticStateCost: cannot set diagonal weight matrix Q.\n";
180 if (p * p != message.q_size())
182 *issues <<
"QuadraticStateCost: weight matrix Q is not square.\n";
191 *issues <<
"QuadraticStateCost: weight matrix Q is not positive definite.\n";
205 void QuadraticStateCost::toMessage(messages::QuadraticStateCost& message)
const
211 message.mutable_q()->Resize(Qdiag.size(), 0);
214 message.set_diagonal_only(
true);
218 Eigen::MatrixXd Q =
_Q;
219 message.mutable_q()->Resize(Q.rows() * Q.cols(), 0);
222 message.set_diagonal_only(
false);