diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3e718e6..c3186da 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,8 +18,10 @@ jobs: distribution: foxy linter: ${{ matrix.linter }} package-name: | + time_rclcpp_example my_first_ros_rclcpp_pkg my_first_ros_rclpy_pkg msg_srv_action_interface_example topic_service_action_rclpy_example topic_service_action_rclcpp_example + ros2env diff --git a/README.md b/README.md index 1e51be2..7ccfb31 100644 --- a/README.md +++ b/README.md @@ -23,70 +23,58 @@ $ git clone https://github.com/robotpilot/ros2-seminar-examples.git $ cd ~/robot_ws && colcon build --symlink-install ``` -## Run (my_first_ros_rclpy_pkg) +## Run time_rclcpp_example package ``` -$ ros2 run my_first_ros_rclpy_pkg helloworld_subscriber +$ ros2 run time_rclcpp_example time_example ``` +## Run my_first_ros_rclpy_pkg package ``` +$ ros2 run my_first_ros_rclpy_pkg helloworld_subscriber $ ros2 run my_first_ros_rclpy_pkg helloworld_publisher ``` -## Run (my_first_ros_rclcpp_pkg) +## Run my_first_ros_rclcpp_pkg package ``` $ ros2 run my_first_ros_rclcpp_pkg helloworld_subscriber -``` - -``` $ ros2 run my_first_ros_rclcpp_pkg helloworld_publisher ``` -## Run (topic_service_action_rclpy_example) -### Topic Publisher (argument node) +## Run topic_service_action_rclpy_example package ``` $ ros2 run topic_service_action_rclpy_example argument -``` -### Service Client (operator node) -``` $ ros2 run topic_service_action_rclpy_example operator -``` -### Topic Subscriber, Service Server, Action Server (calculator node) -``` $ ros2 run topic_service_action_rclpy_example calculator -``` -### Action Client (checker node) -``` $ ros2 run topic_service_action_rclpy_example checker -``` -``` $ ros2 run topic_service_action_rclpy_example checker -g 100 -``` -### Run using launch (argument and calculator nodes) -``` $ ros2 launch topic_service_action_rclpy_example arithmetic.launch.py ``` -## Run (topic_service_action_rclcpp_example) -### Topic Publisher (argument node) +## Run topic_service_action_rclcpp_example package ``` $ ros2 run topic_service_action_rclcpp_example argument -``` -### Service Client (operator node) -``` $ ros2 run topic_service_action_rclcpp_example operator -``` -### Topic Subscriber, Service Server, Action Server (calculator node) -``` $ ros2 run topic_service_action_rclcpp_example calculator -``` -### Action Client (checker node) -``` $ ros2 run topic_service_action_rclcpp_example checker -``` -``` $ ros2 run topic_service_action_rclcpp_example checker -g 100.0 -``` -### Run using launch (argument and calculator nodes) -``` $ ros2 launch topic_service_action_rclcpp_example arithmetic.launch.py ``` + +## Run ros2env package +``` +$ ros2 env +usage: ros2 env [-h] Call `ros2 env -h` for more detailed usage. ... +Various env related sub-commands +optional arguments: + -h, --help show this help message and exit +Commands: + list Output a list of ROS environment variables + set Set ROS environment variables + +$ ros2 env list -a +ROS_VERSION = 2 +ROS_DISTRO = foxy +ROS_PYTHON_VERSION = 3 +ROS_DOMAIN_ID = 7 +RMW_IMPLEMENTATION = rmw_fastrtps_cpp +``` diff --git a/msg_srv_action_interface_example/CHANGELOG.rst b/msg_srv_action_interface_example/CHANGELOG.rst index 289759f..e561b27 100644 --- a/msg_srv_action_interface_example/CHANGELOG.rst +++ b/msg_srv_action_interface_example/CHANGELOG.rst @@ -2,6 +2,9 @@ Changelog for package msg_srv_action_interface_example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.3.0 (2021-01-28) +------------------ + 0.2.0 (2021-01-06) ------------------ * Added new ROS 2 interface package using msg, srv and action for ROS 2 seminar diff --git a/msg_srv_action_interface_example/package.xml b/msg_srv_action_interface_example/package.xml index 330f997..a99e8e5 100644 --- a/msg_srv_action_interface_example/package.xml +++ b/msg_srv_action_interface_example/package.xml @@ -2,7 +2,7 @@ msg_srv_action_interface_example - 0.2.0 + 0.3.0 ROS 2 example for message, service and action interface diff --git a/my_first_ros_rclcpp_pkg/CHANGELOG.rst b/my_first_ros_rclcpp_pkg/CHANGELOG.rst index 7c12c15..642a843 100644 --- a/my_first_ros_rclcpp_pkg/CHANGELOG.rst +++ b/my_first_ros_rclcpp_pkg/CHANGELOG.rst @@ -2,6 +2,9 @@ Changelog for package my_first_ros_rclcpp_pkg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.3.0 (2021-01-28) +------------------ + 0.2.0 (2021-01-06) ------------------ * Added ROS 2 basic package using rclcpp for ROS 2 seminar diff --git a/my_first_ros_rclcpp_pkg/package.xml b/my_first_ros_rclcpp_pkg/package.xml index 271fbbc..3b5d66d 100644 --- a/my_first_ros_rclcpp_pkg/package.xml +++ b/my_first_ros_rclcpp_pkg/package.xml @@ -2,7 +2,7 @@ my_first_ros_rclcpp_pkg - 0.2.0 + 0.3.0 ROS 2 rclcpp basic package for the ROS 2 seminar Pyo Apache License 2.0 diff --git a/my_first_ros_rclpy_pkg/CHANGELOG.rst b/my_first_ros_rclpy_pkg/CHANGELOG.rst index 8103b4c..fa95193 100644 --- a/my_first_ros_rclpy_pkg/CHANGELOG.rst +++ b/my_first_ros_rclpy_pkg/CHANGELOG.rst @@ -2,6 +2,9 @@ Changelog for package my_first_ros_rclpy_pkg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.3.0 (2021-01-28) +------------------ + 0.2.0 (2021-01-06) ------------------ * Added ROS 2 basic package using rclpy for ROS 2 seminar diff --git a/my_first_ros_rclpy_pkg/package.xml b/my_first_ros_rclpy_pkg/package.xml index e2f32ed..6d27613 100644 --- a/my_first_ros_rclpy_pkg/package.xml +++ b/my_first_ros_rclpy_pkg/package.xml @@ -2,7 +2,7 @@ my_first_ros_rclpy_pkg - 0.2.0 + 0.3.0 ROS 2 rclpy basic package for the ROS 2 seminar Pyo Apache License 2.0 diff --git a/my_first_ros_rclpy_pkg/setup.py b/my_first_ros_rclpy_pkg/setup.py index 8f99db7..bc136d7 100644 --- a/my_first_ros_rclpy_pkg/setup.py +++ b/my_first_ros_rclpy_pkg/setup.py @@ -5,7 +5,7 @@ setup( name=package_name, - version='0.2.0', + version='0.3.0', packages=find_packages(exclude=['test']), data_files=[ ('share/ament_index/resource_index/packages', diff --git a/ros2env/CHANGELOG.rst b/ros2env/CHANGELOG.rst new file mode 100644 index 0000000..9da9c1c --- /dev/null +++ b/ros2env/CHANGELOG.rst @@ -0,0 +1,8 @@ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Changelog for package ros2env +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +0.3.0 (2021-01-28) +------------------ +* Added ros2cli command and verbs for example of roc2cli +* Contributors: Pyo diff --git a/ros2env/package.xml b/ros2env/package.xml new file mode 100644 index 0000000..5c0c4fb --- /dev/null +++ b/ros2env/package.xml @@ -0,0 +1,20 @@ + + + + ros2env + 0.3.0 + ROS 2 example package for the ROS 2 command line tools. + Pyo + Apache License 2.0 + Jeremie Deray + Pyo + Darby Lim + ros2cli + ament_copyright + ament_flake8 + ament_pep257 + ament_xmllint + + ament_python + + diff --git a/ros2env/resource/ros2env b/ros2env/resource/ros2env new file mode 100644 index 0000000..e69de29 diff --git a/ros2env/ros2env/__init__.py b/ros2env/ros2env/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ros2env/ros2env/api/__init__.py b/ros2env/ros2env/api/__init__.py new file mode 100644 index 0000000..d2d6def --- /dev/null +++ b/ros2env/ros2env/api/__init__.py @@ -0,0 +1,48 @@ +# Copyright 2018 Open Source Robotics Foundation, Inc. +# Copyright 2019 Canonical Ldt. +# Copyright 2021 OROCA +# +# 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 + + +def get_ros_env_list(): + ros_version = os.getenv('ROS_VERSION', 'None') + ros_distro = os.getenv('ROS_DISTRO', 'None') + ros_python_version = os.getenv('ROS_PYTHON_VERSION', 'None') + ros_env_list = 'ROS_VERSION = {0}\n\ +ROS_DISTRO = {1}\n\ +ROS_PYTHON_VERSION = {2}\n'.format(ros_version, ros_distro, ros_python_version) + return ros_env_list + + +def get_dds_env_list(): + ros_domain_id = os.getenv('ROS_DOMAIN_ID', 'None') + rmw_implementation = os.getenv('RMW_IMPLEMENTATION', 'None') + dds_env_list = 'ROS_DOMAIN_ID = {0}\n\ +RMW_IMPLEMENTATION = {1}\n'.format(ros_domain_id, rmw_implementation) + return dds_env_list + + +def get_all_env_list(): + ros_env_list = get_ros_env_list() + dds_env_list = get_dds_env_list() + all_env_list = ros_env_list + dds_env_list + return all_env_list + + +def set_ros_env(env_name, env_value): + os.environ[env_name] = env_value + value = os.getenv(env_name, 'None') + return '{0} = {1}'.format(env_name, value) diff --git a/ros2env/ros2env/command/__init__.py b/ros2env/ros2env/command/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ros2env/ros2env/command/env.py b/ros2env/ros2env/command/env.py new file mode 100644 index 0000000..399b114 --- /dev/null +++ b/ros2env/ros2env/command/env.py @@ -0,0 +1,40 @@ +# Copyright 2018 Open Source Robotics Foundation, Inc. +# Copyright 2019 Canonical Ldt. +# Copyright 2021 OROCA +# +# 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 ros2cli.command import add_subparsers_on_demand +from ros2cli.command import CommandExtension + + +class EnvCommand(CommandExtension): + """Various env related sub-commands.""" + + def add_arguments(self, parser, cli_name): + self._subparser = parser + + # add arguments and sub-commands of verbs + add_subparsers_on_demand( + parser, cli_name, '_verb', 'ros2env.verb', required=False) + + def main(self, *, parser, args): + if not hasattr(args, '_verb'): + # in case no verb was passed + self._subparser.print_help() + return 0 + + extension = getattr(args, '_verb') + + # call the verb's main method + return extension.main(args=args) diff --git a/ros2env/ros2env/verb/__init__.py b/ros2env/ros2env/verb/__init__.py new file mode 100644 index 0000000..13ca277 --- /dev/null +++ b/ros2env/ros2env/verb/__init__.py @@ -0,0 +1,44 @@ +# Copyright 2018 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 ros2cli.plugin_system import PLUGIN_SYSTEM_VERSION +from ros2cli.plugin_system import satisfies_version + + +class VerbExtension: + """ + The extension point for 'env' verb extensions. + + The following properties must be defined: + * `NAME` (will be set to the entry point name) + + The following methods must be defined: + * `main` + + The following methods can be defined: + * `add_arguments` + """ + + NAME = None + EXTENSION_POINT_VERSION = '0.1' + + def __init__(self): + super(VerbExtension, self).__init__() + satisfies_version(PLUGIN_SYSTEM_VERSION, '^0.1') + + def add_arguments(self, parser, cli_name): + pass + + def main(self, *, args): + raise NotImplementedError() diff --git a/ros2env/ros2env/verb/list.py b/ros2env/ros2env/verb/list.py new file mode 100644 index 0000000..55c4621 --- /dev/null +++ b/ros2env/ros2env/verb/list.py @@ -0,0 +1,44 @@ +# Copyright 2018 Open Source Robotics Foundation, Inc. +# Copyright 2019 Canonical Ldt. +# Copyright 2021 OROCA +# +# 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 ros2env.api import get_all_env_list +from ros2env.api import get_dds_env_list +from ros2env.api import get_ros_env_list +from ros2env.verb import VerbExtension + + +class ListVerb(VerbExtension): + """Output a list of ROS environment variables.""" + + def add_arguments(self, parser, cli_name): + parser.add_argument( + '-a', '--all', action='store_true', + help='Display all environment variables.') + parser.add_argument( + '-r', '--ros-env', action='store_true', + help='Display the ROS environment variables.') + parser.add_argument( + '-d', '--dds-env', action='store_true', + help='Display the DDS environment variables.') + + def main(self, *, args): + if args.ros_env: + message = get_ros_env_list() + elif args.dds_env: + message = get_dds_env_list() + else: + message = get_all_env_list() + print(message) diff --git a/ros2env/ros2env/verb/set.py b/ros2env/ros2env/verb/set.py new file mode 100644 index 0000000..edc375e --- /dev/null +++ b/ros2env/ros2env/verb/set.py @@ -0,0 +1,38 @@ +# Copyright 2018 Open Source Robotics Foundation, Inc. +# Copyright 2019 Canonical Ldt. +# Copyright 2021 OROCA +# +# 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 ros2env.api import get_all_env_list +from ros2env.api import set_ros_env +from ros2env.verb import VerbExtension + + +class SetVerb(VerbExtension): + """Set ROS environment variables.""" + + def add_arguments(self, parser, cli_name): + parser.add_argument( + 'env_name', help='Name of the environment variable') + parser.add_argument( + 'value', help='Value of the environment variable') + + def main(self, *, args): + if args.env_name or args.value: + message = set_ros_env(args.env_name, args.value) + print('[Changed ROS environment variable]:') + print(message) + message = get_all_env_list() + print('\n[Current ROS environment variable]:') + print(message) diff --git a/ros2env/setup.py b/ros2env/setup.py new file mode 100644 index 0000000..0b9dd7b --- /dev/null +++ b/ros2env/setup.py @@ -0,0 +1,44 @@ +from setuptools import find_packages +from setuptools import setup + +package_name = 'ros2env' +share_dir = 'share/' + package_name + +setup( + name=package_name, + version='0.3.0', + packages=find_packages(exclude=['test']), + data_files=[ + ('share/ament_index/resource_index/packages', ['resource/' + package_name]), + (share_dir, ['package.xml']), + ], + install_requires=['ros2cli'], + zip_safe=True, + author='Jeremie Deray, Pyo, Darby Lim', + author_email='jeremie.deray@canonical.org, passionvirus@gmail.com, routiful@gmail.com', + maintainer='Pyo', + maintainer_email='passionvirus@gmail.com', + keywords=['ROS'], + classifiers=[ + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Programming Language :: Python', + 'Topic :: Software Development', + ], + description='ROS 2 example package for the ROS 2 command line tools.', + license='Apache License, Version 2.0', + tests_require=['pytest'], + entry_points={ + 'ros2cli.command': [ + 'env = ros2env.command.env:EnvCommand', + ], + 'ros2cli.extension_point': [ + 'ros2env.verb = ros2env.verb:VerbExtension', + ], + 'ros2env.verb': [ + 'list = ros2env.verb.list:ListVerb', + 'set = ros2env.verb.set:SetVerb', + ], + }, +) diff --git a/ros2env/test/test_copyright.py b/ros2env/test/test_copyright.py new file mode 100644 index 0000000..cf0fae3 --- /dev/null +++ b/ros2env/test/test_copyright.py @@ -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_copyright.main import main +import pytest + + +@pytest.mark.copyright +@pytest.mark.linter +def test_copyright(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found errors' diff --git a/ros2env/test/test_flake8.py b/ros2env/test/test_flake8.py new file mode 100644 index 0000000..eff8299 --- /dev/null +++ b/ros2env/test/test_flake8.py @@ -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 +import pytest + + +@pytest.mark.flake8 +@pytest.mark.linter +def test_flake8(): + rc = main(argv=[]) + assert rc == 0, 'Found errors' diff --git a/ros2env/test/test_pep257.py b/ros2env/test/test_pep257.py new file mode 100644 index 0000000..0e38a6c --- /dev/null +++ b/ros2env/test/test_pep257.py @@ -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_pep257.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.pep257 +def test_pep257(): + rc = main(argv=[]) + assert rc == 0, 'Found code style errors / warnings' diff --git a/ros2env/test/test_xmllint.py b/ros2env/test/test_xmllint.py new file mode 100644 index 0000000..f46285e --- /dev/null +++ b/ros2env/test/test_xmllint.py @@ -0,0 +1,23 @@ +# Copyright 2019 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_xmllint.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.xmllint +def test_xmllint(): + rc = main(argv=[]) + assert rc == 0, 'Found errors' diff --git a/time_rclcpp_example/CHANGELOG.rst b/time_rclcpp_example/CHANGELOG.rst new file mode 100644 index 0000000..d679e27 --- /dev/null +++ b/time_rclcpp_example/CHANGELOG.rst @@ -0,0 +1,8 @@ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Changelog for package time_rclcpp_example +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +0.3.0 (2021-01-28) +------------------ +* Added time example using rclcpp +* Contributors: Darby Lim diff --git a/time_rclcpp_example/CMakeLists.txt b/time_rclcpp_example/CMakeLists.txt new file mode 100644 index 0000000..5668000 --- /dev/null +++ b/time_rclcpp_example/CMakeLists.txt @@ -0,0 +1,45 @@ +################################################################################ +# Set minimum required version of cmake, project name and compile options +################################################################################ +cmake_minimum_required(VERSION 3.5) +project(time_rclcpp_example) + +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) +endif() + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +################################################################################ +# Find and load build settings from external packages +################################################################################ +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) +find_package(std_msgs REQUIRED) + +add_executable(time_example src/main.cpp) +ament_target_dependencies(time_example + rclcpp + std_msgs +) + +install(TARGETS + time_example + DESTINATION lib/${PROJECT_NAME} +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +################################################################################ +# Find and load build settings from external packages +################################################################################ +ament_package() diff --git a/time_rclcpp_example/package.xml b/time_rclcpp_example/package.xml new file mode 100644 index 0000000..49f37f5 --- /dev/null +++ b/time_rclcpp_example/package.xml @@ -0,0 +1,19 @@ + + + + time_rclcpp_example + 0.3.0 + ROS 2 rclcpp example package for understanding time + Pyo + Apache License 2.0 + Pyo + Darby Lim + ament_cmake + rclcpp + std_msgs + ament_lint_auto + ament_lint_common + + ament_cmake + + diff --git a/time_rclcpp_example/src/main.cpp b/time_rclcpp_example/src/main.cpp new file mode 100644 index 0000000..7999260 --- /dev/null +++ b/time_rclcpp_example/src/main.cpp @@ -0,0 +1,56 @@ +// Copyright 2021 OROCA +// +// 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. + +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "rclcpp/time_source.hpp" + +#include "std_msgs/msg/header.hpp" + + +int main(int argc, char * argv[]) +{ + rclcpp::init(argc, argv); + + auto node = rclcpp::Node::make_shared("time_example_node"); + auto time_publisher = node->create_publisher("time", 10); + std_msgs::msg::Header msg; + + rclcpp::WallRate loop_rate(1); + + while (rclcpp::ok()) { + static rclcpp::Time past = node->now(); + + rclcpp::Time now = node->now(); + RCLCPP_INFO(node->get_logger(), "sec %lf nsec %ld", now.seconds(), now.nanoseconds()); + + if ((now - past).nanoseconds() * 1e-9 > 5) { + RCLCPP_INFO(node->get_logger(), "Over 5 seconds!"); + past = node->now(); + } + + rclcpp::Duration duration(1, 0); + msg.stamp = now + duration; + time_publisher->publish(msg); + + rclcpp::spin_some(node); + loop_rate.sleep(); + } + + rclcpp::shutdown(); + + return 0; +} diff --git a/topic_service_action_rclcpp_example/CHANGELOG.rst b/topic_service_action_rclcpp_example/CHANGELOG.rst index 4d30f57..67d836d 100644 --- a/topic_service_action_rclcpp_example/CHANGELOG.rst +++ b/topic_service_action_rclcpp_example/CHANGELOG.rst @@ -2,6 +2,9 @@ Changelog for package topic_service_action_rclcpp_example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.3.0 (2021-01-28) +------------------ + 0.2.0 (2021-01-06) ------------------ * Added new ROS 2 package using rclcpp, topic, service and action for ROS 2 seminar diff --git a/topic_service_action_rclcpp_example/package.xml b/topic_service_action_rclcpp_example/package.xml index fc31f02..ebc3258 100644 --- a/topic_service_action_rclcpp_example/package.xml +++ b/topic_service_action_rclcpp_example/package.xml @@ -2,7 +2,7 @@ topic_service_action_rclcpp_example - 0.2.0 + 0.3.0 ROS 2 rclcpp example package for the topic, service, action Pyo Apache License 2.0 diff --git a/topic_service_action_rclpy_example/CHANGELOG.rst b/topic_service_action_rclpy_example/CHANGELOG.rst index eccbf52..0660b20 100644 --- a/topic_service_action_rclpy_example/CHANGELOG.rst +++ b/topic_service_action_rclpy_example/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog for package topic_service_action_rclpy_example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.3.0 (2021-01-28) +------------------ +* Modified QoS setting for readability +* Contributors: Pyo + 0.2.0 (2021-01-06) ------------------ * Added new ROS 2 package using rclpy, topic, service and action for ROS 2 seminar diff --git a/topic_service_action_rclpy_example/package.xml b/topic_service_action_rclpy_example/package.xml index 98285cf..c202af6 100644 --- a/topic_service_action_rclpy_example/package.xml +++ b/topic_service_action_rclpy_example/package.xml @@ -2,7 +2,7 @@ topic_service_action_rclpy_example - 0.2.0 + 0.3.0 ROS 2 rclpy example package for the topic, service, action Pyo Apache License 2.0 diff --git a/topic_service_action_rclpy_example/setup.py b/topic_service_action_rclpy_example/setup.py index b380c9f..38d997a 100644 --- a/topic_service_action_rclpy_example/setup.py +++ b/topic_service_action_rclpy_example/setup.py @@ -11,7 +11,7 @@ setup( name=package_name, - version='0.2.0', + version='0.3.0', packages=find_packages(exclude=['test']), data_files=[ ('share/ament_index/resource_index/packages', ['resource/' + package_name]), diff --git a/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/argument.py b/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/argument.py index cbb9240..909f0e9 100644 --- a/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/argument.py +++ b/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/argument.py @@ -38,10 +38,10 @@ def __init__(self): self.add_on_set_parameters_callback(self.update_parameter) QOS_RKL10V = QoSProfile( - reliability=QoSReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE, - history=QoSHistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST, + reliability=QoSReliabilityPolicy.RELIABLE, + history=QoSHistoryPolicy.KEEP_LAST, depth=qos_depth, - durability=QoSDurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE) + durability=QoSDurabilityPolicy.VOLATILE) self.arithmetic_argument_publisher = self.create_publisher( ArithmeticArgument, diff --git a/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/operator.py b/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/operator.py index f947c81..4b1e5d5 100644 --- a/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/operator.py +++ b/topic_service_action_rclpy_example/topic_service_action_rclpy_example/arithmetic/operator.py @@ -50,7 +50,7 @@ def main(args=None): if future.done(): try: service_response = future.result() - except Exception as e: + except Exception as e: # noqa: B902 operator.get_logger().warn('Service call failed: {}'.format(str(e))) else: operator.get_logger().info( diff --git a/topic_service_action_rclpy_example/topic_service_action_rclpy_example/calculator/calculator.py b/topic_service_action_rclpy_example/topic_service_action_rclpy_example/calculator/calculator.py index 47c4413..4a36518 100644 --- a/topic_service_action_rclpy_example/topic_service_action_rclpy_example/calculator/calculator.py +++ b/topic_service_action_rclpy_example/topic_service_action_rclpy_example/calculator/calculator.py @@ -42,10 +42,10 @@ def __init__(self): qos_depth = self.get_parameter('qos_depth').value QOS_RKL10V = QoSProfile( - reliability=QoSReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE, - history=QoSHistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST, + reliability=QoSReliabilityPolicy.RELIABLE, + history=QoSHistoryPolicy.KEEP_LAST, depth=qos_depth, - durability=QoSDurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE) + durability=QoSDurabilityPolicy.VOLATILE) self.arithmetic_argument_subscriber = self.create_subscription( ArithmeticArgument,