Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spam of logs on failed hardware component initialization #1719

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 PAL Robotics S.L.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef HARDWARE_INTERFACE__LIFECYCLE_HELPERS_HPP_
#define HARDWARE_INTERFACE__LIFECYCLE_HELPERS_HPP_

#include <lifecycle_msgs/msg/state.hpp>

namespace hardware_interface
{
constexpr bool lifecycleStateThatRequiresNoAction(const lifecycle_msgs::msg::State::_id_type state)
{
return state == lifecycle_msgs::msg::State::PRIMARY_STATE_UNKNOWN ||
state == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED ||
state == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED;
}
} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__LIFECYCLE_HELPERS_HPP_
9 changes: 3 additions & 6 deletions hardware_interface/src/actuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "hardware_interface/actuator_interface.hpp"
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/lifecycle_helpers.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/lifecycle_state_names.hpp"
#include "lifecycle_msgs/msg/state.hpp"
Expand Down Expand Up @@ -246,9 +247,7 @@ return_type Actuator::read(const rclcpp::Time & time, const rclcpp::Duration & p
impl_->get_name().c_str());
return return_type::OK;
}
if (
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED ||
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
if (lifecycleStateThatRequiresNoAction(impl_->get_lifecycle_state().id()))
{
return return_type::OK;
}
Expand Down Expand Up @@ -276,9 +275,7 @@ return_type Actuator::write(const rclcpp::Time & time, const rclcpp::Duration &
impl_->get_name().c_str());
return return_type::OK;
}
if (
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED ||
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
if (lifecycleStateThatRequiresNoAction(impl_->get_lifecycle_state().id()))
{
return return_type::OK;
}
Expand Down
5 changes: 2 additions & 3 deletions hardware_interface/src/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/lifecycle_helpers.hpp"
#include "hardware_interface/sensor_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/lifecycle_state_names.hpp"
Expand Down Expand Up @@ -224,9 +225,7 @@ return_type Sensor::read(const rclcpp::Time & time, const rclcpp::Duration & per
impl_->get_name().c_str());
return return_type::OK;
}
if (
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED ||
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
if (lifecycleStateThatRequiresNoAction(impl_->get_lifecycle_state().id()))
{
return return_type::OK;
}
Expand Down
9 changes: 3 additions & 6 deletions hardware_interface/src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/lifecycle_helpers.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/lifecycle_state_names.hpp"
Expand Down Expand Up @@ -242,9 +243,7 @@ return_type System::read(const rclcpp::Time & time, const rclcpp::Duration & per
impl_->get_name().c_str());
return return_type::OK;
}
if (
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED ||
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
if (lifecycleStateThatRequiresNoAction(impl_->get_lifecycle_state().id()))
{
return return_type::OK;
}
Expand Down Expand Up @@ -272,9 +271,7 @@ return_type System::write(const rclcpp::Time & time, const rclcpp::Duration & pe
impl_->get_name().c_str());
return return_type::OK;
}
if (
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED ||
impl_->get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
if (lifecycleStateThatRequiresNoAction(impl_->get_lifecycle_state().id()))
{
return return_type::OK;
}
Expand Down
Loading