From 2e68df0fc639c07a669b7dee2b036ef24f8e6e49 Mon Sep 17 00:00:00 2001 From: YusukeKato Date: Wed, 28 Aug 2024 10:23:27 +0900 Subject: [PATCH] =?UTF-8?q?2.2.1=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=81=AE=E3=81=9F=E3=82=81=E3=81=ABmaster=E3=81=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=86=85=E5=AE=B9=E3=82=92humble-devel=E3=81=B8?= =?UTF-8?q?=E3=83=9E=E3=83=BC=E3=82=B8=20(#61)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SubscriberとService Clientに別々のcallback_groupを設定 (#58) * subscriberとclientに別々のcallback_groupを設定 * subsciriberをclientの後に宣言するように変更 * サービスクライアントでexecutorを使用しない (#59) * 2.2.1リリースのためにCHANGELOG.rstとpackage.xmlを更新 (#60) * 2.2.1リリースのためにCHANGELOG.rstを更新 * 2.2.1 --- CHANGELOG.rst | 6 +++ launch/teleop_joy.launch.py | 4 +- package.xml | 2 +- raspimouse_ros2_examples/joystick_control.py | 40 +++++++++++++------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6adf1be..9e15dad 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,12 @@ Changelog for package raspimouse_ros2_examples ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2.2.1 (2024-08-28) +------------------ +* サービスクライアントでexecutorを使用しない (`#59 `_) +* SubscriberとService Clientに別々のcallback_groupを設定 (`#58 `_) +* Contributors: ShotaAk, YusukeKato + 2.2.0 (2024-03-05) ------------------ * READMEにSLAM&Navigationパッケージの案内を追加 (`#53 `_) diff --git a/launch/teleop_joy.launch.py b/launch/teleop_joy.launch.py index f416ca0..210b814 100644 --- a/launch/teleop_joy.launch.py +++ b/launch/teleop_joy.launch.py @@ -24,6 +24,7 @@ from launch.substitutions import LaunchConfiguration from launch_ros.actions import Node from launch_ros.actions import LifecycleNode +from launch.events import Shutdown def generate_launch_description(): @@ -65,7 +66,8 @@ def func_get_joyconfig_file_name(context): joystick_control_node = Node( package='raspimouse_ros2_examples', executable='joystick_control.py', - parameters=[LaunchConfiguration('joyconfig_filename')] + parameters=[LaunchConfiguration('joyconfig_filename')], + on_exit=Shutdown(), ) def func_launch_mouse_node(context): diff --git a/package.xml b/package.xml index decb8ad..5169dce 100644 --- a/package.xml +++ b/package.xml @@ -2,7 +2,7 @@ raspimouse_ros2_examples - 2.2.0 + 2.2.1 Raspberry Pi Mouse examples RT Corporation diff --git a/raspimouse_ros2_examples/joystick_control.py b/raspimouse_ros2_examples/joystick_control.py index 05f9024..892c13a 100755 --- a/raspimouse_ros2_examples/joystick_control.py +++ b/raspimouse_ros2_examples/joystick_control.py @@ -29,6 +29,7 @@ import rclpy from rclpy.node import Node +from rclpy.callback_groups import MutuallyExclusiveCallbackGroup from sensor_msgs.msg import Joy from std_msgs.msg import Int16 from std_srvs.srv import SetBool @@ -120,27 +121,36 @@ def __init__(self): self._pub_buzzer = self.create_publisher(Int16, 'buzzer', 1) self._pub_leds = self.create_publisher(Leds, 'leds', 1) - self._sub_joy = self.create_subscription( - Joy, 'joy', self._callback_joy, 1) - self._sub_lightsensor = self.create_subscription( - LightSensors, 'light_sensors', self._callback_lightsensors, 1) - self._sub_switches = self.create_subscription( - Switches, 'switches', self._callback_switches, 1) + self._sub_cb_group = MutuallyExclusiveCallbackGroup() + self._client_cb_group = MutuallyExclusiveCallbackGroup() - self._client_get_state = self.create_client(GetState, 'raspimouse/get_state') + self._client_get_state = self.create_client( + GetState, 'raspimouse/get_state', callback_group=self._client_cb_group) while not self._client_get_state.wait_for_service(timeout_sec=1.0): self._node_logger.warn(self._client_get_state.srv_name + ' service not available') - self._client_change_state = self.create_client(ChangeState, 'raspimouse/change_state') + self._client_change_state = self.create_client( + ChangeState, 'raspimouse/change_state', callback_group=self._client_cb_group) while not self._client_change_state.wait_for_service(timeout_sec=1.0): self._node_logger.warn(self._client_change_state.srv_name + ' service not available') self._activate_raspimouse() - self._client_motor_power = self.create_client(SetBool, 'motor_power') + self._client_motor_power = self.create_client( + SetBool, 'motor_power', callback_group=self._client_cb_group) while not self._client_motor_power.wait_for_service(timeout_sec=1.0): self._node_logger.warn(self._client_motor_power.srv_name + ' service not available') self._motor_on() + self._sub_joy = self.create_subscription( + Joy, 'joy', self._callback_joy, 1, + callback_group=self._sub_cb_group) + self._sub_lightsensor = self.create_subscription( + LightSensors, 'light_sensors', self._callback_lightsensors, 1, + callback_group=self._sub_cb_group) + self._sub_switches = self.create_subscription( + Switches, 'switches', self._callback_switches, 1, + callback_group=self._sub_cb_group) + def _activate_raspimouse(self): self._set_mouse_lifecycle_state(Transition.TRANSITION_CONFIGURE) self._set_mouse_lifecycle_state(Transition.TRANSITION_ACTIVATE) @@ -151,14 +161,12 @@ def _set_mouse_lifecycle_state(self, transition_id): request = ChangeState.Request() request.transition.id = transition_id future = self._client_change_state.call_async(request) - executor = rclpy.executors.SingleThreadedExecutor(context=self.context) - rclpy.spin_until_future_complete(self, future, executor=executor) + rclpy.spin_until_future_complete(self, future) return future.result().success def _get_mouse_lifecycle_state(self): future = self._client_get_state.call_async(GetState.Request()) - executor = rclpy.executors.SingleThreadedExecutor(context=self.context) - rclpy.spin_until_future_complete(self, future, executor=executor) + rclpy.spin_until_future_complete(self, future) return future.result().current_state.label def _motor_request(self, request_data=False): @@ -194,6 +202,7 @@ def _joy_shutdown(self, joy_msg): self._motor_off() self._set_mouse_lifecycle_state(Transition.TRANSITION_DEACTIVATE) self.destroy_node() + raise SystemExit def _joy_motor_onoff(self, joy_msg): if joy_msg.buttons[self._BUTTON_MOTOR_ON]: @@ -397,7 +406,10 @@ def main(args=None): joy_wrapper = JoyWrapper() - rclpy.spin(joy_wrapper) + try: + rclpy.spin(joy_wrapper) + except SystemExit: + rclpy.logging.get_logger("joystick_control").info('_joy_shutdown() has been executed') joy_wrapper.destroy_node()