aligator  0.16.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
expose-problem.cpp
Go to the documentation of this file.
1
7#include <eigenpy/deprecation-policy.hpp>
8
9namespace aligator {
10namespace python {
12 using context::ConstVectorRef;
15 using context::Scalar;
21
22 using PolyUnaryFunction = xyz::polymorphic<UnaryFunction>;
23 using PolyFunction = xyz::polymorphic<context::StageFunction>;
24 using PolyStage = xyz::polymorphic<StageModel>;
25 using PolyCost = xyz::polymorphic<CostAbstract>;
26 using PolyManifold = xyz::polymorphic<Manifold>;
27 using PolySet = xyz::polymorphic<context::ConstraintSet>;
28
29 bp::class_<TrajOptProblem>("TrajOptProblem", "Define a shooting problem.",
30 bp::no_init)
31 .def(
32 bp::init<PolyUnaryFunction, const std::vector<PolyStage> &, PolyCost>(
33 "Constructor adding the initial constraint explicitly.",
34 ("self"_a, "init_constraint", "stages", "term_cost")))
35 .def(bp::init<ConstVectorRef, const std::vector<PolyStage> &, PolyCost>(
36 "Constructor for an initial value problem.",
37 ("self"_a, "x0", "stages", "term_cost")))
38 .def(bp::init<PolyUnaryFunction, PolyCost>(
39 "Constructor adding the initial constraint explicitly (without "
40 "stages).",
41 ("self"_a, "init_constraint", "term_cost")))
42 .def(bp::init<ConstVectorRef, const int, PolyManifold, PolyCost>(
43 "Constructor for an initial value problem (without pre-allocated "
44 "stages).",
45 ("self"_a, "x0", "nu", "space", "term_cost")))
46 .def<void (TrajOptProblem::*)(const PolyStage &)>(
47 "addStage", &TrajOptProblem::addStage, ("self"_a, "new_stage"),
48 "Add a stage to the problem.")
49 .def_readonly("stages", &TrajOptProblem::stages_,
50 "Stages of the shooting problem.")
51 .def_readwrite("term_cost", &TrajOptProblem::term_cost_,
52 "Problem terminal cost.")
53 .def_readwrite("term_constraints", &TrajOptProblem::term_cstrs_,
54 "Set of terminal constraints.")
55 .add_property("num_steps", &TrajOptProblem::numSteps,
56 "Number of stages in the problem.CostPtr")
57 .add_property("x0_init", &TrajOptProblem::getInitState,
58 &TrajOptProblem::setInitState, "Initial state.")
59 .add_property("init_constraint", &TrajOptProblem::init_constraint_,
60 "Get initial state constraint.")
61 .def<void (TrajOptProblem::*)(const PolyFunction &, const PolySet &)>(
62 "addTerminalConstraint", &TrajOptProblem::addTerminalConstraint,
63 ("self"_a, "func", "set"), "Add a terminal constraint.")
64 .def("removeTerminalConstraint",
65 &TrajOptProblem::removeTerminalConstraints,
66 eigenpy::deprecated_member<>(
67 "This method is deprecated (due to a typo which was fixed). Use "
68 "removeTerminalConstraints instead."),
69 ("self"_a), "Remove all terminal constraints.")
70 .def("removeTerminalConstraints",
71 &TrajOptProblem::removeTerminalConstraints, "self"_a,
72 "Remove all terminal constraints.")
73 .def("evaluate", &TrajOptProblem::evaluate,
74 ("self"_a, "xs", "us", "prob_data", "num_threads"_a = 1),
75 "Evaluate the problem costs, dynamics, and constraints.")
76 .def("computeDerivatives", &TrajOptProblem::computeDerivatives,
77 ("self"_a, "xs", "us", "prob_data", "num_threads"_a = 1,
78 "compute_second_order"_a = true),
79 "Evaluate the problem derivatives. Call `evaluate()` first.")
80 .def("replaceStageCircular", &TrajOptProblem::replaceStageCircular,
81 ("self"_a, "model"),
82 "Circularly replace the last stage in the problem, dropping the "
83 "first stage.")
84 .def("checkIntegrity", &TrajOptProblem::checkIntegrity, ("self"_a));
85
86 bp::def("computeTrajectoryCost", computeTrajectoryCost<Scalar>,
87 ("problem_data"_a),
88 "Compute trajectory cost (call evaluate() first!)");
89
90 bp::class_<TrajOptData>(
91 "TrajOptData", "Data struct for shooting problems.",
92 bp::init<const TrajOptProblem &>(("self"_a, "problem")))
93 .def_readwrite("init_data", &TrajOptData::init_data,
94 "Initial stage contraint data.")
95 .def_readwrite("cost", &TrajOptData::cost_,
96 "Current cost of the TO problem.")
97 .def_readwrite("term_cost", &TrajOptData::term_cost_data,
98 "Terminal cost data.")
99 .def_readwrite("term_constraint", &TrajOptData::term_cstr_data,
100 "Terminal constraint data.")
101 .def_readonly("stage_data", &TrajOptData::stage_data,
102 "Data for each stage.");
103}
104
105} // namespace python
106} // namespace aligator
StageModelTpl< Scalar > StageModel
Definition context.hpp:29
CostAbstractTpl< Scalar > CostAbstract
Definition context.hpp:25
ManifoldAbstractTpl< Scalar > Manifold
Definition context.hpp:14
StageDataTpl< Scalar > StageData
Definition context.hpp:30
UnaryFunctionTpl< Scalar > UnaryFunction
Definition context.hpp:18
TrajOptProblemTpl< Scalar > TrajOptProblem
Definition context.hpp:34
TrajOptDataTpl< Scalar > TrajOptData
Definition context.hpp:35
The Python bindings.
Definition blk-matrix.hpp:7
xyz::polymorphic< StageFunction > PolyFunction
xyz::polymorphic< Manifold > PolyManifold
xyz::polymorphic< UnaryFunction > PolyUnaryFunction
xyz::polymorphic< CostAbstract > PolyCost
void exposeProblem()
Expose TrajOptProblem.
xyz::polymorphic< ConstraintSet > PolySet
Main package namespace.
Scalar computeTrajectoryCost(const TrajOptDataTpl< Scalar > &problem_data)
Helper for computing the trajectory cost (from pre-computed problem data).