Skip to content

Commit 64a8030

Browse files
soham2560mergify[bot]
authored andcommitted
added params approach to allow propagation in gz_ros2_control (#2340)
(cherry picked from commit 719fbb1)
1 parent 6f67786 commit 64a8030

3 files changed

Lines changed: 86 additions & 6 deletions

File tree

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
@@ -1894,29 +1894,53 @@ std::string ResourceManager::get_command_interface_data_type(const std::string &
18941894

18951895
void ResourceManager::import_component(
18961896
std::unique_ptr<ActuatorInterface> actuator, const HardwareInfo & hardware_info)
1897+
{
1898+
HardwareComponentParams params;
1899+
params.hardware_info = hardware_info;
1900+
import_component(std::move(actuator), params);
1901+
}
1902+
1903+
void ResourceManager::import_component(
1904+
std::unique_ptr<SensorInterface> sensor, const HardwareInfo & hardware_info)
1905+
{
1906+
HardwareComponentParams params;
1907+
params.hardware_info = hardware_info;
1908+
import_component(std::move(sensor), params);
1909+
}
1910+
1911+
void ResourceManager::import_component(
1912+
std::unique_ptr<SystemInterface> system, const HardwareInfo & hardware_info)
1913+
{
1914+
HardwareComponentParams params;
1915+
params.hardware_info = hardware_info;
1916+
import_component(std::move(system), params);
1917+
}
1918+
1919+
void ResourceManager::import_component(
1920+
std::unique_ptr<ActuatorInterface> actuator, const HardwareComponentParams & params)
18971921
{
18981922
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
1899-
resource_storage_->initialize_actuator(std::move(actuator), hardware_info);
1923+
resource_storage_->initialize_actuator(std::move(actuator), params);
19001924
read_write_status.failed_hardware_names.reserve(
19011925
resource_storage_->actuators_.size() + resource_storage_->sensors_.size() +
19021926
resource_storage_->systems_.size());
19031927
}
19041928

19051929
void ResourceManager::import_component(
1906-
std::unique_ptr<SensorInterface> sensor, const HardwareInfo & hardware_info)
1930+
std::unique_ptr<SensorInterface> sensor, const HardwareComponentParams & params)
19071931
{
19081932
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
1909-
resource_storage_->initialize_sensor(std::move(sensor), hardware_info);
1933+
resource_storage_->initialize_sensor(std::move(sensor), params);
19101934
read_write_status.failed_hardware_names.reserve(
19111935
resource_storage_->actuators_.size() + resource_storage_->sensors_.size() +
19121936
resource_storage_->systems_.size());
19131937
}
19141938

19151939
void ResourceManager::import_component(
1916-
std::unique_ptr<SystemInterface> system, const HardwareInfo & hardware_info)
1940+
std::unique_ptr<SystemInterface> system, const HardwareComponentParams & params)
19171941
{
19181942
std::lock_guard<std::recursive_mutex> guard(resources_lock_);
1919-
resource_storage_->initialize_system(std::move(system), hardware_info);
1943+
resource_storage_->initialize_system(std::move(system), params);
19201944
read_write_status.failed_hardware_names.reserve(
19211945
resource_storage_->actuators_.size() + resource_storage_->sensors_.size() +
19221946
resource_storage_->systems_.size());

0 commit comments

Comments
 (0)