@@ -390,28 +390,28 @@ class ControllerManager : public rclcpp::Node
390390 const std::vector<ControllerSpec> & controllers, int strictness,
391391 const ControllersListIterator controller_it);
392392
393- // / A method to be used in the std::sort method to sort the controllers to be able to
394- // / execute them in a proper order
395393 /* *
396- * Compares the controllers ctrl_a and ctrl_b and then returns which comes first in the sequence
394+ * @brief Inserts a controller into an ordered list based on dependencies to compute the
395+ * controller chain.
397396 *
398- * @note The following conditions needs to be handled while ordering the controller list
399- * 1. The controllers that do not use any state or command interfaces are updated first
400- * 2. The controllers that use only the state system interfaces only are updated next
401- * 3. The controllers that use any of an another controller's reference interface are updated
402- * before the preceding controller
403- * 4. The controllers that use the controller's estimated interfaces are updated after the
404- * preceding controller
405- * 5. The controllers that only use the hardware command interfaces are updated last
406- * 6. All inactive controllers go at the end of the list
397+ * This method computes the controller chain by inserting the provided controller name into an
398+ * ordered list of controllers based on dependencies. It ensures that controllers are inserted in
399+ * the correct order so that dependencies are satisfied.
407400 *
408- * \param[in] controllers list of controllers to compare their names to interface's prefix.
409- *
410- * @return true, if ctrl_a needs to execute first, else false
401+ * @param ctrl_name The name of the controller to be inserted into the chain.
402+ * @param controller_iterator An iterator pointing to the position in the ordered list where the
403+ * controller should be inserted.
404+ * @param append_to_controller Flag indicating whether the controller should be appended or
405+ * prepended to the parsed iterator.
406+ * @note The specification of controller dependencies is in the ControllerChainSpec,
407+ * containing information about following and preceding controllers. This struct should include
408+ * the neighboring controllers with their relationships to the provided controller.
409+ * `following_controllers` specify controllers that come after the provided controller.
410+ * `preceding_controllers` specify controllers that come before the provided controller.
411411 */
412- bool controller_sorting (
413- const ControllerSpec & ctrl_a, const ControllerSpec & ctrl_b ,
414- const std::vector<controller_manager::ControllerSpec> & controllers );
412+ void update_list_with_controller_chain (
413+ const std::string & ctrl_name, std::vector<std::string>::iterator controller_iterator ,
414+ bool append_to_controller );
415415
416416 void controller_activity_diagnostic_callback (diagnostic_updater::DiagnosticStatusWrapper & stat);
417417
@@ -515,6 +515,8 @@ class ControllerManager : public rclcpp::Node
515515 };
516516
517517 RTControllerListWrapper rt_controllers_wrapper_;
518+ std::unordered_map<std::string, ControllerChainSpec> controller_chain_spec_;
519+ std::vector<std::string> ordered_controllers_names_;
518520 // / mutex copied from ROS1 Control, protects service callbacks
519521 // / not needed if we're guaranteed that the callbacks don't come from multiple threads
520522 std::mutex services_lock_;
0 commit comments