Skip to content

Commit 719fbb1

Browse files
authored
added params approach to allow propagation in gz_ros2_control (ros-controls#2340)
1 parent 24d60ed commit 719fbb1

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,12 @@ void ControllerManager::init_resource_manager(const std::string & robot_descript
621621
{
622622
resource_manager_->import_joint_limiters(robot_description_);
623623
}
624-
if (!resource_manager_->load_and_initialize_components(robot_description, update_rate_))
624+
hardware_interface::ResourceManagerParams params;
625+
params.robot_description = robot_description;
626+
params.clock = trigger_clock_;
627+
params.logger = this->get_logger();
628+
params.executor = executor_;
629+
if (!resource_manager_->load_and_initialize_components(params))
625630
{
626631
RCLCPP_WARN(
627632
get_logger(),

hardware_interface/include/hardware_interface/resource_manager.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,57 @@ class ResourceManager
446446
* \param[in] system pointer to the system interface.
447447
* \param[in] hardware_info hardware info
448448
*/
449+
void import_component(
450+
std::unique_ptr<SystemInterface> system, const HardwareComponentParams & params);
451+
452+
/// Import a hardware component which is not listed in the URDF
453+
/**
454+
* Components which are initialized outside a URDF can be added post initialization.
455+
* Nevertheless, there should still be `HardwareInfo` available for this component,
456+
* either parsed from a URDF string (easiest) or filled manually.
457+
*
458+
* \note this might invalidate existing state and command interfaces and should thus
459+
* not be called when a controller is running.
460+
* \note given that no hardware_info is available, the component has to be configured
461+
* externally and prior to the call to import.
462+
* \param[in] actuator pointer to the actuator interface.
463+
* \param[in] params Struct of type HardwareComponentParams containing the hardware info
464+
* and other parameters for the component.
465+
*/
466+
void import_component(
467+
std::unique_ptr<ActuatorInterface> actuator, const HardwareComponentParams & params);
468+
469+
/// Import a hardware component which is not listed in the URDF
470+
/**
471+
* Components which are initialized outside a URDF can be added post initialization.
472+
* Nevertheless, there should still be `HardwareInfo` available for this component,
473+
* either parsed from a URDF string (easiest) or filled manually.
474+
*
475+
* \note this might invalidate existing state and command interfaces and should thus
476+
* not be called when a controller is running.
477+
* \note given that no hardware_info is available, the component has to be configured
478+
* externally and prior to the call to import.
479+
* \param[in] sensor pointer to the sensor interface.
480+
* \param[in] params Struct of type HardwareComponentParams containing the hardware info
481+
* and other parameters for the component.
482+
*/
483+
void import_component(
484+
std::unique_ptr<SensorInterface> sensor, const HardwareComponentParams & params);
485+
486+
/// Import a hardware component which is not listed in the URDF
487+
/**
488+
* Components which are initialized outside a URDF can be added post initialization.
489+
* Nevertheless, there should still be `HardwareInfo` available for this component,
490+
* either parsed from a URDF string (easiest) or filled manually.
491+
*
492+
* \note this might invalidate existing state and command interfaces and should thus
493+
* not be called when a controller is running.
494+
* \note given that no hardware_info is available, the component has to be configured
495+
* externally and prior to the call to import.
496+
* \param[in] system pointer to the system interface.
497+
* \param[in] params Struct of type HardwareComponentParams containing the hardware info
498+
* and other parameters for the component.
499+
*/
449500
void import_component(
450501
std::unique_ptr<SystemInterface> system, const HardwareInfo & hardware_info);
451502

hardware_interface/src/resource_manager.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,29 +1908,53 @@ std::string ResourceManager::get_command_interface_data_type(const std::string &
19081908

19091909
void ResourceManager::import_component(
19101910
std::unique_ptr<ActuatorInterface> actuator, const HardwareInfo & hardware_info)
1911+
{
1912+
HardwareComponentParams params;
1913+
params.hardware_info = hardware_info;
1914+
import_component(std::move(actuator), params);
1915+
}
1916+
1917+
void ResourceManager::import_component(
1918+
std::unique_ptr<SensorInterface> sensor, const HardwareInfo & hardware_info)
1919+
{
1920+
HardwareComponentParams params;
1921+
params.hardware_info = hardware_info;
1922+
import_component(std::move(sensor), params);
1923+
}
1924+
1925+
void ResourceManager::import_component(
1926+
std::unique_ptr<SystemInterface> system, const HardwareInfo & hardware_info)
1927+
{
1928+
HardwareComponentParams params;
1929+
params.hardware_info = hardware_info;
1930+
import_component(std::move(system), params);
1931+
}
1932+
1933+
void ResourceManager::import_component(
1934+
std::unique_ptr<ActuatorInterface> actuator, const HardwareComponentParams & params)
19111935
{
19121936
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
1913-
resource_storage_->initialize_actuator(std::move(actuator), hardware_info);
1937+
resource_storage_->initialize_actuator(std::move(actuator), params);
19141938
read_write_status.failed_hardware_names.reserve(
19151939
resource_storage_->actuators_.size() + resource_storage_->sensors_.size() +
19161940
resource_storage_->systems_.size());
19171941
}
19181942

19191943
void ResourceManager::import_component(
1920-
std::unique_ptr<SensorInterface> sensor, const HardwareInfo & hardware_info)
1944+
std::unique_ptr<SensorInterface> sensor, const HardwareComponentParams & params)
19211945
{
19221946
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
1923-
resource_storage_->initialize_sensor(std::move(sensor), hardware_info);
1947+
resource_storage_->initialize_sensor(std::move(sensor), params);
19241948
read_write_status.failed_hardware_names.reserve(
19251949
resource_storage_->actuators_.size() + resource_storage_->sensors_.size() +
19261950
resource_storage_->systems_.size());
19271951
}
19281952

19291953
void ResourceManager::import_component(
1930-
std::unique_ptr<SystemInterface> system, const HardwareInfo & hardware_info)
1954+
std::unique_ptr<SystemInterface> system, const HardwareComponentParams & params)
19311955
{
19321956
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
1933-
resource_storage_->initialize_system(std::move(system), hardware_info);
1957+
resource_storage_->initialize_system(std::move(system), params);
19341958
read_write_status.failed_hardware_names.reserve(
19351959
resource_storage_->actuators_.size() + resource_storage_->sensors_.size() +
19361960
resource_storage_->systems_.size());

0 commit comments

Comments
 (0)