Skip to content

Commit 0078196

Browse files
authored
Merge pull request #27 from ichiro-its/feature/adapt-main-to-ros2-launch
[Feature / PD-420] Adapt Shisen Main to ROS2 Launch
2 parents d7c8ecb + 9cc5398 commit 0078196

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ target_link_libraries(${PROJECT_NAME}
9393

9494
install(DIRECTORY "include" DESTINATION ".")
9595

96+
install(DIRECTORY
97+
launch
98+
DESTINATION "share/${PROJECT_NAME}")
99+
96100
install(TARGETS ${PROJECT_NAME}
97101
EXPORT export_${PROJECT_NAME}
98102
ARCHIVE DESTINATION "lib"

launch/shisen_cpp_launch.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2024 ICHIRO ITS
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
# THE SOFTWARE.
20+
21+
import os
22+
import socket
23+
from launch import LaunchDescription
24+
from launch_ros.actions import Node
25+
26+
def generate_launch_description():
27+
hostname = socket.gethostname()
28+
config_path = os.path.expanduser(f'~/ros2-ws/configuration/{hostname}/camera/')
29+
30+
return LaunchDescription([
31+
Node(
32+
package='shisen_cpp',
33+
executable='camera',
34+
name='camera',
35+
output='screen',
36+
arguments=[config_path],
37+
respawn=True,
38+
respawn_delay=1
39+
)
40+
])

src/shisen_cpp_main.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
int main(int argc, char ** argv)
2828
{
29-
rclcpp::init(argc, argv);
29+
auto args = rclcpp::init_and_remove_ros_arguments(argc, argv);
3030

3131
shisen_cpp::Options options;
3232
options.field_of_view = 78;
@@ -50,20 +50,20 @@ int main(int argc, char ** argv)
5050
try {
5151
int i = 1;
5252
int pos = 0;
53-
while (i < argc) {
54-
std::string arg = argv[i++];
53+
while (i < args.size()) {
54+
const std::string& arg = args[i++];
5555
if (arg[0] == '-') {
5656
if (arg == "-h" || arg == "--help") {
5757
std::cout << help_message << std::endl;
5858
return 1;
5959
} else if (arg == "--camera-prefix") {
60-
options.camera_prefix = argv[i++];
60+
options.camera_prefix = args[i++];
6161
} else if (arg == "--compression") {
62-
options.compression_quality = atoi(argv[i++]);
62+
options.compression_quality = stoi(args[i++]);
6363
} else if (arg == "--capture-fps") {
64-
options.capture_fps = atoi(argv[i++]);
64+
options.capture_fps = stoi(args[i++]);
6565
} else if (arg == "--field-of-view") {
66-
options.field_of_view = atoi(argv[i++]);
66+
options.field_of_view = stoi(args[i++]);
6767
} else {
6868
std::cout << "Unknown option `" << arg << "`!\n\n" << help_message << std::endl;
6969
return 1;

0 commit comments

Comments
 (0)