|
357 | 357 | showerror(devnull, e) |
358 | 358 | end |
359 | 359 | end |
| 360 | + |
| 361 | + @testset "remove_subtree! - tree mechanism" begin |
| 362 | + mechanism = parse_urdf(joinpath(@__DIR__, "urdf", "atlas.urdf"), floating=true) |
| 363 | + @test_throws AssertionError remove_subtree!(mechanism, root_body(mechanism)) |
| 364 | + |
| 365 | + original_joints = copy(joints(mechanism)) |
| 366 | + |
| 367 | + # Behead. |
| 368 | + num_bodies = length(bodies(mechanism)) |
| 369 | + num_joints = length(joints(mechanism)) |
| 370 | + head = findbody(mechanism, "head") |
| 371 | + neck_joint = joint_to_parent(head, mechanism) |
| 372 | + remove_subtree!(mechanism, head) |
| 373 | + @test length(bodies(mechanism)) == num_bodies - 1 |
| 374 | + @test length(joints(mechanism)) == num_joints - 1 |
| 375 | + @test head ∉ bodies(mechanism) |
| 376 | + @test neck_joint ∉ joints(mechanism) |
| 377 | + |
| 378 | + # Lop off an arm. |
| 379 | + num_bodies = length(bodies(mechanism)) |
| 380 | + num_joints = length(joints(mechanism)) |
| 381 | + r_clav = findbody(mechanism, "r_clav") |
| 382 | + r_hand = findbody(mechanism, "r_hand") |
| 383 | + r_arm = path(mechanism, r_clav, r_hand) |
| 384 | + arm_joints = collect(r_arm) |
| 385 | + arm_bodies = [r_clav; map(joint -> successor(joint, mechanism), arm_joints)] |
| 386 | + remove_subtree!(mechanism, r_clav) |
| 387 | + @test length(joints(mechanism)) == num_joints - length(arm_joints) - 1 |
| 388 | + @test length(bodies(mechanism)) == num_bodies - length(arm_bodies) |
| 389 | + @test isempty(intersect(arm_joints, joints(mechanism))) |
| 390 | + @test isempty(intersect(arm_bodies, bodies(mechanism))) |
| 391 | + @test issorted(joints(mechanism), by=joint ->findfirst(isequal(joint), original_joints)) |
| 392 | + end |
| 393 | + |
| 394 | + @testset "remove_subtree! - maximal coordinates" begin |
| 395 | + original = parse_urdf(joinpath(@__DIR__, "urdf", "atlas.urdf"), floating=true) |
| 396 | + mechanism = maximal_coordinates(original) |
| 397 | + num_bodies = length(bodies(mechanism)) |
| 398 | + num_joints = length(joints(mechanism)) |
| 399 | + @test_throws AssertionError remove_subtree!(mechanism, findbody(original, "head")) # body not in tree |
| 400 | + head = findbody(mechanism, "head") |
| 401 | + head_joints = copy(in_joints(head, mechanism)) |
| 402 | + @test length(head_joints) == 2 # floating joint + neck loop joint |
| 403 | + remove_subtree!(mechanism, head) |
| 404 | + @test length(joints(mechanism)) == num_joints - length(head_joints) |
| 405 | + @test length(bodies(mechanism)) == num_bodies - 1 |
| 406 | + for joint in head_joints |
| 407 | + @test joint ∉ joints(mechanism) |
| 408 | + end |
| 409 | + @test head ∉ bodies(mechanism) |
| 410 | + end |
360 | 411 | end # mechanism modification |
0 commit comments