@@ -11,21 +11,23 @@ using namespace pybind11::literals;
1111
1212class PyTinySolver {
1313 public:
14- PyTinySolver (Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, // A, B
14+ PyTinySolver (Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, // A, B, fdyn
1515 Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, // Q, R
16- float , int , int , int , // rho, nx, nu, N
16+ double , int , int , int , // rho, nx, nu, N
1717 Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, // x_min, x_max
1818 Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, // u_min, u_max
1919 TinySettings*, int ); // settings, verbosity
2020 void set_x0 (Eigen::Ref<tinyVector>);
2121 void set_x_ref (Eigen::Ref<tinyMatrix>);
2222 void set_u_ref (Eigen::Ref<tinyMatrix>);
23+ void set_bound_constraints (Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>,
24+ Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>);
2325 void set_sensitivity_matrices (
2426 Eigen::Ref<tinyMatrix> dK,
2527 Eigen::Ref<tinyMatrix> dP,
2628 Eigen::Ref<tinyMatrix> dC1,
2729 Eigen::Ref<tinyMatrix> dC2,
28- float rho = 0.0 ,
30+ double rho = 0.0 , // CHANGED: float -> double
2931 int verbose = 0 );
3032 void set_cache_terms (
3133 Eigen::Ref<tinyMatrix> Kinf,
@@ -55,9 +57,10 @@ class PyTinySolver {
5557PyTinySolver::PyTinySolver (
5658 Eigen::Ref<tinyMatrix> A,
5759 Eigen::Ref<tinyMatrix> B,
60+ Eigen::Ref<tinyMatrix> fdyn,
5861 Eigen::Ref<tinyMatrix> Q,
5962 Eigen::Ref<tinyMatrix> R,
60- float rho,
63+ double rho,
6164 int nx,
6265 int nu,
6366 int N,
@@ -68,7 +71,14 @@ PyTinySolver::PyTinySolver(
6871 TinySettings *settings,
6972 int verbose) {
7073
71- int status = tiny_setup (&this ->_solver , A, B, Q, R, rho, nx, nu, N, x_min, x_max, u_min, u_max, verbose);
74+
75+ int status = tiny_setup (&this ->_solver , A, B, fdyn, Q, R, rho, nx, nu, N, verbose);
76+
77+
78+ if (status == 0 ) {
79+ status = tiny_set_bound_constraints (this ->_solver , x_min, x_max, u_min, u_max);
80+ }
81+
7282 this ->_solver ->settings = settings;
7383 if (status) {
7484 std::string message = " Error during setup" ;
@@ -88,12 +98,20 @@ void PyTinySolver::set_u_ref(Eigen::Ref<tinyMatrix> u_ref) {
8898 tiny_set_u_ref (this ->_solver , u_ref);
8999}
90100
101+ void PyTinySolver::set_bound_constraints (Eigen::Ref<tinyMatrix> x_min, Eigen::Ref<tinyMatrix> x_max,
102+ Eigen::Ref<tinyMatrix> u_min, Eigen::Ref<tinyMatrix> u_max) {
103+ int status = tiny_set_bound_constraints (this ->_solver , x_min, x_max, u_min, u_max);
104+ if (status) {
105+ throw py::value_error (" Error setting bound constraints" );
106+ }
107+ }
108+
91109void PyTinySolver::set_sensitivity_matrices (
92110 Eigen::Ref<tinyMatrix> dK,
93111 Eigen::Ref<tinyMatrix> dP,
94112 Eigen::Ref<tinyMatrix> dC1,
95113 Eigen::Ref<tinyMatrix> dC2,
96- float rho,
114+ double rho,
97115 int verbose) {
98116 // Create copies of the matrices to ensure they remain valid
99117 tinyMatrix dK_copy = dK;
@@ -293,12 +311,13 @@ PYBIND11_MODULE(ext_tinympc, m) {
293311
294312 // Solver
295313 py::class_<PyTinySolver>(m, " TinySolver" , py::module_local ())
296- .def (py::init<Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, float , int , int , int , Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, TinySettings*, int >(),
297- " A" _a.noconvert (), " B" _a.noconvert (), " Q" _a.noconvert (), " R" _a.noconvert (), " rho" _a, " nx" _a, " nu" _a, " N" _a, " x_min" _a.noconvert (), " x_max" _a.noconvert (), " u_min" _a.noconvert (), " u_max" _a.noconvert (), " settings" _a, " verbose" _a)
314+ .def (py::init<Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, double , int , int , int , Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, Eigen::Ref<tinyMatrix>, TinySettings*, int >(),
315+ " A" _a.noconvert (), " B" _a.noconvert (), " fdyn " _a. noconvert (), " Q" _a.noconvert (), " R" _a.noconvert (), " rho" _a, " nx" _a, " nu" _a, " N" _a, " x_min" _a.noconvert (), " x_max" _a.noconvert (), " u_min" _a.noconvert (), " u_max" _a.noconvert (), " settings" _a, " verbose" _a)
298316 .def_property_readonly (" solution" , &PyTinySolver::get_solution)
299317 .def (" set_x0" , &PyTinySolver::set_x0)
300318 .def (" set_x_ref" , &PyTinySolver::set_x_ref)
301319 .def (" set_u_ref" , &PyTinySolver::set_u_ref)
320+ .def (" set_bound_constraints" , &PyTinySolver::set_bound_constraints)
302321 .def (" update_settings" , &PyTinySolver::update_settings)
303322 .def (" set_sensitivity_matrices" , &PyTinySolver::set_sensitivity_matrices,
304323 " dK" _a.noconvert (), " dP" _a.noconvert (),
0 commit comments