test_arm_finder.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import rostest
5 import unittest
6 from sr_utilities.arm_finder import ArmFinder
7 
8 
9 class TestArmFinder(unittest.TestCase):
10 
12  if rospy.has_param("arm"):
13  rospy.delete_param("arm")
14 
15  if rospy.has_param("hand"):
16  rospy.delete_param("hand")
17 
18  if rospy.has_param("robot_description"):
19  rospy.delete_param("robot_description")
20 
21  arm_finder = ArmFinder()
22  self.assertIsNotNone(arm_finder.get_arm_parameters(), "Parameters extracted.")
23  self.assertIsNotNone(arm_finder.get_arm_joints(), "Joints extracted.")
24 
25  self.assertEqual(len(arm_finder.get_arm_parameters().mapping), 0, "It should be zero mapping")
26  self.assertEqual(len(arm_finder.get_arm_parameters().joint_prefix), 0, "It should be zero joint_prefix")
27  self.assertEqual(len(arm_finder.get_arm_joints().keys()), 0, "It should be zero arm joints")
28 
30  if rospy.has_param("arm"):
31  rospy.delete_param("arm")
32 
33  if rospy.has_param("hand"):
34  rospy.delete_param("hand")
35 
36  if rospy.has_param("robot_description"):
37  rospy.delete_param("robot_description")
38 
39  arm_finder = ArmFinder()
40  self.assertIsNotNone(arm_finder.get_arm_parameters(), "Parameters extracted.")
41  self.assertIsNotNone(arm_finder.get_arm_joints(), "Joints extracted.")
42 
43  self.assertEqual(len(arm_finder.get_arm_parameters().mapping), 0, "It should be zero mapping")
44  self.assertEqual(len(arm_finder.get_arm_parameters().joint_prefix), 0, "It should be zero joint_prefix")
45  self.assertEqual(len(arm_finder.get_arm_joints().keys()), 0, "It should be zero arm joints")
46 
48  if rospy.has_param("arm"):
49  rospy.delete_param("arm")
50 
51  if rospy.has_param("hand"):
52  rospy.delete_param("hand")
53 
54  if rospy.has_param("robot_description"):
55  rospy.delete_param("robot_description")
56 
57  rospy.set_param("robot_description", rospy.get_param("no_hand_one_arm_description"))
58 
59  rospy.set_param("arm/joint_prefix/1", "la_")
60  rospy.set_param("arm/mapping/1", "la")
61 
62  arm_finder = ArmFinder()
63 
64  self.assertIsNotNone(arm_finder.get_arm_parameters(), "Parameters extracted.")
65  self.assertIsNotNone(arm_finder.get_arm_joints(), "Joints extracted.")
66 
67  self.assertEqual(len(arm_finder.get_arm_parameters().mapping), 1, "It should be one mapping")
68  self.assertEqual(len(arm_finder.get_arm_parameters().joint_prefix), 1, "It should be one joint_prefix")
69  self.assertEqual(len(arm_finder.get_arm_joints().keys()), 1, "It should be one arm joints")
70 
71  self.assertIn("la", arm_finder.get_arm_parameters().mapping.values(), "It should be la mapping")
72  self.assertIn("la_", arm_finder.get_arm_parameters().joint_prefix.values(), "It should be la_ prefix")
73  self.assertIn("la", arm_finder.get_arm_joints(), "Maping should be in the joints result")
74 
76  if rospy.has_param("arm"):
77  rospy.delete_param("arm")
78 
79  if rospy.has_param("hand"):
80  rospy.delete_param("hand")
81 
82  if rospy.has_param("robot_description"):
83  rospy.delete_param("robot_description")
84 
85  rospy.set_param("robot_description", rospy.get_param("right_hand_two_arms"))
86 
87  rospy.set_param("hand/joint_prefix/1", "rh_")
88  rospy.set_param("hand/mapping/1", "rh")
89 
90  rospy.set_param("arm/joint_prefix/1", "la_")
91  rospy.set_param("arm/mapping/1", "la")
92 
93  rospy.set_param("arm/joint_prefix/2", "ra_")
94  rospy.set_param("arm/mapping/2", "ra")
95 
96  arm_finder = ArmFinder()
97 
98  self.assertIsNotNone(arm_finder.get_arm_parameters(), "Parameters extracted.")
99  self.assertIsNotNone(arm_finder.get_arm_joints(), "Joints extracted.")
100 
101  self.assertEqual(len(arm_finder.get_arm_parameters().mapping), 2, "It should be two mappings")
102  self.assertEqual(len(arm_finder.get_arm_parameters().joint_prefix), 2, "It should be two joint_prefixes")
103  self.assertEqual(len(arm_finder.get_arm_joints().keys()), 2, "It should be two arm joints mappings")
104 
105  self.assertIn("ra", arm_finder.get_arm_parameters().mapping.values(), "It should be ra mapping")
106  self.assertIn("ra_", arm_finder.get_arm_parameters().joint_prefix.values(), "It should be ra_ prefix")
107  self.assertIn("ra", arm_finder.get_arm_joints(), "Maping should be in the joints result")
108  self.assertEqual(len(arm_finder.get_arm_joints()["ra"]), 1, "It should be one arm joint for mapping")
109 
110  self.assertIn("la", arm_finder.get_arm_parameters().mapping.values(), "It should be la mapping")
111  self.assertIn("la_", arm_finder.get_arm_parameters().joint_prefix.values(), "It should be la_ prefix")
112  self.assertIn("la", arm_finder.get_arm_joints(), "Maping should be in the joints result")
113  self.assertEqual(len(arm_finder.get_arm_joints()["la"]), 1, "It should be one arm joint for mapping")
114 
116  if rospy.has_param("arm"):
117  rospy.delete_param("arm")
118 
119  if rospy.has_param("hand"):
120  rospy.delete_param("hand")
121 
122  if rospy.has_param("robot_description"):
123  rospy.delete_param("robot_description")
124 
125  rospy.set_param("robot_description", rospy.get_param("two_hands_left_arm"))
126 
127  rospy.set_param("hand/joint_prefix/1", "rh_")
128  rospy.set_param("hand/mapping/1", "rh")
129 
130  rospy.set_param("hand/joint_prefix/2", "lh_")
131  rospy.set_param("hand/mapping/2", "lh")
132 
133  rospy.set_param("arm/joint_prefix/1", "la_")
134  rospy.set_param("arm/mapping/1", "la")
135 
136  arm_finder = ArmFinder()
137 
138  self.assertEqual(len(arm_finder.get_arm_parameters().mapping), 1, "It should be one mapping")
139  self.assertEqual(len(arm_finder.get_arm_parameters().joint_prefix), 1, "It should be one joint_prefix")
140  self.assertEqual(len(arm_finder.get_arm_joints().keys()), 1, "It should be one arm joints")
141 
142  self.assertIn("la", arm_finder.get_arm_parameters().mapping.values(), "It should be la mapping")
143  self.assertIn("la_", arm_finder.get_arm_parameters().joint_prefix.values(), "It should be la_ prefix")
144  self.assertIn("la", arm_finder.get_arm_joints(), "Maping should be in the joints result")
145 
146 if __name__ == "__main__":
147  rospy.init_node("test_arm_finder")
148  rostest.rosrun("sr_utilities", "test_arm_finder", TestArmFinder)


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:49