@@ -10,34 +10,60 @@ using namespace simple_mpc;
1010
1111BOOST_AUTO_TEST_CASE (interpolate)
1212{
13- long nx = 27 ;
14- long nu = 12 ;
15- long nv = 18 ;
16- long nf = 12 ;
17- double MPC_timestep = 0.01 ;
18- Interpolator interpolator = Interpolator (nx, nv, nu, nf, MPC_timestep);
13+ Model model;
14+ // Load pinocchio model from example robot data
15+ const std::string urdf_path = EXAMPLE_ROBOT_DATA_MODEL_DIR " /solo_description/robots/solo12.urdf" ;
16+ const std::string srdf_path = EXAMPLE_ROBOT_DATA_MODEL_DIR " /solo_description/srdf/solo.srdf" ;
17+
18+ pinocchio::urdf::buildModel (urdf_path, JointModelFreeFlyer (), model);
19+ double timestep = 0.01 ;
20+ StateInterpolator interpolator = StateInterpolator (model);
1921
2022 std::vector<Eigen::VectorXd> xs;
21- std::vector<Eigen::VectorXd> us;
22- std::vector<Eigen::VectorXd> ddqs;
23- std::vector<Eigen::VectorXd> forces;
2423 for (std::size_t i = 0 ; i < 4 ; i++)
2524 {
26- xs.push_back (Eigen::Vector<double , 27 >::Random ());
27- us.push_back (Eigen::Vector<double , 12 >::Random ());
28- ddqs.push_back (Eigen::Vector<double , 18 >::Random ());
29- forces.push_back (Eigen::Vector<double , 12 >::Random ());
25+ Eigen::VectorXd x0 (model.nq + model.nv );
26+ x0.tail (model.nv ).setRandom ();
27+ x0.head (model.nq ) = pinocchio::neutral (model);
28+ Eigen::VectorXd dq (model.nv );
29+ dq.setRandom ();
30+ pinocchio::integrate (model, x0.head (model.nq ), dq, x0.head (model.nq ));
31+
32+ xs.push_back (x0);
33+ }
34+ double delay = 0.02 ;
35+
36+ Eigen::VectorXd x_interp (model.nq + model.nv );
37+ interpolator.interpolate (delay, timestep, xs, x_interp);
38+
39+ BOOST_CHECK (xs[2 ].isApprox (x_interp));
40+ }
41+
42+ BOOST_AUTO_TEST_CASE (linear_interpolate)
43+ {
44+ Model model;
45+ // Load pinocchio model from example robot data
46+ const std::string urdf_path = EXAMPLE_ROBOT_DATA_MODEL_DIR " /solo_description/robots/solo12.urdf" ;
47+ const std::string srdf_path = EXAMPLE_ROBOT_DATA_MODEL_DIR " /solo_description/srdf/solo.srdf" ;
48+
49+ pinocchio::urdf::buildModel (urdf_path, JointModelFreeFlyer (), model);
50+ double timestep = 0.01 ;
51+ LinearInterpolator interpolator = LinearInterpolator ((size_t )model.nv );
52+
53+ std::vector<Eigen::VectorXd> vs;
54+ for (std::size_t i = 0 ; i < 4 ; i++)
55+ {
56+ Eigen::VectorXd v0 (model.nv );
57+ v0.setRandom ();
58+
59+ vs.push_back (v0);
3060 }
3161 double delay = 0.02 ;
3262
33- interpolator.interpolate (delay, xs, us, ddqs, forces);
63+ Eigen::VectorXd v_interp (model.nv );
64+ interpolator.interpolate (delay, timestep, vs, v_interp);
3465
35- BOOST_CHECK (xs[2 ].isApprox (interpolator.x_interpolated_ ));
36- BOOST_CHECK (us[2 ].isApprox (interpolator.u_interpolated_ ));
37- BOOST_CHECK (ddqs[2 ].isApprox (interpolator.a_interpolated_ ));
38- BOOST_CHECK (forces[2 ].isApprox (interpolator.forces_interpolated_ ));
39- BOOST_CHECK (interpolator.step_nb_ == 2 );
40- BOOST_CHECK (interpolator.step_progress_ == 0 .);
66+ BOOST_CHECK (vs[2 ].isApprox (v_interp));
4167}
4268
4369BOOST_AUTO_TEST_SUITE_END ()
0 commit comments