Skip to content

Commit 4086e07

Browse files
author
Megane Millan
committed
Adding unittest for new api
1 parent f3d9638 commit 4086e07

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

unittest/mjcf.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,21 @@ BOOST_AUTO_TEST_CASE(build_model_no_root_joint)
10921092
BOOST_CHECK_EQUAL(model_m.nq, 29);
10931093
}
10941094

1095+
BOOST_AUTO_TEST_CASE(build_model_with_root_joint_name)
1096+
{
1097+
const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.xml");
1098+
const std::string dir = PINOCCHIO_MODEL_DIR;
1099+
1100+
pinocchio::Model model;
1101+
pinocchio::mjcf::buildModel(filename, pinocchio::JointModelFreeFlyer(), model);
1102+
BOOST_CHECK(model.names[1] == "root_joint");
1103+
1104+
pinocchio::Model model_name;
1105+
const std::string name_ = "freeFlyer_joint";
1106+
pinocchio::mjcf::buildModel(filename, pinocchio::JointModelFreeFlyer(), name_, model_name);
1107+
BOOST_CHECK(model_name.names[1] == name_);
1108+
}
1109+
10951110
#ifdef PINOCCHIO_WITH_URDFDOM
10961111
/// @brief Test all the data of the humanoid model (Need to find the urdf yet)
10971112
/// @param

unittest/python/robot_wrapper.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestRobotWrapper(unittest.TestCase):
1212
def setUp(self):
1313
self.current_file = os.path.dirname(str(os.path.abspath(__file__)))
1414

15-
def test_mjcf(self):
15+
def test_mjcf_without_root_joint(self):
1616
model_path = os.path.abspath(
1717
os.path.join(self.current_file, "../models/test_mjcf.xml")
1818
)
@@ -21,6 +21,59 @@ def test_mjcf(self):
2121
self.assertEqual(robot.nv, 5)
2222
self.assertEqual(robot.model.njoints, 4)
2323

24+
def test_mjcf_with_root_joint(self):
25+
model_path = os.path.abspath(
26+
os.path.join(self.current_file, "../models/test_mjcf.xml")
27+
)
28+
robot = pin.RobotWrapper.BuildFromMJCF(model_path, pin.JointModelFreeFlyer())
29+
self.assertEqual(robot.model.names[1], "root_joint")
30+
31+
def test_mjcf_with_root_joint_and_root_joint_name(self):
32+
model_path = os.path.abspath(
33+
os.path.join(self.current_file, "../models/test_mjcf.xml")
34+
)
35+
name_ = "freeflyer_joint"
36+
robot = pin.RobotWrapper.BuildFromMJCF(
37+
model_path, pin.JointModelFreeFlyer(), name_
38+
)
39+
self.assertEqual(robot.model.names[1], name_)
40+
41+
def test_urdf_with_root_joint(self):
42+
model_path = os.path.abspath(
43+
os.path.join(self.current_file, "../models/3DOF_planar.urdf")
44+
)
45+
robot = pin.RobotWrapper.BuildFromURDF(
46+
model_path, [], pin.JointModelFreeFlyer()
47+
)
48+
self.assertEqual(robot.model.names[1], "root_joint")
49+
50+
def test_urdf_with_root_joint_and_root_joint_name(self):
51+
model_path = os.path.abspath(
52+
os.path.join(self.current_file, "../models/3DOF_planar.urdf")
53+
)
54+
name_ = "freeflyer_joint"
55+
robot = pin.RobotWrapper.BuildFromURDF(
56+
model_path, [], pin.JointModelFreeFlyer(), name_
57+
)
58+
self.assertEqual(robot.model.names[1], name_)
59+
60+
def test_sdf_with_root_joint(self):
61+
model_path = os.path.abspath(
62+
os.path.join(self.current_file, "../../models/simple_humanoid.sdf")
63+
)
64+
robot = pin.RobotWrapper.BuildFromSDF(model_path, [], pin.JointModelFreeFlyer())
65+
self.assertEqual(robot.model.names[1], "root_joint")
66+
67+
def test_sdf_with_root_joint_and_root_joint_name(self):
68+
model_path = os.path.abspath(
69+
os.path.join(self.current_file, "../../models/simple_humanoid.sdf")
70+
)
71+
name_ = "freeflyer_joint"
72+
robot = pin.RobotWrapper.BuildFromSDF(
73+
model_path, [], pin.JointModelFreeFlyer(), root_joint_name=name_
74+
)
75+
self.assertEqual(robot.model.names[1], name_)
76+
2477

2578
if __name__ == "__main__":
2679
unittest.main()

unittest/sdf.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ BOOST_AUTO_TEST_CASE(build_model_without_rootLink)
6666
BOOST_CHECK(model.nq == 69);
6767
}
6868

69+
BOOST_AUTO_TEST_CASE(build_model_with_root_joint_name)
70+
{
71+
const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.sdf");
72+
const std::string dir = PINOCCHIO_MODEL_DIR;
73+
const std::string rootLinkName = "WAIST_LINK0";
74+
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(pinocchio::RigidConstraintModel) contact_models;
75+
pinocchio::Model model;
76+
pinocchio::sdf::buildModel(
77+
filename, pinocchio::JointModelFreeFlyer(), model, contact_models, rootLinkName);
78+
BOOST_CHECK(model.names[1] == "root_joint");
79+
80+
pinocchio::Model model_name;
81+
const std::string name_ = "freeFlyer_joint";
82+
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(pinocchio::RigidConstraintModel) contact_models_name;
83+
pinocchio::sdf::buildModel(
84+
filename, pinocchio::JointModelFreeFlyer(), name_, model_name, contact_models_name,
85+
rootLinkName);
86+
BOOST_CHECK(model_name.names[1] == name_);
87+
}
88+
6989
BOOST_AUTO_TEST_CASE(compare_model_with_urdf)
7090
{
7191
const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.sdf");

unittest/urdf.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ BOOST_AUTO_TEST_CASE(build_model)
3434
BOOST_CHECK(model.nq == 31);
3535
}
3636

37+
BOOST_AUTO_TEST_CASE(build_model_with_root_joint_name)
38+
{
39+
const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
40+
const std::string dir = PINOCCHIO_MODEL_DIR;
41+
42+
pinocchio::Model model;
43+
pinocchio::urdf::buildModel(filename, pinocchio::JointModelFreeFlyer(), model);
44+
BOOST_CHECK(model.names[1] == "root_joint");
45+
46+
pinocchio::Model model_name;
47+
const std::string name_ = "freeFlyer_joint";
48+
pinocchio::urdf::buildModel(filename, pinocchio::JointModelFreeFlyer(), name_, model_name);
49+
BOOST_CHECK(model_name.names[1] == name_);
50+
}
51+
3752
BOOST_AUTO_TEST_CASE(build_model_simple_humanoid)
3853
{
3954
const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");

0 commit comments

Comments
 (0)