test_config.cpp 4.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11

/*--------STD-------------*/
#include <sstream>

/*-----------BOOST TEST SUITE-------------*/
#define BOOST_TEST_MODULE sot_dynamic_config
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <boost/test/output_test_stream.hpp>

/*-----------SOT DYNAMIC ------------*/
12
#include <sot-dynamic-pinocchio/dynamic-pinocchio.h>
13
14
15
16
17
18
19
20
21
#include <sot/core/debug.hh>

/*-----------DYNAMIC GRAPH ------------*/
#include <dynamic-graph/linear-algebra.h>
#include <sot/core/exception-abstract.hh>


/*-----------PINOCCHIO-------------*/
#include <pinocchio/multibody/model.hpp>
22
#include <pinocchio/parsers/urdf.hpp>
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


using namespace dynamicgraph::sot;


#define MATRIX_BOOST_REQUIRE_CLOSE(N, M, LEFT, RIGHT, TOLERANCE)	\
  for (unsigned i = 0; i < N; ++i)					\
    for (unsigned j = 0; j < M; ++j)					\
      BOOST_REQUIRE_CLOSE(LEFT (i, j), RIGHT (i, j), TOLERANCE)

/* ----- TEST SIGNAL CLASS -----*/

BOOST_AUTO_TEST_CASE (config)
{

  /*-----------------------CONSTRUCTOR-----------------------------------------*/
  Dynamic dynamic_("sot_dynamic_test");
 
  /*------------------------CONFIG-------------------------------------------*/
  //Create Empty Robot
  dynamic_.createRobot();
  BOOST_CHECK_EQUAL(dynamic_.m_model.nbody,1);
  BOOST_CHECK_EQUAL(std::strcmp(dynamic_.m_model.names[0].c_str(),"universe"),0);

  //Parse urdf file
  dynamic_.setUrdfFile("urdf/two_link.urdf");
49
50
  dynamic_.parseUrdfFile();
  dynamic_.displayModel();  
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  BOOST_CHECK_EQUAL(dynamic_.m_model.nbody,3);
  BOOST_CHECK_EQUAL(std::strcmp(dynamic_.m_model.names[0].c_str(),"universe"),0);
  BOOST_CHECK_EQUAL(std::strcmp(dynamic_.m_model.names[1].c_str(),"JOINT1"),0);
  BOOST_CHECK_EQUAL(std::strcmp(dynamic_.m_model.names[2].c_str(),"JOINT2"),0);

  //CreateJoint and AddBody
  se3::SE3 joint_3_pos(Eigen::Matrix3d::Identity(),
		       (Eigen::Vector3d() << 1,0,0).finished());
  dynamic_.createJoint("JOINT3","JointModelRZ",joint_3_pos.toHomogeneousMatrix());
  dynamic_.addBody("CHILD2","JOINT3","CHILD3");
  BOOST_CHECK_EQUAL(dynamic_.m_model.nbody,4);
  BOOST_CHECK_EQUAL(dynamic_.m_model.nq,3);
  BOOST_CHECK_EQUAL(std::strcmp(dynamic_.m_model.names[3].c_str(),"JOINT3"),0);

  //Setter and Getter
  dynamic_.setMass("CHILD3",10);
  BOOST_CHECK_EQUAL(dynamic_.m_model.inertias[3].mass(),10);

  Eigen::Vector3d vx; vx<<0.5,0,0;
  dynamic_.setLocalCenterOfMass("CHILD3", vx);
  MATRIX_BOOST_REQUIRE_CLOSE(3, 1, dynamic_.m_model.inertias[3].lever(), vx, 0.0001);
  
  dynamic_.setInertiaMatrix("CHILD3",Eigen::Matrix3d::Identity());
  MATRIX_BOOST_REQUIRE_CLOSE(3, 3, dynamic_.m_model.inertias[3].inertia(), 
			     Eigen::Matrix3d::Identity(), 0.0001);

  dynamicgraph::Vector result_vec;
  dynamic_.setDofBounds("JOINT3",0,0,1.57);
  dynamic_.getLowerPositionLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,Eigen::Vector3d::Zero(), 0.0001);

  dynamic_.getUpperPositionLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,
			     (Eigen::Vector3d() << 3.14,3.14,1.57).finished(), 0.0001);

  dynamic_.setLowerPositionLimit("JOINT3",(Eigen::Matrix<double,1,1>() << 0.2).finished());
  dynamic_.getLowerPositionLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,
			     (Eigen::Vector3d() << 0,0,0.2).finished(), 0.0001);

  dynamic_.setLowerPositionLimit("JOINT3",0.12);
  dynamic_.getLowerPositionLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,
			     (Eigen::Vector3d() << 0,0,0.12).finished(), 0.0001);

  dynamic_.setUpperPositionLimit("JOINT3",2.12);
  dynamic_.getUpperPositionLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,
			     (Eigen::Vector3d() << 3.14,3.14,2.12).finished(), 0.0001);

  dynamic_.setMaxVelocityLimit("JOINT3",9.12);
  dynamic_.getUpperVelocityLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,
			     (Eigen::Vector3d() << 10,10,9.12).finished(), 0.0001);

  dynamic_.setMaxEffortLimit("JOINT3",9.12);
  dynamic_.getMaxEffortLimits(result_vec,0);
  MATRIX_BOOST_REQUIRE_CLOSE(3,1,result_vec,
			     (Eigen::Vector3d() << 12,12,9.12).finished(), 0.0001);
}