367 auto opti = casadi::Opti();
371 auto X = opti.variable(6, N+1);
372 auto P = opti.variable(4);
373 auto F = opti.variable(2, N);
374 auto cost = opti.variable();
377 X0<< 0.0, 0.2, 0.2, 0.5, -0.1, 0.1;
381 Xf<< 0.5, 0.23, -M_PI/4., 0.8, 0.8, 0.1;
383 cost = (
X(0,N) - Xf(0)) * (
X(0,N) - Xf(0))
384 + (
X(1,N) - Xf(1)) * (
X(1,N) - Xf(1))
385 + (
X(2,N) - Xf(2)) * (
X(2,N) - Xf(2))
386 + (
X(3,N) - Xf(3)) * (
X(3,N) - Xf(3))
387 + (
X(4,N) - Xf(4)) * (
X(4,N) - Xf(4))
388 + (
X(5,N) - Xf(5)) * (
X(5,N) - Xf(5));
397 for (
int k = 0; k < N; ++k) {
399 auto X_next =
X(all, k) + dt * dX;
400 opti.subject_to(
X(all, k + 1) == X_next);
403 opti.subject_to(-mu * F(1,k) <= F(0, k) <= mu* F(1,k));
404 opti.subject_to(0<=F(1,k) <= 300.);
406 opti.subject_to (-0.15 <= P(0) <= 0.15);
407 opti.subject_to (-0.15 <= P(2) <= 0.15);
408 opti.subject_to (P(1) == 0.);
409 opti.subject_to (P(3) == 0.);
412 opti.subject_to(F(1, N_fc) == 0.);
414 for(
int i(0); i<6; ++i){
415 opti.subject_to(
X(i, 1) == X0(i));
418 opti.solver(
"ipopt");
419 auto sol = opti.solve();
428 for(
int k(0); k<N; ++k){
429 std::vector<double> x_std_vec = std::vector<double>(sol.value(
X(all, k)));
430 std::vector<double> x_next_std_vec = std::vector<double>(sol.value(
X(all, k+1)));
431 std::vector<double>
f = std::vector<double>(sol.value(F(all, k)));
432 std::vector<double> p = std::vector<double>(sol.value(P(all)));
446 for(
int i(0); i<6; ++i){
447 x_current[i] = x_std_vec[i];
448 x_next[i] = x_next_std_vec[i];
452 EXPECT_TRUE(
almostEqual(x_next, x_next_eigen, .0001));
458 bool b_matlab_file(
true);
461 string filename =
"jump_result.m";
462 file.open(filename.c_str());
463 file <<
"% Results file from " __FILE__ << endl;
464 file <<
"% Generated " __DATE__
" at " __TIME__ << endl;
468 file <<
"xb= " << std::vector<double>(sol.value(
X(0, all) ) ) <<
";" << endl;
469 file <<
"zb= " << std::vector<double>(sol.value(
X(1, all))) <<
";" << endl;
470 file <<
"theta= " << std::vector<double>(sol.value(
X(2, all))) <<
";" << endl;
471 file <<
"dot_xb= " << std::vector<double>(sol.value(
X(3, all) ) ) <<
";" << endl;
472 file <<
"dot_zb= " << std::vector<double>(sol.value(
X(4, all))) <<
";" << endl;
473 file <<
"dot_theta= " << std::vector<double>(sol.value(
X(5, all))) <<
";" << endl;
475 file <<
"Fx = " << std::vector<double>(sol.value(F(0, all) ) ) <<
";" << endl;
476 file <<
"Fz = " << std::vector<double>(sol.value(F(1, all) ) )<<
";" << endl;
478 file <<
"P = " << std::vector<double>(sol.value(P(all) ) ) <<
";" << endl;
MX simple_dyn(const MX &x, const MX &u, const MX &P, int i)
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
DVec< double > simple_dyn_vec(const DVec< double > &x, const DVec< double > &u, const DVec< double > &P, int i)
MX f(const MX &x, const MX &u)