Skip to content
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

Change the controller sorting with an approach similar to directed acyclic graphs #1384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
931fc43
added reference lists of following and preeceding controllers to Cont…
saikishor Dec 3, 2023
72f6ca5
change to a different struct for easiness and ownership
saikishor Dec 4, 2023
34b5694
add a utility method to add elements to the list if they don't exist
saikishor Dec 4, 2023
dd9119c
Add controller_chain_spec and update the following controllers based …
saikishor Dec 4, 2023
6a2ab8b
Add current configured controller to the preceding controller list of…
saikishor Dec 4, 2023
b5a0c74
Apply the same type of logic for state interfaces
saikishor Dec 4, 2023
1d93659
Add utility method to remove elements from the list
saikishor Dec 4, 2023
95c7026
Added a method to cleanup the controller chain spec upon node cleanup…
saikishor Dec 4, 2023
2ba75ff
added a lambda to find the controllerSpec by controller name
saikishor Dec 5, 2023
de7f97f
added a lambda to check if a ControllerSpec for a given controller name
saikishor Dec 5, 2023
f728a3a
comment out the lambdas
saikishor Dec 16, 2023
3042a85
Added 2 new methods to perform controller sorting
saikishor Dec 16, 2023
7ab583d
added lines to start checking out the list
saikishor Dec 16, 2023
9bb56bb
remove resetting the list on configure as there might be another cont…
saikishor Dec 17, 2023
708b42f
initialize empty spec for the broadcasters
saikishor Dec 17, 2023
0a31887
add formatting changes
saikishor Dec 21, 2023
6a43be7
remove the unnecessary conditioning in the insert_controller method
saikishor Feb 4, 2024
aa22855
fix the typo in the tests documentation
saikishor Feb 4, 2024
81f43f1
change the conditioning to set the default ControllerChainSpec
saikishor Feb 4, 2024
a1134b4
add propagate option to the method
saikishor Feb 6, 2024
e82b1f9
comment out unnecessary code and only use insert_controller method
saikishor Feb 6, 2024
81ed774
comment out old sorting and test the current implementation
saikishor Feb 6, 2024
eba4f7e
remove propagate option and check the new controller iterator every i…
saikishor Feb 7, 2024
d5f60d6
remove commented part of the code
saikishor Feb 7, 2024
5a4c46f
cleanup the code and remove commented part
saikishor Feb 8, 2024
fa7c972
remove old controller sorting code
saikishor Feb 11, 2024
4c2f54e
rename the method to update_list_with_controller_chain
saikishor Feb 11, 2024
7218012
remove unnecessary method
saikishor Feb 11, 2024
3cef552
change the logging tot DEBUG
saikishor Feb 11, 2024
0b9584f
modify a bit the logging of reordered list
saikishor Feb 11, 2024
f23139c
fix formatting
saikishor Feb 11, 2024
5ee4d36
Merge branch 'master' into update/controller_sorting_algorithm
saikishor Feb 15, 2024
43846bd
Merge branch 'master' into update/controller_sorting_algorithm
saikishor Feb 21, 2024
b95c255
Merge branch 'master' into update/controller_sorting_algorithm
saikishor Feb 28, 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 @@ -390,28 +390,28 @@ class ControllerManager : public rclcpp::Node
const std::vector<ControllerSpec> & controllers, int strictness,
const ControllersListIterator controller_it);

/// A method to be used in the std::sort method to sort the controllers to be able to
/// execute them in a proper order
/**
* Compares the controllers ctrl_a and ctrl_b and then returns which comes first in the sequence
* @brief Inserts a controller into an ordered list based on dependencies to compute the
* controller chain.
*
* @note The following conditions needs to be handled while ordering the controller list
* 1. The controllers that do not use any state or command interfaces are updated first
* 2. The controllers that use only the state system interfaces only are updated next
* 3. The controllers that use any of an another controller's reference interface are updated
* before the preceding controller
* 4. The controllers that use the controller's estimated interfaces are updated after the
* preceding controller
* 5. The controllers that only use the hardware command interfaces are updated last
* 6. All inactive controllers go at the end of the list
* This method computes the controller chain by inserting the provided controller name into an
* ordered list of controllers based on dependencies. It ensures that controllers are inserted in
* the correct order so that dependencies are satisfied.
*
* \param[in] controllers list of controllers to compare their names to interface's prefix.
*
* @return true, if ctrl_a needs to execute first, else false
* @param ctrl_name The name of the controller to be inserted into the chain.
* @param controller_iterator An iterator pointing to the position in the ordered list where the
* controller should be inserted.
* @param append_to_controller Flag indicating whether the controller should be appended or
* prepended to the parsed iterator.
* @note The specification of controller dependencies is in the ControllerChainSpec,
* containing information about following and preceding controllers. This struct should include
* the neighboring controllers with their relationships to the provided controller.
* `following_controllers` specify controllers that come after the provided controller.
* `preceding_controllers` specify controllers that come before the provided controller.
*/
bool controller_sorting(
const ControllerSpec & ctrl_a, const ControllerSpec & ctrl_b,
const std::vector<controller_manager::ControllerSpec> & controllers);
void update_list_with_controller_chain(
const std::string & ctrl_name, std::vector<std::string>::iterator controller_iterator,
bool append_to_controller);

void controller_activity_diagnostic_callback(diagnostic_updater::DiagnosticStatusWrapper & stat);

Expand Down Expand Up @@ -515,6 +515,8 @@ class ControllerManager : public rclcpp::Node
};

RTControllerListWrapper rt_controllers_wrapper_;
std::unordered_map<std::string, ControllerChainSpec> controller_chain_spec_;
std::vector<std::string> ordered_controllers_names_;
/// mutex copied from ROS1 Control, protects service callbacks
/// not needed if we're guaranteed that the callbacks don't come from multiple threads
std::mutex services_lock_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ struct ControllerSpec
std::shared_ptr<rclcpp::Time> next_update_cycle_time;
};

struct ControllerChainSpec
{
std::vector<std::string> following_controllers;
std::vector<std::string> preceding_controllers;
};
} // namespace controller_manager
#endif // CONTROLLER_MANAGER__CONTROLLER_SPEC_HPP_
Loading
Loading