aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
cost-wrap.hpp
Go to the documentation of this file.
1
3
#pragma once
4
5
#include "
aligator/compat/crocoddyl/fwd.hpp
"
6
#include "
aligator/core/cost-abstract.hpp
"
7
#include <crocoddyl/core/cost-base.hpp>
8
#include <crocoddyl/core/action-base.hpp>
9
10
namespace
aligator::compat::croc
{
11
12
template
<
typename
_Scalar>
13
struct
CrocCostModelWrapperTpl
:
CostAbstractTpl
<_Scalar> {
14
using
Scalar
= _Scalar;
15
ALIGATOR_DYNAMIC_TYPEDEFS
(
Scalar
);
16
using
CrocCostModel
= crocoddyl::CostModelAbstractTpl<Scalar>;
17
using
CrocActionModel
= crocoddyl::ActionModelAbstractTpl<Scalar>;
18
using
Base
=
CostAbstractTpl<Scalar>
;
19
using
BaseData
=
CostDataAbstractTpl<Scalar>
;
20
using
StateWrap
=
StateWrapperTpl<Scalar>
;
21
22
shared_ptr<CrocCostModel>
croc_cost_
;
23
shared_ptr<CrocActionModel>
action_model_
;
24
26
explicit
CrocCostModelWrapperTpl
(shared_ptr<CrocCostModel> cost)
27
:
Base
(
StateWrap
(cost->get_state()), (int)cost->get_nu())
28
,
croc_cost_
(cost) {}
29
31
explicit
CrocCostModelWrapperTpl
(shared_ptr<CrocActionModel> action_model)
32
:
Base
(
StateWrap
(action_model->get_state()), (int)action_model->get_nu())
33
,
action_model_
(action_model) {}
34
35
void
evaluate
(
const
ConstVectorRef &x,
const
ConstVectorRef &u,
36
BaseData
&data)
const
{
37
using
Data =
CrocCostDataWrapperTpl<Scalar>
;
38
Data &d =
static_cast<
Data &
>
(data);
39
if
(
croc_cost_
!= 0) {
40
croc_cost_
->calc(d.croc_cost_data_, x, u);
41
d.value_ = d.croc_cost_data_->cost;
42
}
else
{
43
action_model_
->calc(d.croc_act_data_, x);
44
d.value_ = d.croc_act_data_->cost;
45
}
46
}
47
48
void
computeGradients
(
const
ConstVectorRef &x,
const
ConstVectorRef &u,
49
BaseData
&data)
const
{
50
using
Data =
CrocCostDataWrapperTpl<Scalar>
;
51
Data &d =
static_cast<
Data &
>
(data);
52
if
(
croc_cost_
!= 0) {
53
croc_cost_
->calcDiff(d.croc_cost_data_, x, u);
54
d.Lx_ = d.croc_cost_data_->Lx;
55
d.Lu_ = d.croc_cost_data_->Lu;
56
}
else
{
57
action_model_
->calcDiff(d.croc_act_data_, x);
58
d.Lx_ = d.croc_act_data_->Lx;
59
d.Lu_ = d.croc_act_data_->Lu;
60
}
61
}
62
63
void
computeHessians
(
const
ConstVectorRef &x,
const
ConstVectorRef &u,
64
BaseData
&data)
const
{
65
using
Data =
CrocCostDataWrapperTpl<Scalar>
;
66
Data &d =
static_cast<
Data &
>
(data);
67
if
(
croc_cost_
!= 0) {
68
croc_cost_
->calcDiff(d.croc_cost_data_, x, u);
69
d.Lxx_ = d.croc_cost_data_->Lxx;
70
d.Lxu_ = d.croc_cost_data_->Lxu;
71
d.Luu_ = d.croc_cost_data_->Luu;
72
}
else
{
73
action_model_
->calcDiff(d.croc_act_data_, x);
74
d.Lxx_ = d.croc_act_data_->Lxx;
75
d.Lxu_ = d.croc_act_data_->Lxu;
76
d.Luu_ = d.croc_act_data_->Luu;
77
}
78
}
79
80
shared_ptr<BaseData>
createData
()
const
{
81
if
(
action_model_
!= 0) {
82
shared_ptr<crocoddyl::ActionDataAbstractTpl<Scalar>> am_data =
83
action_model_
->createData();
84
return
std::make_shared<CrocCostDataWrapperTpl<Scalar>>(am_data);
85
}
else
{
86
ALIGATOR_DOMAIN_ERROR
(
"Invalid call. Cannot build Data from"
87
"crocoddyl cost model only."
);
88
}
89
}
90
};
91
92
template
<
typename
Scalar>
93
struct
CrocCostDataWrapperTpl
:
CostDataAbstractTpl
<Scalar> {
94
using
CostData
= ::crocoddyl::CostDataAbstractTpl<Scalar>;
95
using
ActionData
= ::crocoddyl::ActionDataAbstractTpl<Scalar>;
96
using
Base
=
CostDataAbstractTpl<Scalar>
;
97
shared_ptr<CostData>
croc_cost_data_
;
98
shared_ptr<ActionData>
croc_act_data_
;
99
100
explicit
CrocCostDataWrapperTpl
(
const
shared_ptr<CostData> &crocdata)
101
:
Base
((int)crocdata->Lx.rows(), (int)crocdata->Lu.rows())
102
,
croc_cost_data_
(crocdata) {}
103
104
explicit
CrocCostDataWrapperTpl
(
const
shared_ptr<ActionData> &actdata)
105
:
Base
((int)actdata->Lx.rows(), (int)actdata->Lu.rows())
106
,
croc_act_data_
(actdata) {}
107
};
108
109
#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
110
extern
template
struct
CrocCostModelWrapperTpl<context::Scalar>;
111
extern
template
struct
CrocCostDataWrapperTpl<context::Scalar>;
112
#endif
113
114
}
// namespace aligator::compat::croc
cost-abstract.hpp
ALIGATOR_DOMAIN_ERROR
#define ALIGATOR_DOMAIN_ERROR(...)
Definition
exceptions.hpp:16
fwd.hpp
aligator::compat::croc
Headers for the Crocoddyl compatibility module.
Definition
action-model-wrap.hpp:16
aligator::CostAbstractTpl::CostAbstractTpl
CostAbstractTpl(U &&space, const int nu)
Definition
cost-abstract.hpp:28
aligator::CostDataAbstractTpl
Data struct for CostAbstractTpl.
Definition
cost-abstract.hpp:73
aligator::CostDataAbstractTpl< Scalar >::CostDataAbstractTpl
CostDataAbstractTpl(const int ndx, const int nu)
Definition
cost-abstract.hpp:94
aligator::compat::croc::CrocCostDataWrapperTpl
Definition
cost-wrap.hpp:93
aligator::compat::croc::CrocCostDataWrapperTpl::CrocCostDataWrapperTpl
CrocCostDataWrapperTpl(const shared_ptr< CostData > &crocdata)
Definition
cost-wrap.hpp:100
aligator::compat::croc::CrocCostDataWrapperTpl::ActionData
::crocoddyl::ActionDataAbstractTpl< Scalar > ActionData
Definition
cost-wrap.hpp:95
aligator::compat::croc::CrocCostDataWrapperTpl::CrocCostDataWrapperTpl
CrocCostDataWrapperTpl(const shared_ptr< ActionData > &actdata)
Definition
cost-wrap.hpp:104
aligator::compat::croc::CrocCostDataWrapperTpl::CostData
::crocoddyl::CostDataAbstractTpl< Scalar > CostData
Definition
cost-wrap.hpp:94
aligator::compat::croc::CrocCostDataWrapperTpl::croc_cost_data_
shared_ptr< CostData > croc_cost_data_
Definition
cost-wrap.hpp:97
aligator::compat::croc::CrocCostDataWrapperTpl::Base
CostDataAbstractTpl< Scalar > Base
Definition
cost-wrap.hpp:96
aligator::compat::croc::CrocCostDataWrapperTpl::croc_act_data_
shared_ptr< ActionData > croc_act_data_
Definition
cost-wrap.hpp:98
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::Scalar
Scalar Scalar
Definition
cost-wrap.hpp:14
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::BaseData
CostDataAbstractTpl< Scalar > BaseData
Definition
cost-wrap.hpp:19
aligator::compat::croc::CrocCostModelWrapperTpl::computeGradients
void computeGradients(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const
Compute the cost gradients .
Definition
cost-wrap.hpp:48
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::StateWrap
StateWrapperTpl< Scalar > StateWrap
Definition
cost-wrap.hpp:20
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::action_model_
shared_ptr< CrocActionModel > action_model_
Definition
cost-wrap.hpp:23
aligator::compat::croc::CrocCostModelWrapperTpl::createData
shared_ptr< BaseData > createData() const
Definition
cost-wrap.hpp:80
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::croc_cost_
shared_ptr< CrocCostModel > croc_cost_
Definition
cost-wrap.hpp:22
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::CrocActionModel
crocoddyl::ActionModelAbstractTpl< Scalar > CrocActionModel
Definition
cost-wrap.hpp:17
aligator::compat::croc::CrocCostModelWrapperTpl::CrocCostModelWrapperTpl
CrocCostModelWrapperTpl(shared_ptr< CrocCostModel > cost)
Constructor from a crocoddyl cost model.
Definition
cost-wrap.hpp:26
aligator::compat::croc::CrocCostModelWrapperTpl::computeHessians
void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const
Compute the cost Hessians .
Definition
cost-wrap.hpp:63
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::Base
CostAbstractTpl< Scalar > Base
Definition
cost-wrap.hpp:18
aligator::compat::croc::CrocCostModelWrapperTpl::evaluate
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const
Evaluate the cost function.
Definition
cost-wrap.hpp:35
aligator::compat::croc::CrocCostModelWrapperTpl::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::compat::croc::CrocCostModelWrapperTpl< Scalar >::CrocCostModel
crocoddyl::CostModelAbstractTpl< Scalar > CrocCostModel
Definition
cost-wrap.hpp:16
aligator::compat::croc::CrocCostModelWrapperTpl::CrocCostModelWrapperTpl
CrocCostModelWrapperTpl(shared_ptr< CrocActionModel > action_model)
Constructor using a terminal action model.
Definition
cost-wrap.hpp:31
aligator::compat::croc::StateWrapperTpl
Wraps a crocoddyl::StateAbstractTpl to a manifold (aligator::ManifoldAbstractTpl).
Definition
state-wrap.hpp:14
include
aligator
compat
crocoddyl
cost-wrap.hpp
Generated by
1.17.0