forked from ros-controls/ros2_control_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CLI load_controller verb (ros-controls#585)
- Loading branch information
1 parent
25c1f59
commit 297ca13
Showing
7 changed files
with
198 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
joint_trajectory_position_controller: | ||
ros__parameters: | ||
type: joint_trajectory_controller/JointTrajectoryController | ||
|
||
joints: | ||
- joint1 | ||
- joint2 | ||
|
||
command_interfaces: | ||
- position | ||
|
||
state_interfaces: | ||
- position | ||
|
||
action_monitor_rate: 20.0 # Defaults to 20 | ||
|
||
allow_partial_joints_goal: false # Defaults to false | ||
open_loop_control: true | ||
allow_integration_in_goal_trajectories: true | ||
constraints: | ||
stopped_velocity_tolerance: 0.01 # Defaults to 0.01 | ||
goal_time: 0.0 # Defaults to 0.0 (start immediately) |
This file contains 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 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 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,115 @@ | ||
# Copyright (c) 2024 AIT - Austrian Institute of Technology GmbH | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# * Neither the name of the {copyright_holder} nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# Author: Christoph Froehlich | ||
|
||
import os | ||
import pytest | ||
import unittest | ||
import subprocess | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
from launch import LaunchDescription | ||
from launch.actions import IncludeLaunchDescription | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
from launch_testing.actions import ReadyToTest | ||
|
||
# import launch_testing.markers | ||
import rclpy | ||
from rclpy.node import Node | ||
from ros2_control_demo_testing.test_utils import check_controllers_running | ||
|
||
|
||
# Executes the given launch file and checks if all nodes can be started | ||
@pytest.mark.rostest | ||
def generate_test_description(): | ||
launch_include = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource( | ||
os.path.join( | ||
get_package_share_directory("ros2_control_demo_example_1"), | ||
"launch/rrbot.launch.py", | ||
) | ||
), | ||
launch_arguments={"gui": "False"}.items(), | ||
) | ||
|
||
return LaunchDescription([launch_include, ReadyToTest()]) | ||
|
||
|
||
class TestFixtureCliDirect(unittest.TestCase): | ||
|
||
def setUp(self): | ||
rclpy.init() | ||
self.node = Node("test_node") | ||
|
||
def tearDown(self): | ||
self.node.destroy_node() | ||
rclpy.shutdown() | ||
|
||
def test_main(self, proc_output): | ||
|
||
# Command to run the CLI | ||
cname = "joint_trajectory_position_controller" | ||
command = [ | ||
"ros2", | ||
"control", | ||
"load_controller", | ||
"--set-state", | ||
"inactive", | ||
cname, | ||
os.path.join( | ||
get_package_share_directory("ros2_control_demo_example_1"), | ||
"config/rrbot_jtc.yaml", | ||
), | ||
] | ||
subprocess.run(command, check=True) | ||
check_controllers_running(self.node, [cname], state="inactive") | ||
check_controllers_running(self.node, ["forward_position_controller"], state="active") | ||
|
||
command = [ | ||
"ros2", | ||
"control", | ||
"switch_controllers", | ||
"--activate", | ||
cname, | ||
"--deactivate", | ||
"forward_position_controller", | ||
] | ||
subprocess.run(command, check=True) | ||
check_controllers_running(self.node, ["forward_position_controller"], state="inactive") | ||
check_controllers_running(self.node, [cname], state="active") | ||
|
||
|
||
# TODO(anyone): enable this if shutdown of ros2_control_node does not fail anymore | ||
# @launch_testing.post_shutdown_test() | ||
# # These tests are run after the processes in generate_test_description() have shutdown. | ||
# class TestDescriptionCraneShutdown(unittest.TestCase): | ||
|
||
# def test_exit_codes(self, proc_info): | ||
# """Check if the processes exited normally.""" | ||
# launch_testing.asserts.assertExitCodes(proc_info) |
This file contains 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