|
41 | 41 | <body> |
42 | 42 | <inertial pos="0 0 0" mass="1" diaginertia="1 1 1"/> |
43 | 43 | <site pos="0 0 -1" name="mysite" type="sphere"/> |
44 | | - <joint type="hinge" axis="0 1 0"/> |
| 44 | + <joint name="myhinge" type="hinge" axis="0 1 0"/> |
45 | 45 | </body> |
46 | 46 | <body> |
47 | 47 | <inertial pos="0 0 0" mass="1" diaginertia="1 1 1"/> |
|
51 | 51 | <geom type="sphere" size="0.1"/> |
52 | 52 | </body> |
53 | 53 | </worldbody> |
| 54 | + <actuator> |
| 55 | + <position name="myactuator" joint="myhinge"/> |
| 56 | + </actuator> |
54 | 57 | </mujoco> |
55 | 58 | """ |
56 | 59 |
|
@@ -144,6 +147,22 @@ def test_array_keeps_struct_alive(self): |
144 | 147 | del qpos_spring |
145 | 148 | self.assertEqual(sys.getrefcount(capsule) - base_refcount, 1) |
146 | 149 |
|
| 150 | + def test_named_indexing_actuator_ctrl(self): |
| 151 | + actuator_id = mujoco.mj_name2id( |
| 152 | + self.model, mujoco.mjtObj.mjOBJ_ACTUATOR, 'myactuator') |
| 153 | + self.assertIs(self.data.actuator('myactuator'), |
| 154 | + self.data.actuator(actuator_id)) |
| 155 | + self.assertIs(self.data.actuator('myactuator').ctrl, |
| 156 | + self.data.actuator(actuator_id).ctrl) |
| 157 | + self.assertEqual(self.data.actuator('myactuator').ctrl.shape, (1,)) |
| 158 | + |
| 159 | + # Test that the indexer is returning a view into the underlying struct. |
| 160 | + ctrl_from_indexer = self.data.actuator('myactuator').ctrl |
| 161 | + self.data.ctrl[actuator_id] = 5 |
| 162 | + np.testing.assert_array_equal(ctrl_from_indexer, [5]) |
| 163 | + self.data.actuator('myactuator').ctrl = 7 |
| 164 | + np.testing.assert_array_equal(self.data.ctrl[actuator_id], [7]) |
| 165 | + |
147 | 166 | def test_named_indexing_geom_size(self): |
148 | 167 | box_id = mujoco.mj_name2id(self.model, mujoco.mjtObj.mjOBJ_GEOM, 'mybox') |
149 | 168 | self.assertIs(self.model.geom('mybox'), self.model.geom(box_id)) |
|
0 commit comments