@@ -217,14 +217,14 @@ void get_active_controllers_using_command_interfaces_of_controller(
217
217
218
218
void extract_command_interfaces_for_controller (
219
219
const controller_manager::ControllerSpec & ctrl,
220
- const hardware_interface::ResourceManager & resource_manager,
220
+ const std::unique_ptr< hardware_interface::ResourceManager> & resource_manager,
221
221
std::vector<std::string> & request_interface_list)
222
222
{
223
223
auto command_interface_config = ctrl.c ->command_interface_configuration ();
224
224
std::vector<std::string> command_interface_names = {};
225
225
if (command_interface_config.type == controller_interface::interface_configuration_type::ALL)
226
226
{
227
- command_interface_names = resource_manager. available_command_interfaces ();
227
+ command_interface_names = resource_manager-> available_command_interfaces ();
228
228
}
229
229
if (
230
230
command_interface_config.type == controller_interface::interface_configuration_type::INDIVIDUAL)
@@ -238,7 +238,7 @@ void extract_command_interfaces_for_controller(
238
238
void get_controller_list_command_interfaces (
239
239
const std::vector<std::string> & controllers_list,
240
240
const std::vector<controller_manager::ControllerSpec> & controllers_spec,
241
- const hardware_interface::ResourceManager & resource_manager,
241
+ const std::unique_ptr< hardware_interface::ResourceManager> & resource_manager,
242
242
std::vector<std::string> & request_interface_list)
243
243
{
244
244
for (const auto & controller_name : controllers_list)
@@ -1459,12 +1459,12 @@ controller_interface::return_type ControllerManager::switch_controller(
1459
1459
if (in_activate_list)
1460
1460
{
1461
1461
extract_command_interfaces_for_controller (
1462
- controller, * resource_manager_, activate_command_interface_request_);
1462
+ controller, resource_manager_, activate_command_interface_request_);
1463
1463
}
1464
1464
if (in_deactivate_list)
1465
1465
{
1466
1466
extract_command_interfaces_for_controller (
1467
- controller, * resource_manager_, deactivate_command_interface_request_);
1467
+ controller, resource_manager_, deactivate_command_interface_request_);
1468
1468
}
1469
1469
1470
1470
// cache mapping between hardware and controllers for stopping when read/write error happens
@@ -2430,36 +2430,26 @@ void ControllerManager::read(const rclcpp::Time & time, const rclcpp::Duration &
2430
2430
2431
2431
if (!ok)
2432
2432
{
2433
- std::vector<std::string> stop_request = {};
2434
- std::string failed_hardware_string;
2435
- failed_hardware_string.reserve (500 );
2433
+ rt_buffer_.deactivate_controllers_list .clear ();
2436
2434
// Determine controllers to stop
2437
2435
for (const auto & hardware_name : failed_hardware_names)
2438
2436
{
2439
- failed_hardware_string.append (hardware_name);
2440
- failed_hardware_string.append (" " );
2441
2437
auto controllers = resource_manager_->get_cached_controllers_to_hardware (hardware_name);
2442
- stop_request.insert (stop_request.end (), controllers.begin (), controllers.end ());
2443
- }
2444
- std::string stop_request_string;
2445
- stop_request_string.reserve (500 );
2446
- for (const auto & controller : stop_request)
2447
- {
2448
- stop_request_string.append (controller);
2449
- stop_request_string.append (" " );
2438
+ rt_buffer_.deactivate_controllers_list .insert (
2439
+ rt_buffer_.deactivate_controllers_list .end (), controllers.begin (), controllers.end ());
2450
2440
}
2451
2441
RCLCPP_ERROR (
2452
2442
get_logger (),
2453
2443
" Deactivating following hardware components as their read cycle resulted in an error: [ %s]" ,
2454
- failed_hardware_string .c_str ());
2444
+ rt_buffer_. get_concatenated_string (failed_hardware_names) .c_str ());
2455
2445
RCLCPP_ERROR_EXPRESSION (
2456
- get_logger (), !stop_request_string .empty (),
2446
+ get_logger (), !rt_buffer_. deactivate_controllers_list .empty (),
2457
2447
" Deactivating following controllers as their hardware components read cycle resulted in an "
2458
2448
" error: [ %s]" ,
2459
- stop_request_string .c_str ());
2449
+ rt_buffer_. get_concatenated_string (rt_buffer_. deactivate_controllers_list ) .c_str ());
2460
2450
std::vector<ControllerSpec> & rt_controller_list =
2461
2451
rt_controllers_wrapper_.update_and_get_used_by_rt_list ();
2462
- deactivate_controllers (rt_controller_list, stop_request );
2452
+ deactivate_controllers (rt_controller_list, rt_buffer_. deactivate_controllers_list );
2463
2453
// TODO(destogl): do auto-start of broadcasters
2464
2454
}
2465
2455
}
@@ -2532,7 +2522,7 @@ controller_interface::return_type ControllerManager::update(
2532
2522
" configuration (use_sim_time parameter) and if a valid clock source is available" );
2533
2523
}
2534
2524
2535
- std::vector<std::string> failed_controllers_list ;
2525
+ rt_buffer_. deactivate_controllers_list . clear () ;
2536
2526
for (const auto & loaded_controller : rt_controller_list)
2537
2527
{
2538
2528
// TODO(v-lopez) we could cache this information
@@ -2630,21 +2620,18 @@ controller_interface::return_type ControllerManager::update(
2630
2620
2631
2621
if (controller_ret != controller_interface::return_type::OK)
2632
2622
{
2633
- failed_controllers_list .push_back (loaded_controller.info .name );
2623
+ rt_buffer_. deactivate_controllers_list .push_back (loaded_controller.info .name );
2634
2624
ret = controller_ret;
2635
2625
}
2636
2626
}
2637
2627
}
2638
2628
}
2639
- if (!failed_controllers_list .empty ())
2629
+ if (!rt_buffer_. deactivate_controllers_list .empty ())
2640
2630
{
2641
- const auto FALLBACK_STACK_MAX_SIZE = 500 ;
2642
- std::vector<std::string> active_controllers_using_interfaces (failed_controllers_list);
2643
- active_controllers_using_interfaces.reserve (FALLBACK_STACK_MAX_SIZE);
2644
- std::vector<std::string> cumulative_fallback_controllers;
2645
- cumulative_fallback_controllers.reserve (FALLBACK_STACK_MAX_SIZE);
2631
+ rt_buffer_.fallback_controllers_list .clear ();
2632
+ rt_buffer_.activate_controllers_using_interfaces_list .clear ();
2646
2633
2647
- for (const auto & failed_ctrl : failed_controllers_list )
2634
+ for (const auto & failed_ctrl : rt_buffer_. deactivate_controllers_list )
2648
2635
{
2649
2636
auto ctrl_it = std::find_if (
2650
2637
rt_controller_list.begin (), rt_controller_list.end (),
@@ -2653,72 +2640,58 @@ controller_interface::return_type ControllerManager::update(
2653
2640
{
2654
2641
for (const auto & fallback_controller : ctrl_it->info .fallback_controllers_names )
2655
2642
{
2656
- cumulative_fallback_controllers .push_back (fallback_controller);
2643
+ rt_buffer_. fallback_controllers_list .push_back (fallback_controller);
2657
2644
get_active_controllers_using_command_interfaces_of_controller (
2658
- fallback_controller, rt_controller_list, active_controllers_using_interfaces);
2645
+ fallback_controller, rt_controller_list,
2646
+ rt_buffer_.activate_controllers_using_interfaces_list );
2659
2647
}
2660
2648
}
2661
2649
}
2662
- std::string controllers_string;
2663
- controllers_string.reserve (500 );
2664
- for (const auto & controller : failed_controllers_list)
2665
- {
2666
- controllers_string.append (controller);
2667
- controllers_string.append (" " );
2668
- }
2650
+
2669
2651
RCLCPP_ERROR (
2670
2652
get_logger (), " Deactivating controllers : [ %s] as their update resulted in an error!" ,
2671
- controllers_string.c_str ());
2672
- if (active_controllers_using_interfaces.size () > failed_controllers_list.size ())
2673
- {
2674
- controllers_string.clear ();
2675
- for (size_t i = failed_controllers_list.size ();
2676
- i < active_controllers_using_interfaces.size (); i++)
2677
- {
2678
- controllers_string.append (active_controllers_using_interfaces[i]);
2679
- controllers_string.append (" " );
2680
- }
2681
- RCLCPP_ERROR_EXPRESSION (
2682
- get_logger (), !controllers_string.empty (),
2683
- " Deactivating controllers : [ %s] using the command interfaces needed for the fallback "
2684
- " controllers to activate." ,
2685
- controllers_string.c_str ());
2686
- }
2687
- if (!cumulative_fallback_controllers.empty ())
2688
- {
2689
- controllers_string.clear ();
2690
- for (const auto & controller : cumulative_fallback_controllers)
2691
- {
2692
- controllers_string.append (controller);
2693
- controllers_string.append (" " );
2694
- }
2695
- RCLCPP_ERROR (
2696
- get_logger (), " Activating fallback controllers : [ %s]" , controllers_string.c_str ());
2697
- }
2698
- std::vector<std::string> failed_controller_interfaces, fallback_controller_interfaces;
2699
- failed_controller_interfaces.reserve (500 );
2653
+ rt_buffer_.get_concatenated_string (rt_buffer_.deactivate_controllers_list ).c_str ());
2654
+ RCLCPP_ERROR_EXPRESSION (
2655
+ get_logger (), !rt_buffer_.activate_controllers_using_interfaces_list .empty (),
2656
+ " Deactivating controllers : [ %s] using the command interfaces needed for the fallback "
2657
+ " controllers to activate." ,
2658
+ rt_buffer_.get_concatenated_string (rt_buffer_.activate_controllers_using_interfaces_list )
2659
+ .c_str ());
2660
+ RCLCPP_ERROR_EXPRESSION (
2661
+ get_logger (), !rt_buffer_.fallback_controllers_list .empty (),
2662
+ " Activating fallback controllers : [ %s]" ,
2663
+ rt_buffer_.get_concatenated_string (rt_buffer_.fallback_controllers_list ).c_str ());
2664
+ std::for_each (
2665
+ rt_buffer_.activate_controllers_using_interfaces_list .begin (),
2666
+ rt_buffer_.activate_controllers_using_interfaces_list .end (),
2667
+ [this ](const std::string & controller)
2668
+ { add_element_to_list (rt_buffer_.deactivate_controllers_list , controller); });
2669
+
2670
+ // Retrieve the interfaces to start and stop from the hardware end
2671
+ rt_buffer_.interfaces_to_start .clear ();
2672
+ rt_buffer_.interfaces_to_stop .clear ();
2700
2673
get_controller_list_command_interfaces (
2701
- failed_controllers_list , rt_controller_list, * resource_manager_,
2702
- failed_controller_interfaces );
2674
+ rt_buffer_. deactivate_controllers_list , rt_controller_list, resource_manager_,
2675
+ rt_buffer_. interfaces_to_stop );
2703
2676
get_controller_list_command_interfaces (
2704
- cumulative_fallback_controllers , rt_controller_list, * resource_manager_,
2705
- fallback_controller_interfaces );
2706
- if (!failed_controller_interfaces .empty ())
2677
+ rt_buffer_. fallback_controllers_list , rt_controller_list, resource_manager_,
2678
+ rt_buffer_. interfaces_to_start );
2679
+ if (!rt_buffer_. interfaces_to_stop . empty () || !rt_buffer_. interfaces_to_start .empty ())
2707
2680
{
2708
2681
if (!(resource_manager_->prepare_command_mode_switch (
2709
- fallback_controller_interfaces, failed_controller_interfaces ) &&
2682
+ rt_buffer_. interfaces_to_start , rt_buffer_. interfaces_to_stop ) &&
2710
2683
resource_manager_->perform_command_mode_switch (
2711
- fallback_controller_interfaces, failed_controller_interfaces )))
2684
+ rt_buffer_. interfaces_to_start , rt_buffer_. interfaces_to_stop )))
2712
2685
{
2713
2686
RCLCPP_ERROR (
2714
2687
get_logger (),
2715
2688
" Error while attempting mode switch when deactivating controllers in update cycle!" );
2716
2689
}
2717
2690
}
2718
- deactivate_controllers (rt_controller_list, active_controllers_using_interfaces );
2719
- if (!cumulative_fallback_controllers .empty ())
2691
+ deactivate_controllers (rt_controller_list, rt_buffer_. deactivate_controllers_list );
2692
+ if (!rt_buffer_. fallback_controllers_list .empty ())
2720
2693
{
2721
- activate_controllers (rt_controller_list, cumulative_fallback_controllers );
2694
+ activate_controllers (rt_controller_list, rt_buffer_. fallback_controllers_list );
2722
2695
}
2723
2696
}
2724
2697
@@ -2739,37 +2712,27 @@ void ControllerManager::write(const rclcpp::Time & time, const rclcpp::Duration
2739
2712
2740
2713
if (!ok)
2741
2714
{
2742
- std::vector<std::string> stop_request = {};
2743
- std::string failed_hardware_string;
2744
- failed_hardware_string.reserve (500 );
2715
+ rt_buffer_.deactivate_controllers_list .clear ();
2745
2716
// Determine controllers to stop
2746
2717
for (const auto & hardware_name : failed_hardware_names)
2747
2718
{
2748
- failed_hardware_string.append (hardware_name);
2749
- failed_hardware_string.append (" " );
2750
2719
auto controllers = resource_manager_->get_cached_controllers_to_hardware (hardware_name);
2751
- stop_request.insert (stop_request.end (), controllers.begin (), controllers.end ());
2752
- }
2753
- std::string stop_request_string;
2754
- stop_request_string.reserve (500 );
2755
- for (const auto & controller : stop_request)
2756
- {
2757
- stop_request_string.append (controller);
2758
- stop_request_string.append (" " );
2720
+ rt_buffer_.deactivate_controllers_list .insert (
2721
+ rt_buffer_.deactivate_controllers_list .end (), controllers.begin (), controllers.end ());
2759
2722
}
2760
2723
RCLCPP_ERROR (
2761
2724
get_logger (),
2762
2725
" Deactivating following hardware components as their write cycle resulted in an error: [ "
2763
2726
" %s]" ,
2764
- failed_hardware_string .c_str ());
2727
+ rt_buffer_. get_concatenated_string (failed_hardware_names) .c_str ());
2765
2728
RCLCPP_ERROR_EXPRESSION (
2766
- get_logger (), !stop_request_string .empty (),
2729
+ get_logger (), !rt_buffer_. deactivate_controllers_list .empty (),
2767
2730
" Deactivating following controllers as their hardware components write cycle resulted in an "
2768
2731
" error: [ %s]" ,
2769
- stop_request_string .c_str ());
2732
+ rt_buffer_. get_concatenated_string (rt_buffer_. deactivate_controllers_list ) .c_str ());
2770
2733
std::vector<ControllerSpec> & rt_controller_list =
2771
2734
rt_controllers_wrapper_.update_and_get_used_by_rt_list ();
2772
- deactivate_controllers (rt_controller_list, stop_request );
2735
+ deactivate_controllers (rt_controller_list, rt_buffer_. deactivate_controllers_list );
2773
2736
// TODO(destogl): do auto-start of broadcasters
2774
2737
}
2775
2738
}
0 commit comments