moveit2
The MoveIt Motion Planning Framework for ROS 2.
test_robot_model.py
Go to the documentation of this file.
1 import unittest
2 from test_moveit.core.robot_model import JointModelGroup, RobotModel
3 
4 # TODO (peterdavidfagan): depend on moveit_resources package directly.
5 # (https://github.com/peterdavidfagan/moveit2/blob/moveit_py/moveit_core/utils/src/robot_model_test_utils.cpp)
6 
7 import os
8 
9 dir_path = os.path.dirname(os.path.realpath(__file__))
10 URDF_FILE = "{}/fixtures/panda.urdf".format(dir_path)
11 SRDF_FILE = "{}/fixtures/panda.srdf".format(dir_path)
12 
13 
15  """Helper function that returns a RobotModel instance."""
16  return RobotModel(urdf_xml_path=URDF_FILE, srdf_xml_path=SRDF_FILE)
17 
18 
19 class TestRobotModel(unittest.TestCase):
21  """
22  Test that the RobotModel can be initialized with xml filepaths.
23  """
24  robot = get_robot_model()
25  self.assertIsInstance(robot, RobotModel)
26 
27  def test_name_property(self):
28  """
29  Test that the RobotModel name property returns the correct name.
30  """
31  robot = get_robot_model()
32  self.assertEqual(robot.name, "panda")
33 
35  """
36  Test that the RobotModel model_frame property returns the correct name.
37  """
38  robot = get_robot_model()
39  self.assertEqual(robot.model_frame, "world")
40 
42  """
43  Test that the RobotModel root_link property returns the correct name.
44  """
45  robot = get_robot_model()
46  self.assertEqual(robot.root_joint_name, "virtual_joint")
47 
49  """
50  Test that the RobotModel joint_model_group_names property returns the correct names.
51  """
52  robot = get_robot_model()
53  self.assertCountEqual(
54  robot.joint_model_group_names, ["panda_arm", "hand", "panda_arm_hand"]
55  )
56 
58  """
59  Test that the RobotModel joint_model_groups returns a list of JointModelGroups.
60  """
61  robot = get_robot_model()
62  self.assertIsInstance(robot.joint_model_groups[0], JointModelGroup)
63 
65  """
66  Test that the RobotModel has_joint_model_group returns True for existing groups.
67  """
68  robot = get_robot_model()
69  self.assertTrue(robot.has_joint_model_group("panda_arm"))
70  self.assertFalse(robot.has_joint_model_group("The answer is 42."))
71 
73  """
74  Test that the RobotModel get_joint_model_group returns the correct group.
75  """
76  robot = get_robot_model()
77  jmg = robot.get_joint_model_group("panda_arm")
78  self.assertIsInstance(jmg, JointModelGroup)
79  self.assertEqual(jmg.name, "panda_arm")
80 
81 
82 if __name__ == "__main__":
83  unittest.main()