Skip to content
Closed
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
33 changes: 25 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ find_package(diagnostic_msgs REQUIRED)
###########


add_library(${PROJECT_NAME}_node SHARED
## Shared library for composition support
add_library(${PROJECT_NAME}_component SHARED
src/k4a_ros_device.cpp
src/k4a_ros_device_params.cpp
src/k4a_calibration_transform_data.cpp)

ament_target_dependencies(${PROJECT_NAME}_node rclcpp
std_msgs
ament_target_dependencies(${PROJECT_NAME}_component rclcpp
std_msgs
sensor_msgs
visualization_msgs
diagnostic_msgs
Expand All @@ -60,6 +61,12 @@ ament_target_dependencies(${PROJECT_NAME}_node rclcpp
cv_bridge
angles)

## Standalone executable
add_executable(${PROJECT_NAME}_node
src/k4a_ros_bridge_node.cpp)

ament_target_dependencies(${PROJECT_NAME}_node rclcpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
Expand Down Expand Up @@ -90,7 +97,7 @@ find_package(k4abt 1.0.0 QUIET MODULE)
if (k4abt_FOUND)
list(APPEND K4A_LIBS k4abt::k4abt)
message(STATUS "Body Tracking SDK found: compiling support for Body Tracking")
target_compile_definitions(${PROJECT_NAME}_node PUBLIC K4A_BODY_TRACKING)
target_compile_definitions(${PROJECT_NAME}_component PUBLIC K4A_BODY_TRACKING)
else()
message("!!! Body Tracking SDK not found: body tracking features will not be available !!!")
endif()
Expand All @@ -104,11 +111,16 @@ include(Installk4a)
##################################
include_directories(include)

target_link_libraries(${PROJECT_NAME}_node
target_link_libraries(${PROJECT_NAME}_component
${K4A_LIBS}
)

rclcpp_components_register_nodes(${PROJECT_NAME}_node "K4AROSDevice")
# Link standalone executable to the component library
target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME}_component
)

rclcpp_components_register_nodes(${PROJECT_NAME}_component "K4AROSDevice")

#############
## Install ##
Expand All @@ -118,10 +130,15 @@ rclcpp_components_register_nodes(${PROJECT_NAME}_node "K4AROSDevice")
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executables and/or libraries for installation
install(TARGETS ${PROJECT_NAME}_node
install(TARGETS ${PROJECT_NAME}_component
LIBRARY DESTINATION lib
)
ament_export_libraries(${library_name})

install(TARGETS ${PROJECT_NAME}_node
DESTINATION lib/${PROJECT_NAME}
)

ament_export_libraries(${PROJECT_NAME}_component)

message("Added libs")

Expand Down
24 changes: 8 additions & 16 deletions src/k4a_ros_bridge_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,37 @@ int main(int argc, char** argv)
{
rclcpp::init(argc, argv);

// Create Node for handling info and error messages
rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("k4a_bridge");


// Setup the K4A device
std::shared_ptr<K4AROSDevice> device(new K4AROSDevice);
// Setup the K4A device (K4AROSDevice is now a rclcpp::Node)
rclcpp::NodeOptions options;
auto device = std::make_shared<K4AROSDevice>(options);

k4a_result_t result = device->startCameras();

if (result != K4A_RESULT_SUCCEEDED)
{
RCLCPP_ERROR_STREAM(node->get_logger(),"Failed to start cameras");
RCLCPP_ERROR_STREAM(device->get_logger(), "Failed to start cameras");
return -1;
}

result = device->startImu();
if (result != K4A_RESULT_SUCCEEDED)
{
RCLCPP_ERROR_STREAM(node->get_logger(),"Failed to start IMU");
RCLCPP_ERROR_STREAM(device->get_logger(), "Failed to start IMU");
return -2;
}

RCLCPP_INFO(node->get_logger(),"K4A Started");
RCLCPP_INFO(device->get_logger(), "K4A Started");

if (result == K4A_RESULT_SUCCEEDED)
{
rclcpp::spin(node);
rclcpp::spin(device);

RCLCPP_INFO(node->get_logger(),"ROS Exit Started");
RCLCPP_INFO(device->get_logger(), "ROS Exit Started");
}

device.reset();

RCLCPP_INFO(node->get_logger(),"ROS Exit");

rclcpp::shutdown();

RCLCPP_INFO(node->get_logger(),"ROS Shutdown complete");

RCLCPP_INFO(node->get_logger(),"Finished ros bridge main");
return 0;
}