unittest/python/robot_wrapper.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 #
3 # SPDX-License-Identifier: BSD-2-Clause
4 
5 import unittest
6 from pathlib import Path
7 
8 import pinocchio as pin
9 
10 
11 class TestRobotWrapper(unittest.TestCase):
12  def setUp(self):
13  self.current_dir = Path(__file__).parent
14 
16  model_path = self.current_dir.parent / "models" / "test_mjcf.xml"
17  robot = pin.RobotWrapper.BuildFromMJCF(model_path)
18  self.assertEqual(robot.nq, 6)
19  self.assertEqual(robot.nv, 5)
20  self.assertEqual(robot.model.njoints, 4)
21 
23  model_path = self.current_dir.parent / "models" / "test_mjcf.xml"
24  robot = pin.RobotWrapper.BuildFromMJCF(model_path, pin.JointModelFreeFlyer())
25  self.assertEqual(robot.model.names[1], "root_joint")
26 
28  model_path = self.current_dir.parent / "models" / "test_mjcf.xml"
29  name_ = "freeflyer_joint"
30  robot = pin.RobotWrapper.BuildFromMJCF(
31  model_path, pin.JointModelFreeFlyer(), name_
32  )
33  self.assertEqual(robot.model.names[1], name_)
34 
36  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
37  robot = pin.RobotWrapper.BuildFromURDF(
38  model_path, [], pin.JointModelFreeFlyer()
39  )
40  self.assertEqual(robot.model.names[1], "root_joint")
41 
43  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
44  name_ = "freeflyer_joint"
45  robot = pin.RobotWrapper.BuildFromURDF(
46  model_path, [], pin.JointModelFreeFlyer(), name_
47  )
48  self.assertEqual(robot.model.names[1], name_)
49 
51  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
52  package_dir = self.current_dir.parent / "models"
53  robot = pin.RobotWrapper.BuildFromURDF(
54  model_path, str(package_dir), pin.JointModelFreeFlyer()
55  )
56  self.assertEqual(robot.model.names[1], "root_joint")
57 
59  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
60  package_dir = self.current_dir.parent / "models"
61  robot = pin.RobotWrapper.BuildFromURDF(
62  model_path, package_dir, pin.JointModelFreeFlyer()
63  )
64  self.assertEqual(robot.model.names[1], "root_joint")
65 
67  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
68  package_dir = self.current_dir.parent / "models"
69  robot = pin.RobotWrapper.BuildFromURDF(
70  model_path, [str(package_dir)], pin.JointModelFreeFlyer()
71  )
72  self.assertEqual(robot.model.names[1], "root_joint")
73 
75  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
76  package_dir = self.current_dir.parent / "models"
77  robot = pin.RobotWrapper.BuildFromURDF(
78  model_path, [package_dir], pin.JointModelFreeFlyer()
79  )
80  self.assertEqual(robot.model.names[1], "root_joint")
81 
83  model_path = self.current_dir.parent / "models" / "3DOF_planar.urdf"
84  robot = pin.RobotWrapper.BuildFromURDF(
85  model_path, None, pin.JointModelFreeFlyer()
86  )
87  self.assertEqual(robot.model.names[1], "root_joint")
88 
89  @unittest.skipUnless(pin.WITH_SDFORMAT, "Needs SDFORMAT")
91  model_path = self.current_dir.parent.parent / "models" / "simple_humanoid.sdf"
92  mesh_path = self.current_dir.parent.parent / "models"
93  robot = pin.RobotWrapper.BuildFromSDF(
94  model_path, [mesh_path], pin.JointModelFreeFlyer(), verbose=True
95  )
96  self.assertEqual(robot.model.names[1], "root_joint")
97 
98  @unittest.skipUnless(pin.WITH_SDFORMAT, "Needs SDFORMAT")
100  model_path = self.current_dir.parent.parent / "models" / "simple_humanoid.sdf"
101  mesh_path = self.current_dir.parent.parent / "models"
102  name_ = "freeflyer_joint"
103  robot = pin.RobotWrapper.BuildFromSDF(
104  model_path, [mesh_path], pin.JointModelFreeFlyer(), root_joint_name=name_
105  )
106  self.assertEqual(robot.model.names[1], name_)
107 
108 
109 if __name__ == "__main__":
110  unittest.main()
robot_wrapper.TestRobotWrapper.current_dir
current_dir
Definition: unittest/python/robot_wrapper.py:13
robot_wrapper.TestRobotWrapper.setUp
def setUp(self)
Definition: unittest/python/robot_wrapper.py:12
robot_wrapper.TestRobotWrapper.test_urdf_with_None_pkg_dirs
def test_urdf_with_None_pkg_dirs(self)
Definition: unittest/python/robot_wrapper.py:82
robot_wrapper.TestRobotWrapper.test_mjcf_without_root_joint
def test_mjcf_without_root_joint(self)
Definition: unittest/python/robot_wrapper.py:15
robot_wrapper.TestRobotWrapper.test_urdf_with_path_pkg_dirs
def test_urdf_with_path_pkg_dirs(self)
Definition: unittest/python/robot_wrapper.py:58
robot_wrapper.TestRobotWrapper.test_mjcf_with_root_joint
def test_mjcf_with_root_joint(self)
Definition: unittest/python/robot_wrapper.py:22
robot_wrapper.TestRobotWrapper.test_urdf_with_path_list_pkg_dirs
def test_urdf_with_path_list_pkg_dirs(self)
Definition: unittest/python/robot_wrapper.py:74
robot_wrapper.TestRobotWrapper.test_sdf_with_root_joint_and_root_joint_name
def test_sdf_with_root_joint_and_root_joint_name(self)
Definition: unittest/python/robot_wrapper.py:99
robot_wrapper.TestRobotWrapper
Definition: unittest/python/robot_wrapper.py:11
robot_wrapper.TestRobotWrapper.test_urdf_with_str_pkg_dirs
def test_urdf_with_str_pkg_dirs(self)
Definition: unittest/python/robot_wrapper.py:50
robot_wrapper.TestRobotWrapper.test_mjcf_with_root_joint_and_root_joint_name
def test_mjcf_with_root_joint_and_root_joint_name(self)
Definition: unittest/python/robot_wrapper.py:27
robot_wrapper.TestRobotWrapper.test_urdf_with_root_joint
def test_urdf_with_root_joint(self)
Definition: unittest/python/robot_wrapper.py:35
robot_wrapper.TestRobotWrapper.test_urdf_with_root_joint_and_root_joint_name
def test_urdf_with_root_joint_and_root_joint_name(self)
Definition: unittest/python/robot_wrapper.py:42
robot_wrapper.TestRobotWrapper.test_urdf_with_str_list_pkg_dirs
def test_urdf_with_str_list_pkg_dirs(self)
Definition: unittest/python/robot_wrapper.py:66
robot_wrapper.TestRobotWrapper.test_sdf_with_root_joint
def test_sdf_with_root_joint(self)
Definition: unittest/python/robot_wrapper.py:90


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:32