-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbind_objective.cpp
More file actions
64 lines (55 loc) · 2.86 KB
/
bind_objective.cpp
File metadata and controls
64 lines (55 loc) · 2.86 KB
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
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include "cddp_core/objective.hpp"
namespace py = pybind11;
// Trampoline for NonlinearObjective
class PyNonlinearObjective : public cddp::NonlinearObjective {
public:
using cddp::NonlinearObjective::NonlinearObjective;
double running_cost(const Eigen::VectorXd& state,
const Eigen::VectorXd& control,
int index) const override {
PYBIND11_OVERRIDE(double, cddp::NonlinearObjective,
running_cost, state, control, index);
}
double terminal_cost(const Eigen::VectorXd& final_state) const override {
PYBIND11_OVERRIDE(double, cddp::NonlinearObjective,
terminal_cost, final_state);
}
double evaluate(const std::vector<Eigen::VectorXd>& states,
const std::vector<Eigen::VectorXd>& controls) const override {
PYBIND11_OVERRIDE(double, cddp::NonlinearObjective,
evaluate, states, controls);
}
};
void bind_objective(py::module_& m) {
py::class_<cddp::Objective>(m, "Objective")
.def("evaluate", &cddp::Objective::evaluate,
py::arg("states"), py::arg("controls"))
.def("running_cost", &cddp::Objective::running_cost,
py::arg("state"), py::arg("control"), py::arg("index"))
.def("terminal_cost", &cddp::Objective::terminal_cost,
py::arg("final_state"))
.def("get_reference_state", &cddp::Objective::getReferenceState)
.def("set_reference_state", &cddp::Objective::setReferenceState,
py::arg("reference_state"))
.def("set_reference_states", &cddp::Objective::setReferenceStates,
py::arg("reference_states"));
py::class_<cddp::QuadraticObjective, cddp::Objective>(m, "QuadraticObjective")
.def(py::init<const Eigen::MatrixXd&, const Eigen::MatrixXd&,
const Eigen::MatrixXd&, const Eigen::VectorXd&,
const std::vector<Eigen::VectorXd>&, double>(),
py::arg("Q"), py::arg("R"), py::arg("Qf"),
py::arg("reference_state") = Eigen::VectorXd::Zero(0),
py::arg("reference_states") = std::vector<Eigen::VectorXd>(),
py::arg("timestep") = 0.1)
.def_property_readonly("Q", &cddp::QuadraticObjective::getQ)
.def_property_readonly("R", &cddp::QuadraticObjective::getR)
.def_property_readonly("Qf", &cddp::QuadraticObjective::getQf)
.def("set_Q", &cddp::QuadraticObjective::setQ, py::arg("Q"))
.def("set_R", &cddp::QuadraticObjective::setR, py::arg("R"))
.def("set_Qf", &cddp::QuadraticObjective::setQf, py::arg("Qf"));
py::class_<cddp::NonlinearObjective, cddp::Objective, PyNonlinearObjective>(m, "NonlinearObjective")
.def(py::init<double>(), py::arg("timestep") = 0.1);
}