-
Notifications
You must be signed in to change notification settings - Fork 174
/
ddp.cpp
614 lines (530 loc) · 18.2 KB
/
ddp.cpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh,
// University of Oxford, Heriot-Watt University
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
#include "crocoddyl/core/solvers/ddp.hpp"
#include <iostream>
#include "crocoddyl/core/utils/exception.hpp"
namespace crocoddyl {
SolverDDP::SolverDDP(boost::shared_ptr<ShootingProblem> problem)
: SolverAbstract(problem),
reg_incfactor_(10.),
reg_decfactor_(10.),
reg_min_(1e-9),
reg_max_(1e9),
cost_try_(0.),
th_grad_(1e-12),
th_stepdec_(0.5),
th_stepinc_(0.01) {
allocateData();
const std::size_t n_alphas = 10;
alphas_.resize(n_alphas);
for (std::size_t n = 0; n < n_alphas; ++n) {
alphas_[n] = 1. / pow(2., static_cast<double>(n));
}
if (th_stepinc_ < alphas_[n_alphas - 1]) {
th_stepinc_ = alphas_[n_alphas - 1];
std::cerr << "Warning: th_stepinc has higher value than lowest alpha "
"value, set to "
<< std::to_string(alphas_[n_alphas - 1]) << std::endl;
}
}
SolverDDP::~SolverDDP() {}
bool SolverDDP::solve(const std::vector<Eigen::VectorXd>& init_xs,
const std::vector<Eigen::VectorXd>& init_us,
const std::size_t maxiter, const bool is_feasible,
const double init_reg) {
START_PROFILER("SolverDDP::solve");
if (problem_->is_updated()) {
resizeData();
}
xs_try_[0] =
problem_->get_x0(); // it is needed in case that init_xs[0] is infeasible
setCandidate(init_xs, init_us, is_feasible);
if (std::isnan(init_reg)) {
preg_ = reg_min_;
dreg_ = reg_min_;
} else {
preg_ = init_reg;
dreg_ = init_reg;
}
was_feasible_ = false;
bool recalcDiff = true;
for (iter_ = 0; iter_ < maxiter; ++iter_) {
while (true) {
try {
computeDirection(recalcDiff);
} catch (std::exception& e) {
recalcDiff = false;
increaseRegularization();
if (preg_ == reg_max_) {
return false;
} else {
continue;
}
}
break;
}
expectedImprovement();
// We need to recalculate the derivatives when the step length passes
recalcDiff = false;
for (std::vector<double>::const_iterator it = alphas_.begin();
it != alphas_.end(); ++it) {
steplength_ = *it;
try {
dV_ = tryStep(steplength_);
} catch (std::exception& e) {
continue;
}
dVexp_ = steplength_ * (d_[0] + 0.5 * steplength_ * d_[1]);
if (dVexp_ >= 0) { // descend direction
if (std::abs(d_[0]) < th_grad_ || !is_feasible_ ||
dV_ > th_acceptstep_ * dVexp_) {
was_feasible_ = is_feasible_;
setCandidate(xs_try_, us_try_, true);
cost_ = cost_try_;
recalcDiff = true;
break;
}
}
}
if (steplength_ > th_stepdec_) {
decreaseRegularization();
}
if (steplength_ <= th_stepinc_) {
increaseRegularization();
if (preg_ == reg_max_) {
STOP_PROFILER("SolverDDP::solve");
return false;
}
}
stoppingCriteria();
const std::size_t n_callbacks = callbacks_.size();
for (std::size_t c = 0; c < n_callbacks; ++c) {
CallbackAbstract& callback = *callbacks_[c];
callback(*this);
}
if (was_feasible_ && stop_ < th_stop_) {
STOP_PROFILER("SolverDDP::solve");
return true;
}
}
STOP_PROFILER("SolverDDP::solve");
return false;
}
void SolverDDP::computeDirection(const bool recalcDiff) {
START_PROFILER("SolverDDP::computeDirection");
if (recalcDiff) {
calcDiff();
}
backwardPass();
STOP_PROFILER("SolverDDP::computeDirection");
}
double SolverDDP::tryStep(const double steplength) {
START_PROFILER("SolverDDP::tryStep");
forwardPass(steplength);
STOP_PROFILER("SolverDDP::tryStep");
return cost_ - cost_try_;
}
double SolverDDP::stoppingCriteria() {
// This stopping criteria represents the expected reduction in the value
// function. If this reduction is less than a certain threshold, then the
// algorithm reaches the local minimum. For more details, see C. Mastalli et
// al. "Inverse-dynamics MPC via Nullspace Resolution".
stop_ = std::abs(d_[0] + 0.5 * d_[1]);
return stop_;
}
const Eigen::Vector2d& SolverDDP::expectedImprovement() {
d_.fill(0);
const std::size_t T = this->problem_->get_T();
const std::vector<boost::shared_ptr<ActionModelAbstract> >& models =
problem_->get_runningModels();
for (std::size_t t = 0; t < T; ++t) {
const std::size_t nu = models[t]->get_nu();
if (nu != 0) {
d_[0] += Qu_[t].dot(k_[t]);
d_[1] -= k_[t].dot(Quuk_[t]);
}
}
return d_;
}
void SolverDDP::resizeData() {
START_PROFILER("SolverDDP::resizeData");
SolverAbstract::resizeData();
const std::size_t T = problem_->get_T();
const std::size_t ndx = problem_->get_ndx();
const std::vector<boost::shared_ptr<ActionModelAbstract> >& models =
problem_->get_runningModels();
for (std::size_t t = 0; t < T; ++t) {
const boost::shared_ptr<ActionModelAbstract>& model = models[t];
const std::size_t nu = model->get_nu();
Qxu_[t].conservativeResize(ndx, nu);
Quu_[t].conservativeResize(nu, nu);
Qu_[t].conservativeResize(nu);
K_[t].conservativeResize(nu, ndx);
k_[t].conservativeResize(nu);
us_try_[t].conservativeResize(nu);
FuTVxx_p_[t].conservativeResize(nu, ndx);
Quuk_[t].conservativeResize(nu);
if (nu != 0) {
FuTVxx_p_[t].setZero();
}
}
STOP_PROFILER("SolverDDP::resizeData");
}
double SolverDDP::calcDiff() {
START_PROFILER("SolverDDP::calcDiff");
if (iter_ == 0) {
problem_->calc(xs_, us_);
}
cost_ = problem_->calcDiff(xs_, us_);
ffeas_ = computeDynamicFeasibility();
gfeas_ = computeInequalityFeasibility();
hfeas_ = computeEqualityFeasibility();
STOP_PROFILER("SolverDDP::calcDiff");
return cost_;
}
void SolverDDP::backwardPass() {
START_PROFILER("SolverDDP::backwardPass");
const boost::shared_ptr<ActionDataAbstract>& d_T =
problem_->get_terminalData();
Vxx_.back() = d_T->Lxx;
Vx_.back() = d_T->Lx;
if (!std::isnan(preg_)) {
Vxx_.back().diagonal().array() += preg_;
}
if (!is_feasible_) {
Vx_.back().noalias() += Vxx_.back() * fs_.back();
}
const std::vector<boost::shared_ptr<ActionModelAbstract> >& models =
problem_->get_runningModels();
const std::vector<boost::shared_ptr<ActionDataAbstract> >& datas =
problem_->get_runningDatas();
for (int t = static_cast<int>(problem_->get_T()) - 1; t >= 0; --t) {
const boost::shared_ptr<ActionModelAbstract>& m = models[t];
const boost::shared_ptr<ActionDataAbstract>& d = datas[t];
// Compute the linear-quadratic approximation of the control Hamiltonian
// function
computeActionValueFunction(t, m, d);
// Compute the feedforward and feedback gains
computeGains(t);
// Compute the linear-quadratic approximation of the Value function
computeValueFunction(t, m);
if (raiseIfNaN(Vx_[t].lpNorm<Eigen::Infinity>())) {
throw_pretty("backward_error");
}
if (raiseIfNaN(Vxx_[t].lpNorm<Eigen::Infinity>())) {
throw_pretty("backward_error");
}
}
STOP_PROFILER("SolverDDP::backwardPass");
}
void SolverDDP::forwardPass(const double steplength) {
if (steplength > 1. || steplength < 0.) {
throw_pretty("Invalid argument: "
<< "invalid step length, value is between 0. to 1.");
}
START_PROFILER("SolverDDP::forwardPass");
cost_try_ = 0.;
const std::size_t T = problem_->get_T();
const std::vector<boost::shared_ptr<ActionModelAbstract> >& models =
problem_->get_runningModels();
const std::vector<boost::shared_ptr<ActionDataAbstract> >& datas =
problem_->get_runningDatas();
for (std::size_t t = 0; t < T; ++t) {
const boost::shared_ptr<ActionModelAbstract>& m = models[t];
const boost::shared_ptr<ActionDataAbstract>& d = datas[t];
m->get_state()->diff(xs_[t], xs_try_[t], dx_[t]);
if (m->get_nu() != 0) {
us_try_[t].noalias() = us_[t];
us_try_[t].noalias() -= k_[t] * steplength;
us_try_[t].noalias() -= K_[t] * dx_[t];
m->calc(d, xs_try_[t], us_try_[t]);
} else {
m->calc(d, xs_try_[t]);
}
xs_try_[t + 1] = d->xnext;
cost_try_ += d->cost;
if (raiseIfNaN(cost_try_)) {
STOP_PROFILER("SolverDDP::forwardPass");
throw_pretty("forward_error");
}
if (raiseIfNaN(xs_try_[t + 1].lpNorm<Eigen::Infinity>())) {
STOP_PROFILER("SolverDDP::forwardPass");
throw_pretty("forward_error");
}
}
const boost::shared_ptr<ActionModelAbstract>& m =
problem_->get_terminalModel();
const boost::shared_ptr<ActionDataAbstract>& d = problem_->get_terminalData();
m->calc(d, xs_try_.back());
cost_try_ += d->cost;
if (raiseIfNaN(cost_try_)) {
STOP_PROFILER("SolverDDP::forwardPass");
throw_pretty("forward_error");
}
STOP_PROFILER("SolverDDP::forwardPass");
}
void SolverDDP::computeActionValueFunction(
const std::size_t t, const boost::shared_ptr<ActionModelAbstract>& model,
const boost::shared_ptr<ActionDataAbstract>& data) {
assert_pretty(t < problem_->get_T(),
"Invalid argument: t should be between 0 and " +
std::to_string(problem_->get_T()););
const std::size_t nu = model->get_nu();
const Eigen::MatrixXd& Vxx_p = Vxx_[t + 1];
const Eigen::VectorXd& Vx_p = Vx_[t + 1];
FxTVxx_p_.noalias() = data->Fx.transpose() * Vxx_p;
START_PROFILER("SolverDDP::Qx");
Qx_[t] = data->Lx;
Qx_[t].noalias() += data->Fx.transpose() * Vx_p;
STOP_PROFILER("SolverDDP::Qx");
START_PROFILER("SolverDDP::Qxx");
Qxx_[t] = data->Lxx;
Qxx_[t].noalias() += FxTVxx_p_ * data->Fx;
STOP_PROFILER("SolverDDP::Qxx");
if (nu != 0) {
FuTVxx_p_[t].noalias() = data->Fu.transpose() * Vxx_p;
START_PROFILER("SolverDDP::Qu");
Qu_[t] = data->Lu;
Qu_[t].noalias() += data->Fu.transpose() * Vx_p;
STOP_PROFILER("SolverDDP::Qu");
START_PROFILER("SolverDDP::Quu");
Quu_[t] = data->Luu;
Quu_[t].noalias() += FuTVxx_p_[t] * data->Fu;
STOP_PROFILER("SolverDDP::Quu");
START_PROFILER("SolverDDP::Qxu");
Qxu_[t] = data->Lxu;
Qxu_[t].noalias() += FxTVxx_p_ * data->Fu;
STOP_PROFILER("SolverDDP::Qxu");
if (!std::isnan(preg_)) {
Quu_[t].diagonal().array() += preg_;
}
}
}
void SolverDDP::computeValueFunction(
const std::size_t t, const boost::shared_ptr<ActionModelAbstract>& model) {
assert_pretty(t < problem_->get_T(),
"Invalid argument: t should be between 0 and " +
std::to_string(problem_->get_T()););
const std::size_t nu = model->get_nu();
Vx_[t] = Qx_[t];
Vxx_[t] = Qxx_[t];
if (nu != 0) {
START_PROFILER("SolverDDP::Vx");
Quuk_[t].noalias() = Quu_[t] * k_[t];
Vx_[t].noalias() -= K_[t].transpose() * Qu_[t];
STOP_PROFILER("SolverDDP::Vx");
START_PROFILER("SolverDDP::Vxx");
Vxx_[t].noalias() -= Qxu_[t] * K_[t];
STOP_PROFILER("SolverDDP::Vxx");
}
Vxx_tmp_ = 0.5 * (Vxx_[t] + Vxx_[t].transpose());
Vxx_[t] = Vxx_tmp_;
if (!std::isnan(preg_)) {
Vxx_[t].diagonal().array() += preg_;
}
// Compute and store the Vx gradient at end of the interval (rollout state)
if (!is_feasible_) {
Vx_[t].noalias() += Vxx_[t] * fs_[t];
}
}
void SolverDDP::computeGains(const std::size_t t) {
assert_pretty(t < problem_->get_T(),
"Invalid argument: t should be between 0 and " +
std::to_string(problem_->get_T()));
START_PROFILER("SolverDDP::computeGains");
const std::size_t nu = problem_->get_runningModels()[t]->get_nu();
if (nu > 0) {
START_PROFILER("SolverDDP::Quu_inv");
Quu_llt_[t].compute(Quu_[t]);
STOP_PROFILER("SolverDDP::Quu_inv");
const Eigen::ComputationInfo& info = Quu_llt_[t].info();
if (info != Eigen::Success) {
STOP_PROFILER("SolverDDP::computeGains");
throw_pretty("backward_error");
}
K_[t] = Qxu_[t].transpose();
START_PROFILER("SolverDDP::Quu_inv_Qux");
Quu_llt_[t].solveInPlace(K_[t]);
STOP_PROFILER("SolverDDP::Quu_inv_Qux");
k_[t] = Qu_[t];
Quu_llt_[t].solveInPlace(k_[t]);
}
STOP_PROFILER("SolverDDP::computeGains");
}
void SolverDDP::increaseRegularization() {
preg_ *= reg_incfactor_;
if (preg_ > reg_max_) {
preg_ = reg_max_;
}
dreg_ = preg_;
}
void SolverDDP::decreaseRegularization() {
preg_ /= reg_decfactor_;
if (preg_ < reg_min_) {
preg_ = reg_min_;
}
dreg_ = preg_;
}
void SolverDDP::allocateData() {
const std::size_t T = problem_->get_T();
Vxx_.resize(T + 1);
Vx_.resize(T + 1);
Qxx_.resize(T);
Qxu_.resize(T);
Quu_.resize(T);
Qx_.resize(T);
Qu_.resize(T);
K_.resize(T);
k_.resize(T);
xs_try_.resize(T + 1);
us_try_.resize(T);
dx_.resize(T);
FuTVxx_p_.resize(T);
Quu_llt_.resize(T);
Quuk_.resize(T);
const std::size_t ndx = problem_->get_ndx();
const std::vector<boost::shared_ptr<ActionModelAbstract> >& models =
problem_->get_runningModels();
for (std::size_t t = 0; t < T; ++t) {
const boost::shared_ptr<ActionModelAbstract>& model = models[t];
const std::size_t nu = model->get_nu();
Vxx_[t] = Eigen::MatrixXd::Zero(ndx, ndx);
Vx_[t] = Eigen::VectorXd::Zero(ndx);
Qxx_[t] = Eigen::MatrixXd::Zero(ndx, ndx);
Qxu_[t] = Eigen::MatrixXd::Zero(ndx, nu);
Quu_[t] = Eigen::MatrixXd::Zero(nu, nu);
Qx_[t] = Eigen::VectorXd::Zero(ndx);
Qu_[t] = Eigen::VectorXd::Zero(nu);
K_[t] = MatrixXdRowMajor::Zero(nu, ndx);
k_[t] = Eigen::VectorXd::Zero(nu);
if (t == 0) {
xs_try_[t] = problem_->get_x0();
} else {
xs_try_[t] = model->get_state()->zero();
}
us_try_[t] = Eigen::VectorXd::Zero(nu);
dx_[t] = Eigen::VectorXd::Zero(ndx);
FuTVxx_p_[t] = MatrixXdRowMajor::Zero(nu, ndx);
Quu_llt_[t] = Eigen::LLT<Eigen::MatrixXd>(nu);
Quuk_[t] = Eigen::VectorXd(nu);
}
Vxx_.back() = Eigen::MatrixXd::Zero(ndx, ndx);
Vxx_tmp_ = Eigen::MatrixXd::Zero(ndx, ndx);
Vx_.back() = Eigen::VectorXd::Zero(ndx);
xs_try_.back() = problem_->get_terminalModel()->get_state()->zero();
FxTVxx_p_ = MatrixXdRowMajor::Zero(ndx, ndx);
fTVxx_p_ = Eigen::VectorXd::Zero(ndx);
}
double SolverDDP::get_reg_incfactor() const { return reg_incfactor_; }
double SolverDDP::get_reg_decfactor() const { return reg_decfactor_; }
double SolverDDP::get_regfactor() const { return reg_incfactor_; }
double SolverDDP::get_reg_min() const { return reg_min_; }
double SolverDDP::get_regmin() const { return reg_min_; }
double SolverDDP::get_reg_max() const { return reg_max_; }
double SolverDDP::get_regmax() const { return reg_max_; }
const std::vector<double>& SolverDDP::get_alphas() const { return alphas_; }
double SolverDDP::get_th_stepdec() const { return th_stepdec_; }
double SolverDDP::get_th_stepinc() const { return th_stepinc_; }
double SolverDDP::get_th_grad() const { return th_grad_; }
const std::vector<Eigen::MatrixXd>& SolverDDP::get_Vxx() const { return Vxx_; }
const std::vector<Eigen::VectorXd>& SolverDDP::get_Vx() const { return Vx_; }
const std::vector<Eigen::MatrixXd>& SolverDDP::get_Qxx() const { return Qxx_; }
const std::vector<Eigen::MatrixXd>& SolverDDP::get_Qxu() const { return Qxu_; }
const std::vector<Eigen::MatrixXd>& SolverDDP::get_Quu() const { return Quu_; }
const std::vector<Eigen::VectorXd>& SolverDDP::get_Qx() const { return Qx_; }
const std::vector<Eigen::VectorXd>& SolverDDP::get_Qu() const { return Qu_; }
const std::vector<typename MathBaseTpl<double>::MatrixXsRowMajor>&
SolverDDP::get_K() const {
return K_;
}
const std::vector<Eigen::VectorXd>& SolverDDP::get_k() const { return k_; }
void SolverDDP::set_reg_incfactor(const double regfactor) {
if (regfactor <= 1.) {
throw_pretty(
"Invalid argument: " << "reg_incfactor value is higher than 1.");
}
reg_incfactor_ = regfactor;
}
void SolverDDP::set_reg_decfactor(const double regfactor) {
if (regfactor <= 1.) {
throw_pretty(
"Invalid argument: " << "reg_decfactor value is higher than 1.");
}
reg_decfactor_ = regfactor;
}
void SolverDDP::set_regfactor(const double regfactor) {
if (regfactor <= 1.) {
throw_pretty("Invalid argument: " << "regfactor value is higher than 1.");
}
set_reg_incfactor(regfactor);
set_reg_decfactor(regfactor);
}
void SolverDDP::set_reg_min(const double regmin) {
if (0. > regmin) {
throw_pretty("Invalid argument: " << "regmin value has to be positive.");
}
reg_min_ = regmin;
}
void SolverDDP::set_regmin(const double regmin) {
if (0. > regmin) {
throw_pretty("Invalid argument: " << "regmin value has to be positive.");
}
reg_min_ = regmin;
}
void SolverDDP::set_reg_max(const double regmax) {
if (0. > regmax) {
throw_pretty("Invalid argument: " << "regmax value has to be positive.");
}
reg_max_ = regmax;
}
void SolverDDP::set_regmax(const double regmax) {
if (0. > regmax) {
throw_pretty("Invalid argument: " << "regmax value has to be positive.");
}
reg_max_ = regmax;
}
void SolverDDP::set_alphas(const std::vector<double>& alphas) {
double prev_alpha = alphas[0];
if (prev_alpha != 1.) {
std::cerr << "Warning: alpha[0] should be 1" << std::endl;
}
for (std::size_t i = 1; i < alphas.size(); ++i) {
double alpha = alphas[i];
if (0. >= alpha) {
throw_pretty("Invalid argument: " << "alpha values has to be positive.");
}
if (alpha >= prev_alpha) {
throw_pretty(
"Invalid argument: " << "alpha values are monotonously decreasing.");
}
prev_alpha = alpha;
}
alphas_ = alphas;
}
void SolverDDP::set_th_stepdec(const double th_stepdec) {
if (0. >= th_stepdec || th_stepdec > 1.) {
throw_pretty(
"Invalid argument: " << "th_stepdec value should between 0 and 1.");
}
th_stepdec_ = th_stepdec;
}
void SolverDDP::set_th_stepinc(const double th_stepinc) {
if (0. >= th_stepinc || th_stepinc > 1.) {
throw_pretty(
"Invalid argument: " << "th_stepinc value should between 0 and 1.");
}
th_stepinc_ = th_stepinc;
}
void SolverDDP::set_th_grad(const double th_grad) {
if (0. > th_grad) {
throw_pretty("Invalid argument: " << "th_grad value has to be positive.");
}
th_grad_ = th_grad;
}
} // namespace crocoddyl