Skip to content

Commit

Permalink
Use rcutils to log (#37)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde authored Aug 26, 2024
1 parent d1e6546 commit 54ae24c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion urdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(urdf)

find_package(ament_cmake_ros REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rcutils REQUIRED)
find_package(urdf_parser_plugin REQUIRED)
find_package(urdfdom REQUIRED)
find_package(urdfdom_headers REQUIRED)
Expand Down Expand Up @@ -45,6 +46,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
urdf_parser_plugin::urdf_parser_plugin
urdfdom_headers::urdfdom_headers
pluginlib::pluginlib
rcutils::rcutils
)

if(WIN32)
Expand Down Expand Up @@ -126,7 +128,6 @@ ament_export_libraries(${PROJECT_NAME})
# Export modern CMake targets
ament_export_targets(${PROJECT_NAME})

ament_export_dependencies(pluginlib)
ament_export_dependencies(urdf_parser_plugin)
ament_export_dependencies(urdfdom)
ament_export_dependencies(urdfdom_headers)
Expand Down
3 changes: 2 additions & 1 deletion urdf/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@
<buildtool_depend>ament_cmake_ros</buildtool_depend>

<build_depend>pluginlib</build_depend>
<build_depend>rcutils</build_depend>
<build_depend>tinyxml2_vendor</build_depend>
<build_depend>urdfdom</build_depend>
<build_depend>urdf_parser_plugin</build_depend>
<!-- use ROS 2 package urdfdom_headers until upstream provides 1.0.0.-->
<build_depend>urdfdom_headers</build_depend>

<exec_depend>pluginlib</exec_depend>
<exec_depend>rcutils</exec_depend>
<exec_depend>tinyxml2_vendor</exec_depend>
<exec_depend>urdfdom</exec_depend>
<!-- while `urdf_parser_plugin` is a header only lib, `pluginlib` requires the package to exist during runtime. -->
<exec_depend>urdf_parser_plugin</exec_depend>
<!-- use ROS 2 package urdfdom_headers until upstream provides 1.0.0.-->
<exec_depend>urdfdom_headers</exec_depend>

<build_export_depend>pluginlib</build_export_depend>
<build_export_depend>urdf_parser_plugin</build_export_depend>
<build_export_depend>urdfdom</build_export_depend>
<!-- use ROS 2 package urdfdom_headers until upstream provides 1.0.0.-->
Expand Down
14 changes: 10 additions & 4 deletions urdf/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "urdf/model.h"

#include <rcutils/logging_macros.h>

#include <cassert>
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -117,7 +119,8 @@ bool Model::initFile(const std::string & filename)
xml_file.close();
return Model::initString(xml_string);
} else {
fprintf(stderr, "Could not open file [%s] for parsing.\n", filename.c_str());
RCUTILS_LOG_WARN_NAMED(
"urdf", "Could not open file [%s] for parsing.\n", filename.c_str());
return false;
}
}
Expand All @@ -129,7 +132,8 @@ ModelImplementation::load_plugin(const std::string & plugin_name)
try {
plugin_instance = loader_.createUniqueInstance(plugin_name);
} catch (const pluginlib::CreateClassException &) {
fprintf(stderr, "Failed to load urdf_parser_plugin [%s]\n", plugin_name.c_str());
RCUTILS_LOG_ERROR_NAMED(
"urdf", "Failed to load urdf_parser_plugin [%s]\n", plugin_name.c_str());
}
return plugin_instance;
}
Expand Down Expand Up @@ -166,15 +170,17 @@ bool Model::initString(const std::string & data)
}

if (!best_plugin) {
fprintf(stderr, "No plugin found for given robot description.\n");
RCUTILS_LOG_WARN_NAMED(
"urdf", "No plugin found for given robot description.\n");
return false;
}

model = best_plugin->parse(data);

// copy data from model into this object
if (!model) {
fprintf(stderr, "Failed to parse robot description using: %s\n", best_plugin_name.c_str());
RCUTILS_LOG_WARN_NAMED(
"urdf", "Failed to parse robot description using: %s\n", best_plugin_name.c_str());
return false;
}

Expand Down

0 comments on commit 54ae24c

Please sign in to comment.