Skip to content

Commit

Permalink
add interface for warning, error and report
Browse files Browse the repository at this point in the history
  • Loading branch information
mamueluth committed Jan 11, 2024
1 parent 923866c commit ff092df
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,36 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
return actuator_commands_.at(interface_name)->get_value();
}

void set_warning_code(const std::string & interface_name, const double & warning_code)
{
actuator_states_.at(interface_name)->warning_code(warning_code);
}

double get_warning_code(const std::string & interface_name) const
{
return actuator_states_.at(interface_name)->warning_code();
}

void set_error_code(const std::string & interface_name, const double & error_code)
{
actuator_states_.at(interface_name)->error_code(error_code);
}

double get_error_code(const std::string & interface_name) const
{
return actuator_states_.at(interface_name)->error_code();
}

void set_report_message(const std::string & interface_name, const double & report_message)
{
actuator_states_.at(interface_name)->report_message(report_message);
}

double get_report_message(const std::string & interface_name) const
{
return actuator_states_.at(interface_name)->report_message();
}

protected:
HardwareInfo info_;
std::map<std::string, InterfaceDescription> joint_state_interfaces_;
Expand Down
33 changes: 33 additions & 0 deletions hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,39 @@ class StateInterface : public Handle

StateInterface(StateInterface && other) = default;

double warning_code() const
{
const double * warning_code = std::get_if<double>(&value_);
// This means the value does not store the expected datatype. How should we handle this
// properly?
THROW_ON_NOT_NULLPTR(warning_code);
return *warning_code;
}

void warning_code(const double & warning_code) { value_ = warning_code; }

double error_code() const
{
const auto error_code = std::get_if<double>(&value_);
// This means the value does not store the expected datatype. How should we handle this
// properly?
THROW_ON_NOT_NULLPTR(error_code);
return *error_code;
}

void error_code(const double & error_code) { value_ = error_code; }

double report_message() const
{
const auto report_message = std::get_if<double>(&value_);
// This means the value does not store the expected datatype. How should we handle this
// properly?
THROW_ON_NOT_NULLPTR(report_message);
return *report_message;
}

void report_message(const double & report_message) { value_ = report_message; }

using Handle::Handle;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class LoanedStateInterface

double get_value() const { return state_interface_.get_value(); }

double get_warning_code() const { return state_interface_.warning_code(); }

double get_error_code() const { return state_interface_.error_code(); }

double get_report_message() const { return state_interface_.report_message(); }

protected:
StateInterface & state_interface_;
Deleter deleter_;
Expand Down
30 changes: 30 additions & 0 deletions hardware_interface/include/hardware_interface/sensor_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,36 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
return sensor_states_.at(interface_name)->get_value();
}

void set_warning_code(const std::string & interface_name, const double & warning_code)
{
sensor_states_.at(interface_name)->warning_code(warning_code);
}

double get_warning_code(const std::string & interface_name) const
{
return sensor_states_.at(interface_name)->warning_code();
}

void set_error_code(const std::string & interface_name, const double & error_code)
{
sensor_states_.at(interface_name)->error_code(error_code);
}

double get_error_code(const std::string & interface_name) const
{
return sensor_states_.at(interface_name)->error_code();
}

void set_report_message(const std::string & interface_name, const double & report_message)
{
sensor_states_.at(interface_name)->report_message(report_message);
}

double get_report_message(const std::string & interface_name) const
{
return sensor_states_.at(interface_name)->report_message();
}

protected:
HardwareInfo info_;

Expand Down
30 changes: 30 additions & 0 deletions hardware_interface/include/hardware_interface/system_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,36 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
return system_commands_.at(interface_name)->get_value();
}

void set_warning_code(const std::string & interface_name, const double & warning_code)
{
system_states_.at(interface_name)->warning_code(warning_code);
}

double get_warning_code(const std::string & interface_name) const
{
return system_states_.at(interface_name)->warning_code();
}

void set_error_code(const std::string & interface_name, const double & error_code)
{
system_states_.at(interface_name)->error_code(error_code);
}

double get_error_code(const std::string & interface_name) const
{
return system_states_.at(interface_name)->error_code();
}

void set_report_message(const std::string & interface_name, const double & report_message)
{
system_states_.at(interface_name)->report_message(report_message);
}

double get_report_message(const std::string & interface_name) const
{
return system_states_.at(interface_name)->report_message();
}

protected:
HardwareInfo info_;
std::map<std::string, InterfaceDescription> joint_state_interfaces_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
//
// 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__TYPES__HARDWARE_INTERFACE_ERROR_CODES_HPP_
#define HARDWARE_INTERFACE__TYPES__HARDWARE_INTERFACE_ERROR_CODES_HPP_

#include <cstdint>

namespace hardware_interface
{
enum class error_code : std::uint8_t
{
ERROR_CODE_0 = 0,
ERROR_CODE_1 = 1,
ERROR_CODE_2 = 2,
ERROR_CODE_3 = 3,
ERROR_CODE_4 = 4,
ERROR_CODE_5 = 5,
ERROR_CODE_6 = 6,
ERROR_CODE_7 = 7,
ERROR_CODE_8 = 8,
ERROR_CODE_9 = 9,
ERROR_CODE_10 = 10,
ERROR_CODE_11 = 11,
ERROR_CODE_12 = 12,
ERROR_CODE_13 = 13,
ERROR_CODE_14 = 14,
ERROR_CODE_15 = 15,
ERROR_CODE_16 = 16,
ERROR_CODE_17 = 17,
ERROR_CODE_18 = 18,
ERROR_CODE_19 = 19,
ERROR_CODE_20 = 20,
ERROR_CODE_21 = 21,
ERROR_CODE_22 = 22,
ERROR_CODE_23 = 23,
ERROR_CODE_24 = 24,
ERROR_CODE_25 = 25,
ERROR_CODE_26 = 26,
ERROR_CODE_27 = 27,
ERROR_CODE_28 = 28,
ERROR_CODE_29 = 29,
ERROR_CODE_30 = 30,
ERROR_CODE_31 = 31,
};

} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__TYPES__HARDWARE_INTERFACE_ERROR_CODES_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
//
// 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__TYPES__HARDWARE_INTERFACE_WARNING_CODES_HPP_
#define HARDWARE_INTERFACE__TYPES__HARDWARE_INTERFACE_WARNING_CODES_HPP_

#include <cstdint>

namespace hardware_interface
{
enum class warning_code : std::int8_t
{
WARNING_CODE_0 = 0,
WARNING_CODE_1 = 1,
WARNING_CODE_2 = 2,
WARNING_CODE_3 = 3,
WARNING_CODE_4 = 4,
WARNING_CODE_5 = 5,
WARNING_CODE_6 = 6,
WARNING_CODE_7 = 7,
WARNING_CODE_8 = 8,
WARNING_CODE_9 = 9,
WARNING_CODE_10 = 10,
WARNING_CODE_11 = 11,
WARNING_CODE_12 = 12,
WARNING_CODE_13 = 13,
WARNING_CODE_14 = 14,
WARNING_CODE_15 = 15,
WARNING_CODE_16 = 16,
WARNING_CODE_17 = 17,
WARNING_CODE_18 = 18,
WARNING_CODE_19 = 19,
WARNING_CODE_20 = 20,
WARNING_CODE_21 = 21,
WARNING_CODE_22 = 22,
WARNING_CODE_23 = 23,
WARNING_CODE_24 = 24,
WARNING_CODE_25 = 25,
WARNING_CODE_26 = 26,
WARNING_CODE_27 = 27,
WARNING_CODE_28 = 28,
WARNING_CODE_29 = 29,
WARNING_CODE_30 = 30,
WARNING_CODE_31 = 31,
};

} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__TYPES__HARDWARE_INTERFACE_WARNING_CODES_HPP_

0 comments on commit ff092df

Please sign in to comment.