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

camera_readerのparameter設定 #53

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion device/camera_reader/camera_reader/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ def __init__(self):
super().__init__("camera")
self.publisher_ = self.create_publisher(Image, "camera_image", 10)
self.timer = self.create_timer(0.01, self.timer_callback)
self.cap = cv2.VideoCapture(0)
param = self.declare_parameter("camera_id", 0)
camera_id = (
self.get_parameter_or(param.name, param).get_parameter_value().integer_value
)
assert isinstance(camera_id, int)
self.cap = cv2.VideoCapture(camera_id)
self.bridge = CvBridge()
if not self.cap.isOpened():
self.get_logger().error("Failed to open camera")
Expand Down
3 changes: 3 additions & 0 deletions device/camera_reader/config/default_param.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*:
ros__parameters:
camera_id: 0
9 changes: 9 additions & 0 deletions device/camera_reader/launch/camera_reader_launch.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node


def generate_launch_description():
config = os.path.join(
get_package_share_directory("camera_reader"),
"config",
"default_param.yml",
)
return LaunchDescription(
[
Node(
package="camera_reader",
executable="camera",
namespace="device",
parameters=[config],
remappings=[("/device/camera_image", "/packet/camera_image")],
),
],
Expand Down
4 changes: 4 additions & 0 deletions device/camera_reader/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
os.path.join("share", package_name, "launch"),
glob(os.path.join("launch", "*")),
),
(
os.path.join("share", package_name, "config"),
glob(os.path.join("config", "*")),
),
],
install_requires=["setuptools"],
zip_safe=True,
Expand Down