|
| 1 | +# |
| 2 | +# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# |
| 4 | +# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual |
| 5 | +# property and proprietary rights in and to this material, related |
| 6 | +# documentation and any modifications thereto. Any use, reproduction, |
| 7 | +# disclosure or distribution of this material and related documentation |
| 8 | +# without an express license agreement from NVIDIA CORPORATION or |
| 9 | +# its affiliates is strictly prohibited. |
| 10 | +# |
| 11 | + |
| 12 | +# Third Party |
| 13 | +import pytest |
| 14 | +import torch |
| 15 | + |
| 16 | +# CuRobo |
| 17 | +from curobo.types.base import TensorDeviceType |
| 18 | +from curobo.types.robot import JointState |
| 19 | +from curobo.util_file import get_robot_configs_path, join_path, load_yaml |
| 20 | +from curobo.wrap.reacher.evaluator import TrajEvaluatorConfig |
| 21 | +from curobo.wrap.reacher.motion_gen import MotionGen, MotionGenConfig, MotionGenPlanConfig |
| 22 | + |
| 23 | + |
| 24 | +def run_motion_gen(robot_file, evaluate_interpolated_trajectory, max_acc, max_jerk): |
| 25 | + tensor_args = TensorDeviceType() |
| 26 | + world_file = "collision_test.yml" |
| 27 | + robot_data = load_yaml(join_path(get_robot_configs_path(), robot_file)) |
| 28 | + dof = len(robot_data["robot_cfg"]["kinematics"]["cspace"]["joint_names"]) |
| 29 | + |
| 30 | + robot_data["robot_cfg"]["kinematics"]["cspace"]["max_acceleration"] = [ |
| 31 | + max_acc for i in range(9) |
| 32 | + ] |
| 33 | + robot_data["robot_cfg"]["kinematics"]["cspace"]["max_jerk"] = [max_jerk for i in range(9)] |
| 34 | + |
| 35 | + motion_gen_config = MotionGenConfig.load_from_robot_config( |
| 36 | + robot_data, |
| 37 | + world_file, |
| 38 | + tensor_args, |
| 39 | + use_cuda_graph=False, |
| 40 | + maximum_trajectory_dt=1.5, |
| 41 | + evaluate_interpolated_trajectory=evaluate_interpolated_trajectory, |
| 42 | + ) |
| 43 | + motion_gen = MotionGen(motion_gen_config) |
| 44 | + |
| 45 | + retract_cfg = motion_gen.get_retract_config() |
| 46 | + |
| 47 | + start_state = JointState.from_position(retract_cfg.view(1, -1).clone()) |
| 48 | + goal_state = JointState.from_position(retract_cfg.view(1, -1).clone() + 0.2) |
| 49 | + |
| 50 | + result = motion_gen.plan_single_js( |
| 51 | + start_state, goal_state, MotionGenPlanConfig(max_attempts=5, enable_graph_attempt=10) |
| 52 | + ) |
| 53 | + return result |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.parametrize( |
| 57 | + "robot_file, evaluate_interpolated_traj, max_acc, max_jerk", |
| 58 | + [ |
| 59 | + ("franka.yml", False, 1.0, 500.0), |
| 60 | + ("franka.yml", True, 0.1, 500.0), |
| 61 | + ("franka.yml", True, 1.0, 500.0), |
| 62 | + ("ur5e.yml", False, 1.0, 500.0), |
| 63 | + ("ur5e.yml", True, 0.1, 500.0), |
| 64 | + ("ur5e.yml", True, 1.0, 500.0), |
| 65 | + ], |
| 66 | +) |
| 67 | +def test_motion_gen_trajectory(robot_file, evaluate_interpolated_traj, max_acc, max_jerk): |
| 68 | + result = run_motion_gen(robot_file, evaluate_interpolated_traj, max_acc, max_jerk) |
| 69 | + |
| 70 | + assert result.success.item() |
| 71 | + assert torch.max(torch.abs(result.optimized_plan.acceleration)) <= max_acc |
| 72 | + assert torch.max(torch.abs(result.optimized_plan.jerk)) <= max_jerk |
0 commit comments