Skip to content
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

Test controller #46

Merged
merged 10 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions rosbot_xl_controller/CMakeLists.txt

This file was deleted.

4 changes: 3 additions & 1 deletion rosbot_xl_controller/launch/controller.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def generate_launch_description():
declare_mecanum_arg = DeclareLaunchArgument(
"mecanum",
default_value="False",
description="Whether to use mecanum drive controller (otherwise diff drive controller is used)",
description=(
"Whether to use mecanum drive controller (otherwise diff drive controller is used)",
),
)

lidar_model = LaunchConfiguration("lidar_model")
Expand Down
23 changes: 20 additions & 3 deletions rosbot_xl_controller/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

<author email="maciej.stepien@husarion.com">Maciej Stepien</author>
<author email="krzysztof.wojciechowski@husarion.com">Krzysztof Wojciechowski</author>
<author email="jakub.delicat@husarion.com">Jakub Delicat</author>
<maintainer email="support@husarion.com">Husarion</maintainer>

<url type="website">https://husarion.com/</url>
<url type="repository">https://github.com/husarion/rosbot_xl_ros</url>
<url type="bugtracker">https://github.com/husarion/rosbot_xl_ros/issues</url>

<buildtool_depend>ament_cmake</buildtool_depend>

<exec_depend>rosbot_xl_description</exec_depend>

<exec_depend>launch</exec_depend>
Expand All @@ -33,7 +32,25 @@

<exec_depend>rosbot_hardware_interfaces</exec_depend>

<test_depend>python3-pytest</test_depend>
<test_depend>launch</test_depend>
<test_depend>launch_ros</test_depend>
<test_depend>launch_pytest</test_depend>

<test_depend>xacro</test_depend>
<test_depend>sensor_msgs</test_depend>
<test_depend>nav_msgs</test_depend>

<test_depend>rosbot_xl_description</test_depend>
<test_depend>ros_components_description</test_depend>

<test_depend>controller_manager</test_depend>
<test_depend>joint_state_broadcaster</test_depend>
<test_depend>imu_sensor_broadcaster</test_depend>
<test_depend>diff_drive_controller</test_depend>
<test_depend>mecanum_drive_controller</test_depend>

<export>
<build_type>ament_cmake</build_type>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions rosbot_xl_controller/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/rosbot_xl_controller
[install]
install_scripts=$base/lib/rosbot_xl_controller
41 changes: 41 additions & 0 deletions rosbot_xl_controller/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from glob import glob
from setuptools import find_packages, setup

package_name = "rosbot_xl_controller"

setup(
name=package_name,
version="0.8.2",
packages=find_packages(exclude=["test"]),
data_files=[
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
("share/" + package_name, ["package.xml"]),
(os.path.join("share", package_name, "launch"), glob("launch/*.launch.py")),
(os.path.join("share", package_name, "config"), glob("config/*.yaml")),
],
install_requires=["setuptools"],
zip_safe=True,
maintainer="Husarion",
maintainer_email="contact@husarion.com",
description="Hardware configuration for ROSbot XL",
license="Apache License 2.0",
tests_require=["pytest"],
entry_points={
"console_scripts": [],
},
)
23 changes: 23 additions & 0 deletions rosbot_xl_controller/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=[".", "test"])
assert rc == 0, "Found errors"
96 changes: 96 additions & 0 deletions rosbot_xl_controller/test/test_diff_drive_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
# Copyright 2023 Intel Corporation. All Rights Reserved.
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import launch_pytest
import pytest
import rclpy

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import PathJoinSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from test_utils import ControllersTestNode


@launch_pytest.fixture
def generate_test_description():
rosbot_xl_controller = get_package_share_directory("rosbot_xl_controller")
bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_xl_controller,
"launch",
"controller.launch.py",
]
)
),
launch_arguments={
"use_sim": "False",
"mecanum": "False",
"use_gpu": "False",
}.items(),
)

return LaunchDescription([bringup_launch])


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_fail():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert (
not msgs_received_flag
), "Expected JointStates message not received. Check joint_state_broadcaster!"
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
not msgs_received_flag
), "Expected Odom message not received. Check rosbot_base_controller!"
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, "Expected Imu message not received. Check imu_broadcaster!"
finally:
rclpy.shutdown()


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_success():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected JointStates message but it was not received. Check joint_state_broadcaster!"
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Odom message but it was not received. Check rosbot_base_controller!"
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Imu message but it was not received. Check imu_broadcaster!"
finally:
rclpy.shutdown()
23 changes: 23 additions & 0 deletions rosbot_xl_controller/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, "Found %d code style errors / warnings:\n" % len(errors) + "\n".join(errors)
96 changes: 96 additions & 0 deletions rosbot_xl_controller/test/test_mecanum_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
# Copyright 2023 Intel Corporation. All Rights Reserved.
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import launch_pytest
import pytest
import rclpy

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import PathJoinSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from test_utils import ControllersTestNode


@launch_pytest.fixture
def generate_test_description():
rosbot_xl_controller = get_package_share_directory("rosbot_xl_controller")
bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_xl_controller,
"launch",
"controller.launch.py",
]
)
),
launch_arguments={
"use_sim": "False",
"mecanum": "True",
"use_gpu": "False",
}.items(),
)

return LaunchDescription([bringup_launch])


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_fail():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert (
not msgs_received_flag
), "Expected JointStates message not received. Check joint_state_broadcaster!"
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
not msgs_received_flag
), "Expected Odom message not received. Check rosbot_base_controller!"
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, "Expected Imu message not received. Check imu_broadcaster!"
finally:
rclpy.shutdown()


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_success():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected JointStates message but it was not received. Check joint_state_broadcaster!"
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Odom message but it was not received. Check rosbot_base_controller!"
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Imu message but it was not received. Check imu_broadcaster!"
finally:
rclpy.shutdown()
23 changes: 23 additions & 0 deletions rosbot_xl_controller/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=[".", "test"])
assert rc == 0, "Found code style errors / warnings"
Loading
Loading