From 8646c8c3e4a2f7a3a4fc94d019b5683d718b8c54 Mon Sep 17 00:00:00 2001 From: Maciej Majek <46171033+maciejmajek@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:33:23 +0200 Subject: [PATCH] chore: remove use-case specific code (#174) --- src/examples/led_strip/led_strip/__init__.py | 0 .../led_strip/led_strip/led_strip_node.py | 113 ------------------ src/examples/led_strip/package.xml | 18 --- src/examples/led_strip/resource/led_strip | 0 src/examples/led_strip/setup.cfg | 4 - src/examples/led_strip/setup.py | 23 ---- src/examples/led_strip/test/test_copyright.py | 27 ----- src/examples/led_strip/test/test_flake8.py | 25 ---- src/examples/led_strip/test/test_pep257.py | 23 ---- 9 files changed, 233 deletions(-) delete mode 100644 src/examples/led_strip/led_strip/__init__.py delete mode 100644 src/examples/led_strip/led_strip/led_strip_node.py delete mode 100644 src/examples/led_strip/package.xml delete mode 100644 src/examples/led_strip/resource/led_strip delete mode 100644 src/examples/led_strip/setup.cfg delete mode 100644 src/examples/led_strip/setup.py delete mode 100644 src/examples/led_strip/test/test_copyright.py delete mode 100644 src/examples/led_strip/test/test_flake8.py delete mode 100644 src/examples/led_strip/test/test_pep257.py diff --git a/src/examples/led_strip/led_strip/__init__.py b/src/examples/led_strip/led_strip/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/examples/led_strip/led_strip/led_strip_node.py b/src/examples/led_strip/led_strip/led_strip_node.py deleted file mode 100644 index 1bb52a8c..00000000 --- a/src/examples/led_strip/led_strip/led_strip_node.py +++ /dev/null @@ -1,113 +0,0 @@ -import numpy as np -import rclpy -from rclpy.node import Node -from sensor_msgs.msg import Image -from std_msgs.msg import String - -STATE_TO_COLOR = { - "waiting": (255, 255, 255), # white - "processing": (255, 134, 0), # yellow - "recording": (0, 255, 0), # green - "playing": (0, 0, 255), # blue -} -DEFAULT_COLOR = (255, 0, 0) # red, unknown state -PULSE_FREQUENCY = 0.5 # Hz - - -class LEDStripController(Node): - - def __init__(self): - super().__init__("led_strip_controller") - self.asr_state = "waiting" - self.hmi_state = "waiting" - self.tts_state = "waiting" - - self.create_subscription(String, "/asr_status", self.asr_status_callback, 10) - self.create_subscription(String, "/hmi_status", self.hmi_status_callback, 10) - self.create_subscription(String, "/tts_status", self.tts_status_callback, 10) - - self.timer = self.create_timer(0.05, self.timer_callback) - - self.publisher_ = self.create_publisher(Image, "/led_strip", 10) - - self.led_state = "waiting" - - def asr_status_callback(self, msg: String) -> None: - if isinstance(msg.data, str): - self.asr_state = msg.data - self.calculate_state() - - def hmi_status_callback(self, msg: String) -> None: - if isinstance(msg.data, str): - self.hmi_state = msg.data - self.calculate_state() - - def tts_status_callback(self, msg: String) -> None: - if isinstance(msg.data, str): - self.tts_state = msg.data - self.calculate_state() - - def calculate_state(self) -> str: - # priority order: recording > playing > processing > waiting - if self.asr_state == "recording" and self.tts_state == "playing": - self.get_logger().warn( - "ASR is recording and TTS is playing at the same time!" - ) - return "" - - if self.asr_state == "recording" and self.hmi_state == "processing": - self.get_logger().warn( - "ASR is recording and HMI is processing at the same time!" - ) - return "" - - if self.led_state == "waiting": - if self.tts_state == "playing": - self.led_state = "playing" - elif self.asr_state == "recording": - self.led_state = "recording" - elif self.led_state == "recording": - if self.asr_state == "transcribing": - self.led_state = "processing" - elif self.led_state == "processing": - if self.tts_state == "playing": - self.led_state = "playing" - elif self.asr_state == "dropping": - self.led_state = "waiting" - elif self.led_state == "playing": - if self.tts_state == "waiting": - self.led_state = "waiting" - - def timer_callback(self): - color = STATE_TO_COLOR.get(self.led_state, DEFAULT_COLOR) - - if self.led_state == "playing": - t = self.get_clock().now().nanoseconds / 1e9 - value: float = 0.1 + 0.45 * (np.sin(2 * np.pi * PULSE_FREQUENCY * t) + 1.0) - color = np.array(color) - color = (value * color).astype(np.uint8) - - led_colors = np.full((1, 18, 3), color, dtype=np.uint8) - - msg = Image() - msg.header.stamp = self.get_clock().now().to_msg() - msg.height = 1 - msg.width = 18 - msg.encoding = "rgb8" - msg.is_bigendian = False - msg.step = 18 * 3 - msg.data = led_colors.flatten().tolist() - - self.publisher_.publish(msg) - - -def main(args=None): - rclpy.init(args=args) - node = LEDStripController() - rclpy.spin(node) - node.destroy_node() - rclpy.shutdown() - - -if __name__ == "__main__": - main() diff --git a/src/examples/led_strip/package.xml b/src/examples/led_strip/package.xml deleted file mode 100644 index fe2b0f58..00000000 --- a/src/examples/led_strip/package.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - led_strip - 0.0.0 - TODO: Package description - wsiekierska - TODO: License declaration - - ament_copyright - ament_flake8 - ament_pep257 - python3-pytest - - - ament_python - - diff --git a/src/examples/led_strip/resource/led_strip b/src/examples/led_strip/resource/led_strip deleted file mode 100644 index e69de29b..00000000 diff --git a/src/examples/led_strip/setup.cfg b/src/examples/led_strip/setup.cfg deleted file mode 100644 index d913fef4..00000000 --- a/src/examples/led_strip/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[develop] -script_dir=$base/lib/led_strip -[install] -install_scripts=$base/lib/led_strip diff --git a/src/examples/led_strip/setup.py b/src/examples/led_strip/setup.py deleted file mode 100644 index 62c930ab..00000000 --- a/src/examples/led_strip/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -from setuptools import find_packages, setup - -package_name = "led_strip" - -setup( - name=package_name, - version="0.0.0", - packages=find_packages(exclude=["test"]), - data_files=[ - ("share/ament_index/resource_index/packages", ["resource/" + package_name]), - ("share/" + package_name, ["package.xml"]), - ], - install_requires=["setuptools"], - zip_safe=True, - maintainer="wsiekierska", - maintainer_email="wiktoria.siekierska@robotec.ai", - description="TODO: Package description", - license="TODO: License declaration", - tests_require=["pytest"], - entry_points={ - "console_scripts": ["led_strip_node = led_strip.led_strip_node:main"], - }, -) diff --git a/src/examples/led_strip/test/test_copyright.py b/src/examples/led_strip/test/test_copyright.py deleted file mode 100644 index 8f18fa4b..00000000 --- a/src/examples/led_strip/test/test_copyright.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2015 Open Source Robotics Foundation, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import pytest -from ament_copyright.main import main - - -# Remove the `skip` decorator once the source file(s) have a copyright header -@pytest.mark.skip( - reason="No copyright header has been placed in the generated source file." -) -@pytest.mark.copyright -@pytest.mark.linter -def test_copyright(): - rc = main(argv=[".", "test"]) - assert rc == 0, "Found errors" diff --git a/src/examples/led_strip/test/test_flake8.py b/src/examples/led_strip/test/test_flake8.py deleted file mode 100644 index f494570f..00000000 --- a/src/examples/led_strip/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. - -import pytest -from ament_flake8.main import main_with_errors - - -@pytest.mark.flake8 -@pytest.mark.linter -def test_flake8(): - rc, errors = main_with_errors(argv=[]) - assert rc == 0, "Found %d code style errors / warnings:\n" % len( - errors - ) + "\n".join(errors) diff --git a/src/examples/led_strip/test/test_pep257.py b/src/examples/led_strip/test/test_pep257.py deleted file mode 100644 index 4eddb46e..00000000 --- a/src/examples/led_strip/test/test_pep257.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2015 Open Source Robotics Foundation, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import pytest -from ament_pep257.main import main - - -@pytest.mark.linter -@pytest.mark.pep257 -def test_pep257(): - rc = main(argv=[".", "test"]) - assert rc == 0, "Found code style errors / warnings"