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

changed bringup to ament_python | added tests #3

Open
wants to merge 2 commits into
base: humble
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .github/workflows/black.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Black python lint

on:
workflow_call:
pull_request:
push:

jobs:
Expand Down
12 changes: 0 additions & 12 deletions rosbot_bringup/CMakeLists.txt

This file was deleted.

20 changes: 18 additions & 2 deletions rosbot_bringup/launch/bringup.launch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# 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.

from launch import LaunchDescription
from launch_ros.actions import Node, SetParameter
from launch.substitutions import PathJoinSubstitution
from ament_index_python.packages import get_package_share_directory
from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument
from launch.launch_description_sources import PythonLaunchDescriptionSource
Expand Down Expand Up @@ -37,7 +50,10 @@ 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)"
),
)

controller_launch = IncludeLaunchDescription(
Expand Down
12 changes: 9 additions & 3 deletions rosbot_bringup/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
<url type="repository">https://github.com/husarion/rosbot_ros</url>
<url type="bugtracker">https://github.com/husarion/rosbot_ros/issues</url>

<buildtool_depend>ament_cmake</buildtool_depend>

<exec_depend>launch</exec_depend>
<exec_depend>launch_ros</exec_depend>
<exec_depend>rosbot_controller</exec_depend>
<exec_depend>robot_localization</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>robot_localization</test_depend>
<test_depend>rosbot_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_bringup/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/rosbot_bringup
[install]
install_scripts=$base/lib/rosbot_bringup
27 changes: 27 additions & 0 deletions rosbot_bringup/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
from glob import glob
from setuptools import find_packages, setup

package_name = "rosbot_bringup"

setup(
name=package_name,
version="0.8.0",
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="[email protected]",
description="ROSbot 2, 2R, PRO bringup package",
license="Apache License 2.0",
tests_require=["pytest"],
entry_points={
"console_scripts": [],
},
)
80 changes: 80 additions & 0 deletions rosbot_bringup/test/bringup_test_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
# 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 rclpy

from threading import Event
from threading import Thread

from rclpy.node import Node

from sensor_msgs.msg import JointState, Imu
from nav_msgs.msg import Odometry


class BringupTestNode(Node):
ROSBOT_HARDWARE_PUBLISHERS_RATE = 10.0

__test__ = False

def __init__(self, name="test_node"):
super().__init__(name)
self.odom_msg_event = Event()

def create_test_subscribers_and_publishers(self):
self.imu_publisher = self.create_publisher(Imu, "_imu/data_raw", 10)

self.joint_states_publisher = self.create_publisher(
JointState, "_motors_response", 10
)

self.odom_sub = self.create_subscription(
Odometry, "/odometry/filtered", self.odometry_callback, 10
)
self.timer = None

def start_node_thread(self):
self.ros_spin_thread = Thread(
target=lambda node: rclpy.spin(node), args=(self,)
)
self.ros_spin_thread.start()

def odometry_callback(self, data):
self.odom_msg_event.set()

def start_publishing_fake_hardware(self):
self.timer = self.create_timer(
1.0 / self.ROSBOT_HARDWARE_PUBLISHERS_RATE,
self.publish_fake_hardware_messages,
)

def publish_fake_hardware_messages(self):
imu_msg = Imu()
imu_msg.header.stamp = self.get_clock().now().to_msg()
imu_msg.header.frame_id = "imu_link"

joint_state_msg = JointState()
joint_state_msg.header.stamp = self.get_clock().now().to_msg()
joint_state_msg.name = [
"fl_wheel_joint",
"fr_wheel_joint",
"rl_wheel_joint",
"rr_wheel_joint",
]
joint_state_msg.position = [0.0, 0.0, 0.0, 0.0]
joint_state_msg.velocity = [0.0, 0.0, 0.0, 0.0]

self.imu_publisher.publish(imu_msg)
self.joint_states_publisher.publish(joint_state_msg)
23 changes: 23 additions & 0 deletions rosbot_bringup/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"
66 changes: 66 additions & 0 deletions rosbot_bringup/test/test_diff_drive_ekf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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 bringup_test_node import BringupTestNode


@launch_pytest.fixture
def generate_test_description():
rosbot_bringup = get_package_share_directory("rosbot_bringup")
bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_bringup,
"launch",
"bringup.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_bringup_startup_success():
rclpy.init()
try:
node = BringupTestNode("test_bringup")
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Did not receive Odom message, check robot_localization node!"
finally:
rclpy.shutdown()
25 changes: 25 additions & 0 deletions rosbot_bringup/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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)
66 changes: 66 additions & 0 deletions rosbot_bringup/test/test_mecanum_ekf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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 bringup_test_node import BringupTestNode


@launch_pytest.fixture
def generate_test_description():
rosbot_bringup = get_package_share_directory("rosbot_bringup")
bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_bringup,
"launch",
"bringup.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_bringup_startup_success():
rclpy.init()
try:
node = BringupTestNode("test_bringup")
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Did not receive Odom message, check robot_localization node!"
finally:
rclpy.shutdown()
Loading