Skip to content

Commit 6b6e4eb

Browse files
committed
typing fixes
1 parent 4fe96c5 commit 6b6e4eb

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

genesis/engine/entities/rigid_entity/rigid_entity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def get_jacobian(self, link, local_point=None):
838838
return jacobian
839839

840840
@ti.func
841-
def _impl_get_jacobian(self, tgt_link_idx, i_b, p_vec: ti.types.vector(3, ti.f64)):
841+
def _impl_get_jacobian(self, tgt_link_idx, i_b, p_vec):
842842
self._func_get_jacobian(
843843
tgt_link_idx,
844844
i_b,
@@ -849,14 +849,14 @@ def _impl_get_jacobian(self, tgt_link_idx, i_b, p_vec: ti.types.vector(3, ti.f64
849849

850850
@ti.kernel
851851
def _kernel_get_jacobian(self, tgt_link_idx: ti.i32, p_local: ti.types.ndarray()):
852-
p_vec = ti.Vector([p_local[0], p_local[1], p_local[2]], dt=ti.f64)
852+
p_vec = ti.Vector([p_local[0], p_local[1], p_local[2]], dt=gs.ti_float)
853853
for i_b in range(self._solver._B):
854854
self._impl_get_jacobian(tgt_link_idx, i_b, p_vec)
855855

856856
@ti.kernel
857857
def _kernel_get_jacobian_zero(self, tgt_link_idx: ti.i32):
858858
for i_b in range(self._solver._B):
859-
self._impl_get_jacobian(tgt_link_idx, i_b, ti.Vector.zero(ti.f64, 3))
859+
self._impl_get_jacobian(tgt_link_idx, i_b, ti.Vector.zero(gs.ti_float, 3))
860860

861861
@ti.func
862862
def _func_get_jacobian(self, tgt_link_idx, i_b, p_local, pos_mask, rot_mask):

tests/test_rigid_physics.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,37 @@ def test_terrain_size(show_viewer, tol):
21692169
assert_allclose((height_ref * 2.0), height_test, tol=tol)
21702170

21712171

2172+
@pytest.mark.required
2173+
@pytest.mark.parametrize("backend", [gs.cpu])
2174+
def test_get_weld_constraints_basic(show_viewer, tol):
2175+
scene = gs.Scene(show_viewer=show_viewer)
2176+
2177+
cube1 = scene.add_entity(gs.morphs.Box(size=(0.05,) * 3, pos=(0.0, 0.0, 0.05)))
2178+
cube2 = scene.add_entity(gs.morphs.Box(size=(0.05,) * 3, pos=(0.2, 0.0, 0.05)))
2179+
2180+
scene.build(n_envs=1)
2181+
2182+
rigid = scene.sim.rigid_solver
2183+
2184+
link_a = torch.tensor([cube1.base_link.idx], dtype=gs.tc_int, device=gs.device)
2185+
link_b = torch.tensor([cube2.base_link.idx], dtype=gs.tc_int, device=gs.device)
2186+
2187+
rigid.add_weld_constraint(link_a, link_b)
2188+
scene.step()
2189+
2190+
welds = rigid.get_weld_constraints(as_tensor=True, to_torch=False)
2191+
2192+
env_id = 0 if "env" not in welds else int(welds["env"][0])
2193+
2194+
row = np.array(
2195+
[env_id, int(welds["obj_a"][0]), int(welds["obj_b"][0])],
2196+
dtype=np.int32,
2197+
)
2198+
ref = np.array([0, link_a.item(), link_b.item()], dtype=np.int32)
2199+
2200+
assert_allclose(row, ref, tol=tol)
2201+
2202+
21722203
@pytest.mark.required
21732204
@pytest.mark.parametrize("backend", [gs.cpu])
21742205
def test_urdf_parsing(show_viewer, tol):
@@ -2302,37 +2333,6 @@ def test_urdf_mimic(show_viewer, tol):
23022333
assert_allclose(gs_qpos[-1], gs_qpos[-2], tol=tol)
23032334

23042335

2305-
@pytest.mark.required
2306-
@pytest.mark.merge_fixed_links(False)
2307-
@pytest.mark.parametrize("model_name", ["pendulum"])
2308-
@pytest.mark.parametrize("gs_solver", [gs.constraint_solver.CG])
2309-
@pytest.mark.parametrize("gs_integrator", [gs.integrator.Euler])
2310-
def test_jacobian(gs_sim, tol):
2311-
pendulum = gs_sim.entities[0]
2312-
angle = 0.7
2313-
pendulum.set_qpos(np.array([angle], dtype=np.float64))
2314-
gs_sim.scene.step()
2315-
2316-
link = pendulum.get_link("PendulumArm_0")
2317-
2318-
p_local = np.array([0.05, -0.02, 0.12], dtype=np.float64)
2319-
J_o = pendulum.get_jacobian(link).cpu().numpy()
2320-
J_p = pendulum.get_jacobian(link, p_local).cpu().numpy()
2321-
2322-
c, s = np.cos(angle), np.sin(angle)
2323-
Rx = np.array([[1, 0, 0], [0, c, -s], [0, s, c]], dtype=np.float64)
2324-
r_world = Rx @ p_local
2325-
r_cross = np.array(
2326-
[[0, -r_world[2], r_world[1]], [r_world[2], 0, -r_world[0]], [-r_world[1], r_world[0], 0]], dtype=np.float64
2327-
)
2328-
2329-
lin_o, ang_o = J_o[:3, 0], J_o[3:, 0]
2330-
lin_expected = lin_o - r_cross @ ang_o
2331-
2332-
assert_allclose(J_p[3:, 0], ang_o, tol=tol)
2333-
assert_allclose(J_p[:3, 0], lin_expected, tol=tol)
2334-
2335-
23362336
@pytest.mark.required
23372337
@pytest.mark.parametrize("backend", [gs.cpu])
23382338
def test_gravity(show_viewer, tol):

0 commit comments

Comments
 (0)