diff --git a/control/gravity_compasation.cpp b/control/gravity_compasation.cpp index d77893a..dbe6286 100644 --- a/control/gravity_compasation.cpp +++ b/control/gravity_compasation.cpp @@ -1,4 +1,4 @@ -// Copyright 2025 Enactic, Inc. +// Copyright 2025-2026 Enactic, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -72,7 +72,9 @@ int main(int argc, char** argv) { (arm_side == "left_arm") ? "openarm_left_hand" : "openarm_right_hand"; Dynamics arm_dynamics(urdf_path, root_link, leaf_link); - arm_dynamics.Init(); + if (!arm_dynamics.Init()) { + return 1; + } std::cout << "=== Initializing Leader OpenArm ===" << std::endl; openarm::can::socket::OpenArm* openarm = diff --git a/control/openarm_bilateral_control.cpp b/control/openarm_bilateral_control.cpp index a23f3df..063f9de 100644 --- a/control/openarm_bilateral_control.cpp +++ b/control/openarm_bilateral_control.cpp @@ -1,4 +1,4 @@ -// Copyright 2025 Enactic, Inc. +// Copyright 2025-2026 Enactic, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -227,10 +227,14 @@ int main(int argc, char **argv) { std::vector follower_Fo = follower_loader.get_vector("FollowerArmParam", "Fo"); Dynamics *leader_arm_dynamics = new Dynamics(leader_urdf_path, root_link, leaf_link); - leader_arm_dynamics->Init(); + if (!leader_arm_dynamics->Init()) { + return 1; + } Dynamics *follower_arm_dynamics = new Dynamics(follower_urdf_path, root_link, leaf_link); - follower_arm_dynamics->Init(); + if (!follower_arm_dynamics->Init()) { + return 1; + } std::cout << "=== Initializing Leader OpenArm ===" << std::endl; openarm::can::socket::OpenArm *leader_openarm = diff --git a/control/openarm_unilateral_control.cpp b/control/openarm_unilateral_control.cpp index 622c661..4354501 100644 --- a/control/openarm_unilateral_control.cpp +++ b/control/openarm_unilateral_control.cpp @@ -1,4 +1,4 @@ -// Copyright 2025 Enactic, Inc. +// Copyright 2025-2026 Enactic, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -228,10 +228,14 @@ int main(int argc, char **argv) { std::vector follower_Fo = follower_loader.get_vector("FollowerArmParam", "Fo"); Dynamics *leader_arm_dynamics = new Dynamics(leader_urdf_path, root_link, leaf_link); - leader_arm_dynamics->Init(); + if (!leader_arm_dynamics->Init()) { + return 1; + } Dynamics *follower_arm_dynamics = new Dynamics(follower_urdf_path, root_link, leaf_link); - follower_arm_dynamics->Init(); + if (!follower_arm_dynamics->Init()) { + return 1; + } std::cout << "=== Initializing Leader OpenArm ===" << std::endl; openarm::can::socket::OpenArm *leader_openarm = diff --git a/src/controller/dynamics.cpp b/src/controller/dynamics.cpp index 283f43c..3653afe 100644 --- a/src/controller/dynamics.cpp +++ b/src/controller/dynamics.cpp @@ -1,4 +1,4 @@ -// Copyright 2025 Enactic, Inc. +// Copyright 2025-2026 Enactic, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,7 +45,8 @@ bool Dynamics::Init() { } if (!kdl_tree.getChain(start_link, end_link, kdl_chain)) { - fprintf(stderr, "Failed to get KDL chain\n"); + fprintf(stderr, "Failed to get KDL chain: %s: %s -> %s\n", urdf_path.c_str(), + start_link.c_str(), end_link.c_str()); return false; } diff --git a/test/control/test_dynamics_init.py b/test/control/test_dynamics_init.py index 8479535..0c45fcd 100644 --- a/test/control/test_dynamics_init.py +++ b/test/control/test_dynamics_init.py @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# The executables must set up the dynamics from the given URDF. +# The executables must stop before they touch any motor when they +# can't set up the dynamics from the given URDF. # A CAN interface that doesn't exist. An executable that passed the # dynamics setup fails with CAN_ERROR instead of touching a real one. @@ -20,6 +21,11 @@ CAN_ERROR = "Failed to initialize socket for interface" +def chain_error(urdf, side): + return (f"Failed to get KDL chain: {urdf}: " + f"openarm_body_link0 -> openarm_{side}_hand") + + def test_gravity_comp(run_gravity_comp, write_urdf): urdf = write_urdf("openarm.urdf", "hand") result = run_gravity_comp("right_arm", CAN_INTERFACE, urdf) @@ -27,8 +33,36 @@ def test_gravity_comp(run_gravity_comp, write_urdf): assert CAN_ERROR in result.stdout +def test_gravity_comp_no_leaf_link(run_gravity_comp, write_urdf): + urdf = write_urdf("openarm.urdf", "ee_base_link") + result = run_gravity_comp("right_arm", CAN_INTERFACE, urdf) + assert result.returncode == 1 + assert chain_error(urdf, "right") in result.stdout + assert CAN_ERROR not in result.stdout + + def test_teleop(run_teleop, write_urdf): urdf = write_urdf("openarm.urdf", "hand") result = run_teleop(urdf, urdf, "left_arm", CAN_INTERFACE, CAN_INTERFACE) assert "Failed to get KDL chain" not in result.stdout assert CAN_ERROR in result.stdout + + +def test_teleop_no_leader_leaf_link(run_teleop, write_urdf): + leader_urdf = write_urdf("leader.urdf", "ee_base_link") + follower_urdf = write_urdf("follower.urdf", "hand") + result = run_teleop(leader_urdf, follower_urdf, "left_arm", + CAN_INTERFACE, CAN_INTERFACE) + assert result.returncode == 1 + assert chain_error(leader_urdf, "left") in result.stdout + assert CAN_ERROR not in result.stdout + + +def test_teleop_no_follower_leaf_link(run_teleop, write_urdf): + leader_urdf = write_urdf("leader.urdf", "hand") + follower_urdf = write_urdf("follower.urdf", "ee_base_link") + result = run_teleop(leader_urdf, follower_urdf, "left_arm", + CAN_INTERFACE, CAN_INTERFACE) + assert result.returncode == 1 + assert chain_error(follower_urdf, "left") in result.stdout + assert CAN_ERROR not in result.stdout