Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log_level #62

Merged
merged 21 commits into from
Nov 28, 2024
6 changes: 4 additions & 2 deletions device/joystick/joystick/joystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def __init__(self):
super().__init__("joystick")
self._timer = self.create_timer(0.01, self._timer_callback)
self._joy_publisher = self.create_publisher(Joy, "joystick", 10)
# TODO: ここparameterで変えられるようにしたい
self._joystick = pygame.joystick.Joystick(0)
# Doing: ここparameterで変えられるようにしたい
joystick_id = self.declare_parameter("joystick_id", 0).get_parameter_value().integer_value
self._joystick = pygame.joystick.Joystick(joystick_id)
self._joystick.init()
H1rono marked this conversation as resolved.
Show resolved Hide resolved
# logging
name = self._joystick.get_name()
self.get_logger().info(f"Using controller: {name}")
Expand Down
56 changes: 46 additions & 10 deletions device/joystick/launch/joystick_launch.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
from typing import Any

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import Node


def generate_launch_description():
return LaunchDescription(
[
Node(
package="joystick",
executable="joystick",
namespace="device",
remappings=[("/device/joystick", "/packet/joystick")],
),
],
def joystick_node(**kwargs: Any) -> Node:
kwargs["package"] = "joystick"
kwargs["executable"] = "joystick"
kwargs["namespace"] = "device"
return Node(**kwargs)

def generate_launch_description() -> LaunchDescription:
index_arg = DeclareLaunchArgument("index",default_value="-1")
H1rono marked this conversation as resolved.
Show resolved Hide resolved
log_level_arg = DeclareLaunchArgument(
"log_level",
default_value="info",
choices=["debug","info","warn","error","fatal"],
)
joystick_id_arg = DeclareLaunchArgument(
"joystick_id",
default_value="0",
)
index = LaunchConfiguration("index")
log_level = LaunchConfiguration("log_level")

index_specified = PythonExpression([index,">= 0"])

indexed_joystick = joystick_node(
name=["joystick_",index],
remappings=[("/device/joystick","/packet/joystick")],
ros_arguments=["--log-level",log_level],
condition=IfCondition(index_specified),
)

unindexed_joystick = joystick_node(
remappings=[("/device/joystick","/packet/joystick")],
ros_arguments=["--log-level",log_level],
condition=UnlessCondition(index_specified),
)

return LaunchDescription([
index_arg,
log_level_arg,
joystick_id_arg,
indexed_joystick,
unindexed_joystick
])
Loading