mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-11 06:59:49 +08:00
add py launch file
This commit is contained in:
@@ -1,21 +1,12 @@
|
|||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, GroupAction, ExecuteProcess
|
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, GroupAction, ExecuteProcess
|
||||||
from launch.substitutions import LaunchConfiguration
|
|
||||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
from launch_ros.substitutions import FindPackageShare
|
|
||||||
from launch_ros.actions import Node
|
from launch_ros.actions import Node
|
||||||
|
from ament_index_python.packages import get_package_share_directory
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
# Declare arguments
|
|
||||||
camera_name = DeclareLaunchArgument('camera_name', default_value='camera')
|
|
||||||
d_sensor = DeclareLaunchArgument('3d_sensor', default_value='gemini2')
|
|
||||||
camera1_prefix = DeclareLaunchArgument('camera1_prefix', default_value='01')
|
|
||||||
camera2_prefix = DeclareLaunchArgument('camera2_prefix', default_value='02')
|
|
||||||
camera1_usb_port = DeclareLaunchArgument('camera1_usb_port', default_value='2-3.3')
|
|
||||||
camera2_usb_port = DeclareLaunchArgument('camera2_usb_port', default_value='1-4.4')
|
|
||||||
device_num = DeclareLaunchArgument('device_num', default_value='2')
|
|
||||||
|
|
||||||
# Node configuration
|
# Node configuration
|
||||||
cleanup_node = Node(
|
cleanup_node = Node(
|
||||||
package='orbbec_camera',
|
package='orbbec_camera',
|
||||||
@@ -25,46 +16,37 @@ def generate_launch_description():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Include launch files
|
# Include launch files
|
||||||
launch_file_dir = FindPackageShare('orbbec_camera').find('orbbec_camera') + '/launch'
|
package_dir = get_package_share_directory('orbbec_camera')
|
||||||
|
launch_file_dir = os.path.join(package_dir, 'launch')
|
||||||
launch1_include = IncludeLaunchDescription(
|
launch1_include = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(launch_file_dir + '/' + (LaunchConfiguration('3d_sensor') + '.launch.py')),
|
PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(launch_file_dir, 'gemini2.launch.py')
|
||||||
|
),
|
||||||
launch_arguments={
|
launch_arguments={
|
||||||
'camera_name': 'camera_' + LaunchConfiguration('camera1_prefix'),
|
'camera_name': 'camera_01',
|
||||||
'usb_port': LaunchConfiguration('camera1_usb_port'),
|
'usb_port': '6-2.4.4.2',
|
||||||
'device_num': LaunchConfiguration('device_num')
|
'device_num': '2'
|
||||||
}.items()
|
}.items()
|
||||||
)
|
)
|
||||||
|
|
||||||
launch2_include = IncludeLaunchDescription(
|
launch2_include = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(launch_file_dir + '/' + (LaunchConfiguration('3d_sensor') + '.launch.py')),
|
PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(launch_file_dir, 'gemini2.launch.py')
|
||||||
|
),
|
||||||
launch_arguments={
|
launch_arguments={
|
||||||
'camera_name': 'camera_' + LaunchConfiguration('camera2_prefix'),
|
'camera_name': 'camera_02',
|
||||||
'usb_port': LaunchConfiguration('camera2_usb_port'),
|
'usb_port': '6-2.4.1',
|
||||||
'device_num': LaunchConfiguration('device_num')
|
'device_num': '2'
|
||||||
}.items()
|
}.items()
|
||||||
)
|
)
|
||||||
|
|
||||||
# Static TF publisher
|
# If you need more cameras, just add more launch_include here, and change the usb_port and device_num
|
||||||
tf_publisher = Node(
|
|
||||||
package='tf2_ros',
|
|
||||||
executable='static_transform_publisher',
|
|
||||||
name='camera_tf',
|
|
||||||
arguments=['0', '0', '0', '0', '0', '0', 'camera01_link', 'camera02_link']
|
|
||||||
)
|
|
||||||
|
|
||||||
# Launch description
|
# Launch description
|
||||||
ld = LaunchDescription([
|
ld = LaunchDescription([
|
||||||
camera_name,
|
|
||||||
d_sensor,
|
|
||||||
camera1_prefix,
|
|
||||||
camera2_prefix,
|
|
||||||
camera1_usb_port,
|
|
||||||
camera2_usb_port,
|
|
||||||
device_num,
|
|
||||||
cleanup_node,
|
cleanup_node,
|
||||||
GroupAction([launch1_include]),
|
GroupAction([launch1_include]),
|
||||||
GroupAction([launch2_include]),
|
GroupAction([launch2_include]),
|
||||||
tf_publisher
|
|
||||||
])
|
])
|
||||||
|
|
||||||
return ld
|
return ld
|
||||||
|
|||||||
@@ -4,17 +4,25 @@
|
|||||||
#include <orbbec_camera/utils.h>
|
#include <orbbec_camera/utils.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto context = std::make_unique<ob::Context>();
|
try {
|
||||||
context->setLoggerSeverity(OBLogSeverity::OB_LOG_SEVERITY_NONE);
|
auto context = std::make_unique<ob::Context>();
|
||||||
auto list = context->queryDeviceList();
|
context->setLoggerSeverity(OBLogSeverity::OB_LOG_SEVERITY_NONE);
|
||||||
for (size_t i = 0; i < list->deviceCount(); i++) {
|
auto list = context->queryDeviceList();
|
||||||
auto device = list->getDevice(i);
|
for (size_t i = 0; i < list->deviceCount(); i++) {
|
||||||
auto device_info = device->getDeviceInfo();
|
auto device = list->getDevice(i);
|
||||||
std::string serial = device_info->serialNumber();
|
auto device_info = device->getDeviceInfo();
|
||||||
std::string uid = device_info->uid();
|
std::string serial = device_info->serialNumber();
|
||||||
auto usb_port = orbbec_camera::parseUsbPort(uid);
|
std::string uid = device_info->uid();
|
||||||
RCLCPP_INFO_STREAM(rclcpp::get_logger("list_device_node"), "serial: " << serial);
|
auto usb_port = orbbec_camera::parseUsbPort(uid);
|
||||||
RCLCPP_INFO_STREAM(rclcpp::get_logger("list_device_node"), "usb port: " << usb_port);
|
RCLCPP_INFO_STREAM(rclcpp::get_logger("list_device_node"), "serial: " << serial);
|
||||||
|
RCLCPP_INFO_STREAM(rclcpp::get_logger("list_device_node"), "usb port: " << usb_port);
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
RCLCPP_ERROR_STREAM(rclcpp::get_logger("list_device_node"), e.what());
|
||||||
|
} catch (ob::Error &e) {
|
||||||
|
RCLCPP_ERROR_STREAM(rclcpp::get_logger("list_device_node"), e.getMessage());
|
||||||
|
} catch (...) {
|
||||||
|
RCLCPP_ERROR_STREAM(rclcpp::get_logger("list_device_node"), "unknown error");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user