Skip to content

Commit 2e68df0

Browse files
authored
2.2.1リリースのためにmasterの更新内容をhumble-develへマージ (#61)
* 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
1 parent 20a17fb commit 2e68df0

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog for package raspimouse_ros2_examples
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
2.2.1 (2024-08-28)
6+
------------------
7+
* サービスクライアントでexecutorを使用しない (`#59 <https://github.com/rt-net/raspimouse_ros2_examples/issues/59>`_)
8+
* SubscriberとService Clientに別々のcallback_groupを設定 (`#58 <https://github.com/rt-net/raspimouse_ros2_examples/issues/58>`_)
9+
* Contributors: ShotaAk, YusukeKato
10+
511
2.2.0 (2024-03-05)
612
------------------
713
* READMEにSLAM&Navigationパッケージの案内を追加 (`#53 <https://github.com/rt-net/raspimouse_ros2_examples/issues/53>`_)

launch/teleop_joy.launch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from launch.substitutions import LaunchConfiguration
2525
from launch_ros.actions import Node
2626
from launch_ros.actions import LifecycleNode
27+
from launch.events import Shutdown
2728

2829

2930
def generate_launch_description():
@@ -65,7 +66,8 @@ def func_get_joyconfig_file_name(context):
6566
joystick_control_node = Node(
6667
package='raspimouse_ros2_examples',
6768
executable='joystick_control.py',
68-
parameters=[LaunchConfiguration('joyconfig_filename')]
69+
parameters=[LaunchConfiguration('joyconfig_filename')],
70+
on_exit=Shutdown(),
6971
)
7072

7173
def func_launch_mouse_node(context):

package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>raspimouse_ros2_examples</name>
5-
<version>2.2.0</version>
5+
<version>2.2.1</version>
66
<description>Raspberry Pi Mouse examples</description>
77
<maintainer email="shop@rt-net.jp">RT Corporation</maintainer>
88

raspimouse_ros2_examples/joystick_control.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import rclpy
3131
from rclpy.node import Node
32+
from rclpy.callback_groups import MutuallyExclusiveCallbackGroup
3233
from sensor_msgs.msg import Joy
3334
from std_msgs.msg import Int16
3435
from std_srvs.srv import SetBool
@@ -120,27 +121,36 @@ def __init__(self):
120121
self._pub_buzzer = self.create_publisher(Int16, 'buzzer', 1)
121122
self._pub_leds = self.create_publisher(Leds, 'leds', 1)
122123

123-
self._sub_joy = self.create_subscription(
124-
Joy, 'joy', self._callback_joy, 1)
125-
self._sub_lightsensor = self.create_subscription(
126-
LightSensors, 'light_sensors', self._callback_lightsensors, 1)
127-
self._sub_switches = self.create_subscription(
128-
Switches, 'switches', self._callback_switches, 1)
124+
self._sub_cb_group = MutuallyExclusiveCallbackGroup()
125+
self._client_cb_group = MutuallyExclusiveCallbackGroup()
129126

130-
self._client_get_state = self.create_client(GetState, 'raspimouse/get_state')
127+
self._client_get_state = self.create_client(
128+
GetState, 'raspimouse/get_state', callback_group=self._client_cb_group)
131129
while not self._client_get_state.wait_for_service(timeout_sec=1.0):
132130
self._node_logger.warn(self._client_get_state.srv_name + ' service not available')
133131

134-
self._client_change_state = self.create_client(ChangeState, 'raspimouse/change_state')
132+
self._client_change_state = self.create_client(
133+
ChangeState, 'raspimouse/change_state', callback_group=self._client_cb_group)
135134
while not self._client_change_state.wait_for_service(timeout_sec=1.0):
136135
self._node_logger.warn(self._client_change_state.srv_name + ' service not available')
137136
self._activate_raspimouse()
138137

139-
self._client_motor_power = self.create_client(SetBool, 'motor_power')
138+
self._client_motor_power = self.create_client(
139+
SetBool, 'motor_power', callback_group=self._client_cb_group)
140140
while not self._client_motor_power.wait_for_service(timeout_sec=1.0):
141141
self._node_logger.warn(self._client_motor_power.srv_name + ' service not available')
142142
self._motor_on()
143143

144+
self._sub_joy = self.create_subscription(
145+
Joy, 'joy', self._callback_joy, 1,
146+
callback_group=self._sub_cb_group)
147+
self._sub_lightsensor = self.create_subscription(
148+
LightSensors, 'light_sensors', self._callback_lightsensors, 1,
149+
callback_group=self._sub_cb_group)
150+
self._sub_switches = self.create_subscription(
151+
Switches, 'switches', self._callback_switches, 1,
152+
callback_group=self._sub_cb_group)
153+
144154
def _activate_raspimouse(self):
145155
self._set_mouse_lifecycle_state(Transition.TRANSITION_CONFIGURE)
146156
self._set_mouse_lifecycle_state(Transition.TRANSITION_ACTIVATE)
@@ -151,14 +161,12 @@ def _set_mouse_lifecycle_state(self, transition_id):
151161
request = ChangeState.Request()
152162
request.transition.id = transition_id
153163
future = self._client_change_state.call_async(request)
154-
executor = rclpy.executors.SingleThreadedExecutor(context=self.context)
155-
rclpy.spin_until_future_complete(self, future, executor=executor)
164+
rclpy.spin_until_future_complete(self, future)
156165
return future.result().success
157166

158167
def _get_mouse_lifecycle_state(self):
159168
future = self._client_get_state.call_async(GetState.Request())
160-
executor = rclpy.executors.SingleThreadedExecutor(context=self.context)
161-
rclpy.spin_until_future_complete(self, future, executor=executor)
169+
rclpy.spin_until_future_complete(self, future)
162170
return future.result().current_state.label
163171

164172
def _motor_request(self, request_data=False):
@@ -194,6 +202,7 @@ def _joy_shutdown(self, joy_msg):
194202
self._motor_off()
195203
self._set_mouse_lifecycle_state(Transition.TRANSITION_DEACTIVATE)
196204
self.destroy_node()
205+
raise SystemExit
197206

198207
def _joy_motor_onoff(self, joy_msg):
199208
if joy_msg.buttons[self._BUTTON_MOTOR_ON]:
@@ -397,7 +406,10 @@ def main(args=None):
397406

398407
joy_wrapper = JoyWrapper()
399408

400-
rclpy.spin(joy_wrapper)
409+
try:
410+
rclpy.spin(joy_wrapper)
411+
except SystemExit:
412+
rclpy.logging.get_logger("joystick_control").info('_joy_shutdown() has been executed')
401413

402414
joy_wrapper.destroy_node()
403415

0 commit comments

Comments
 (0)