diff --git a/moveit_core/utils/CMakeLists.txt b/moveit_core/utils/CMakeLists.txt index 7be8dd822d2..5fa121ad7da 100644 --- a/moveit_core/utils/CMakeLists.txt +++ b/moveit_core/utils/CMakeLists.txt @@ -2,12 +2,13 @@ add_library(moveit_utils SHARED src/lexical_casts.cpp src/message_checks.cpp src/rclcpp_utils.cpp + src/logger.cpp ) target_include_directories(moveit_utils PUBLIC $ $ ) -ament_target_dependencies(moveit_utils Boost moveit_msgs) +ament_target_dependencies(moveit_utils Boost moveit_msgs rclcpp) set_target_properties(moveit_utils PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}") install(DIRECTORY include/ DESTINATION include/moveit_core) @@ -28,5 +29,6 @@ ament_target_dependencies(moveit_test_utils srdfdom urdfdom urdfdom_headers + rclcpp ) set_target_properties(moveit_test_utils PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}") diff --git a/moveit_core/utils/include/moveit/utils/logger.hpp b/moveit_core/utils/include/moveit/utils/logger.hpp new file mode 100644 index 00000000000..72ac08a8cba --- /dev/null +++ b/moveit_core/utils/include/moveit/utils/logger.hpp @@ -0,0 +1,51 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2023, PickNik Robotics Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Willow Garage nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +/* Author: Tyler Weaver */ + +#pragma once + +#include + +namespace moveit +{ + +// Function for getting a reference to a logger object kept on the stack +// Use get_logger_mut to set the logger to a node logger +const rclcpp::Logger& get_logger(); + +// Mutable access to global logger for setting to node logger +rclcpp::Logger& get_logger_mut(); + +} // namespace moveit diff --git a/moveit_core/utils/src/logger.cpp b/moveit_core/utils/src/logger.cpp new file mode 100644 index 00000000000..0dd2d3ee6ef --- /dev/null +++ b/moveit_core/utils/src/logger.cpp @@ -0,0 +1,57 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2023, PickNik Robotics Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Willow Garage nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +/* Author: Tyler Weaver */ + +#include +#include + +namespace moveit +{ + +// Function for getting a reference to a logger object kept on the stack +// Use get_logger_mut to set the logger to a node logger +const rclcpp::Logger& get_logger() +{ + return get_logger_mut(); +} + +// Mutable access to global logger for setting to node logger +rclcpp::Logger& get_logger_mut() +{ + static rclcpp::Logger logger = rclcpp::get_logger("moveit"); + return logger; +} + +} // namespace moveit diff --git a/moveit_ros/warehouse/src/broadcast.cpp b/moveit_ros/warehouse/src/broadcast.cpp index 208713d589f..7a5cd4aafa3 100644 --- a/moveit_ros/warehouse/src/broadcast.cpp +++ b/moveit_ros/warehouse/src/broadcast.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ static const std::string CONSTRAINTS_TOPIC = "constraints"; static const std::string STATES_TOPIC = "robot_states"; using namespace std::chrono_literals; +using moveit::get_logger; int main(int argc, char** argv) { @@ -73,7 +75,7 @@ int main(int argc, char** argv) node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("publish_warehouse_data", node_options); - const auto logger = node->get_logger(); + moveit::get_logger_mut() = node->get_logger(); // time to wait in between publishing messages double delay = 0.001; @@ -140,7 +142,7 @@ int main(int argc, char** argv) moveit_warehouse::PlanningSceneWithMetadata pswm; if (pss.getPlanningScene(pswm, scene_name)) { - RCLCPP_INFO(logger, "Publishing scene '%s'", + RCLCPP_INFO(get_logger(), "Publishing scene '%s'", pswm->lookupString(moveit_warehouse::PlanningSceneStorage::PLANNING_SCENE_ID_NAME).c_str()); pub_scene->publish(static_cast(*pswm)); executor.spin_once(0ns); @@ -153,14 +155,14 @@ int main(int argc, char** argv) std::vector planning_queries; std::vector query_names; pss.getPlanningQueries(planning_queries, query_names, pswm->name); - RCLCPP_INFO(logger, "There are %d planning queries associated to the scene", + RCLCPP_INFO(get_logger(), "There are %d planning queries associated to the scene", static_cast(planning_queries.size())); rclcpp::sleep_for(500ms); for (std::size_t i = 0; i < planning_queries.size(); ++i) { if (req) { - RCLCPP_INFO(logger, "Publishing query '%s'", query_names[i].c_str()); + RCLCPP_INFO(get_logger(), "Publishing query '%s'", query_names[i].c_str()); pub_req->publish(static_cast(*planning_queries[i])); executor.spin_once(0ns); } @@ -194,7 +196,7 @@ int main(int argc, char** argv) moveit_warehouse::ConstraintsWithMetadata cwm; if (cs.getConstraints(cwm, cname)) { - RCLCPP_INFO(logger, "Publishing constraints '%s'", + RCLCPP_INFO(get_logger(), "Publishing constraints '%s'", cwm->lookupString(moveit_warehouse::ConstraintsStorage::CONSTRAINTS_ID_NAME).c_str()); pub_constr->publish(static_cast(*cwm)); executor.spin_once(0ns); @@ -216,7 +218,7 @@ int main(int argc, char** argv) moveit_warehouse::RobotStateWithMetadata rswm; if (rs.getRobotState(rswm, rname)) { - RCLCPP_INFO(logger, "Publishing state '%s'", + RCLCPP_INFO(get_logger(), "Publishing state '%s'", rswm->lookupString(moveit_warehouse::RobotStateStorage::STATE_NAME).c_str()); pub_state->publish(static_cast(*rswm)); executor.spin_once(0ns); @@ -226,7 +228,7 @@ int main(int argc, char** argv) } rclcpp::sleep_for(1s); - RCLCPP_INFO(logger, "Done."); + RCLCPP_INFO(get_logger(), "Done."); return 0; } diff --git a/moveit_ros/warehouse/src/constraints_storage.cpp b/moveit_ros/warehouse/src/constraints_storage.cpp index f7258594142..ccd9e5a15ff 100644 --- a/moveit_ros/warehouse/src/constraints_storage.cpp +++ b/moveit_ros/warehouse/src/constraints_storage.cpp @@ -35,6 +35,7 @@ /* Author: Ioan Sucan */ #include +#include #include @@ -44,8 +45,7 @@ const std::string moveit_warehouse::ConstraintsStorage::CONSTRAINTS_ID_NAME = "c const std::string moveit_warehouse::ConstraintsStorage::CONSTRAINTS_GROUP_NAME = "group_id"; const std::string moveit_warehouse::ConstraintsStorage::ROBOT_NAME = "robot_id"; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.constraints_storage"); - +using moveit::get_logger; using warehouse_ros::Metadata; using warehouse_ros::Query; @@ -81,7 +81,7 @@ void moveit_warehouse::ConstraintsStorage::addConstraints(const moveit_msgs::msg metadata->append(ROBOT_NAME, robot); metadata->append(CONSTRAINTS_GROUP_NAME, group); constraints_collection_->insert(msg, metadata); - RCLCPP_DEBUG(LOGGER, "%s constraints '%s'", replace ? "Replaced" : "Added", msg.name.c_str()); + RCLCPP_DEBUG(get_logger(), "%s constraints '%s'", replace ? "Replaced" : "Added", msg.name.c_str()); } bool moveit_warehouse::ConstraintsStorage::hasConstraints(const std::string& name, const std::string& robot, @@ -158,7 +158,7 @@ void moveit_warehouse::ConstraintsStorage::renameConstraints(const std::string& Metadata::Ptr m = constraints_collection_->createMetadata(); m->append(CONSTRAINTS_ID_NAME, new_name); constraints_collection_->modifyMetadata(q, m); - RCLCPP_DEBUG(LOGGER, "Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str()); } void moveit_warehouse::ConstraintsStorage::removeConstraints(const std::string& name, const std::string& robot, @@ -171,5 +171,5 @@ void moveit_warehouse::ConstraintsStorage::removeConstraints(const std::string& if (!group.empty()) q->append(CONSTRAINTS_GROUP_NAME, group); unsigned int rem = constraints_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u Constraints messages (named '%s')", rem, name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u Constraints messages (named '%s')", rem, name.c_str()); } diff --git a/moveit_ros/warehouse/src/import_from_text.cpp b/moveit_ros/warehouse/src/import_from_text.cpp index 6b91501433b..bded956345f 100644 --- a/moveit_ros/warehouse/src/import_from_text.cpp +++ b/moveit_ros/warehouse/src/import_from_text.cpp @@ -45,10 +45,11 @@ #include #include #include +#include -static const std::string ROBOT_DESCRIPTION = "robot_description"; +using moveit::get_logger; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.planning_scene_storage"); +static const std::string ROBOT_DESCRIPTION = "robot_description"; void parseStart(std::istream& in, planning_scene_monitor::PlanningSceneMonitor* psm, moveit_warehouse::RobotStateStorage* rs) @@ -90,7 +91,7 @@ void parseStart(std::istream& in, planning_scene_monitor::PlanningSceneMonitor* st.setVariablePositions(v); moveit_msgs::msg::RobotState msg; moveit::core::robotStateToRobotStateMsg(st, msg); - RCLCPP_INFO(LOGGER, "Parsed start state '%s'", name.c_str()); + RCLCPP_INFO(get_logger(), "Parsed start state '%s'", name.c_str()); rs->addRobotState(msg, name); } } @@ -135,7 +136,7 @@ void parseLinkConstraint(std::istream& in, planning_scene_monitor::PlanningScene Eigen::AngleAxisd(y, Eigen::Vector3d::UnitZ())); } else - RCLCPP_ERROR(LOGGER, "Unknown link constraint element: '%s'", type.c_str()); + RCLCPP_ERROR(get_logger(), "Unknown link constraint element: '%s'", type.c_str()); in >> type; } @@ -150,7 +151,7 @@ void parseLinkConstraint(std::istream& in, planning_scene_monitor::PlanningScene pose.header.frame_id = psm->getRobotModel()->getModelFrame(); moveit_msgs::msg::Constraints constr = kinematic_constraints::constructGoalConstraints(link_name, pose); constr.name = name; - RCLCPP_INFO(LOGGER, "Parsed link constraint '%s'", name.c_str()); + RCLCPP_INFO(get_logger(), "Parsed link constraint '%s'", name.c_str()); cs->addConstraints(constr); } } @@ -180,7 +181,7 @@ void parseGoal(std::istream& in, planning_scene_monitor::PlanningSceneMonitor* p } else { - RCLCPP_INFO(LOGGER, "Unknown goal type: '%s'", type.c_str()); + RCLCPP_INFO(get_logger(), "Unknown goal type: '%s'", type.c_str()); } } } @@ -209,7 +210,7 @@ void parseQueries(std::istream& in, planning_scene_monitor::PlanningSceneMonitor } else { - RCLCPP_ERROR(LOGGER, "Unknown query type: '%s'", type.c_str()); + RCLCPP_ERROR(get_logger(), "Unknown query type: '%s'", type.c_str()); } } } @@ -222,6 +223,7 @@ int main(int argc, char** argv) node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("import_from_text_to_warehouse", node_options); + moveit::get_logger_mut() = node->get_logger(); // clang-format off boost::program_options::options_description desc; @@ -251,7 +253,7 @@ int main(int argc, char** argv) planning_scene_monitor::PlanningSceneMonitor psm(node, ROBOT_DESCRIPTION); if (!psm.getPlanningScene()) { - RCLCPP_ERROR(LOGGER, "Unable to initialize PlanningSceneMonitor"); + RCLCPP_ERROR(get_logger(), "Unable to initialize PlanningSceneMonitor"); return 1; } diff --git a/moveit_ros/warehouse/src/initialize_demo_db.cpp b/moveit_ros/warehouse/src/initialize_demo_db.cpp index 3123e484281..b1350890c4e 100644 --- a/moveit_ros/warehouse/src/initialize_demo_db.cpp +++ b/moveit_ros/warehouse/src/initialize_demo_db.cpp @@ -52,10 +52,11 @@ #include #include #include +#include static const std::string ROBOT_DESCRIPTION = "robot_description"; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.initialize_demo_db"); +using moveit::get_logger; int main(int argc, char** argv) { @@ -64,6 +65,7 @@ int main(int argc, char** argv) node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("initialize_demo_db", node_options); + moveit::get_logger_mut() = node->get_logger(); boost::program_options::options_description desc; desc.add_options()("help", "Show help message")("host", boost::program_options::value(), @@ -90,7 +92,7 @@ int main(int argc, char** argv) planning_scene_monitor::PlanningSceneMonitor psm(node, ROBOT_DESCRIPTION); if (!psm.getPlanningScene()) { - RCLCPP_ERROR(LOGGER, "Unable to initialize PlanningSceneMonitor"); + RCLCPP_ERROR(get_logger(), "Unable to initialize PlanningSceneMonitor"); return 1; } @@ -106,12 +108,12 @@ int main(int argc, char** argv) psm.getPlanningScene()->getPlanningSceneMsg(psmsg); psmsg.name = "default"; pss.addPlanningScene(psmsg); - RCLCPP_INFO(LOGGER, "Added default scene: '%s'", psmsg.name.c_str()); + RCLCPP_INFO(get_logger(), "Added default scene: '%s'", psmsg.name.c_str()); moveit_msgs::msg::RobotState rsmsg; moveit::core::robotStateToRobotStateMsg(psm.getPlanningScene()->getCurrentState(), rsmsg); rs.addRobotState(rsmsg, "default"); - RCLCPP_INFO(LOGGER, "Added default state"); + RCLCPP_INFO(get_logger(), "Added default state"); const std::vector& gnames = psm.getRobotModel()->getJointModelGroupNames(); for (const std::string& gname : gnames) @@ -138,9 +140,9 @@ int main(int argc, char** argv) cmsg.orientation_constraints.resize(1, ocm); cmsg.name = ocm.link_name + ":upright"; cs.addConstraints(cmsg, psm.getRobotModel()->getName(), jmg->getName()); - RCLCPP_INFO(LOGGER, "Added default constraint: '%s'", cmsg.name.c_str()); + RCLCPP_INFO(get_logger(), "Added default constraint: '%s'", cmsg.name.c_str()); } - RCLCPP_INFO(LOGGER, "Default MoveIt Warehouse was reset."); + RCLCPP_INFO(get_logger(), "Default MoveIt Warehouse was reset."); rclcpp::spin(node); diff --git a/moveit_ros/warehouse/src/planning_scene_storage.cpp b/moveit_ros/warehouse/src/planning_scene_storage.cpp index ae7b9710ead..b3aec0b8ad5 100644 --- a/moveit_ros/warehouse/src/planning_scene_storage.cpp +++ b/moveit_ros/warehouse/src/planning_scene_storage.cpp @@ -38,17 +38,17 @@ #include #include #include +#include const std::string moveit_warehouse::PlanningSceneStorage::DATABASE_NAME = "moveit_planning_scenes"; const std::string moveit_warehouse::PlanningSceneStorage::PLANNING_SCENE_ID_NAME = "planning_scene_id"; const std::string moveit_warehouse::PlanningSceneStorage::MOTION_PLAN_REQUEST_ID_NAME = "motion_request_id"; +using moveit::get_logger; using warehouse_ros::Metadata; using warehouse_ros::Query; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.planning_scene_storage"); - moveit_warehouse::PlanningSceneStorage::PlanningSceneStorage(warehouse_ros::DatabaseConnection::Ptr conn) : MoveItMessageStorage(std::move(conn)) { @@ -85,7 +85,7 @@ void moveit_warehouse::PlanningSceneStorage::addPlanningScene(const moveit_msgs: Metadata::Ptr metadata = planning_scene_collection_->createMetadata(); metadata->append(PLANNING_SCENE_ID_NAME, scene.name); planning_scene_collection_->insert(scene, metadata); - RCLCPP_DEBUG(LOGGER, "%s scene '%s'", replace ? "Replaced" : "Added", scene.name.c_str()); + RCLCPP_DEBUG(get_logger(), "%s scene '%s'", replace ? "Replaced" : "Added", scene.name.c_str()); } bool moveit_warehouse::PlanningSceneStorage::hasPlanningScene(const std::string& name) const @@ -173,7 +173,7 @@ moveit_warehouse::PlanningSceneStorage::addNewPlanningRequest(const moveit_msgs: metadata->append(PLANNING_SCENE_ID_NAME, scene_name); metadata->append(MOTION_PLAN_REQUEST_ID_NAME, id); motion_plan_request_collection_->insert(planning_query, metadata); - RCLCPP_DEBUG(LOGGER, "Saved planning query '%s' for scene '%s'", id.c_str(), scene_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Saved planning query '%s' for scene '%s'", id.c_str(), scene_name.c_str()); return id; } @@ -231,7 +231,7 @@ bool moveit_warehouse::PlanningSceneStorage::getPlanningScene(PlanningSceneWithM std::vector planning_scenes = planning_scene_collection_->queryList(q, false); if (planning_scenes.empty()) { - RCLCPP_WARN(LOGGER, "Planning scene '%s' was not found in the database", scene_name.c_str()); + RCLCPP_WARN(get_logger(), "Planning scene '%s' was not found in the database", scene_name.c_str()); return false; } scene_m = planning_scenes.back(); @@ -251,7 +251,7 @@ bool moveit_warehouse::PlanningSceneStorage::getPlanningQuery(MotionPlanRequestW std::vector planning_queries = motion_plan_request_collection_->queryList(q, false); if (planning_queries.empty()) { - RCLCPP_ERROR(LOGGER, "Planning query '%s' not found for scene '%s'", query_name.c_str(), scene_name.c_str()); + RCLCPP_ERROR(get_logger(), "Planning query '%s' not found for scene '%s'", query_name.c_str(), scene_name.c_str()); return false; } else @@ -369,7 +369,7 @@ void moveit_warehouse::PlanningSceneStorage::renamePlanningScene(const std::stri Metadata::Ptr m = planning_scene_collection_->createMetadata(); m->append(PLANNING_SCENE_ID_NAME, new_scene_name); planning_scene_collection_->modifyMetadata(q, m); - RCLCPP_DEBUG(LOGGER, "Renamed planning scene from '%s' to '%s'", old_scene_name.c_str(), new_scene_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Renamed planning scene from '%s' to '%s'", old_scene_name.c_str(), new_scene_name.c_str()); } void moveit_warehouse::PlanningSceneStorage::renamePlanningQuery(const std::string& scene_name, @@ -382,7 +382,7 @@ void moveit_warehouse::PlanningSceneStorage::renamePlanningQuery(const std::stri Metadata::Ptr m = motion_plan_request_collection_->createMetadata(); m->append(MOTION_PLAN_REQUEST_ID_NAME, new_query_name); motion_plan_request_collection_->modifyMetadata(q, m); - RCLCPP_DEBUG(LOGGER, "Renamed planning query for scene '%s' from '%s' to '%s'", scene_name.c_str(), + RCLCPP_DEBUG(get_logger(), "Renamed planning query for scene '%s' from '%s' to '%s'", scene_name.c_str(), old_query_name.c_str(), new_query_name.c_str()); } @@ -392,7 +392,7 @@ void moveit_warehouse::PlanningSceneStorage::removePlanningScene(const std::stri Query::Ptr q = planning_scene_collection_->createQuery(); q->append(PLANNING_SCENE_ID_NAME, scene_name); unsigned int rem = planning_scene_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u PlanningScene messages (named '%s')", rem, scene_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u PlanningScene messages (named '%s')", rem, scene_name.c_str()); } void moveit_warehouse::PlanningSceneStorage::removePlanningQueries(const std::string& scene_name) @@ -401,7 +401,7 @@ void moveit_warehouse::PlanningSceneStorage::removePlanningQueries(const std::st Query::Ptr q = motion_plan_request_collection_->createQuery(); q->append(PLANNING_SCENE_ID_NAME, scene_name); unsigned int rem = motion_plan_request_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u MotionPlanRequest messages for scene '%s'", rem, scene_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u MotionPlanRequest messages for scene '%s'", rem, scene_name.c_str()); } void moveit_warehouse::PlanningSceneStorage::removePlanningQuery(const std::string& scene_name, @@ -412,8 +412,8 @@ void moveit_warehouse::PlanningSceneStorage::removePlanningQuery(const std::stri q->append(PLANNING_SCENE_ID_NAME, scene_name); q->append(MOTION_PLAN_REQUEST_ID_NAME, query_name); unsigned int rem = motion_plan_request_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u MotionPlanRequest messages for scene '%s', query '%s'", rem, scene_name.c_str(), - query_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u MotionPlanRequest messages for scene '%s', query '%s'", rem, + scene_name.c_str(), query_name.c_str()); } void moveit_warehouse::PlanningSceneStorage::removePlanningResults(const std::string& scene_name) @@ -421,7 +421,7 @@ void moveit_warehouse::PlanningSceneStorage::removePlanningResults(const std::st Query::Ptr q = robot_trajectory_collection_->createQuery(); q->append(PLANNING_SCENE_ID_NAME, scene_name); unsigned int rem = robot_trajectory_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u RobotTrajectory messages for scene '%s'", rem, scene_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u RobotTrajectory messages for scene '%s'", rem, scene_name.c_str()); } void moveit_warehouse::PlanningSceneStorage::removePlanningResults(const std::string& scene_name, @@ -431,6 +431,6 @@ void moveit_warehouse::PlanningSceneStorage::removePlanningResults(const std::st q->append(PLANNING_SCENE_ID_NAME, scene_name); q->append(MOTION_PLAN_REQUEST_ID_NAME, query_name); unsigned int rem = robot_trajectory_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u RobotTrajectory messages for scene '%s', query '%s'", rem, scene_name.c_str(), + RCLCPP_DEBUG(get_logger(), "Removed %u RobotTrajectory messages for scene '%s', query '%s'", rem, scene_name.c_str(), query_name.c_str()); } diff --git a/moveit_ros/warehouse/src/planning_scene_world_storage.cpp b/moveit_ros/warehouse/src/planning_scene_world_storage.cpp index 310e060f562..9934bbd5bdc 100644 --- a/moveit_ros/warehouse/src/planning_scene_world_storage.cpp +++ b/moveit_ros/warehouse/src/planning_scene_world_storage.cpp @@ -35,14 +35,14 @@ /* Author: Ioan Sucan */ #include +#include #include const std::string moveit_warehouse::PlanningSceneWorldStorage::DATABASE_NAME = "moveit_planning_scene_worlds"; const std::string moveit_warehouse::PlanningSceneWorldStorage::PLANNING_SCENE_WORLD_ID_NAME = "world_id"; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.planning_scene_world_storage"); - +using moveit::get_logger; using warehouse_ros::Metadata; using warehouse_ros::Query; @@ -77,7 +77,7 @@ void moveit_warehouse::PlanningSceneWorldStorage::addPlanningSceneWorld(const mo Metadata::Ptr metadata = planning_scene_world_collection_->createMetadata(); metadata->append(PLANNING_SCENE_WORLD_ID_NAME, name); planning_scene_world_collection_->insert(msg, metadata); - RCLCPP_DEBUG(LOGGER, "%s planning scene world '%s'", replace ? "Replaced" : "Added", name.c_str()); + RCLCPP_DEBUG(get_logger(), "%s planning scene world '%s'", replace ? "Replaced" : "Added", name.c_str()); } bool moveit_warehouse::PlanningSceneWorldStorage::hasPlanningSceneWorld(const std::string& name) const @@ -133,7 +133,7 @@ void moveit_warehouse::PlanningSceneWorldStorage::renamePlanningSceneWorld(const Metadata::Ptr m = planning_scene_world_collection_->createMetadata(); m->append(PLANNING_SCENE_WORLD_ID_NAME, new_name); planning_scene_world_collection_->modifyMetadata(q, m); - RCLCPP_DEBUG(LOGGER, "Renamed planning scene world from '%s' to '%s'", old_name.c_str(), new_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Renamed planning scene world from '%s' to '%s'", old_name.c_str(), new_name.c_str()); } void moveit_warehouse::PlanningSceneWorldStorage::removePlanningSceneWorld(const std::string& name) @@ -141,5 +141,5 @@ void moveit_warehouse::PlanningSceneWorldStorage::removePlanningSceneWorld(const Query::Ptr q = planning_scene_world_collection_->createQuery(); q->append(PLANNING_SCENE_WORLD_ID_NAME, name); unsigned int rem = planning_scene_world_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u PlanningSceneWorld messages (named '%s')", rem, name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u PlanningSceneWorld messages (named '%s')", rem, name.c_str()); } diff --git a/moveit_ros/warehouse/src/save_as_text.cpp b/moveit_ros/warehouse/src/save_as_text.cpp index d42ae85996c..187d2d5ab01 100644 --- a/moveit_ros/warehouse/src/save_as_text.cpp +++ b/moveit_ros/warehouse/src/save_as_text.cpp @@ -49,14 +49,15 @@ #include #include #include +#include static const std::string ROBOT_DESCRIPTION = "robot_description"; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.save_to_text"); - typedef std::pair LinkConstraintPair; typedef std::map LinkConstraintMap; +using moveit::get_logger; + void collectLinkConstraints(const moveit_msgs::msg::Constraints& constraints, LinkConstraintMap& lcmap) { for (const moveit_msgs::msg::PositionConstraint& position_constraint : constraints.position_constraints) @@ -75,7 +76,7 @@ void collectLinkConstraints(const moveit_msgs::msg::Constraints& constraints, Li } else { - RCLCPP_WARN(LOGGER, "Orientation constraint for %s has no matching position constraint", + RCLCPP_WARN(get_logger(), "Orientation constraint for %s has no matching position constraint", orientation_constraint.link_name.c_str()); } } @@ -88,6 +89,7 @@ int main(int argc, char** argv) node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("save_warehouse_as_text", node_options); + moveit::get_logger_mut() = node->get_logger(); boost::program_options::options_description desc; desc.add_options()("help", "Show help message")("host", boost::program_options::value(), @@ -125,7 +127,7 @@ int main(int argc, char** argv) moveit_warehouse::PlanningSceneWithMetadata pswm; if (pss.getPlanningScene(pswm, scene_name)) { - RCLCPP_INFO(LOGGER, "Saving scene '%s'", scene_name.c_str()); + RCLCPP_INFO(get_logger(), "Saving scene '%s'", scene_name.c_str()); psm.getPlanningScene()->setPlanningSceneMsg(static_cast(*pswm)); std::ofstream fout((scene_name + ".scene").c_str()); psm.getPlanningScene()->saveGeometryToStream(fout); @@ -155,7 +157,8 @@ int main(int argc, char** argv) qfout << robot_state_names.size() << '\n'; for (const std::string& robot_state_name : robot_state_names) { - RCLCPP_INFO(LOGGER, "Saving start state %s for scene %s", robot_state_name.c_str(), scene_name.c_str()); + RCLCPP_INFO(get_logger(), "Saving start state %s for scene %s", robot_state_name.c_str(), + scene_name.c_str()); qfout << robot_state_name << '\n'; moveit_warehouse::RobotStateWithMetadata robot_state; rss.getRobotState(robot_state, robot_state_name); @@ -172,7 +175,7 @@ int main(int argc, char** argv) qfout << constraint_names.size() << '\n'; for (const std::string& constraint_name : constraint_names) { - RCLCPP_INFO(LOGGER, "Saving goal %s for scene %s", constraint_name.c_str(), scene_name.c_str()); + RCLCPP_INFO(get_logger(), "Saving goal %s for scene %s", constraint_name.c_str(), scene_name.c_str()); qfout << "link_constraint" << '\n'; qfout << constraint_name << '\n'; moveit_warehouse::ConstraintsWithMetadata constraints; @@ -198,7 +201,7 @@ int main(int argc, char** argv) } } - RCLCPP_INFO(LOGGER, "Done."); + RCLCPP_INFO(get_logger(), "Done."); rclcpp::spin(node); return 0; } diff --git a/moveit_ros/warehouse/src/save_to_warehouse.cpp b/moveit_ros/warehouse/src/save_to_warehouse.cpp index 894212587dc..ffff2f9bdd5 100644 --- a/moveit_ros/warehouse/src/save_to_warehouse.cpp +++ b/moveit_ros/warehouse/src/save_to_warehouse.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -59,13 +60,13 @@ #include #include -static const std::string ROBOT_DESCRIPTION = "robot_description"; +using moveit::get_logger; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.save_to_warehouse"); +static const std::string ROBOT_DESCRIPTION = "robot_description"; void onSceneUpdate(planning_scene_monitor::PlanningSceneMonitor& psm, moveit_warehouse::PlanningSceneStorage& pss) { - RCLCPP_INFO(LOGGER, "Received an update to the planning scene..."); + RCLCPP_INFO(get_logger(), "Received an update to the planning scene..."); if (!psm.getPlanningScene()->getName().empty()) { @@ -77,12 +78,12 @@ void onSceneUpdate(planning_scene_monitor::PlanningSceneMonitor& psm, moveit_war } else { - RCLCPP_INFO(LOGGER, "Scene '%s' was previously added. Not adding again.", + RCLCPP_INFO(get_logger(), "Scene '%s' was previously added. Not adding again.", psm.getPlanningScene()->getName().c_str()); } } else - RCLCPP_INFO(LOGGER, "Scene name is empty. Not saving."); + RCLCPP_INFO(get_logger(), "Scene name is empty. Not saving."); } void onMotionPlanRequest(const moveit_msgs::msg::MotionPlanRequest& req, @@ -90,7 +91,7 @@ void onMotionPlanRequest(const moveit_msgs::msg::MotionPlanRequest& req, { if (psm.getPlanningScene()->getName().empty()) { - RCLCPP_INFO(LOGGER, "Scene name is empty. Not saving planning request."); + RCLCPP_INFO(get_logger(), "Scene name is empty. Not saving planning request."); return; } pss.addPlanningQuery(req, psm.getPlanningScene()->getName()); @@ -100,19 +101,19 @@ void onConstraints(const moveit_msgs::msg::Constraints& msg, moveit_warehouse::C { if (msg.name.empty()) { - RCLCPP_INFO(LOGGER, "No name specified for constraints. Not saving."); + RCLCPP_INFO(get_logger(), "No name specified for constraints. Not saving."); return; } if (cs.hasConstraints(msg.name)) { - RCLCPP_INFO(LOGGER, "Replacing constraints '%s'", msg.name.c_str()); + RCLCPP_INFO(get_logger(), "Replacing constraints '%s'", msg.name.c_str()); cs.removeConstraints(msg.name); cs.addConstraints(msg); } else { - RCLCPP_INFO(LOGGER, "Adding constraints '%s'", msg.name.c_str()); + RCLCPP_INFO(get_logger(), "Adding constraints '%s'", msg.name.c_str()); cs.addConstraints(msg); } } @@ -126,7 +127,7 @@ void onRobotState(const moveit_msgs::msg::RobotState& msg, moveit_warehouse::Rob while (names_set.find("S" + std::to_string(n)) != names_set.end()) n++; std::string name = "S" + std::to_string(n); - RCLCPP_INFO(LOGGER, "Adding robot state '%s'", name.c_str()); + RCLCPP_INFO(get_logger(), "Adding robot state '%s'", name.c_str()); rs.addRobotState(msg, name); } @@ -137,6 +138,7 @@ int main(int argc, char** argv) node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("save_to_warehouse", node_options); + moveit::get_logger_mut() = node->get_logger(); boost::program_options::options_description desc; desc.add_options()("help", "Show help message")("host", boost::program_options::value(), @@ -163,7 +165,7 @@ int main(int argc, char** argv) planning_scene_monitor::PlanningSceneMonitor psm(node, ROBOT_DESCRIPTION); if (!psm.getPlanningScene()) { - RCLCPP_ERROR(LOGGER, "Unable to initialize PlanningSceneMonitor"); + RCLCPP_ERROR(get_logger(), "Unable to initialize PlanningSceneMonitor"); return 1; } @@ -176,35 +178,35 @@ int main(int argc, char** argv) pss.getPlanningSceneNames(names); if (names.empty()) { - RCLCPP_INFO(LOGGER, "There are no previously stored scenes"); + RCLCPP_INFO(get_logger(), "There are no previously stored scenes"); } else { - RCLCPP_INFO(LOGGER, "Previously stored scenes:"); + RCLCPP_INFO(get_logger(), "Previously stored scenes:"); for (const std::string& name : names) - RCLCPP_INFO(LOGGER, " * %s", name.c_str()); + RCLCPP_INFO(get_logger(), " * %s", name.c_str()); } cs.getKnownConstraints(names); if (names.empty()) { - RCLCPP_INFO(LOGGER, "There are no previously stored constraints"); + RCLCPP_INFO(get_logger(), "There are no previously stored constraints"); } else { - RCLCPP_INFO(LOGGER, "Previously stored constraints:"); + RCLCPP_INFO(get_logger(), "Previously stored constraints:"); for (const std::string& name : names) - RCLCPP_INFO(LOGGER, " * %s", name.c_str()); + RCLCPP_INFO(get_logger(), " * %s", name.c_str()); } rs.getKnownRobotStates(names); if (names.empty()) { - RCLCPP_INFO(LOGGER, "There are no previously stored robot states"); + RCLCPP_INFO(get_logger(), "There are no previously stored robot states"); } else { - RCLCPP_INFO(LOGGER, "Previously stored robot states:"); + RCLCPP_INFO(get_logger(), "Previously stored robot states:"); for (const std::string& name : names) - RCLCPP_INFO(LOGGER, " * %s", name.c_str()); + RCLCPP_INFO(get_logger(), " * %s", name.c_str()); } psm.addUpdateCallback([&](auto&&) { return onSceneUpdate(psm, pss); }); @@ -221,10 +223,11 @@ int main(int argc, char** argv) std::vector topics; psm.getMonitoredTopics(topics); - RCLCPP_INFO_STREAM(LOGGER, "Listening for scene updates on topics " << fmt::format("{}", fmt::join(topics, ", "))); - RCLCPP_INFO_STREAM(LOGGER, "Listening for planning requests on topic " << mplan_req_sub->get_topic_name()); - RCLCPP_INFO_STREAM(LOGGER, "Listening for named constraints on topic " << constr_sub->get_topic_name()); - RCLCPP_INFO_STREAM(LOGGER, "Listening for states on topic " << state_sub->get_topic_name()); + RCLCPP_INFO_STREAM(get_logger(), + "Listening for scene updates on topics " << fmt::format("{}", fmt::join(topics, ", "))); + RCLCPP_INFO_STREAM(get_logger(), "Listening for planning requests on topic " << mplan_req_sub->get_topic_name()); + RCLCPP_INFO_STREAM(get_logger(), "Listening for named constraints on topic " << constr_sub->get_topic_name()); + RCLCPP_INFO_STREAM(get_logger(), "Listening for states on topic " << state_sub->get_topic_name()); rclcpp::spin(node); return 0; diff --git a/moveit_ros/warehouse/src/state_storage.cpp b/moveit_ros/warehouse/src/state_storage.cpp index cea0e6a52f9..d5c7ad205e5 100644 --- a/moveit_ros/warehouse/src/state_storage.cpp +++ b/moveit_ros/warehouse/src/state_storage.cpp @@ -35,6 +35,7 @@ /* Author: Ioan Sucan */ #include +#include #include @@ -43,8 +44,7 @@ const std::string moveit_warehouse::RobotStateStorage::DATABASE_NAME = "moveit_r const std::string moveit_warehouse::RobotStateStorage::STATE_NAME = "state_id"; const std::string moveit_warehouse::RobotStateStorage::ROBOT_NAME = "robot_id"; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.state_storage"); - +using moveit::get_logger; using warehouse_ros::Metadata; using warehouse_ros::Query; @@ -79,7 +79,7 @@ void moveit_warehouse::RobotStateStorage::addRobotState(const moveit_msgs::msg:: metadata->append(STATE_NAME, name); metadata->append(ROBOT_NAME, robot); state_collection_->insert(msg, metadata); - RCLCPP_DEBUG(LOGGER, "%s robot state '%s'", replace ? "Replaced" : "Added", name.c_str()); + RCLCPP_DEBUG(get_logger(), "%s robot state '%s'", replace ? "Replaced" : "Added", name.c_str()); } bool moveit_warehouse::RobotStateStorage::hasRobotState(const std::string& name, const std::string& robot) const @@ -143,7 +143,7 @@ void moveit_warehouse::RobotStateStorage::renameRobotState(const std::string& ol Metadata::Ptr m = state_collection_->createMetadata(); m->append(STATE_NAME, new_name); state_collection_->modifyMetadata(q, m); - RCLCPP_DEBUG(LOGGER, "Renamed robot state from '%s' to '%s'", old_name.c_str(), new_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Renamed robot state from '%s' to '%s'", old_name.c_str(), new_name.c_str()); } void moveit_warehouse::RobotStateStorage::removeRobotState(const std::string& name, const std::string& robot) @@ -153,5 +153,5 @@ void moveit_warehouse::RobotStateStorage::removeRobotState(const std::string& na if (!robot.empty()) q->append(ROBOT_NAME, robot); unsigned int rem = state_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u RobotState messages (named '%s')", rem, name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u RobotState messages (named '%s')", rem, name.c_str()); } diff --git a/moveit_ros/warehouse/src/trajectory_constraints_storage.cpp b/moveit_ros/warehouse/src/trajectory_constraints_storage.cpp index 8ba11a3ba1d..fcc8744db07 100644 --- a/moveit_ros/warehouse/src/trajectory_constraints_storage.cpp +++ b/moveit_ros/warehouse/src/trajectory_constraints_storage.cpp @@ -35,6 +35,7 @@ /* Author: Mario Prats, Ioan Sucan */ #include +#include #include @@ -44,8 +45,7 @@ const std::string moveit_warehouse::TrajectoryConstraintsStorage::CONSTRAINTS_ID const std::string moveit_warehouse::TrajectoryConstraintsStorage::CONSTRAINTS_GROUP_NAME = "group_id"; const std::string moveit_warehouse::TrajectoryConstraintsStorage::ROBOT_NAME = "robot_id"; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.trajectory_constraints_storage"); - +using moveit::get_logger; using warehouse_ros::Metadata; using warehouse_ros::Query; @@ -83,7 +83,7 @@ void moveit_warehouse::TrajectoryConstraintsStorage::addTrajectoryConstraints( metadata->append(ROBOT_NAME, robot); metadata->append(CONSTRAINTS_GROUP_NAME, group); constraints_collection_->insert(msg, metadata); - RCLCPP_DEBUG(LOGGER, "%s constraints '%s'", replace ? "Replaced" : "Added", name.c_str()); + RCLCPP_DEBUG(get_logger(), "%s constraints '%s'", replace ? "Replaced" : "Added", name.c_str()); } bool moveit_warehouse::TrajectoryConstraintsStorage::hasTrajectoryConstraints(const std::string& name, @@ -165,7 +165,7 @@ void moveit_warehouse::TrajectoryConstraintsStorage::renameTrajectoryConstraints Metadata::Ptr m = constraints_collection_->createMetadata(); m->append(CONSTRAINTS_ID_NAME, new_name); constraints_collection_->modifyMetadata(q, m); - RCLCPP_DEBUG(LOGGER, "Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str()); + RCLCPP_DEBUG(get_logger(), "Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str()); } void moveit_warehouse::TrajectoryConstraintsStorage::removeTrajectoryConstraints(const std::string& name, @@ -179,5 +179,5 @@ void moveit_warehouse::TrajectoryConstraintsStorage::removeTrajectoryConstraints if (!group.empty()) q->append(CONSTRAINTS_GROUP_NAME, group); unsigned int rem = constraints_collection_->removeMessages(q); - RCLCPP_DEBUG(LOGGER, "Removed %u TrajectoryConstraints messages (named '%s')", rem, name.c_str()); + RCLCPP_DEBUG(get_logger(), "Removed %u TrajectoryConstraints messages (named '%s')", rem, name.c_str()); } diff --git a/moveit_ros/warehouse/src/warehouse_connector.cpp b/moveit_ros/warehouse/src/warehouse_connector.cpp index f75123c50b9..b87590b16e4 100644 --- a/moveit_ros/warehouse/src/warehouse_connector.cpp +++ b/moveit_ros/warehouse/src/warehouse_connector.cpp @@ -40,17 +40,18 @@ #include #include #include +#include -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.warehouse_connector"); +using moveit::get_logger; #ifdef _WIN32 void kill(int, int) { - RCLCPP_ERROR(LOGGER, "Warehouse connector not supported on Windows"); + RCLCPP_ERROR(get_logger(), "Warehouse connector not supported on Windows"); } // Should never be called int fork() { - RCLCPP_ERROR(LOGGER, "Warehouse connector not supported on Windows"); + RCLCPP_ERROR(get_logger(), "Warehouse connector not supported on Windows"); return -1; } #else @@ -77,7 +78,7 @@ bool WarehouseConnector::connectToDatabase(const std::string& dirname) child_pid_ = fork(); if (child_pid_ == -1) { - RCLCPP_ERROR(LOGGER, "Error forking process."); + RCLCPP_ERROR(get_logger(), "Error forking process."); child_pid_ = 0; return false; } @@ -105,7 +106,7 @@ bool WarehouseConnector::connectToDatabase(const std::string& dirname) delete[] argv[1]; delete[] argv[2]; delete[] argv; - RCLCPP_ERROR_STREAM(LOGGER, + RCLCPP_ERROR_STREAM(get_logger(), "execv() returned " << code << ", errno=" << errno << " string errno = " << strerror(errno)); } return false; diff --git a/moveit_ros/warehouse/src/warehouse_services.cpp b/moveit_ros/warehouse/src/warehouse_services.cpp index 46c7e8046c1..1136015636c 100644 --- a/moveit_ros/warehouse/src/warehouse_services.cpp +++ b/moveit_ros/warehouse/src/warehouse_services.cpp @@ -48,10 +48,11 @@ #include #include #include +#include -static const std::string ROBOT_DESCRIPTION = "robot_description"; +using moveit::get_logger; -static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.warehouse_services"); +static const std::string ROBOT_DESCRIPTION = "robot_description"; bool storeState(const std::shared_ptr& request, const std::shared_ptr& response, @@ -59,7 +60,7 @@ bool storeState(const std::shared_ptrname.empty()) { - RCLCPP_ERROR(LOGGER, "You must specify a name to store a state"); + RCLCPP_ERROR(get_logger(), "You must specify a name to store a state"); return (response->success = false); } rs.addRobotState(request->state, request->name, request->robot); @@ -95,7 +96,7 @@ bool getState(const std::shared_ptrname, request->robot)) { - RCLCPP_ERROR_STREAM(LOGGER, "No state called '" << request->name << "' for robot '" << request->robot << "'."); + RCLCPP_ERROR_STREAM(get_logger(), "No state called '" << request->name << "' for robot '" << request->robot << "'."); moveit_msgs::msg::RobotState dummy; response->state = dummy; return false; @@ -112,7 +113,8 @@ bool renameState(const std::shared_ptrold_name, request->robot)) { - RCLCPP_ERROR_STREAM(LOGGER, "No state called '" << request->old_name << "' for robot '" << request->robot << "'."); + RCLCPP_ERROR_STREAM(get_logger(), + "No state called '" << request->old_name << "' for robot '" << request->robot << "'."); return false; } rs.renameRobotState(request->old_name, request->new_name, request->robot); @@ -125,7 +127,7 @@ bool deleteState(const std::shared_ptrname, request->robot)) { - RCLCPP_ERROR_STREAM(LOGGER, "No state called '" << request->name << "' for robot '" << request->robot << "'."); + RCLCPP_ERROR_STREAM(get_logger(), "No state called '" << request->name << "' for robot '" << request->robot << "'."); return false; } rs.removeRobotState(request->name, request->robot); @@ -139,6 +141,7 @@ int main(int argc, char** argv) node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("moveit_warehouse_services", node_options); + moveit::get_logger_mut() = node->get_logger(); std::string host; @@ -158,23 +161,23 @@ int main(int argc, char** argv) conn = moveit_warehouse::loadDatabase(node); conn->setParams(host, port, connection_timeout); - RCLCPP_INFO(LOGGER, "Connecting to warehouse on %s:%d", host.c_str(), port); + RCLCPP_INFO(get_logger(), "Connecting to warehouse on %s:%d", host.c_str(), port); int tries = 0; while (!conn->connect()) { ++tries; - RCLCPP_WARN(LOGGER, "Failed to connect to DB on %s:%d (try %d/%d).", host.c_str(), port, tries, + RCLCPP_WARN(get_logger(), "Failed to connect to DB on %s:%d (try %d/%d).", host.c_str(), port, tries, connection_retries); if (tries == connection_retries) { - RCLCPP_FATAL(LOGGER, "Failed to connect too many times, giving up"); + RCLCPP_FATAL(get_logger(), "Failed to connect too many times, giving up"); return 1; } } } catch (std::exception& ex) { - RCLCPP_ERROR(LOGGER, "%s", ex.what()); + RCLCPP_ERROR(get_logger(), "%s", ex.what()); return 1; } @@ -184,13 +187,13 @@ int main(int argc, char** argv) rs.getKnownRobotStates(names); if (names.empty()) { - RCLCPP_INFO(LOGGER, "There are no previously stored robot states"); + RCLCPP_INFO(get_logger(), "There are no previously stored robot states"); } else { - RCLCPP_INFO(LOGGER, "Previously stored robot states:"); + RCLCPP_INFO(get_logger(), "Previously stored robot states:"); for (const std::string& name : names) - RCLCPP_INFO(LOGGER, " * %s", name.c_str()); + RCLCPP_INFO(get_logger(), " * %s", name.c_str()); } auto save_cb = [&](const std::shared_ptr& request,