From a296551cbe3d5e293e1ac36ef2f1c8611ec0c0e6 Mon Sep 17 00:00:00 2001
From: ad-daniel <44834743+ad-daniel@users.noreply.github.com>
Date: Thu, 19 Jan 2023 08:53:20 +0100
Subject: [PATCH] Enforce clang format (#599)
* Apply clangformat
* Add test sources
* Test pep8
* Fix workflow
* Fix workflow
* Fix script
* pep8 fixes
* Cpp fixes
* Remove ament pep257 & flake8
* Update urdf2webots submodule
* Revert "Update urdf2webots submodule"
This reverts commit fa45543bd5d0e94de462342e9b192262baa6aab5.
* Revert "Remove ament pep257 & flake8"
This reverts commit 92df8a316d916d1e260b482c87dfcc3bebd35839.
* Revert "Cpp fixes"
This reverts commit c3a497cff51c6dd7e4f7da791e2515e9f6b578b2.
* Revert "pep8 fixes"
This reverts commit 141b0c85aaa55f942734cd616a8b636d5a7dd963.
* Revert "Revert "pep8 fixes""
This reverts commit ad007a456bc8739f48b14dc2220f1716f909d74d.
* Test
* Revert "Test"
This reverts commit 25934ef9d581bdecebc3eb4635d2c5cb571b01a3.
* Revert "Revert "Cpp fixes""
This reverts commit 8462d81851bf866b3b742a4313e4c4e52b9deeb5.
* Revert "Revert "Remove ament pep257 & flake8""
This reverts commit c689352da0ba037b7ab794434c7428259628a862.
* Revert "Revert "Update urdf2webots submodule""
This reverts commit e2ed2b3efb03de99594277bc0c4c58782112697f.
* Order fixes
* Skip submodule tests
* Finalize
---
.clang-format | 88 +++++++++
.github/ISSUE_TEMPLATE/bug_report.md | 2 +-
.github/workflows/tests_sources.yml | 45 +++++
tests/.gitignore | 1 +
tests/sources/requirements.txt | 3 +
tests/sources/test_clang_format.py | 152 ++++++++++++++
tests/sources/test_cppcheck.py | 116 +++++++++++
tests/sources/test_pep8.py | 187 ++++++++++++++++++
.../test_pep257.py => tests/test_sources.py | 20 +-
webots_ros2/package.xml | 2 -
webots_ros2/test/test_flake8.py | 25 ---
webots_ros2/test/test_pep257.py | 25 ---
.../webots_ros2_control/Ros2Control.hpp | 37 ++--
.../webots_ros2_control/Ros2ControlSystem.hpp | 42 ++--
.../Ros2ControlSystemInterface.hpp | 39 ++--
webots_ros2_control/src/Ros2Control.cpp | 70 +++----
webots_ros2_control/src/Ros2ControlSystem.cpp | 101 +++++-----
.../webots_ros2_driver/PluginInterface.hpp | 39 ++--
.../webots_ros2_driver/PythonPlugin.hpp | 28 ++-
.../include/webots_ros2_driver/WebotsNode.hpp | 14 +-
.../plugins/Ros2SensorPlugin.hpp | 15 +-
.../plugins/dynamic/Ros2IMU.hpp | 14 +-
.../plugins/static/Ros2Camera.hpp | 21 +-
.../plugins/static/Ros2DistanceSensor.hpp | 15 +-
.../plugins/static/Ros2GPS.hpp | 10 +-
.../plugins/static/Ros2LED.hpp | 16 +-
.../plugins/static/Ros2Lidar.hpp | 15 +-
.../plugins/static/Ros2LightSensor.hpp | 15 +-
.../plugins/static/Ros2RangeFinder.hpp | 15 +-
.../include/webots_ros2_driver/utils/Math.hpp | 7 +-
.../webots_ros2_driver/utils/Utils.hpp | 9 +-
.../scripts/webots_tcp_client.py | 3 +-
webots_ros2_driver/src/Driver.cpp | 7 +-
webots_ros2_driver/src/PythonPlugin.cpp | 114 ++++++-----
webots_ros2_driver/src/WebotsNode.cpp | 145 ++++++--------
.../src/plugins/Ros2SensorPlugin.cpp | 11 +-
.../src/plugins/dynamic/Ros2IMU.cpp | 47 ++---
.../src/plugins/static/Ros2Camera.cpp | 88 ++++-----
.../src/plugins/static/Ros2DistanceSensor.cpp | 28 +--
.../src/plugins/static/Ros2GPS.cpp | 46 ++---
.../src/plugins/static/Ros2LED.cpp | 23 +--
.../src/plugins/static/Ros2Lidar.cpp | 41 ++--
.../src/plugins/static/Ros2LightSensor.cpp | 28 ++-
.../src/plugins/static/Ros2RangeFinder.cpp | 53 ++---
webots_ros2_driver/src/utils/Math.cpp | 69 ++-----
webots_ros2_driver/src/utils/Utils.cpp | 37 ++--
.../webots_ros2_driver/ros2_supervisor.py | 54 ++---
.../webots_ros2_driver/urdf_spawner.py | 14 +-
.../webots_ros2_driver/utils.py | 16 +-
.../webots_ros2_driver/webots_launcher.py | 18 +-
webots_ros2_epuck/package.xml | 2 -
webots_ros2_epuck/test/test_flake8.py | 25 ---
webots_ros2_epuck/test/test_pep257.py | 25 ---
webots_ros2_importer/package.xml | 2 -
webots_ros2_importer/pytest.ini | 4 +-
webots_ros2_importer/test/test_flake8.py | 25 ---
.../webots_ros2_importer/urdf2webots | 2 +-
webots_ros2_mavic/package.xml | 2 -
webots_ros2_mavic/test/test_flake8.py | 25 ---
webots_ros2_mavic/test/test_pep257.py | 25 ---
.../msg/CameraRecognitionObject.msg | 2 +-
webots_ros2_tesla/package.xml | 2 -
webots_ros2_tesla/test/test_flake8.py | 25 ---
webots_ros2_tesla/test/test_pep257.py | 25 ---
webots_ros2_tests/package.xml | 2 -
webots_ros2_tests/test/test_flake8.py | 23 ---
webots_ros2_tests/test/test_pep257.py | 23 ---
webots_ros2_tiago/package.xml | 2 -
webots_ros2_tiago/test/test_flake8.py | 25 ---
webots_ros2_tiago/test/test_pep257.py | 25 ---
webots_ros2_turtlebot/package.xml | 2 -
webots_ros2_turtlebot/test/test_flake8.py | 25 ---
webots_ros2_turtlebot/test/test_pep257.py | 25 ---
webots_ros2_universal_robot/package.xml | 2 -
.../resource/moveit_movegroup.yaml | 2 +-
.../test/test_flake8.py | 25 ---
.../test/test_pep257.py | 25 ---
77 files changed, 1213 insertions(+), 1214 deletions(-)
create mode 100644 .clang-format
create mode 100644 .github/workflows/tests_sources.yml
create mode 100644 tests/.gitignore
create mode 100644 tests/sources/requirements.txt
create mode 100755 tests/sources/test_clang_format.py
create mode 100755 tests/sources/test_cppcheck.py
create mode 100755 tests/sources/test_pep8.py
rename webots_ros2_importer/test/test_pep257.py => tests/test_sources.py (64%)
mode change 100644 => 100755
delete mode 100644 webots_ros2/test/test_flake8.py
delete mode 100644 webots_ros2/test/test_pep257.py
delete mode 100644 webots_ros2_epuck/test/test_flake8.py
delete mode 100644 webots_ros2_epuck/test/test_pep257.py
delete mode 100644 webots_ros2_importer/test/test_flake8.py
delete mode 100644 webots_ros2_mavic/test/test_flake8.py
delete mode 100644 webots_ros2_mavic/test/test_pep257.py
delete mode 100644 webots_ros2_tesla/test/test_flake8.py
delete mode 100644 webots_ros2_tesla/test/test_pep257.py
delete mode 100644 webots_ros2_tests/test/test_flake8.py
delete mode 100644 webots_ros2_tests/test/test_pep257.py
delete mode 100644 webots_ros2_tiago/test/test_flake8.py
delete mode 100644 webots_ros2_tiago/test/test_pep257.py
delete mode 100644 webots_ros2_turtlebot/test/test_flake8.py
delete mode 100644 webots_ros2_turtlebot/test/test_pep257.py
delete mode 100644 webots_ros2_universal_robot/test/test_flake8.py
delete mode 100644 webots_ros2_universal_robot/test/test_pep257.py
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000..bc49dbcb2
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,88 @@
+---
+Language: Cpp
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignEscapedNewlines: Left
+AlignOperands: true
+AllowAllConstructorInitializersOnNextLine: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: InlineOnly
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: AfterColon
+BreakStringLiterals: true
+ColumnLimit: 128
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 2
+ContinuationIndentWidth: 2
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeCategories:
+ - Regex: '^<.*\.h>'
+ Priority: 1
+ - Regex: '^<.*'
+ Priority: 2
+ - Regex: '.*'
+ Priority: 3
+IncludeIsMainRegex: '([-_](test|unittest))?$'
+IndentCaseLabels: true
+IndentWidth: 2
+IndentWrappedFunctionNames: true
+JavaScriptQuotes: Single
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 8
+UseTab: Never
+...
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 5723c44df..e713da515 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -26,7 +26,7 @@ If applicable, add screenshots to help explain your problem.
**System**
- Webots Version: [e.g., R2019b, R2020a revision 1]
- - ROS Version: [e.g., Dashing, Eloquent]
+ - ROS Version: [e.g., Dashing, Eloquent]
- Operating System: [e.g., Windows 10, Linux Ubuntu 18.04, macOS Mojave]
- Graphics Card: [e.g., NVIDIA GeForce RTX 2080 11 GB, AMD Radeon RX 580 8GB, etc.]
diff --git a/.github/workflows/tests_sources.yml b/.github/workflows/tests_sources.yml
new file mode 100644
index 000000000..239e5a2f9
--- /dev/null
+++ b/.github/workflows/tests_sources.yml
@@ -0,0 +1,45 @@
+name: Test Sources
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened, labeled, unlabeled]
+ branches-ignore:
+ - 'released'
+ schedule:
+ - cron: '0 22 * * *'
+
+defaults:
+ run:
+ shell: bash
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ test-sources:
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-20.04]
+ python: ['3.10']
+ include:
+ - os: ubuntu-20.04
+ DEPENDENCIES_INSTALLATION: "sudo apt -y install clang-format-10 cppcheck"
+ runs-on: ${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v3
+ if: github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
+ with:
+ submodules: true
+ - name: Set up Python 3.10
+ if: github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.10'
+ - name: Test Sources
+ if: github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
+ run: |
+ ${{ matrix.DEPENDENCIES_INSTALLATION }}
+ pip install -r tests/sources/requirements.txt
+ python3 -m unittest discover -s tests/sources/
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 000000000..174b880f6
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1 @@
+/cppcheck_report.txt
diff --git a/tests/sources/requirements.txt b/tests/sources/requirements.txt
new file mode 100644
index 000000000..faecd21e9
--- /dev/null
+++ b/tests/sources/requirements.txt
@@ -0,0 +1,3 @@
+pycodestyle
+pyflakes
+image
diff --git a/tests/sources/test_clang_format.py b/tests/sources/test_clang_format.py
new file mode 100755
index 000000000..9d21390c2
--- /dev/null
+++ b/tests/sources/test_clang_format.py
@@ -0,0 +1,152 @@
+#!/usr/bin/env python
+
+# Copyright 1996-2023 Cyberbotics Ltd.
+#
+# 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.
+
+"""Test that the C, C++ and shader source code is compliant with ClangFormat."""
+import unittest
+
+import difflib
+import os
+import shutil
+import subprocess
+
+from io import open
+
+
+class TestClangFormat(unittest.TestCase):
+ """Unit test for ClangFormat compliance."""
+
+ def setUp(self):
+ """Set up called before each test."""
+ self.ROOT_FOLDER = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ print(self.ROOT_FOLDER)
+
+ def _runClangFormat(self, f):
+ """Run clang format on 'f' file."""
+ return subprocess.check_output(['clang-format', '-style=file', f])
+
+ def test_clang_format_is_correctly_installed(self):
+ """Test ClangFormat is correctly installed."""
+ self.assertTrue(
+ shutil.which('clang-format') is not None,
+ msg='ClangFormat is not installed on this computer.'
+ )
+ clangFormatConfigFile = os.path.join(self.ROOT_FOLDER, '.clang-format')
+ self.assertTrue(
+ os.path.exists(clangFormatConfigFile),
+ msg=clangFormatConfigFile + ' not found.'
+ )
+
+ def test_sources_are_clang_format_compliant(self):
+ """Test that sources are ClangFormat compliant."""
+ directories = [
+ 'webots_ros2',
+ 'webots_ros2_control',
+ 'webots_ros2_driver',
+ 'webots_ros2_epuck',
+ 'webots_ros2_importer',
+ 'webots_ros2_mavic',
+ 'webots_ros2_msgs',
+ 'webots_ros2_tesla',
+ 'webots_ros2_tests',
+ 'webots_ros2_tiago',
+ 'webots_ros2_turtlebot',
+ 'webots_ros2_universal_robot'
+ ]
+ skippedPaths = [
+ 'webots_ros2_driver/webots/',
+ 'webots_ros2_importer/webots_ros2_importer/urdf2webots/tests'
+ ]
+ skippedFiles = [
+ ]
+ skippedDirectories = [
+ ]
+ skippedPathsFull = [os.path.join(self.ROOT_FOLDER, os.path.normpath(path)) for path in skippedPaths]
+ skippedFilesFull = [os.path.join(self.ROOT_FOLDER, os.path.normpath(file)) for file in skippedFiles]
+
+ extensions = ['c', 'h', 'cpp', 'hpp', 'cc', 'hh', 'c++', 'h++', 'vert', 'frag']
+ modified_files = os.path.join(self.ROOT_FOLDER, 'tests', 'sources', 'modified_files.txt')
+ sources = []
+ if os.path.isfile(modified_files):
+ with open(modified_files, 'r') as file:
+ for line in file:
+ line = line.strip()
+ extension = os.path.splitext(line)[1][1:].lower()
+ if extension not in extensions:
+ continue
+ found = False
+ for directory in directories:
+ if line.startswith(directory):
+ found = True
+ break
+ if not found:
+ continue
+ found = False
+ for directory in skippedPaths + skippedFiles:
+ if line.startswith(directory):
+ found = True
+ break
+ if found:
+ continue
+ for directory in skippedDirectories:
+ currentDirectories = line.split(os.sep)
+ if directory in currentDirectories:
+ found = True
+ if found:
+ continue
+ sources.append(os.path.normpath(line))
+ else:
+ for directory in directories:
+ path = os.path.join(self.ROOT_FOLDER, os.path.normpath(directory))
+ for rootPath, dirNames, fileNames in os.walk(path):
+ shouldContinue = False
+ for skippedPath in skippedPathsFull:
+ if rootPath.startswith(skippedPath):
+ shouldContinue = True
+ break
+ for directory in skippedDirectories:
+ currentDirectories = rootPath.replace(self.ROOT_FOLDER + os.sep, '').split(os.sep)
+ if directory in currentDirectories:
+ shouldContinue = True
+ break
+ if shouldContinue:
+ continue
+ for fileName in fileNames:
+ extension = os.path.splitext(fileName)[1][1:].lower()
+ if extension not in extensions:
+ continue
+ path = os.path.normpath(os.path.join(rootPath, fileName))
+ if path not in skippedFilesFull:
+ sources.append(path)
+ curdir = os.getcwd()
+ os.chdir(self.ROOT_FOLDER)
+ for source in sources:
+ diff = ''
+ with open(source, encoding='utf8') as file:
+ try:
+ for line in difflib.context_diff(self._runClangFormat(source).decode('utf-8').splitlines(),
+ file.read().splitlines()):
+ diff += line + '\n'
+ except UnicodeDecodeError:
+ self.assertTrue(False, msg='utf-8 decode problem in %s' % source)
+ self.assertTrue(
+ len(diff) == 0,
+ msg='Source file "%s" is not compliant with ClangFormat:\n\nDIFF:%s' % (source, diff)
+ )
+ os.chdir(curdir)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/sources/test_cppcheck.py b/tests/sources/test_cppcheck.py
new file mode 100755
index 000000000..48d88029d
--- /dev/null
+++ b/tests/sources/test_cppcheck.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+
+# Copyright 1996-2023 Cyberbotics Ltd.
+#
+# 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.
+
+"""Test quality of the source code using Cppcheck."""
+import unittest
+import os
+import multiprocessing
+import shutil
+
+
+class TestCppCheck(unittest.TestCase):
+ """Unit test for CppCheck errors."""
+
+ def setUp(self):
+ """Set up called before each test."""
+ self.ROOT_FOLDER = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ self.reportFilename = os.path.join(self.ROOT_FOLDER, 'tests', 'cppcheck_report.txt')
+ self.extensions = ['c', 'h', 'cpp', 'hpp', 'cc', 'hh', 'c++', 'h++']
+
+ def test_cppcheck_is_correctly_installed(self):
+ """Test Cppcheck is correctly installed."""
+ self.assertTrue(
+ shutil.which('cppcheck') is not None,
+ msg='Cppcheck is not installed on this computer.'
+ )
+
+ def run_cppcheck(self, command):
+ """Run Cppcheck command and check for errors."""
+ curdir = os.getcwd()
+ os.chdir(self.ROOT_FOLDER)
+ if os.path.isfile(self.reportFilename):
+ os.remove(self.reportFilename)
+ os.system(command) # warning: on Windows, the length of command is limited to 8192 characters
+ if os.path.isfile(self.reportFilename):
+ with open(self.reportFilename, 'r') as reportFile:
+ reportText = reportFile.read()
+ self.assertTrue(
+ not reportText,
+ msg='Cppcheck detected some errors:\n\n%s' % reportText
+ )
+ os.remove(self.reportFilename)
+ os.chdir(curdir)
+
+ def add_source_files(self, sourceDirs, skippedDirs, skippedfiles=[]):
+ command = ''
+ modified_files = os.path.join(self.ROOT_FOLDER, 'tests', 'sources', 'modified_files.txt')
+ if os.path.isfile(modified_files):
+ with open(modified_files, 'r') as file:
+ for line in file:
+ line = line.strip()
+ extension = os.path.splitext(line)[1][1:].lower()
+ if extension not in self.extensions:
+ continue
+ for sourceDir in sourceDirs:
+ if line.startswith(sourceDir):
+ shouldSkip = False
+ for skipped in skippedDirs + skippedfiles:
+ if line.startswith(skipped):
+ shouldSkip = True
+ break
+ if not shouldSkip:
+ command += ' \"' + line + '\"'
+ continue
+ for source in skippedfiles:
+ command += ' --suppress=\"*:' + source + '\"'
+ else:
+ for source in skippedfiles:
+ command += ' --suppress=\"*:' + source + '\"'
+ for source in skippedDirs:
+ command += ' -i\"' + source + '\"'
+ for source in sourceDirs:
+ command += ' \"' + source + '\"'
+ return command
+
+ def test_sources_with_cppcheck(self):
+ """Test with Cppcheck."""
+ sourceDirs = [
+ 'webots_ros2_control/src',
+ 'webots_ros2_driver/src',
+ ]
+ skippedDirs = [
+
+ ]
+ includeDirs = [
+ 'webots_ros2_control/include',
+ ]
+ command = 'cppcheck --enable=warning,style,performance,portability --inconclusive --force -q'
+ command += ' -j %s' % str(multiprocessing.cpu_count())
+ command += ' --inline-suppr --suppress=invalidPointerCast --suppress=useStlAlgorithm --suppress=uninitMemberVar '
+ command += ' --suppress=noCopyConstructor --suppress=noOperatorEq --suppress=strdupCalled --suppress=unknownMacro'
+ # command += ' --xml ' # Uncomment this line to get more information on the errors
+ command += ' --output-file=\"' + self.reportFilename + '\"'
+ for include in includeDirs:
+ command += ' -I\"' + include + '\"'
+ sources = self.add_source_files(sourceDirs, skippedDirs)
+ if not sources:
+ return
+ command += sources
+ self.run_cppcheck(command)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/sources/test_pep8.py b/tests/sources/test_pep8.py
new file mode 100755
index 000000000..71b0dabf3
--- /dev/null
+++ b/tests/sources/test_pep8.py
@@ -0,0 +1,187 @@
+#!/usr/bin/env python
+
+# Copyright 1996-2023 Cyberbotics Ltd.
+#
+# 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.
+
+"""Test module of the PEP8 format in the tests."""
+import unittest
+
+import _ast
+import fnmatch
+import pycodestyle
+import os
+import sys
+from io import open # needed for compatibility with Python 2.7 for open(file, encoding='utf-8')
+
+from pyflakes import checker
+from pyflakes.reporter import Reporter
+
+ROOT_FOLDER = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+skippedDirectories = [
+ '.git',
+ 'webots_ros2_importer/webots_ros2_importer/urdf2webots/',
+ 'webots_ros2_driver/webots/lib'
+]
+skippedDirectoriesFull = [os.path.join(ROOT_FOLDER, os.path.normpath(path)) for path in skippedDirectories]
+
+
+class FlakesReporter(Reporter):
+ """Flakes reporter."""
+
+ def __init__(self):
+ self.error = ''
+
+ def unexpectedError(self, filename, msg):
+ """Handle unexpected errors."""
+ self.error += '%s: %s\n' % (filename, msg)
+
+ def syntaxError(self, filename, msg, lineno, offset, text):
+ """Handle syntax errors."""
+ line = text.splitlines()[-1]
+ if offset is not None:
+ offset = offset - (len(text) - len(line))
+ self.error += '%s:%d: %s\n' % (filename, lineno, msg)
+ self.error += line + '\n'
+ if offset is not None:
+ self.error += ' ' * (offset + 1) + '^\n'
+
+ def flake(self, message):
+ """Add message to error string."""
+ self.error += str(message) + '\n'
+
+
+def checkFlakes(codeString, filename, reporter):
+ """Check the Python source given by codeString} for flakes."""
+ # First, compile into an AST and handle syntax errors.
+ try:
+ tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
+ except SyntaxError:
+ value = sys.exc_info()[1]
+ msg = value.args[0]
+ (lineno, offset, text) = value.lineno, value.offset, value.text
+ # If there's an encoding problem with the file, the text is None.
+ if text is None:
+ # Avoid using msg, since for the only known case, it contains a
+ # bogus message that claims the encoding the file declared was
+ # unknown.
+ reporter.unexpectedError(filename, 'problem decoding source')
+ else:
+ reporter.syntaxError(filename, msg, lineno, offset, text)
+ return
+ except Exception:
+ reporter.unexpectedError(filename, 'problem decoding source')
+ return
+ # Okay, it's syntactically valid. Now check it.
+ w = checker.Checker(tree, filename)
+ w.messages.sort(key=lambda m: m.lineno)
+ for warning in w.messages:
+ reporter.flake(warning)
+
+
+def checkFlakesPath(filename, reporter):
+ """Check the given path, printing out any warnings detected."""
+ try:
+ with open(filename, encoding='utf-8') as f:
+ codestr = f.read() + '\n'
+ except UnicodeError:
+ reporter.unexpectedError(filename, 'problem decoding source')
+ return
+ except IOError:
+ msg = sys.exc_info()[1]
+ reporter.unexpectedError(filename, msg.args[1])
+ return
+ checkFlakes(codestr.encode('utf-8'), filename, reporter)
+
+
+class CustomReport(pycodestyle.StandardReport):
+ """Collect report, and overload the string operator."""
+
+ results = []
+
+ def get_file_results(self):
+ """Overload this function to collect the report."""
+ if self._deferred_print:
+ self._deferred_print.sort()
+ for line_number, offset, code, text, _ in self._deferred_print:
+ self.results.append({
+ 'path': self.filename,
+ 'row': self.line_offset + line_number,
+ 'col': offset + 1,
+ 'code': code,
+ 'text': text,
+ })
+ return self.file_errors
+
+ def __str__(self):
+ """Overload the string operator."""
+ output = 'Report:\n'
+ for result in self.results:
+ output += '%s:%d:%d: %s: %s\n' % (
+ result['path'],
+ result['row'],
+ result['col'],
+ result['code'],
+ result['text']
+ )
+ return output
+
+
+class TestCodeFormat(unittest.TestCase):
+ """Unit test of the PEP8 format in the tests."""
+
+ def setUp(self):
+ """Get all the python files."""
+ self.files = []
+ for rootPath, dirNames, fileNames in os.walk(ROOT_FOLDER):
+ for fileName in fnmatch.filter(fileNames, '*.py'):
+ shouldContinue = False
+ for skippedDirectory in skippedDirectoriesFull:
+ if rootPath.startswith(skippedDirectory):
+ shouldContinue = True
+ break
+ if shouldContinue:
+ continue
+ filePath = os.path.join(rootPath, fileName)
+ if sys.version_info[0] < 3:
+ with open(filePath) as file:
+ if file.readline().startswith('#!/usr/bin/env python3'):
+ continue
+ self.files.append(filePath)
+
+ def test_pep8_conformance(self):
+ """Test that the tests are PEP8 compliant."""
+ # Use pep8 module to detect 'W' and 'E' errors
+ checker = pycodestyle.StyleGuide(
+ quiet=True,
+ paths=self.files,
+ reporter=CustomReport,
+ )
+ checker.options.max_line_length = 128
+ report = checker.check_files()
+ self.assertEqual(
+ report.total_errors, 0,
+ msg='PEP8 errors:\n%s' % (report)
+ )
+ # Use flakes module to detect 'F' errors
+ reporter = FlakesReporter()
+ for fileName in self.files:
+ checkFlakesPath(fileName, reporter)
+ self.assertTrue(
+ not reporter.error,
+ msg='PEP8 errors:\n%s' % (reporter.error)
+ )
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/webots_ros2_importer/test/test_pep257.py b/tests/test_sources.py
old mode 100644
new mode 100755
similarity index 64%
rename from webots_ros2_importer/test/test_pep257.py
rename to tests/test_sources.py
index 06a350a3f..3f247627b
--- a/webots_ros2_importer/test/test_pep257.py
+++ b/tests/test_sources.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright 1996-2023 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,14 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Test that python files respect pep257."""
-
-from ament_pep257.main import main
-import pytest
-
+"""Unit test."""
+import sys
+import unittest
-@pytest.mark.linter
-@pytest.mark.pep257
-def test_pep257():
- rc = main(argv=['.', '--exclude', 'webots_ros2_importer/urdf2webots/'])
- assert rc == 0, 'Found code style errors / warnings'
+# Run the sources tests
+test_suite = unittest.defaultTestLoader.discover('sources', '*.py')
+test_runner = unittest.TextTestRunner(verbosity=2, resultclass=unittest.TextTestResult)
+result = test_runner.run(test_suite)
+sys.exit(not result.wasSuccessful())
diff --git a/webots_ros2/package.xml b/webots_ros2/package.xml
index 0a3dd8903..d46ee8a86 100644
--- a/webots_ros2/package.xml
+++ b/webots_ros2/package.xml
@@ -26,8 +26,6 @@
webots_ros2_universal_robot
ament_copyright
- ament_flake8
- ament_pep257
python3-pytest
webots_ros2_tests
diff --git a/webots_ros2/test/test_flake8.py b/webots_ros2/test/test_flake8.py
deleted file mode 100644
index c79ba0d9c..000000000
--- a/webots_ros2/test/test_flake8.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# 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.
-
-"""Test that python files respect flake8."""
-
-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/webots_ros2/test/test_pep257.py b/webots_ros2/test/test_pep257.py
deleted file mode 100644
index fac857efd..000000000
--- a/webots_ros2/test/test_pep257.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 1996-2023 Cyberbotics Ltd.
-#
-# 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.
-
-"""Test that python files respect pep257."""
-
-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/webots_ros2_control/include/webots_ros2_control/Ros2Control.hpp b/webots_ros2_control/include/webots_ros2_control/Ros2Control.hpp
index 13988a3b8..6dc1262e5 100644
--- a/webots_ros2_control/include/webots_ros2_control/Ros2Control.hpp
+++ b/webots_ros2_control/include/webots_ros2_control/Ros2Control.hpp
@@ -17,42 +17,41 @@
#include
#include
-#include
#include
+#include
#if FOXY
- #include "hardware_interface/base_interface.hpp"
- #include "hardware_interface/types/hardware_interface_status_values.hpp"
+#include "hardware_interface/base_interface.hpp"
+#include "hardware_interface/types/hardware_interface_status_values.hpp"
#endif
-#include "hardware_interface/system_interface.hpp"
+#include "controller_manager/controller_manager.hpp"
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
+#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
-#include "controller_manager/controller_manager.hpp"
#include "rclcpp/macros.hpp"
+#include "webots_ros2_control/Ros2ControlSystemInterface.hpp"
#include "webots_ros2_driver/PluginInterface.hpp"
#include "webots_ros2_driver/WebotsNode.hpp"
-#include "webots_ros2_control/Ros2ControlSystemInterface.hpp"
-namespace webots_ros2_control
-{
- class Ros2Control : public webots_ros2_driver::PluginInterface
- {
+namespace webots_ros2_control {
+ class Ros2Control : public webots_ros2_driver::PluginInterface {
public:
+ Ros2Control();
void step() override;
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
- private:
- webots_ros2_driver::WebotsNode *mNode;
- std::shared_ptr> mHardwareLoader;
- std::shared_ptr mControllerManager;
- int mControlPeriodMs;
- int mLastControlUpdateMs;
+ private:
+ webots_ros2_driver::WebotsNode *mNode;
+ std::shared_ptr> mHardwareLoader;
+ std::shared_ptr mControllerManager;
+ int mControlPeriodMs;
+ int mLastControlUpdateMs;
- std::thread mThreadExecutor;
- rclcpp::executors::MultiThreadedExecutor::SharedPtr mExecutor;
+ std::thread mThreadExecutor;
+ rclcpp::executors::MultiThreadedExecutor::SharedPtr mExecutor;
};
-}
+} // namespace webots_ros2_control
#endif
diff --git a/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystem.hpp b/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystem.hpp
index e924d94da..3a38af0a6 100644
--- a/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystem.hpp
+++ b/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystem.hpp
@@ -20,24 +20,23 @@
#include
#if FOXY
- #include "hardware_interface/base_interface.hpp"
- #include "hardware_interface/types/hardware_interface_status_values.hpp"
+#include "hardware_interface/base_interface.hpp"
+#include "hardware_interface/types/hardware_interface_status_values.hpp"
#endif
-#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
+#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "rclcpp/macros.hpp"
#include "webots_ros2_driver/PluginInterface.hpp"
#include "webots_ros2_driver/WebotsNode.hpp"
-#include "webots_ros2_control/Ros2ControlSystemInterface.hpp"
#include "webots/motor.h"
#include "webots/position_sensor.h"
+#include "webots_ros2_control/Ros2ControlSystemInterface.hpp"
-namespace webots_ros2_control
-{
+namespace webots_ros2_control {
struct Joint {
double positionCommand;
double position;
@@ -53,20 +52,23 @@ namespace webots_ros2_control
WbDeviceTag sensor;
};
- class Ros2ControlSystem : public Ros2ControlSystemInterface
- {
+ class Ros2ControlSystem : public Ros2ControlSystemInterface {
public:
+ Ros2ControlSystem();
void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) override;
- #if FOXY
- hardware_interface::return_type configure(const hardware_interface::HardwareInfo &info) override;
- hardware_interface::return_type start() override;
- hardware_interface::return_type stop() override;
- #else
- rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_init(const hardware_interface::HardwareInfo &info) override;
- rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(const rclcpp_lifecycle::State & /*previous_state*/) override;
- rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/) override;
- #endif
+#if FOXY
+ hardware_interface::return_type configure(const hardware_interface::HardwareInfo &info) override;
+ hardware_interface::return_type start() override;
+ hardware_interface::return_type stop() override;
+#else
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_init(
+ const hardware_interface::HardwareInfo &info) override;
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(
+ const rclcpp_lifecycle::State & /*previous_state*/) override;
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_deactivate(
+ const rclcpp_lifecycle::State & /*previous_state*/) override;
+#endif
std::vector export_state_interfaces() override;
std::vector export_command_interfaces() override;
@@ -74,14 +76,14 @@ namespace webots_ros2_control
hardware_interface::return_type read() override;
hardware_interface::return_type write() override;
#else // HUMBLE, ROLLING
- hardware_interface::return_type read(const rclcpp::Time &/*time*/, const rclcpp::Duration &/*period*/) override;
- hardware_interface::return_type write(const rclcpp::Time &/*time*/, const rclcpp::Duration &/*period*/) override;
+ hardware_interface::return_type read(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override;
+ hardware_interface::return_type write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override;
#endif
private:
webots_ros2_driver::WebotsNode *mNode;
std::vector mJoints;
};
-}
+} // namespace webots_ros2_control
#endif
diff --git a/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystemInterface.hpp b/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystemInterface.hpp
index d25be9128..f9cbac55e 100644
--- a/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystemInterface.hpp
+++ b/webots_ros2_control/include/webots_ros2_control/Ros2ControlSystemInterface.hpp
@@ -20,34 +20,31 @@
#include
#if FOXY
- #include "hardware_interface/base_interface.hpp"
- #include "hardware_interface/types/hardware_interface_status_values.hpp"
+#include "hardware_interface/base_interface.hpp"
+#include "hardware_interface/types/hardware_interface_status_values.hpp"
#endif
-#include "hardware_interface/system_interface.hpp"
+#include
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
+#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "webots_ros2_driver/PluginInterface.hpp"
-#include
#include "webots_ros2_driver/WebotsNode.hpp"
-namespace webots_ros2_control
-{
- #if FOXY
- class Ros2ControlSystemInterface : public hardware_interface::BaseInterface
- {
- public:
- virtual void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) = 0;
- };
- #else
- class Ros2ControlSystemInterface : public hardware_interface::SystemInterface
- {
- public:
- virtual void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) = 0;
- };
- #endif
-
-}
+namespace webots_ros2_control {
+#if FOXY
+ class Ros2ControlSystemInterface : public hardware_interface::BaseInterface {
+ public:
+ virtual void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) = 0;
+ };
+#else
+ class Ros2ControlSystemInterface : public hardware_interface::SystemInterface {
+ public:
+ virtual void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) = 0;
+ };
+#endif
+
+} // namespace webots_ros2_control
#endif
diff --git a/webots_ros2_control/src/Ros2Control.cpp b/webots_ros2_control/src/Ros2Control.cpp
index 466627d8f..a79d805fe 100644
--- a/webots_ros2_control/src/Ros2Control.cpp
+++ b/webots_ros2_control/src/Ros2Control.cpp
@@ -20,11 +20,11 @@
#include
#include
-#include "hardware_interface/types/hardware_interface_type_values.hpp"
-#include "hardware_interface/resource_manager.hpp"
#include "hardware_interface/component_parser.hpp"
-#include "rclcpp/rclcpp.hpp"
+#include "hardware_interface/resource_manager.hpp"
+#include "hardware_interface/types/hardware_interface_type_values.hpp"
#include "pluginlib/class_list_macros.hpp"
+#include "rclcpp/rclcpp.hpp"
#include
@@ -32,19 +32,18 @@
const double CONTROLLER_MANAGER_ALLOWED_SAMPLE_ERROR_MS = 1.0;
-namespace webots_ros2_control
-{
+namespace webots_ros2_control {
- void Ros2Control::step()
- {
+ Ros2Control::Ros2Control() { mNode = NULL; }
+
+ void Ros2Control::step() {
const int nowMs = wb_robot_get_time() * 1000.0;
const int periodMs = nowMs - mLastControlUpdateMs;
- const rclcpp::Duration dt = rclcpp::Duration::from_seconds(mControlPeriodMs / 1000.0);
- if (periodMs >= mControlPeriodMs)
- {
+ if (periodMs >= mControlPeriodMs) {
#if FOXY
mControllerManager->read();
#else
+ const rclcpp::Duration dt = rclcpp::Duration::from_seconds(mControlPeriodMs / 1000.0);
mControllerManager->read(mNode->get_clock()->now(), dt);
#endif
@@ -56,55 +55,46 @@ namespace webots_ros2_control
#endif
#if FOXY
- mControllerManager->write();
-#else // HUMBLE, ROLLING
- mControllerManager->write(mNode->get_clock()->now(), dt);
+ mControllerManager->write();
+#else // HUMBLE, ROLLING
+ mControllerManager->write(mNode->get_clock()->now(), dt);
#endif
}
}
- void Ros2Control::init(webots_ros2_driver::WebotsNode *node, std::unordered_map &)
- {
+ void Ros2Control::init(webots_ros2_driver::WebotsNode *node, std::unordered_map &) {
mNode = node;
mLastControlUpdateMs = 0;
// Load hardware
- try
- {
+ try {
mHardwareLoader.reset(new pluginlib::ClassLoader(
- "webots_ros2_control",
- "webots_ros2_control::Ros2ControlSystemInterface"));
- }
- catch (pluginlib::LibraryLoadException &ex)
- {
+ "webots_ros2_control", "webots_ros2_control::Ros2ControlSystemInterface"));
+ } catch (pluginlib::LibraryLoadException &ex) {
throw std::runtime_error("Hardware loader cannot be created: " + atoi(ex.what()));
}
// Control Hardware
std::string urdfString;
std::vector controlHardware;
- std::unique_ptr resourceManager = std::make_unique();
- try
- {
+ std::unique_ptr resourceManager =
+ std::make_unique();
+ try {
urdfString = mNode->urdf();
controlHardware = hardware_interface::parse_control_resources_from_urdf(urdfString);
- }
- catch (const std::runtime_error &ex)
- {
+ } catch (const std::runtime_error &ex) {
throw std::runtime_error("URDF cannot be parsed by a `ros2_control` component parser: " + atoi(ex.what()));
}
- for (unsigned int i = 0; i < controlHardware.size(); i++)
- {
-
+ for (unsigned int i = 0; i < controlHardware.size(); i++) {
// Necessary hotfix for renamed variables present in "hardware_interface" package for versions above 3.5 (#590)
#if HARDWARE_INTERFACE_VERSION_MAJOR >= 3 && HARDWARE_INTERFACE_VERSION_MINOR >= 5
const std::string pluginName = controlHardware[i].hardware_plugin_name;
- auto webotsSystem = std::unique_ptr(
- mHardwareLoader->createUnmanagedInstance(pluginName));
+ auto webotsSystem =
+ std::unique_ptr(mHardwareLoader->createUnmanagedInstance(pluginName));
#else
const std::string hardwareType = controlHardware[i].hardware_class_type;
auto webotsSystem = std::unique_ptr(
- mHardwareLoader->createUnmanagedInstance(hardwareType));
+ mHardwareLoader->createUnmanagedInstance(hardwareType));
#endif
webotsSystem->init(mNode, controlHardware[i]);
#if FOXY
@@ -131,17 +121,21 @@ namespace webots_ros2_control
controlPeriodProductMs += wb_robot_get_basic_time_step();
if (abs(controlPeriodProductMs - mControlPeriodMs) > CONTROLLER_MANAGER_ALLOWED_SAMPLE_ERROR_MS)
- RCLCPP_WARN_STREAM(node->get_logger(), "Desired controller update period (" << mControlPeriodMs << "ms / " << updateRate << "Hz) is different from the Webots timestep (" << wb_robot_get_basic_time_step() << "ms). Please adjust the `update_rate` parameter in the `controller_manager` or the `basicTimeStep` parameter in the Webots `WorldInfo` node.");
+ RCLCPP_WARN_STREAM(node->get_logger(), "Desired controller update period ("
+ << mControlPeriodMs << "ms / " << updateRate
+ << "Hz) is different from the Webots timestep ("
+ << wb_robot_get_basic_time_step()
+ << "ms). Please adjust the `update_rate` parameter in the `controller_manager` "
+ "or the `basicTimeStep` parameter in the Webots `WorldInfo` node.");
// Spin
mExecutor->add_node(mControllerManager);
- auto spin = [this]()
- {
+ auto spin = [this]() {
while (rclcpp::ok())
mExecutor->spin_once();
};
mThreadExecutor = std::thread(spin);
}
-}
+} // namespace webots_ros2_control
PLUGINLIB_EXPORT_CLASS(webots_ros2_control::Ros2Control, webots_ros2_driver::PluginInterface)
diff --git a/webots_ros2_control/src/Ros2ControlSystem.cpp b/webots_ros2_control/src/Ros2ControlSystem.cpp
index 415466066..3dd151fe2 100644
--- a/webots_ros2_control/src/Ros2ControlSystem.cpp
+++ b/webots_ros2_control/src/Ros2ControlSystem.cpp
@@ -21,28 +21,26 @@
#include
#include "hardware_interface/types/hardware_interface_type_values.hpp"
-#include "rclcpp/rclcpp.hpp"
#include "pluginlib/class_list_macros.hpp"
+#include "rclcpp/rclcpp.hpp"
-#include
#include
+#include
-namespace webots_ros2_control
-{
- void Ros2ControlSystem::init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info)
- {
+namespace webots_ros2_control {
+ Ros2ControlSystem::Ros2ControlSystem() { mNode = NULL; }
+ void Ros2ControlSystem::init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) {
mNode = node;
- for (hardware_interface::ComponentInfo component : info.joints)
- {
+ for (hardware_interface::ComponentInfo component : info.joints) {
Joint joint;
joint.name = component.name;
WbDeviceTag device = wb_robot_get_device(joint.name.c_str());
WbNodeType type = wb_device_get_node_type(device);
- joint.motor = (type == WB_NODE_LINEAR_MOTOR || type == WB_NODE_ROTATIONAL_MOTOR) ? device : wb_position_sensor_get_motor(device);
- device = (component.parameters.count("sensor") == 0) ?
- wb_robot_get_device(joint.name.c_str()) :
- wb_robot_get_device(component.parameters.at("sensor").c_str());
+ joint.motor =
+ (type == WB_NODE_LINEAR_MOTOR || type == WB_NODE_ROTATIONAL_MOTOR) ? device : wb_position_sensor_get_motor(device);
+ device = (component.parameters.count("sensor") == 0) ? wb_robot_get_device(joint.name.c_str()) :
+ wb_robot_get_device(component.parameters.at("sensor").c_str());
type = wb_device_get_node_type(device);
joint.sensor = (type == WB_NODE_POSITION_SENSOR) ? device : wb_motor_get_position_sensor(device);
@@ -63,8 +61,7 @@ namespace webots_ros2_control
joint.acceleration = NAN;
// Configure the command interface
- for (hardware_interface::InterfaceInfo commandInterface : component.command_interfaces)
- {
+ for (hardware_interface::InterfaceInfo commandInterface : component.command_interfaces) {
if (commandInterface.name == "position")
joint.controlPosition = true;
else if (commandInterface.name == "velocity")
@@ -74,8 +71,7 @@ namespace webots_ros2_control
else
throw std::runtime_error("Invalid hardware info name `" + commandInterface.name + "`");
}
- if (joint.motor && joint.controlVelocity && !joint.controlPosition)
- {
+ if (joint.motor && joint.controlVelocity && !joint.controlPosition) {
wb_motor_set_position(joint.motor, INFINITY);
wb_motor_set_velocity(joint.motor, 0.0);
}
@@ -85,75 +81,74 @@ namespace webots_ros2_control
}
#if FOXY
- hardware_interface::return_type Ros2ControlSystem::configure(const hardware_interface::HardwareInfo &info)
- {
- if (configure_default(info) != hardware_interface::return_type::OK)
- {
+ hardware_interface::return_type Ros2ControlSystem::configure(const hardware_interface::HardwareInfo &info) {
+ if (configure_default(info) != hardware_interface::return_type::OK) {
return hardware_interface::return_type::ERROR;
}
status_ = hardware_interface::status::CONFIGURED;
return hardware_interface::return_type::OK;
}
#else
- rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn Ros2ControlSystem::on_init(const hardware_interface::HardwareInfo &info)
- {
- if (hardware_interface::SystemInterface::on_init(info) != rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS)
- {
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn Ros2ControlSystem::on_init(
+ const hardware_interface::HardwareInfo &info) {
+ if (hardware_interface::SystemInterface::on_init(info) !=
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS) {
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
}
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}
#endif
- std::vector Ros2ControlSystem::export_state_interfaces()
- {
+ std::vector Ros2ControlSystem::export_state_interfaces() {
std::vector interfaces;
for (Joint &joint : mJoints)
if (joint.sensor) {
- interfaces.emplace_back(hardware_interface::StateInterface(joint.name, hardware_interface::HW_IF_POSITION, &(joint.position)));
- interfaces.emplace_back(hardware_interface::StateInterface(joint.name, hardware_interface::HW_IF_VELOCITY, &(joint.velocity)));
- interfaces.emplace_back(hardware_interface::StateInterface(joint.name, hardware_interface::HW_IF_ACCELERATION, &(joint.acceleration)));
+ interfaces.emplace_back(
+ hardware_interface::StateInterface(joint.name, hardware_interface::HW_IF_POSITION, &(joint.position)));
+ interfaces.emplace_back(
+ hardware_interface::StateInterface(joint.name, hardware_interface::HW_IF_VELOCITY, &(joint.velocity)));
+ interfaces.emplace_back(
+ hardware_interface::StateInterface(joint.name, hardware_interface::HW_IF_ACCELERATION, &(joint.acceleration)));
}
return interfaces;
}
- std::vector Ros2ControlSystem::export_command_interfaces()
- {
+ std::vector Ros2ControlSystem::export_command_interfaces() {
std::vector interfaces;
for (Joint &joint : mJoints)
- if (joint.motor)
- {
+ if (joint.motor) {
if (joint.controlPosition)
- interfaces.emplace_back(hardware_interface::CommandInterface(joint.name, hardware_interface::HW_IF_POSITION, &(joint.positionCommand)));
+ interfaces.emplace_back(
+ hardware_interface::CommandInterface(joint.name, hardware_interface::HW_IF_POSITION, &(joint.positionCommand)));
if (joint.controlEffort)
- interfaces.emplace_back(hardware_interface::CommandInterface(joint.name, hardware_interface::HW_IF_EFFORT, &(joint.effortCommand)));
+ interfaces.emplace_back(
+ hardware_interface::CommandInterface(joint.name, hardware_interface::HW_IF_EFFORT, &(joint.effortCommand)));
if (joint.controlVelocity)
- interfaces.emplace_back(hardware_interface::CommandInterface(joint.name, hardware_interface::HW_IF_VELOCITY, &(joint.velocityCommand)));
+ interfaces.emplace_back(
+ hardware_interface::CommandInterface(joint.name, hardware_interface::HW_IF_VELOCITY, &(joint.velocityCommand)));
}
return interfaces;
}
#if FOXY
- hardware_interface::return_type Ros2ControlSystem::start()
- {
+ hardware_interface::return_type Ros2ControlSystem::start() {
status_ = hardware_interface::status::STARTED;
return hardware_interface::return_type::OK;
}
- hardware_interface::return_type Ros2ControlSystem::stop()
- {
+ hardware_interface::return_type Ros2ControlSystem::stop() {
status_ = hardware_interface::status::STOPPED;
return hardware_interface::return_type::OK;
}
#else
- rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn Ros2ControlSystem::on_activate(const rclcpp_lifecycle::State & /*previous_state*/)
- {
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn Ros2ControlSystem::on_activate(
+ const rclcpp_lifecycle::State & /*previous_state*/) {
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}
- rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn Ros2ControlSystem::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/)
- {
+ rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn Ros2ControlSystem::on_deactivate(
+ const rclcpp_lifecycle::State & /*previous_state*/) {
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}
#endif
@@ -161,7 +156,7 @@ namespace webots_ros2_control
#if FOXY
hardware_interface::return_type Ros2ControlSystem::read()
#else // HUMBLE, ROLLING
- hardware_interface::return_type Ros2ControlSystem::read(const rclcpp::Time &/*time*/, const rclcpp::Duration &/*period*/)
+ hardware_interface::return_type Ros2ControlSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
#endif
{
static double lastReadTime = 0;
@@ -169,8 +164,7 @@ namespace webots_ros2_control
const double deltaTime = wb_robot_get_time() - lastReadTime;
lastReadTime = wb_robot_get_time();
- for (Joint &joint : mJoints)
- {
+ for (Joint &joint : mJoints) {
if (joint.sensor) {
const double position = wb_position_sensor_get_value(joint.sensor);
const double velocity = std::isnan(joint.position) ? NAN : (position - joint.position) / deltaTime;
@@ -188,17 +182,14 @@ namespace webots_ros2_control
#if FOXY
hardware_interface::return_type Ros2ControlSystem::write()
#else // HUMBLE, ROLLING
- hardware_interface::return_type Ros2ControlSystem::write(const rclcpp::Time &/*time*/, const rclcpp::Duration &/*period*/)
+ hardware_interface::return_type Ros2ControlSystem::write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
#endif
{
- for (Joint &joint : mJoints)
- {
- if (joint.motor)
- {
+ for (Joint &joint : mJoints) {
+ if (joint.motor) {
if (joint.controlPosition && !std::isnan(joint.positionCommand))
wb_motor_set_position(joint.motor, joint.positionCommand);
- if (joint.controlVelocity && !std::isnan(joint.velocityCommand))
- {
+ if (joint.controlVelocity && !std::isnan(joint.velocityCommand)) {
// In the position control mode the velocity cannot be negative.
const double velocityCommand = joint.controlPosition ? abs(joint.velocityCommand) : joint.velocityCommand;
wb_motor_set_velocity(joint.motor, velocityCommand);
@@ -209,6 +200,6 @@ namespace webots_ros2_control
}
return hardware_interface::return_type::OK;
}
-}
+} // namespace webots_ros2_control
PLUGINLIB_EXPORT_CLASS(webots_ros2_control::Ros2ControlSystem, webots_ros2_control::Ros2ControlSystemInterface)
diff --git a/webots_ros2_driver/include/webots_ros2_driver/PluginInterface.hpp b/webots_ros2_driver/include/webots_ros2_driver/PluginInterface.hpp
index e0a36124b..8aca6140b 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/PluginInterface.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/PluginInterface.hpp
@@ -15,29 +15,28 @@
#ifndef PLUGIN_INTERFACE
#define PLUGIN_INTERFACE
-#include
#include
+#include
-namespace webots_ros2_driver
-{
- class WebotsNode;
+namespace webots_ros2_driver {
+ class WebotsNode;
- class PluginInterface
- {
- public:
- /// Prepare your plugin in this method.
- /// Fired before the node is spinned.
- /// Parameters are passed from the WebotsNode and/or from URDF.
- /**
- * \param[in] node WebotsNode inherited from `rclcpp::Node` with a few extra methods related
- * \param[in] parameters Parameters (key-value pairs) located under a (dynamically loaded plugins) or (statically loaded plugins).
- */
- virtual void init(WebotsNode *node, std::unordered_map ¶meters) = 0;
+ class PluginInterface {
+ public:
+ /// Prepare your plugin in this method.
+ /// Fired before the node is spinned.
+ /// Parameters are passed from the WebotsNode and/or from URDF.
+ /**
+ * \param[in] node WebotsNode inherited from `rclcpp::Node` with a few extra methods related
+ * \param[in] parameters Parameters (key-value pairs) located under a (dynamically loaded plugins) or
+ * (statically loaded plugins).
+ */
+ virtual void init(WebotsNode *node, std::unordered_map ¶meters) = 0;
- /// This method is called on each timestep.
- /// You should not call `robot.step()` in this method as it is automatically called.
- virtual void step() = 0;
- };
-}
+ /// This method is called on each timestep.
+ /// You should not call `robot.step()` in this method as it is automatically called.
+ virtual void step() = 0;
+ };
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/PythonPlugin.hpp b/webots_ros2_driver/include/webots_ros2_driver/PythonPlugin.hpp
index 848914d54..b5f20a358 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/PythonPlugin.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/PythonPlugin.hpp
@@ -15,29 +15,27 @@
#ifndef PYTHON_PLUGIN_HPP
#define PYTHON_PLUGIN_HPP
-#include
#include
#include
+#include
#include
#include
-namespace webots_ros2_driver
-{
- class PythonPlugin : public PluginInterface
- {
- public:
- void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
- void step() override;
+namespace webots_ros2_driver {
+ class PythonPlugin : public PluginInterface {
+ public:
+ void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
+ void step() override;
- static std::shared_ptr createFromType(const std::string &type);
+ static std::shared_ptr createFromType(const std::string &type);
- private:
- PythonPlugin(PyObject *pyPlugin);
+ private:
+ PythonPlugin(PyObject *pyPlugin);
- PyObject *mPyPlugin;
- PyObject *getPyWebotsNodeInstance();
- };
-}
+ PyObject *mPyPlugin;
+ PyObject *getPyWebotsNodeInstance();
+ };
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/WebotsNode.hpp b/webots_ros2_driver/include/webots_ros2_driver/WebotsNode.hpp
index 8d88b1a14..3e6fac187 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/WebotsNode.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/WebotsNode.hpp
@@ -15,27 +15,25 @@
#ifndef WEBOTS_NODE_HPP
#define WEBOTS_NODE_HPP
-#include
#include
+#include
#include
#include
#include
-#include
+#include
#include
+#include
#include
-#include
#include "webots_ros2_driver/PluginInterface.hpp"
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
class PluginInterface;
- class WebotsNode : public rclcpp::Node
- {
+ class WebotsNode : public rclcpp::Node {
public:
WebotsNode(std::string name);
void init();
@@ -65,6 +63,6 @@ namespace webots_ros2_driver
std::shared_ptr loadPlugin(const std::string &type);
};
-} // end namespace webots_ros2_driver
+} // end namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/Ros2SensorPlugin.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/Ros2SensorPlugin.hpp
index 1a17d269e..ba80b4fac 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/Ros2SensorPlugin.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/Ros2SensorPlugin.hpp
@@ -15,26 +15,23 @@
#ifndef ROS2_SENSOR_PLUGIN_HPP
#define ROS2_SENSOR_PLUGIN_HPP
-#include
#include
+#include
#include
#include
-
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
/// Utility class for common Webots sensors
- class Ros2SensorPlugin : public PluginInterface
- {
+ class Ros2SensorPlugin : public PluginInterface {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
protected:
/// Checks if a sensor has data ready and updates the last update time
/**
- * \return Should publishing from the sensor be considered
- */
+ * \return Should publishing from the sensor be considered
+ */
bool preStep();
webots_ros2_driver::WebotsNode *mNode;
@@ -47,6 +44,6 @@ namespace webots_ros2_driver
double mLastUpdate;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/dynamic/Ros2IMU.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/dynamic/Ros2IMU.hpp
index f0135f4e3..2b0668946 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/dynamic/Ros2IMU.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/dynamic/Ros2IMU.hpp
@@ -17,20 +17,18 @@
#include
-#include
-#include
#include
+#include
+#include
#include
-#include
#include
+#include
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
- class Ros2IMU : public Ros2SensorPlugin
- {
+ class Ros2IMU : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -50,6 +48,6 @@ namespace webots_ros2_driver
bool mIsEnabled;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Camera.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Camera.hpp
index 478f7313f..9f7e7ace1 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Camera.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Camera.hpp
@@ -19,14 +19,14 @@
#include
-#include
#include
+#include
#include
-#if defined (HUMBLE) || defined (ROLLING)
+#if defined(HUMBLE) || defined(ROLLING)
#include
#else
// Deprecated in Humble and Rolling
-#include
+#include
#endif
#include
#include
@@ -36,18 +36,15 @@
#include
#include
+#include
+#include
+#include
#include
#include
-#include
-#include
-#include
-
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
- class Ros2Camera : public Ros2SensorPlugin
- {
+ class Ros2Camera : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -73,6 +70,6 @@ namespace webots_ros2_driver
bool mRecognitionIsEnabled;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2DistanceSensor.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2DistanceSensor.hpp
index 6e69af39e..ea64882f8 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2DistanceSensor.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2DistanceSensor.hpp
@@ -15,18 +15,15 @@
#ifndef ROS2_DISTANCE_SENSOR_HPP
#define ROS2_DISTANCE_SENSOR_HPP
-#include
-#include
#include
-#include
+#include
+#include
#include
+#include
+namespace webots_ros2_driver {
-namespace webots_ros2_driver
-{
-
- class Ros2DistanceSensor : public Ros2SensorPlugin
- {
+ class Ros2DistanceSensor : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -43,6 +40,6 @@ namespace webots_ros2_driver
bool mIsEnabled;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2GPS.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2GPS.hpp
index 1c075d490..e43681f85 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2GPS.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2GPS.hpp
@@ -21,13 +21,11 @@
#include
#include
#include
-#include
#include
+#include
-namespace webots_ros2_driver
-{
- class Ros2GPS : public Ros2SensorPlugin
- {
+namespace webots_ros2_driver {
+ class Ros2GPS : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -55,5 +53,5 @@ namespace webots_ros2_driver
bool mIsEnabled;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LED.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LED.hpp
index b285def97..1eab45e29 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LED.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LED.hpp
@@ -15,18 +15,16 @@
#ifndef ROS2_LED_HPP
#define ROS2_LED_HPP
-#include
-#include
#include
-#include
-#include
+#include
+#include
#include
+#include
+#include
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
- class Ros2LED : public PluginInterface
- {
+ class Ros2LED : public PluginInterface {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -39,6 +37,6 @@ namespace webots_ros2_driver
rclcpp::Subscription::SharedPtr mSubscriber;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Lidar.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Lidar.hpp
index c941b3e01..09331776b 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Lidar.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2Lidar.hpp
@@ -15,19 +15,16 @@
#ifndef ROS2_LIDAR_HPP
#define ROS2_LIDAR_HPP
-#include
+#include
#include
#include
#include
-#include
+#include
#include
-#include
-
+#include
-namespace webots_ros2_driver
-{
- class Ros2Lidar : public Ros2SensorPlugin
- {
+namespace webots_ros2_driver {
+ class Ros2Lidar : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -49,6 +46,6 @@ namespace webots_ros2_driver
bool mIsPointCloudEnabled;
};
-} // end namespace webots_ros2_driver
+} // end namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LightSensor.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LightSensor.hpp
index 94a531afb..4bc4cbbc0 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LightSensor.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2LightSensor.hpp
@@ -15,18 +15,15 @@
#ifndef ROS2_LIGHT_SENSOR_HPP
#define ROS2_LIGHT_SENSOR_HPP
-#include
-#include
#include
-#include
+#include
+#include
#include
+#include
+namespace webots_ros2_driver {
-namespace webots_ros2_driver
-{
-
- class Ros2LightSensor : public Ros2SensorPlugin
- {
+ class Ros2LightSensor : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -44,6 +41,6 @@ namespace webots_ros2_driver
bool mIsEnabled;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2RangeFinder.hpp b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2RangeFinder.hpp
index c99074d98..3f2821436 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2RangeFinder.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/plugins/static/Ros2RangeFinder.hpp
@@ -15,20 +15,17 @@
#ifndef ROS2_RANGE_FINDER_HPP
#define ROS2_RANGE_FINDER_HPP
-#include
+#include
#include
#include
#include
-#include
-#include
+#include
#include
+#include
+namespace webots_ros2_driver {
-namespace webots_ros2_driver
-{
-
- class Ros2RangeFinder : public Ros2SensorPlugin
- {
+ class Ros2RangeFinder : public Ros2SensorPlugin {
public:
void init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) override;
void step() override;
@@ -49,6 +46,6 @@ namespace webots_ros2_driver
bool mIsEnabled;
};
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/utils/Math.hpp b/webots_ros2_driver/include/webots_ros2_driver/utils/Math.hpp
index 205fa7291..33edcb4a3 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/utils/Math.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/utils/Math.hpp
@@ -15,16 +15,15 @@
#ifndef MATH_HPP
#define MATH_HPP
+#include
#include
#include
-#include
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
void matrixToQuaternion(const double *matrix, geometry_msgs::msg::Quaternion &q);
void axisAngleToQuaternion(const double *axisAngle, geometry_msgs::msg::Quaternion &q);
void quaternionToAxisAngle(const geometry_msgs::msg::Quaternion &q, double *axisAngle);
double interpolateLookupTable(double value, std::vector &table);
-}
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/include/webots_ros2_driver/utils/Utils.hpp b/webots_ros2_driver/include/webots_ros2_driver/utils/Utils.hpp
index 06396778e..7479ac402 100644
--- a/webots_ros2_driver/include/webots_ros2_driver/utils/Utils.hpp
+++ b/webots_ros2_driver/include/webots_ros2_driver/utils/Utils.hpp
@@ -17,10 +17,9 @@
#include
-namespace webots_ros2_driver
-{
- int getDeviceTimestepMsFromPublishTimestep(double publishTimestep, int basicTimestepMs);
- std::string getFixedNameString(const std::string &name);
-}
+namespace webots_ros2_driver {
+ int getDeviceTimestepMsFromPublishTimestep(double publishTimestep, int basicTimestepMs);
+ std::string getFixedNameString(const std::string &name);
+} // namespace webots_ros2_driver
#endif
diff --git a/webots_ros2_driver/scripts/webots_tcp_client.py b/webots_ros2_driver/scripts/webots_tcp_client.py
index bbe64c01e..411aa430a 100644
--- a/webots_ros2_driver/scripts/webots_tcp_client.py
+++ b/webots_ros2_driver/scripts/webots_tcp_client.py
@@ -55,7 +55,8 @@ def host_shared_folder():
while tcp_socket.connect_ex((HOST, PORT)) != 0:
- print('WARNING: Unable to start Webots. Please start the local simulation server on your host machine. Next connection attempt in 1 second.', file=sys.stderr)
+ print('WARNING: Unable to start Webots. Please start the local simulation server on your host machine. Next connection '
+ 'attempt in 1 second.', file=sys.stderr)
time.sleep(1)
command = 'webots ' + launch_arguments + ' ' + os.path.join(host_shared_folder(), world_name)
tcp_socket.sendall(command.encode('utf-8'))
diff --git a/webots_ros2_driver/src/Driver.cpp b/webots_ros2_driver/src/Driver.cpp
index 65f367ed5..6f8d116ad 100644
--- a/webots_ros2_driver/src/Driver.cpp
+++ b/webots_ros2_driver/src/Driver.cpp
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include
+#include
#include
#include
-#include
-#include
#include
int main(int argc, char **argv) {
@@ -40,8 +40,7 @@ int main(int argc, char **argv) {
for (char notAllowedChar : " -.)(")
std::replace(robotName.begin(), robotName.end(), notAllowedChar, '_');
- std::shared_ptr node =
- std::make_shared(robotName);
+ std::shared_ptr node = std::make_shared(robotName);
node->init();
while (true) {
if (node->step() == -1)
diff --git a/webots_ros2_driver/src/PythonPlugin.cpp b/webots_ros2_driver/src/PythonPlugin.cpp
index af83742e4..39dbf3df4 100644
--- a/webots_ros2_driver/src/PythonPlugin.cpp
+++ b/webots_ros2_driver/src/PythonPlugin.cpp
@@ -2,39 +2,36 @@
static PyObject *gPyWebotsNode = NULL;
-namespace webots_ros2_driver
-{
- PythonPlugin::PythonPlugin(PyObject *pyPlugin) : mPyPlugin(pyPlugin){};
-
- void PythonPlugin::init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters)
- {
- PyObject *pyParameters = PyDict_New();
- for (const std::pair ¶meter : parameters)
- PyDict_SetItem(pyParameters, PyUnicode_FromString(parameter.first.c_str()), PyUnicode_FromString(parameter.second.c_str()));
-
- PyObject_CallMethod(mPyPlugin, "init", "OO", getPyWebotsNodeInstance(), pyParameters);
- PyErr_Print();
- }
-
- void PythonPlugin::step()
- {
- PyObject_CallMethod(mPyPlugin, "step", "");
- PyErr_Print();
- }
-
- PyObject *PythonPlugin::getPyWebotsNodeInstance()
- {
- if (gPyWebotsNode)
- return gPyWebotsNode;
-
- PyObject *pyWebotsExtraModuleSource = Py_CompileString(
- R"EOT(
+namespace webots_ros2_driver {
+ PythonPlugin::PythonPlugin(PyObject *pyPlugin) : mPyPlugin(pyPlugin){};
+
+ void PythonPlugin::init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) {
+ PyObject *pyParameters = PyDict_New();
+ for (const std::pair ¶meter : parameters)
+ PyDict_SetItem(pyParameters, PyUnicode_FromString(parameter.first.c_str()),
+ PyUnicode_FromString(parameter.second.c_str()));
+
+ PyObject_CallMethod(mPyPlugin, "init", "OO", getPyWebotsNodeInstance(), pyParameters);
+ PyErr_Print();
+ }
+
+ void PythonPlugin::step() {
+ PyObject_CallMethod(mPyPlugin, "step", "");
+ PyErr_Print();
+ }
+
+ PyObject *PythonPlugin::getPyWebotsNodeInstance() {
+ if (gPyWebotsNode)
+ return gPyWebotsNode;
+
+ PyObject *pyWebotsExtraModuleSource = Py_CompileString(
+ R"EOT(
import os
import sys
# Set WEBOTS_HOME to the webots_ros2_driver installation folder
# to load the correct libController libraries from the Python API
-from ament_index_python.packages import get_package_prefix
+from ament_index_python.packages import get_package_prefix
os.environ['WEBOTS_HOME'] = get_package_prefix('webots_ros2_driver')
import controller
@@ -52,44 +49,43 @@ class WebotsNode:
else:
self.robot = Supervisor()
)EOT",
- "webots_extra", Py_file_input);
+ "webots_extra", Py_file_input);
- if (!pyWebotsExtraModuleSource)
- throw std::runtime_error("Error: The Python module with the WebotsNode class cannot be compiled.");
+ if (!pyWebotsExtraModuleSource)
+ throw std::runtime_error("Error: The Python module with the WebotsNode class cannot be compiled.");
- PyObject *pyWebotsExtraModule = PyImport_ExecCodeModule("webots_extra", pyWebotsExtraModuleSource);
+ PyObject *pyWebotsExtraModule = PyImport_ExecCodeModule("webots_extra", pyWebotsExtraModuleSource);
- if (!pyWebotsExtraModule)
- throw std::runtime_error("Error: The Python module with the WebotsNode class cannot be executed.");
+ if (!pyWebotsExtraModule)
+ throw std::runtime_error("Error: The Python module with the WebotsNode class cannot be executed.");
- PyObject *pyDict = PyModule_GetDict(pyWebotsExtraModule);
- PyObject *pyClass = PyDict_GetItemString(pyDict, "WebotsNode");
- gPyWebotsNode = PyObject_CallObject(pyClass, nullptr);
- return gPyWebotsNode;
- }
+ PyObject *pyDict = PyModule_GetDict(pyWebotsExtraModule);
+ PyObject *pyClass = PyDict_GetItemString(pyDict, "WebotsNode");
+ gPyWebotsNode = PyObject_CallObject(pyClass, nullptr);
+ return gPyWebotsNode;
+ }
- std::shared_ptr PythonPlugin::createFromType(const std::string &type)
- {
- const std::string moduleName = type.substr(0, type.find_last_of("."));
- const std::string className = type.substr(type.find_last_of(".") + 1);
+ std::shared_ptr PythonPlugin::createFromType(const std::string &type) {
+ const std::string moduleName = type.substr(0, type.find_last_of("."));
+ const std::string className = type.substr(type.find_last_of(".") + 1);
- Py_Initialize();
+ Py_Initialize();
- PyObject *pyName = PyUnicode_FromString(moduleName.c_str());
- PyObject *pyModule = PyImport_Import(pyName);
- PyErr_Print();
+ PyObject *pyName = PyUnicode_FromString(moduleName.c_str());
+ PyObject *pyModule = PyImport_Import(pyName);
+ PyErr_Print();
- // If the module cannot be found the error should be handled in the upper level (e.g. try loading C++ plugin)
- if (!pyModule)
- return NULL;
+ // If the module cannot be found the error should be handled in the upper level (e.g. try loading C++ plugin)
+ if (!pyModule)
+ return NULL;
- PyObject *pyDict = PyModule_GetDict(pyModule);
- PyObject *pyClass = PyDict_GetItemString(pyDict, className.c_str());
- PyErr_Print();
- if (!pyClass)
- throw std::runtime_error("Error in plugin " + type + ": The class " + className + " cannot be found.");
+ PyObject *pyDict = PyModule_GetDict(pyModule);
+ PyObject *pyClass = PyDict_GetItemString(pyDict, className.c_str());
+ PyErr_Print();
+ if (!pyClass)
+ throw std::runtime_error("Error in plugin " + type + ": The class " + className + " cannot be found.");
- PyObject *pyPlugin = PyObject_CallObject(pyClass, nullptr);
- return std::shared_ptr(new PythonPlugin(pyPlugin));
- }
-}
+ PyObject *pyPlugin = PyObject_CallObject(pyClass, nullptr);
+ return std::shared_ptr(new PythonPlugin(pyPlugin));
+ }
+} // namespace webots_ros2_driver
diff --git a/webots_ros2_driver/src/WebotsNode.cpp b/webots_ros2_driver/src/WebotsNode.cpp
index de86aca53..db7854910 100644
--- a/webots_ros2_driver/src/WebotsNode.cpp
+++ b/webots_ros2_driver/src/WebotsNode.cpp
@@ -18,23 +18,22 @@
#include
#include
-#include
#include
+#include
-#include "webots_ros2_driver/PluginInterface.hpp"
-#include
#include
-#include
-#include
#include
-#include
+#include
#include
+#include
+#include
+#include
+#include "webots_ros2_driver/PluginInterface.hpp"
#include "webots_ros2_driver/PluginInterface.hpp"
#include "webots_ros2_driver/PythonPlugin.hpp"
-namespace webots_ros2_driver
-{
+namespace webots_ros2_driver {
const char *gDeviceReferenceAttribute = "reference";
const char *gDeviceRosTag = "ros";
const char *gPluginInterface = "webots_ros2_driver::PluginInterface";
@@ -42,17 +41,12 @@ namespace webots_ros2_driver
bool gShutdownSignalReceived = false;
- void handleSigint(int sig)
- {
- gShutdownSignalReceived = true;
- }
+ void handleSigint(int sig) { gShutdownSignalReceived = true; }
- WebotsNode::WebotsNode(std::string name) : Node(name), mPluginLoader(gPluginInterfaceName, gPluginInterface)
- {
+ WebotsNode::WebotsNode(std::string name) : Node(name), mPluginLoader(gPluginInterfaceName, gPluginInterface) {
mRobotDescription = this->declare_parameter("robot_description", "");
mSetRobotStatePublisher = this->declare_parameter("set_robot_state_publisher", false);
- if (mRobotDescription != "")
- {
+ if (mRobotDescription != "") {
mRobotDescriptionDocument = std::make_shared();
mRobotDescriptionDocument->Parse(mRobotDescription.c_str());
if (!mRobotDescriptionDocument)
@@ -61,9 +55,7 @@ namespace webots_ros2_driver
if (!robotXMLElement)
throw std::runtime_error("Invalid URDF, it doesn't contain a tag");
mWebotsXMLElement = robotXMLElement->FirstChildElement("webots");
- }
- else
- {
+ } else {
mWebotsXMLElement = NULL;
RCLCPP_INFO(get_logger(), "Robot description is not passed, using default parameters.");
}
@@ -72,15 +64,12 @@ namespace webots_ros2_driver
mRemoveUrdfRobotMessage.data = name;
}
- std::unordered_map WebotsNode::getPluginProperties(tinyxml2::XMLElement *pluginElement) const
- {
+ std::unordered_map WebotsNode::getPluginProperties(tinyxml2::XMLElement *pluginElement) const {
std::unordered_map properties;
- if (pluginElement)
- {
+ if (pluginElement) {
tinyxml2::XMLElement *deviceChild = pluginElement->FirstChildElement();
- while (deviceChild)
- {
+ while (deviceChild) {
properties[deviceChild->Name()] = deviceChild->GetText();
deviceChild = deviceChild->NextSiblingElement();
}
@@ -89,8 +78,7 @@ namespace webots_ros2_driver
return properties;
}
- std::unordered_map WebotsNode::getDeviceRosProperties(const std::string &name) const
- {
+ std::unordered_map WebotsNode::getDeviceRosProperties(const std::string &name) const {
std::unordered_map properties({{"enabled", "true"}});
// No URDF file specified
@@ -98,8 +86,7 @@ namespace webots_ros2_driver
return properties;
tinyxml2::XMLElement *deviceChild = mWebotsXMLElement->FirstChildElement();
- while (deviceChild)
- {
+ while (deviceChild) {
if (deviceChild->Attribute(gDeviceReferenceAttribute) && deviceChild->Attribute(gDeviceReferenceAttribute) == name)
break;
deviceChild = deviceChild->NextSiblingElement();
@@ -111,8 +98,7 @@ namespace webots_ros2_driver
// Store ROS properties
tinyxml2::XMLElement *propertyChild = deviceChild->FirstChildElement(gDeviceRosTag)->FirstChildElement();
- while (propertyChild)
- {
+ while (propertyChild) {
properties[propertyChild->Name()] = propertyChild->GetText();
propertyChild = propertyChild->NextSiblingElement();
}
@@ -120,13 +106,12 @@ namespace webots_ros2_driver
return properties;
}
- void WebotsNode::init()
- {
- if (mSetRobotStatePublisher){
+ void WebotsNode::init() {
+ if (mSetRobotStatePublisher) {
std::string prefix = "";
setAnotherNodeParameter("robot_state_publisher", "robot_description", wb_robot_get_urdf(prefix.c_str()));
}
-
+
mStep = wb_robot_get_basic_time_step();
// Load static plugins
@@ -134,8 +119,7 @@ namespace webots_ros2_driver
// The static plugins will try to guess parameter based on the robot model,
// but one can overwrite the default behavior in the section.
// Typical static plugins are ROS 2 interfaces for Webots devices.
- for (int i = 0; i < wb_robot_get_number_of_devices(); i++)
- {
+ for (int i = 0; i < wb_robot_get_number_of_devices(); i++) {
WbDeviceTag device = wb_robot_get_device_by_index(i);
// Prepare parameters
@@ -145,32 +129,30 @@ namespace webots_ros2_driver
parameters["name"] = wb_device_get_name(device);
std::shared_ptr plugin = nullptr;
- switch (wb_device_get_node_type(device))
- {
- case WB_NODE_LIDAR:
- plugin = std::make_shared();
- break;
- case WB_NODE_CAMERA:
- plugin = std::make_shared();
- break;
- case WB_NODE_GPS:
- plugin = std::make_shared();
- break;
- case WB_NODE_RANGE_FINDER:
- plugin = std::make_shared();
- break;
- case WB_NODE_DISTANCE_SENSOR:
- plugin = std::make_shared();
- break;
- case WB_NODE_LIGHT_SENSOR:
- plugin = std::make_shared();
- break;
- case WB_NODE_LED:
- plugin = std::make_shared();
- break;
+ switch (wb_device_get_node_type(device)) {
+ case WB_NODE_LIDAR:
+ plugin = std::make_shared();
+ break;
+ case WB_NODE_CAMERA:
+ plugin = std::make_shared();
+ break;
+ case WB_NODE_GPS:
+ plugin = std::make_shared();
+ break;
+ case WB_NODE_RANGE_FINDER:
+ plugin = std::make_shared();
+ break;
+ case WB_NODE_DISTANCE_SENSOR:
+ plugin = std::make_shared();
+ break;
+ case WB_NODE_LIGHT_SENSOR:
+ plugin = std::make_shared();
+ break;
+ case WB_NODE_LED:
+ plugin = std::make_shared();
+ break;
}
- if (plugin)
- {
+ if (plugin) {
plugin->init(this, parameters);
mPlugins.push_back(plugin);
}
@@ -184,10 +166,10 @@ namespace webots_ros2_driver
return;
tinyxml2::XMLElement *pluginElement = mWebotsXMLElement->FirstChildElement("plugin");
- while (pluginElement)
- {
+ while (pluginElement) {
if (!pluginElement->Attribute("type"))
- throw std::runtime_error("Invalid URDF, a plugin is missing a `type` property at line " + std::to_string(pluginElement->GetLineNum()));
+ throw std::runtime_error("Invalid URDF, a plugin is missing a `type` property at line " +
+ std::to_string(pluginElement->GetLineNum()));
const std::string type = pluginElement->Attribute("type");
@@ -200,20 +182,14 @@ namespace webots_ros2_driver
}
}
- std::shared_ptr WebotsNode::loadPlugin(const std::string &type)
- {
+ std::shared_ptr WebotsNode::loadPlugin(const std::string &type) {
// First, we assume the plugin is C++
- try
- {
+ try {
std::shared_ptr plugin(mPluginLoader.createUnmanagedInstance(type));
return plugin;
- }
- catch (const pluginlib::LibraryLoadException &e)
- {
+ } catch (const pluginlib::LibraryLoadException &e) {
// It may be a Python plugin
- }
- catch (const pluginlib::CreateClassException &e)
- {
+ } catch (const pluginlib::CreateClassException &e) {
throw std::runtime_error("The " + type + " class cannot be initialized.");
}
@@ -224,10 +200,8 @@ namespace webots_ros2_driver
return plugin;
}
- int WebotsNode::step()
- {
- if (gShutdownSignalReceived && !mWaitingForUrdfRobotToBeRemoved)
- {
+ int WebotsNode::step() {
+ if (gShutdownSignalReceived && !mWaitingForUrdfRobotToBeRemoved) {
mRemoveUrdfRobotPublisher->publish(mRemoveUrdfRobotMessage);
mWaitingForUrdfRobotToBeRemoved = true;
}
@@ -241,11 +215,11 @@ namespace webots_ros2_driver
return result;
}
- void WebotsNode::setAnotherNodeParameter(std::string anotherNodeName, std::string parameterName, std::string parameterValue)
- {
+ void WebotsNode::setAnotherNodeParameter(std::string anotherNodeName, std::string parameterName, std::string parameterValue) {
mClient = create_client(get_namespace() + anotherNodeName + "/set_parameters");
mClient->wait_for_service(std::chrono::seconds(1));
- rcl_interfaces::srv::SetParameters::Request::SharedPtr request = std::make_shared();
+ rcl_interfaces::srv::SetParameters::Request::SharedPtr request =
+ std::make_shared();
rcl_interfaces::msg::Parameter parameter;
parameter.name = parameterName;
parameter.value.string_value = parameterValue;
@@ -254,8 +228,5 @@ namespace webots_ros2_driver
mClient->async_send_request(request);
}
- void WebotsNode::handleSignals()
- {
- signal(SIGINT, handleSigint);
- }
-} // end namespace webots_ros2_driver
+ void WebotsNode::handleSignals() { signal(SIGINT, handleSigint); }
+} // end namespace webots_ros2_driver
diff --git a/webots_ros2_driver/src/plugins/Ros2SensorPlugin.cpp b/webots_ros2_driver/src/plugins/Ros2SensorPlugin.cpp
index cf28147ce..3e0a412a8 100644
--- a/webots_ros2_driver/src/plugins/Ros2SensorPlugin.cpp
+++ b/webots_ros2_driver/src/plugins/Ros2SensorPlugin.cpp
@@ -17,10 +17,8 @@
#include
-namespace webots_ros2_driver
-{
- void Ros2SensorPlugin::init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters)
- {
+namespace webots_ros2_driver {
+ void Ros2SensorPlugin::init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) {
mNode = node;
mLastUpdate = 0;
@@ -33,12 +31,11 @@ namespace webots_ros2_driver
mPublishTimestepSyncedMs = getDeviceTimestepMsFromPublishTimestep(mPublishTimestep, wb_robot_get_basic_time_step());
}
- bool Ros2SensorPlugin::preStep()
- {
+ bool Ros2SensorPlugin::preStep() {
// Update only if needed
if (wb_robot_get_time() - mLastUpdate < mPublishTimestep)
return false;
mLastUpdate = wb_robot_get_time();
return true;
}
-}
+} // namespace webots_ros2_driver
diff --git a/webots_ros2_driver/src/plugins/dynamic/Ros2IMU.cpp b/webots_ros2_driver/src/plugins/dynamic/Ros2IMU.cpp
index fa214300e..1e0ea352a 100644
--- a/webots_ros2_driver/src/plugins/dynamic/Ros2IMU.cpp
+++ b/webots_ros2_driver/src/plugins/dynamic/Ros2IMU.cpp
@@ -17,14 +17,11 @@
#include
#include "pluginlib/class_list_macros.hpp"
-#include
#include
+#include
-
-namespace webots_ros2_driver
-{
- void Ros2IMU::init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters)
- {
+namespace webots_ros2_driver {
+ void Ros2IMU::init(webots_ros2_driver::WebotsNode *node, std::unordered_map ¶meters) {
Ros2SensorPlugin::init(node, parameters);
mIsEnabled = false;
mInertialUnit = 0;
@@ -32,24 +29,22 @@ namespace webots_ros2_driver
mAccelerometer = 0;
if (!parameters.count("inertialUnitName") && !parameters.count("gyroName") && !parameters.count("accelerometerName"))
- throw std::runtime_error("The IMU plugins has to contain at least of: