Skip to content

Commit

Permalink
2.2.1リリースのためにmasterの更新内容をhumble-develへマージ (#61)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
YusukeKato authored Aug 28, 2024
1 parent 20a17fb commit 2e68df0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog for package raspimouse_ros2_examples
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2.2.1 (2024-08-28)
------------------
* サービスクライアントでexecutorを使用しない (`#59 <https://github.com/rt-net/raspimouse_ros2_examples/issues/59>`_)
* SubscriberとService Clientに別々のcallback_groupを設定 (`#58 <https://github.com/rt-net/raspimouse_ros2_examples/issues/58>`_)
* Contributors: ShotaAk, YusukeKato

2.2.0 (2024-03-05)
------------------
* READMEにSLAM&Navigationパッケージの案内を追加 (`#53 <https://github.com/rt-net/raspimouse_ros2_examples/issues/53>`_)
Expand Down
4 changes: 3 additions & 1 deletion launch/teleop_joy.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>raspimouse_ros2_examples</name>
<version>2.2.0</version>
<version>2.2.1</version>
<description>Raspberry Pi Mouse examples</description>
<maintainer email="[email protected]">RT Corporation</maintainer>

Expand Down
40 changes: 26 additions & 14 deletions raspimouse_ros2_examples/joystick_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 2e68df0

Please sign in to comment.