Skip to content

Commit 9c56d77

Browse files
Included ResourceManager in Ros2ControlSystem::init()
1 parent 4b2aa16 commit 9c56d77

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

webots_ros2_control/include/webots_ros2_control/Ros2ControlSystem.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "hardware_interface/handle.hpp"
2323
#include "hardware_interface/hardware_info.hpp"
2424
#include "hardware_interface/system_interface.hpp"
25+
#include "hardware_interface/resource_manager.hpp"
2526
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2627
#include "rclcpp/macros.hpp"
2728
#include "webots_ros2_driver/PluginInterface.hpp"
@@ -50,7 +51,7 @@ namespace webots_ros2_control {
5051
class Ros2ControlSystem : public Ros2ControlSystemInterface {
5152
public:
5253
Ros2ControlSystem();
53-
void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) override;
54+
void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info, const hardware_interface::ResourceManager &resource) override;
5455

5556
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_init(
5657
const hardware_interface::HardwareInfo &info) override;

webots_ros2_control/include/webots_ros2_control/Ros2ControlSystemInterface.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
#include "hardware_interface/handle.hpp"
2424
#include "hardware_interface/hardware_info.hpp"
2525
#include "hardware_interface/system_interface.hpp"
26+
#include "hardware_interface/resource_manager.hpp"
2627
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2728
#include "webots_ros2_driver/PluginInterface.hpp"
2829
#include "webots_ros2_driver/WebotsNode.hpp"
2930

3031
namespace webots_ros2_control {
3132
class Ros2ControlSystemInterface : public hardware_interface::SystemInterface {
3233
public:
33-
virtual void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) = 0;
34+
virtual void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info, const hardware_interface::ResourceManager &resource) = 0;
3435
};
3536
} // namespace webots_ros2_control
3637

webots_ros2_control/src/Ros2Control.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace webots_ros2_control {
8787
auto webotsSystem = std::unique_ptr<webots_ros2_control::Ros2ControlSystemInterface>(
8888
mHardwareLoader->createUnmanagedInstance(hardwareType));
8989
#endif
90-
webotsSystem->init(mNode, controlHardware[i]);
90+
webotsSystem->init(mNode, controlHardware[i], *resourceManager);
9191
resourceManager->import_component(std::move(webotsSystem), controlHardware[i]);
9292

9393
// Configure and activate all components

webots_ros2_control/src/Ros2ControlSystem.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace webots_ros2_control {
3131
Ros2ControlSystem::Ros2ControlSystem() {
3232
mNode = NULL;
3333
}
34-
void Ros2ControlSystem::init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) {
34+
void Ros2ControlSystem::init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info, const hardware_interface::ResourceManager &resource) {
3535
mNode = node;
3636
for (hardware_interface::ComponentInfo component : info.joints) {
3737
Joint joint;
@@ -64,14 +64,16 @@ namespace webots_ros2_control {
6464

6565
// Configure the command interface
6666
for (hardware_interface::InterfaceInfo commandInterface : component.command_interfaces) {
67-
if (commandInterface.name == "position")
68-
joint.controlPosition = true;
69-
else if (commandInterface.name == "velocity")
70-
joint.controlVelocity = true;
71-
else if (commandInterface.name == "effort")
72-
joint.controlEffort = true;
73-
else
74-
throw std::runtime_error("Invalid hardware info name `" + commandInterface.name + "`");
67+
if (resource.command_interface_is_claimed(commandInterface.name)) {
68+
if (commandInterface.name == "position")
69+
joint.controlPosition = true;
70+
else if (commandInterface.name == "velocity")
71+
joint.controlVelocity = true;
72+
else if (commandInterface.name == "effort")
73+
joint.controlEffort = true;
74+
else
75+
throw std::runtime_error("Invalid hardware info name `" + commandInterface.name + "`");
76+
}
7577
}
7678
if (joint.motor && joint.controlVelocity && !joint.controlPosition) {
7779
wb_motor_set_position(joint.motor, INFINITY);

0 commit comments

Comments
 (0)