Skip to content

[RM] Rename load_urdf method to load_and_initialize_components and add error handling there to avoid stack crashing when error happens. #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a31acf8
__ -> _
bmagyar Jan 29, 2024
c47ac65
Added functionality and tests for getting robot description from the …
destogl Dec 18, 2023
c1ba8bc
Fixed compilation and tests.
destogl Jan 31, 2024
26585af
Don't throw exception if something goes wrong with loading and initia…
destogl Feb 1, 2024
62e4384
Make sure that we can send new robot description over topic is the fi…
destogl Feb 1, 2024
2e13c3c
Add some additional tests.
destogl Feb 1, 2024
90df9a3
Merge branch 'master' into rename_load_urdf_method
destogl Feb 1, 2024
15fb5c6
Optimize tests according to comments.
destogl Feb 2, 2024
0c6761f
Apply suggestions from code review
destogl Feb 28, 2024
4c03455
Update hardware_interface/include/hardware_interface/resource_manager…
destogl Feb 28, 2024
abbd74f
Merge branch 'master' into rename_load_urdf_method
destogl Feb 28, 2024
2b4d9c0
Adjust docs.
destogl Mar 4, 2024
c612aa8
Merge branch 'master' into rename_load_urdf_method
destogl Mar 4, 2024
5d7bebf
Update hardware_interface/include/hardware_interface/resource_manager…
destogl Mar 11, 2024
7b11c37
Fixup formatting.
destogl Mar 11, 2024
e6417b0
Merge branch 'master' into rename_load_urdf_method
destogl Mar 11, 2024
01cd760
Merge branch 'master' into rename_load_urdf_method
destogl Mar 28, 2024
b54fa76
Fix typo when merging master.
destogl Apr 1, 2024
9c5b684
Prepara RM for overriding.
destogl Apr 1, 2024
2c0a022
Change how update rate is passed to RM so that we always work with co…
destogl Apr 1, 2024
f3a9cad
Apply suggestions from code review
destogl Apr 3, 2024
fd49fd4
Merge branch 'master' into rename_load_urdf_method
destogl Jun 17, 2024
9246300
Fix merge error.
destogl Jun 17, 2024
069572f
Fix tests and remove dupplicated test after changes.
destogl Jun 19, 2024
b2bd5b6
Correct formatting.
destogl Jun 19, 2024
366f65c
Correct formatting.
destogl Jun 19, 2024
ff682bd
Merge branch 'master' into rename_load_urdf_method
destogl Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ class ControllerManager : public rclcpp::Node
return resource_manager_->are_components_initialized();
}

/// Update rate of the main control loop in the controller manager.
/**
* Update rate of the main control loop in the controller manager.
* The method is used for per-controller update rate support.
*
* \returns update rate of the controller manager.
*/
CONTROLLER_MANAGER_PUBLIC
unsigned int get_update_rate() const;

Expand Down
4 changes: 2 additions & 2 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ ControllerManager::ControllerManager(
const std::string & node_namespace, const rclcpp::NodeOptions & options)
: rclcpp::Node(manager_node_name, node_namespace, options),
resource_manager_(std::make_unique<hardware_interface::ResourceManager>(
update_rate_, this->get_node_clock_interface())),
this->get_node_clock_interface())),
diagnostics_updater_(this),
executor_(executor),
loader_(std::make_shared<pluginlib::ClassLoader<controller_interface::ControllerInterface>>(
Expand Down Expand Up @@ -295,7 +295,7 @@ void ControllerManager::robot_description_callback(const std_msgs::msg::String &

void ControllerManager::init_resource_manager(const std::string & robot_description)
{
if (!resource_manager_->load_and_initialize_components(robot_description))
if (!resource_manager_->load_and_initialize_components(robot_description, update_rate_))
{
RCLCPP_WARN(
get_logger(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager
public:
/// Default constructor for the Resource Manager.
ResourceManager(
unsigned int update_rate = 100,
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface = nullptr);

/// Constructor for the Resource Manager.
Expand All @@ -68,8 +67,7 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager
* used for triggering async components.
*/
explicit ResourceManager(
const std::string & urdf, bool activate_all = false, unsigned int update_rate = 100,
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface = nullptr);
const std::string & urdf, bool activate_all = false, const unsigned int update_rate = 100, rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface = nullptr);

ResourceManager(const ResourceManager &) = delete;

Expand All @@ -82,9 +80,10 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager
* in which the URDF might not be present at first initialization.
*
* \param[in] urdf string containing the URDF.
* \param[in] update_rate update rate of the main control loop, i.e., of the controller manager.
* \returns false if URDF validation has failed.
*/
bool load_and_initialize_components(const std::string & urdf);
virtual bool load_and_initialize_components(const std::string & urdf, const unsigned int update_rate = 100);

/**
* @brief if the resource manager load_and_initialize_components(...) function has been called
Expand Down
19 changes: 9 additions & 10 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ class ResourceStorage
// TODO(VX792): Change this when HW ifs get their own update rate,
// because the ResourceStorage really shouldn't know about the cm's parameters
ResourceStorage(
unsigned int update_rate = 100,
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface = nullptr)
: actuator_loader_(pkg_name, actuator_interface_name),
sensor_loader_(pkg_name, sensor_interface_name),
system_loader_(pkg_name, system_interface_name),
cm_update_rate_(update_rate),
clock_interface_(clock_interface)
{
}
Expand Down Expand Up @@ -762,24 +760,23 @@ class ResourceStorage

// Update rate of the controller manager, and the clock interface of its node
// Used by async components.
unsigned int cm_update_rate_;
unsigned int cm_update_rate_ = 100;
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface_;
};

ResourceManager::ResourceManager(
unsigned int update_rate, rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface)
: resource_storage_(std::make_unique<ResourceStorage>(update_rate, clock_interface))
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface)
: resource_storage_(std::make_unique<ResourceStorage>(clock_interface))
{
}

ResourceManager::~ResourceManager() = default;

ResourceManager::ResourceManager(
const std::string & urdf, bool activate_all, unsigned int update_rate,
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface)
: resource_storage_(std::make_unique<ResourceStorage>(update_rate, clock_interface))
const std::string & urdf, bool activate_all, const unsigned int update_rate, rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface)
: resource_storage_(std::make_unique<ResourceStorage>(clock_interface))
{
load_and_initialize_components(urdf);
load_and_initialize_components(urdf, update_rate);

if (activate_all)
{
Expand All @@ -793,10 +790,12 @@ ResourceManager::ResourceManager(
}

// CM API: Called in "callback/slow"-thread
bool ResourceManager::load_and_initialize_components(const std::string & urdf)
bool ResourceManager::load_and_initialize_components(const std::string & urdf, const unsigned int update_rate)
{
components_are_loaded_and_initialized_ = true;

resource_storage_->cm_update_rate_ = update_rate;

const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf);

const std::string system_type = "system";
Expand Down