-
Notifications
You must be signed in to change notification settings - Fork 166
Add ability to preempt execution and add test #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2379896
Add ability to preempt execution and add test
MarqRazz 04234a0
persistent action_client
MarqRazz f5987dd
Fix indentation
rhaschke 464c45f
Simplify test code
rhaschke 7b963b9
Simplify Task::execute()
rhaschke 2cb84e1
unique node per task and fix test depends
MarqRazz 5d1f23b
revert changes to demo.launch.py
MarqRazz b011321
pre-commit
MarqRazz 2774466
give move_group more time to start in execution test
MarqRazz f42b159
remove post_shutdown_test because move_group fails
MarqRazz eb1e941
Revert "remove post_shutdown_test because move_group fails"
rhaschke dcb1069
Remove not required depencencies
rhaschke b005349
Replace EXPECT_TRUE with EXPECT_EQ if appropriate
rhaschke 320ae2b
Increase CurrentState timeout to 5s
rhaschke 3fc04e3
Increase timeout to 10s
rhaschke e49d040
Revert "Increase timeout to 10s"
rhaschke 5408d7c
Use ASSERT_TRUE(task.plan())
rhaschke 0259d51
Disable execution test with asan build
rhaschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
############# | ||
## Testing ## | ||
############# | ||
|
||
## Add gtest based cpp test target | ||
if (BUILD_TESTING AND NOT (CMAKE_CXX_FLAGS MATCHES "-fsanitize")) | ||
find_package(ament_cmake_gtest REQUIRED) | ||
find_package(launch_testing_ament_cmake REQUIRED) | ||
find_package(moveit_task_constructor_core REQUIRED) | ||
|
||
ament_add_gtest_executable(test_execution test_task_execution.cpp) | ||
add_launch_test(test_execution.launch.py TARGET test_execution | ||
ARGS "test_binary:=$<TARGET_FILE:test_execution>") | ||
ament_target_dependencies(test_execution moveit_task_constructor_core) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import unittest | ||
import os | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
import launch_testing | ||
import pytest | ||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument | ||
from launch.substitutions import LaunchConfiguration | ||
from launch_ros.actions import Node | ||
from launch_testing.actions import ReadyToTest | ||
from launch_testing.util import KeepAliveProc | ||
from moveit_configs_utils import MoveItConfigsBuilder | ||
|
||
|
||
@pytest.mark.launch_test | ||
def generate_test_description(): | ||
moveit_config = ( | ||
MoveItConfigsBuilder("moveit_resources_panda") | ||
.planning_pipelines(pipelines=["ompl"]) | ||
.robot_description(file_path="config/panda.urdf.xacro") | ||
.to_moveit_configs() | ||
) | ||
|
||
# Load ExecuteTaskSolutionCapability so we can test executing solutions | ||
move_group_capabilities = {"capabilities": "move_group/ExecuteTaskSolutionCapability"} | ||
|
||
# Start the actual move_group node/action server | ||
move_group_node = Node( | ||
package="moveit_ros_move_group", | ||
executable="move_group", | ||
output="screen", | ||
parameters=[ | ||
moveit_config.to_dict(), | ||
move_group_capabilities, | ||
], | ||
) | ||
|
||
# Static TF | ||
static_tf = Node( | ||
package="tf2_ros", | ||
executable="static_transform_publisher", | ||
name="static_transform_publisher", | ||
output="log", | ||
arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"], | ||
) | ||
|
||
# Publish joint states to TF | ||
robot_state_publisher = Node( | ||
package="robot_state_publisher", | ||
executable="robot_state_publisher", | ||
name="robot_state_publisher", | ||
output="both", | ||
parameters=[moveit_config.robot_description], | ||
) | ||
|
||
# ros2_control using FakeSystem as hardware | ||
ros2_controllers_path = os.path.join( | ||
get_package_share_directory("moveit_resources_panda_moveit_config"), | ||
"config", | ||
"ros2_controllers.yaml", | ||
) | ||
ros2_control_node = Node( | ||
package="controller_manager", | ||
executable="ros2_control_node", | ||
parameters=[moveit_config.robot_description, ros2_controllers_path], | ||
output="both", | ||
) | ||
|
||
controller_spawner = Node( | ||
package="controller_manager", | ||
executable="spawner", | ||
arguments=[ | ||
"panda_arm_controller", | ||
"joint_state_broadcaster", | ||
"--controller-manager", | ||
"/controller_manager", | ||
], | ||
) | ||
|
||
test_exec = Node( | ||
executable=[ | ||
LaunchConfiguration("test_binary"), | ||
], | ||
output="screen", | ||
parameters=[ | ||
moveit_config.robot_description, | ||
moveit_config.robot_description_semantic, | ||
moveit_config.robot_description_kinematics, | ||
moveit_config.joint_limits, | ||
], | ||
) | ||
|
||
return ( | ||
LaunchDescription( | ||
[ | ||
static_tf, | ||
robot_state_publisher, | ||
move_group_node, | ||
ros2_control_node, | ||
controller_spawner, | ||
DeclareLaunchArgument( | ||
name="test_binary", | ||
description="Test executable", | ||
), | ||
test_exec, | ||
KeepAliveProc(), | ||
ReadyToTest(), | ||
] | ||
), | ||
{"test_exec": test_exec}, | ||
) | ||
|
||
|
||
class TestTerminatingProcessStops(unittest.TestCase): | ||
def test_gtest_run_complete(self, proc_info, test_exec): | ||
proc_info.assertWaitForShutdown(process=test_exec, timeout=4000.0) | ||
|
||
|
||
@launch_testing.post_shutdown_test() | ||
class TaskModelTestAfterShutdown(unittest.TestCase): | ||
def test_exit_code(self, proc_info): | ||
# Check that all processes in the launch exit with code 0 | ||
launch_testing.asserts.assertExitCodes(proc_info) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <moveit/task_constructor/task.h> | ||
#include <moveit/task_constructor/stages/current_state.h> | ||
#include <moveit/task_constructor/stages/move_to.h> | ||
#include <moveit/task_constructor/solvers/joint_interpolation.h> | ||
#include <moveit_task_constructor_msgs/msg/solution.hpp> | ||
#include <moveit/robot_model/robot_model.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace moveit::task_constructor; | ||
|
||
// provide a basic test fixture that prepares a Task | ||
struct PandaMoveTo : public testing::Test | ||
{ | ||
Task t; | ||
stages::MoveTo* move_to; | ||
rclcpp::Node::SharedPtr node; | ||
|
||
PandaMoveTo() { | ||
node = rclcpp::Node::make_shared("test_task_execution"); | ||
t.loadRobotModel(node); | ||
|
||
auto group = t.getRobotModel()->getJointModelGroup("panda_arm"); | ||
|
||
auto initial = std::make_unique<stages::CurrentState>("current state"); | ||
t.add(std::move(initial)); | ||
|
||
auto move = std::make_unique<stages::MoveTo>("move", std::make_shared<solvers::JointInterpolationPlanner>()); | ||
move_to = move.get(); | ||
move_to->setGroup(group->getName()); | ||
t.add(std::move(move)); | ||
} | ||
}; | ||
|
||
// The arm starts in the "ready" pose so make sure we can move to a different known location | ||
TEST_F(PandaMoveTo, successExecution) { | ||
move_to->setGoal("extended"); | ||
ASSERT_TRUE(t.plan()); | ||
auto result = t.execute(*t.solutions().front()); | ||
EXPECT_EQ(result.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS); | ||
} | ||
|
||
// After the arm successfully moved to "extended", move back to "ready" and make sure preempt() works as expected | ||
TEST_F(PandaMoveTo, preemptExecution) { | ||
move_to->setGoal("ready"); | ||
ASSERT_TRUE(t.plan()); | ||
// extract the expected execution time (for this task its in the last sub_trajectory) | ||
moveit_task_constructor_msgs::msg::Solution s; | ||
t.solutions().front()->toMsg(s, nullptr); | ||
rclcpp::Duration exec_duration{ s.sub_trajectory.back().trajectory.joint_trajectory.points.back().time_from_start }; | ||
|
||
moveit::core::MoveItErrorCode result; | ||
std::thread execute_thread{ [this, &result]() { result = t.execute(*t.solutions().front()); } }; | ||
|
||
// cancel the trajectory half way through the expected execution time | ||
rclcpp::sleep_for(exec_duration.to_chrono<std::chrono::milliseconds>() / 2); | ||
t.preempt(); | ||
if (execute_thread.joinable()) { | ||
execute_thread.join(); | ||
} | ||
|
||
EXPECT_EQ(result.val, moveit_msgs::msg::MoveItErrorCodes::PREEMPTED); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
testing::InitGoogleTest(&argc, argv); | ||
rclcpp::init(argc, argv); | ||
|
||
// wait some time for move_group to come up | ||
rclcpp::sleep_for(std::chrono::seconds(5)); | ||
|
||
return RUN_ALL_TESTS(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.