Skip to content

Commit 2f45ebf

Browse files
committed
add interface for warning, error and report
* ddd basic test for error codes setting * docs for error and warning signals
1 parent 265f66d commit 2f45ebf

13 files changed

+1823
-17
lines changed

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Concepts
2727
Controller Chaining / Cascade Control <../controller_manager/doc/controller_chaining.rst>
2828
Joint Kinematics <../hardware_interface/doc/joints_userdoc.rst>
2929
Hardware Components <../hardware_interface/doc/hardware_components_userdoc.rst>
30+
Hardware Components <../hardware_interface/doc/error_and_warning_interfaces_userdoc.rst>
3031
Mock Components <../hardware_interface/doc/mock_components_userdoc.rst>
3132

3233
=====================================

hardware_interface/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ if(BUILD_TESTING)
8484
target_link_libraries(test_component_interfaces_custom_export hardware_interface)
8585
ament_target_dependencies(test_component_interfaces_custom_export ros2_control_test_assets)
8686

87+
ament_add_gmock(test_error_warning_codes test/test_error_warning_codes.cpp)
88+
target_link_libraries(test_error_warning_codes hardware_interface)
89+
ament_target_dependencies(test_error_warning_codes ros2_control_test_assets)
90+
8791
ament_add_gmock(test_component_parser test/test_component_parser.cpp)
8892
target_link_libraries(test_component_parser hardware_interface)
8993
ament_target_dependencies(test_component_parser ros2_control_test_assets)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
:github_url: https://github.com/ros-controls/ros2_control/blob/{REPOS_FILE_BRANCH}/hardware_interface/doc/error_and_warning_interfaces_userdoc.rst
2+
3+
.. _error_and_warning_interfaces_userdoc:
4+
5+
Error and Warning Interfaces
6+
============================
7+
8+
By default we now create the following error and warning interfaces:
9+
10+
+-----------------+--------------+----------------------------------------------------------------------------------------------------------------------+
11+
| Type | Datatype | Description |
12+
+=================+====================+================================================================================================================+
13+
| Emergency Stop | Bool | Used for signaling that hardwares emergency stop is active. Only for Actuator and System. |
14+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
15+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
16+
| Error Code | array<uint8_t, 32> | Used for sending 32 error codes (uint8_t) at the same time. |
17+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
18+
| Error Message | array<string, 32> | Used for sending 32 error messages where the message at position x corresponds to error code at position x. |
19+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
20+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
21+
| Warning Code | array<int8_t, 32> | Used for sending 32 Warning codes (int8_t) at the same time. |
22+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
23+
| Warning Message | array<string, 32> | Used for sending 32 warning messages where the message at position x corresponds to warning code at position x.|
24+
+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------+
25+
26+
The error and warning interfaces are created as ``StateInterfaces`` and are stored inside the Actuator-, Sensor- or SystemInterface. They can be accessed via getter and setter methods. E.g. if you want to get/set the emergency stop signal you can do so with the ``get_emergency_stop()`` or ``set_emergency_stop(const bool & emergency_stop)`` methods. For the error and warning signals similar getters and setters exist.
27+
28+
Note: The SensorInterface does not have a Emergency Stop interface.

hardware_interface/include/hardware_interface/actuator_interface.hpp

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
#include "hardware_interface/component_parser.hpp"
2626
#include "hardware_interface/handle.hpp"
2727
#include "hardware_interface/hardware_info.hpp"
28+
#include "hardware_interface/types/hardware_interface_emergency_stop_signal.hpp"
29+
#include "hardware_interface/types/hardware_interface_error_signals.hpp"
2830
#include "hardware_interface/types/hardware_interface_return_values.hpp"
31+
#include "hardware_interface/types/hardware_interface_warning_signals.hpp"
2932
#include "hardware_interface/types/lifecycle_state_names.hpp"
3033
#include "lifecycle_msgs/msg/state.hpp"
3134
#include "rclcpp/duration.hpp"
@@ -125,6 +128,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
125128
info_ = hardware_info;
126129
import_state_interface_descriptions(info_);
127130
import_command_interface_descriptions(info_);
131+
create_report_interfaces();
128132
return CallbackReturn::SUCCESS;
129133
};
130134

@@ -156,6 +160,52 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
156160
}
157161
}
158162

163+
/**
164+
* Creates all interfaces used for reporting emergency stop, warning and error messages.
165+
* The available report interfaces are: EMERGENCY_STOP_SIGNAL, ERROR_SIGNAL, ERROR_SIGNAL_MESSAGE,
166+
* WARNING_SIGNAL and WARNING_SIGNAL_MESSAGE. Where the <report_type>_MESSAGE hold the message for
167+
* the corresponding report signal.
168+
* The interfaces are named like <hardware_name>/<report_interface_type>. E.g. if hardware is
169+
* called joint_1 -> interface for WARNING_SIGNAL is called: joint_1/WARNING_SIGNAL
170+
*/
171+
void create_report_interfaces()
172+
{
173+
// EMERGENCY STOP
174+
InterfaceInfo emergency_interface_info;
175+
emergency_interface_info.name = hardware_interface::EMERGENCY_STOP_SIGNAL;
176+
emergency_interface_info.data_type = "bool";
177+
InterfaceDescription emergency_interface_descr(info_.name, emergency_interface_info);
178+
emergency_stop_ = std::make_shared<StateInterface>(emergency_interface_descr);
179+
180+
// ERROR
181+
// create error signal interface
182+
InterfaceInfo error_interface_info;
183+
error_interface_info.name = hardware_interface::ERROR_SIGNAL_INTERFACE_NAME;
184+
error_interface_info.data_type = "array<uint8_t>[32]";
185+
InterfaceDescription error_interface_descr(info_.name, error_interface_info);
186+
error_signal_ = std::make_shared<StateInterface>(error_interface_descr);
187+
// create error signal report message interface
188+
InterfaceInfo error_msg_interface_info;
189+
error_msg_interface_info.name = hardware_interface::ERROR_SIGNAL_MESSAGE_INTERFACE_NAME;
190+
error_msg_interface_info.data_type = "array<string>[32]";
191+
InterfaceDescription error_msg_interface_descr(info_.name, error_msg_interface_info);
192+
error_signal_message_ = std::make_shared<StateInterface>(error_msg_interface_descr);
193+
194+
// WARNING
195+
// create warning signal interface
196+
InterfaceInfo warning_interface_info;
197+
warning_interface_info.name = hardware_interface::WARNING_SIGNAL_INTERFACE_NAME;
198+
warning_interface_info.data_type = "array<int8_t>[32]";
199+
InterfaceDescription warning_interface_descr(info_.name, warning_interface_info);
200+
warning_signal_ = std::make_shared<StateInterface>(warning_interface_descr);
201+
// create warning signal report message interface
202+
InterfaceInfo warning_msg_interface_info;
203+
warning_msg_interface_info.name = hardware_interface::WARNING_SIGNAL_MESSAGE_INTERFACE_NAME;
204+
warning_msg_interface_info.data_type = "array<string>[32]";
205+
InterfaceDescription warning_msg_interface_descr(info_.name, warning_msg_interface_info);
206+
warning_signal_message_ = std::make_shared<StateInterface>(warning_msg_interface_descr);
207+
}
208+
159209
/// Exports all state interfaces for this hardware interface.
160210
/**
161211
* Old way of exporting the StateInterfaces. If a empty vector is returned then
@@ -230,6 +280,14 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
230280
actuator_states_.insert(std::make_pair(name, state_interface));
231281
state_interfaces.push_back(state_interface);
232282
}
283+
284+
// export warning signal interfaces
285+
state_interfaces.push_back(emergency_stop_);
286+
state_interfaces.push_back(error_signal_);
287+
state_interfaces.push_back(error_signal_message_);
288+
state_interfaces.push_back(warning_signal_);
289+
state_interfaces.push_back(warning_signal_message_);
290+
233291
return state_interfaces;
234292
}
235293

@@ -416,6 +474,35 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
416474
return actuator_commands_.at(interface_name)->get_value();
417475
}
418476

477+
void set_emergency_stop(const double & emergency_stop)
478+
{
479+
emergency_stop_->set_value(emergency_stop);
480+
}
481+
482+
double get_emergency_stop() const { return emergency_stop_->get_value(); }
483+
484+
void set_error_code(const double & error_code) { error_signal_->set_value(error_code); }
485+
486+
double get_error_code() const { return error_signal_->get_value(); }
487+
488+
void set_error_message(const double & error_message)
489+
{
490+
error_signal_message_->set_value(error_message);
491+
}
492+
493+
double get_error_message() const { return error_signal_message_->get_value(); }
494+
495+
void set_warning_code(const double & warning_codes) { warning_signal_->set_value(warning_codes); }
496+
497+
double get_warning_code() const { return warning_signal_->get_value(); }
498+
499+
void set_warning_message(const double & error_message)
500+
{
501+
warning_signal_message_->set_value(error_message);
502+
}
503+
504+
double get_warning_message() const { return warning_signal_message_->get_value(); }
505+
419506
protected:
420507
/// Get the logger of the ActuatorInterface.
421508
/**
@@ -436,13 +523,19 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
436523
std::unordered_map<std::string, InterfaceDescription> unlisted_state_interfaces_;
437524
std::unordered_map<std::string, InterfaceDescription> unlisted_command_interfaces_;
438525

439-
rclcpp_lifecycle::State lifecycle_state_;
440-
441526
private:
442527
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface_;
443528
rclcpp::Logger actuator_logger_;
444529
std::unordered_map<std::string, std::shared_ptr<StateInterface>> actuator_states_;
445530
std::unordered_map<std::string, std::shared_ptr<CommandInterface>> actuator_commands_;
531+
532+
std::shared_ptr<StateInterface> emergency_stop_;
533+
std::shared_ptr<StateInterface> error_signal_;
534+
std::shared_ptr<StateInterface> error_signal_message_;
535+
std::shared_ptr<StateInterface> warning_signal_;
536+
std::shared_ptr<StateInterface> warning_signal_message_;
537+
538+
rclcpp_lifecycle::State lifecycle_state_;
446539
};
447540

448541
} // namespace hardware_interface

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef HARDWARE_INTERFACE__HANDLE_HPP_
1616
#define HARDWARE_INTERFACE__HANDLE_HPP_
1717

18+
#include <array>
1819
#include <limits>
1920
#include <memory>
2021
#include <string>
@@ -23,8 +24,9 @@
2324

2425
#include "hardware_interface/hardware_info.hpp"
2526
#include "hardware_interface/macros.hpp"
27+
#include "hardware_interface/types/hardware_interface_error_signals.hpp"
28+
#include "hardware_interface/types/hardware_interface_warning_signals.hpp"
2629
#include "hardware_interface/visibility_control.h"
27-
2830
namespace hardware_interface
2931
{
3032

hardware_interface/include/hardware_interface/sensor_interface.hpp

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include "hardware_interface/component_parser.hpp"
2626
#include "hardware_interface/handle.hpp"
2727
#include "hardware_interface/hardware_info.hpp"
28+
#include "hardware_interface/types/hardware_interface_error_signals.hpp"
2829
#include "hardware_interface/types/hardware_interface_return_values.hpp"
30+
#include "hardware_interface/types/hardware_interface_warning_signals.hpp"
2931
#include "hardware_interface/types/lifecycle_state_names.hpp"
3032
#include "lifecycle_msgs/msg/state.hpp"
3133
#include "rclcpp/duration.hpp"
@@ -124,6 +126,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
124126
{
125127
info_ = hardware_info;
126128
import_state_interface_descriptions(info_);
129+
create_report_interfaces();
127130
return CallbackReturn::SUCCESS;
128131
};
129132

@@ -141,6 +144,45 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
141144
}
142145
}
143146

147+
/**
148+
* Creates all interfaces used for reporting warning and error messages.
149+
* The available report interfaces are: ERROR_SIGNAL, ERROR_SIGNAL_MESSAGE,
150+
* WARNING_SIGNAL and WARNING_SIGNAL_MESSAGE. Where the <report_type>_MESSAGE hold the message for
151+
* the corresponding report signal.
152+
* The interfaces are named like <hardware_name>/<report_interface_type>. E.g. if hardware is
153+
* called sensor_1 -> interface for WARNING_SIGNAL is called: sensor_1/WARNING_SIGNAL
154+
*/
155+
void create_report_interfaces()
156+
{
157+
// ERROR
158+
// create error signal interface
159+
InterfaceInfo error_interface_info;
160+
error_interface_info.name = hardware_interface::ERROR_SIGNAL_INTERFACE_NAME;
161+
error_interface_info.data_type = "array<uint8_t>[32]";
162+
InterfaceDescription error_interface_descr(info_.name, error_interface_info);
163+
error_signal_ = std::make_shared<StateInterface>(error_interface_descr);
164+
// create error signal report message interface
165+
InterfaceInfo error_msg_interface_info;
166+
error_msg_interface_info.name = hardware_interface::ERROR_SIGNAL_MESSAGE_INTERFACE_NAME;
167+
error_msg_interface_info.data_type = "array<string>[32]";
168+
InterfaceDescription error_msg_interface_descr(info_.name, error_msg_interface_info);
169+
error_signal_message_ = std::make_shared<StateInterface>(error_msg_interface_descr);
170+
171+
// WARNING
172+
// create warning signal interface
173+
InterfaceInfo warning_interface_info;
174+
warning_interface_info.name = hardware_interface::WARNING_SIGNAL_INTERFACE_NAME;
175+
warning_interface_info.data_type = "array<int8_t>[32]";
176+
InterfaceDescription warning_interface_descr(info_.name, warning_interface_info);
177+
warning_signal_ = std::make_shared<StateInterface>(warning_interface_descr);
178+
// create warning signal report message interface
179+
InterfaceInfo warning_msg_interface_info;
180+
warning_msg_interface_info.name = hardware_interface::WARNING_SIGNAL_MESSAGE_INTERFACE_NAME;
181+
warning_msg_interface_info.data_type = "array<string>[32]";
182+
InterfaceDescription warning_msg_interface_descr(info_.name, warning_msg_interface_info);
183+
warning_signal_message_ = std::make_shared<StateInterface>(warning_msg_interface_descr);
184+
}
185+
144186
/// Exports all state interfaces for this hardware interface.
145187
/**
146188
* Old way of exporting the StateInterfaces. If a empty vector is returned then
@@ -217,6 +259,12 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
217259
state_interfaces.push_back(state_interface);
218260
}
219261

262+
// export warning signal interfaces
263+
state_interfaces.push_back(error_signal_);
264+
state_interfaces.push_back(error_signal_message_);
265+
state_interfaces.push_back(warning_signal_);
266+
state_interfaces.push_back(warning_signal_message_);
267+
220268
return state_interfaces;
221269
}
222270

@@ -266,6 +314,28 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
266314
return sensor_states_.at(interface_name)->get_value();
267315
}
268316

317+
void set_error_code(const double & error_code) { error_signal_->set_value(error_code); }
318+
319+
double get_error_code() const { return error_signal_->get_value(); }
320+
321+
void set_error_message(const double & error_message)
322+
{
323+
error_signal_message_->set_value(error_message);
324+
}
325+
326+
double get_error_message() const { return error_signal_message_->get_value(); }
327+
328+
void set_warning_code(const double & warning_codes) { warning_signal_->set_value(warning_codes); }
329+
330+
double get_warning_code() const { return warning_signal_->get_value(); }
331+
332+
void set_warning_message(const double & error_message)
333+
{
334+
warning_signal_message_->set_value(error_message);
335+
}
336+
337+
double get_warning_message() const { return warning_signal_message_->get_value(); }
338+
269339
protected:
270340
/// Get the logger of the SensorInterface.
271341
/**
@@ -284,12 +354,17 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
284354
std::unordered_map<std::string, InterfaceDescription> sensor_state_interfaces_;
285355
std::unordered_map<std::string, InterfaceDescription> unlisted_state_interfaces_;
286356

287-
rclcpp_lifecycle::State lifecycle_state_;
288-
289357
private:
290358
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface_;
291359
rclcpp::Logger sensor_logger_;
292360
std::unordered_map<std::string, std::shared_ptr<StateInterface>> sensor_states_;
361+
362+
std::shared_ptr<StateInterface> error_signal_;
363+
std::shared_ptr<StateInterface> error_signal_message_;
364+
std::shared_ptr<StateInterface> warning_signal_;
365+
std::shared_ptr<StateInterface> warning_signal_message_;
366+
367+
rclcpp_lifecycle::State lifecycle_state_;
293368
};
294369

295370
} // namespace hardware_interface

0 commit comments

Comments
 (0)