Skip to content

Commit

Permalink
Merge branch 'master' into 133_pr_rebase_again
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich authored Jul 30, 2024
2 parents deb77fa + 902b4bd commit a22feb4
Show file tree
Hide file tree
Showing 90 changed files with 2,065 additions and 302 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
.kdev4/


*~
*.kate-swp
*.kdev4
.ccache
.work
2 changes: 2 additions & 0 deletions example_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
)

# find dependencies
find_package(backward_ros REQUIRED)
find_package(ament_cmake REQUIRED)
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
Expand Down Expand Up @@ -66,6 +67,7 @@ if(BUILD_TESTING)

ament_add_pytest_test(example_1_urdf_xacro test/test_urdf_xacro.py)
ament_add_pytest_test(view_example_1_launch test/test_view_robot_launch.py)
ament_add_pytest_test(run_example_1_launch test/test_rrbot_launch.py)
endif()


Expand Down
9 changes: 3 additions & 6 deletions example_1/bringup/config/rrbot_controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ controller_manager:
joint_state_broadcaster:
type: joint_state_broadcaster/JointStateBroadcaster

forward_position_controller:
type: forward_command_controller/ForwardCommandController

joint_trajectory_position_controller:
type: joint_trajectory_controller/JointTrajectoryController


forward_position_controller:
ros__parameters:
type: forward_command_controller/ForwardCommandController
joints:
- joint1
- joint2
Expand All @@ -22,6 +17,8 @@ forward_position_controller:

joint_trajectory_position_controller:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController

joints:
- joint1
- joint2
Expand Down
17 changes: 9 additions & 8 deletions example_1/bringup/launch/rrbot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def generate_launch_description():
joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"],
arguments=["joint_state_broadcaster"],
)

robot_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["forward_position_controller", "--controller-manager", "/controller_manager"],
arguments=["forward_position_controller", "--param-file", robot_controllers],
)

# Delay rviz start after `joint_state_broadcaster`
Expand All @@ -105,20 +105,21 @@ def generate_launch_description():
)
)

# Delay start of robot_controller after `joint_state_broadcaster`
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
# Delay start of joint_state_broadcaster after `robot_controller`
# TODO(anyone): This is a workaround for flaky tests. Remove when fixed.
delay_joint_state_broadcaster_after_robot_controller_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_broadcaster_spawner,
on_exit=[robot_controller_spawner],
target_action=robot_controller_spawner,
on_exit=[joint_state_broadcaster_spawner],
)
)

nodes = [
control_node,
robot_state_pub_node,
joint_state_broadcaster_spawner,
robot_controller_spawner,
delay_rviz_after_joint_state_broadcaster_spawner,
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner,
delay_joint_state_broadcaster_after_robot_controller_spawner,
]

return LaunchDescription(declared_arguments + nodes)
3 changes: 2 additions & 1 deletion example_1/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>backward_ros</depend>
<depend>hardware_interface</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
Expand All @@ -34,9 +35,9 @@
<exec_depend>xacro</exec_depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>launch_testing_ament_cmake</test_depend>
<test_depend>launch_testing_ros</test_depend>
<test_depend>liburdfdom-tools</test_depend>
<test_depend>ros2_control_demo_testing</test_depend>
<test_depend>xacro</test_depend>

<export>
Expand Down
99 changes: 99 additions & 0 deletions example_1/test/test_rrbot_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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

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,
check_if_js_published,
check_node_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()])


# This is our test fixture. Each method is a test case.
# These run alongside the processes specified in generate_test_description()
class TestFixture(unittest.TestCase):

def setUp(self):
rclpy.init()
self.node = Node("test_node")

def tearDown(self):
self.node.destroy_node()
rclpy.shutdown()

def test_node_start(self, proc_output):
check_node_running(self.node, "robot_state_publisher")

def test_controller_running(self, proc_output):

cnames = ["forward_position_controller", "joint_state_broadcaster"]

check_controllers_running(self.node, cnames)

def test_check_if_msgs_published(self):
check_if_js_published("/joint_states", ["joint1", "joint2"])


# 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)
2 changes: 2 additions & 0 deletions example_10/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
)

# find dependencies
find_package(backward_ros REQUIRED)
find_package(ament_cmake REQUIRED)
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
Expand Down Expand Up @@ -77,6 +78,7 @@ if(BUILD_TESTING)

ament_add_pytest_test(example_10_urdf_xacro test/test_urdf_xacro.py)
ament_add_pytest_test(view_example_10_launch test/test_view_robot_launch.py)
ament_add_pytest_test(run_example_10_launch test/test_rrbot_launch.py)
endif()

## EXPORTS
Expand Down
8 changes: 2 additions & 6 deletions example_10/bringup/config/rrbot_controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ controller_manager:
joint_state_broadcaster:
type: joint_state_broadcaster/JointStateBroadcaster

forward_position_controller:
type: forward_command_controller/ForwardCommandController

gpio_controller:
type: ros2_control_demo_example_10/GPIOController


forward_position_controller:
ros__parameters:
type: forward_command_controller/ForwardCommandController
joints:
- joint1
- joint2
interface_name: position

gpio_controller:
ros__parameters:
type: ros2_control_demo_example_10/GPIOController
inputs:
- flange_analog_IOs/analog_output1
- flange_analog_IOs/analog_input1
Expand Down
27 changes: 17 additions & 10 deletions example_10/bringup/launch/rrbot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,42 @@ def generate_launch_description():
joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"],
arguments=["joint_state_broadcaster"],
)

robot_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["forward_position_controller", "-c", "/controller_manager"],
arguments=["forward_position_controller", "--param-file", robot_controllers],
)

gpio_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["gpio_controller", "-c", "/controller_manager"],
arguments=["gpio_controller", "--param-file", robot_controllers],
)

# Delay start of robot_controller after `joint_state_broadcaster`
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
# Delay start of joint_state_broadcaster after `robot_controller`
# TODO(anyone): This is a workaround for flaky tests. Remove when fixed.
delay_gpio_after_robot_controller_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_broadcaster_spawner,
on_exit=[robot_controller_spawner],
target_action=robot_controller_spawner,
on_exit=[gpio_controller_spawner],
)
)
delay_joint_state_broadcaster_after_gpio_controller_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=gpio_controller_spawner,
on_exit=[joint_state_broadcaster_spawner],
)
)

nodes = [
control_node,
robot_state_pub_node,
joint_state_broadcaster_spawner,
gpio_controller_spawner,
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner,
robot_controller_spawner,
delay_gpio_after_robot_controller_spawner,
delay_joint_state_broadcaster_after_gpio_controller_spawner,
]

return LaunchDescription(declared_arguments + nodes)
4 changes: 2 additions & 2 deletions example_10/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>backward_ros</depend>
<depend>hardware_interface</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
Expand All @@ -32,11 +33,10 @@
<exec_depend>rviz2</exec_depend>
<exec_depend>xacro</exec_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>launch_testing_ament_cmake</test_depend>
<test_depend>launch_testing_ros</test_depend>
<test_depend>liburdfdom-tools</test_depend>
<test_depend>ros2_control_demo_testing</test_depend>
<test_depend>xacro</test_depend>

<export>
Expand Down
Loading

0 comments on commit a22feb4

Please sign in to comment.