Skip to content

Commit

Permalink
feat: adapt main to remove ros arguments, add ros2 launch
Browse files Browse the repository at this point in the history
  • Loading branch information
hiikariri committed Jun 16, 2024
1 parent d7c8ecb commit e94f5f2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

# Set the build type to Debug if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -fPIC)
add_compile_options(-Wall -Wextra -Wpedantic -fPIC -g3)
endif()

find_package(ament_cmake REQUIRED)
Expand Down Expand Up @@ -93,6 +98,10 @@ target_link_libraries(${PROJECT_NAME}

install(DIRECTORY "include" DESTINATION ".")

install(DIRECTORY
launch
DESTINATION "share/${PROJECT_NAME}")

install(TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
Expand Down
40 changes: 40 additions & 0 deletions launch/shisen_cpp_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2024 ICHIRO ITS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import os
import socket
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
hostname = socket.gethostname()
config_path = os.path.expanduser(f'~/ros2-ws/configuration/{hostname}/camera/')

return LaunchDescription([
Node(
package='shisen_cpp',
executable='camera',
name='camera',
output='screen',
arguments=[config_path],
respawn=True,
respawn_delay=1
)
])
14 changes: 7 additions & 7 deletions src/shisen_cpp_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
auto args = rclcpp::init_and_remove_ros_arguments(argc, argv);

shisen_cpp::Options options;
options.field_of_view = 78;
Expand All @@ -50,20 +50,20 @@ int main(int argc, char ** argv)
try {
int i = 1;
int pos = 0;
while (i < argc) {
std::string arg = argv[i++];
while (i < args.size()) {
std::string arg = args[i++];
if (arg[0] == '-') {
if (arg == "-h" || arg == "--help") {
std::cout << help_message << std::endl;
return 1;
} else if (arg == "--camera-prefix") {
options.camera_prefix = argv[i++];
options.camera_prefix = args[i++];
} else if (arg == "--compression") {
options.compression_quality = atoi(argv[i++]);
options.compression_quality = stoi(args[i++]);
} else if (arg == "--capture-fps") {
options.capture_fps = atoi(argv[i++]);
options.capture_fps = stoi(args[i++]);
} else if (arg == "--field-of-view") {
options.field_of_view = atoi(argv[i++]);
options.field_of_view = stoi(args[i++]);
} else {
std::cout << "Unknown option `" << arg << "`!\n\n" << help_message << std::endl;
return 1;
Expand Down

0 comments on commit e94f5f2

Please sign in to comment.