@@ -291,6 +291,12 @@ TEST_F(TestLoadController, spawner_test_with_params_file_string_parameter)
291
291
ASSERT_THAT (
292
292
ctrl_node->get_parameter (" joint_names" ).as_string_array (),
293
293
std::vector<std::string>({" joint0" }));
294
+
295
+ if (!ctrl_node->has_parameter (" interface_name" ))
296
+ {
297
+ ctrl_node->declare_parameter (" interface_name" , " invalid_interface" );
298
+ }
299
+ ASSERT_EQ (ctrl_node->get_parameter (" interface_name" ).as_string (), " position" );
294
300
}
295
301
296
302
TEST_F (TestLoadController, spawner_test_type_in_params_file)
@@ -397,6 +403,114 @@ TEST_F(TestLoadController, unload_on_kill_activate_as_group)
397
403
ASSERT_EQ (cm_->get_loaded_controllers ().size (), 0ul );
398
404
}
399
405
406
+ TEST_F (TestLoadController, spawner_test_to_check_parameter_overriding)
407
+ {
408
+ const std::string main_test_file_path =
409
+ ament_index_cpp::get_package_prefix (" controller_manager" ) +
410
+ " /test/test_controller_spawner_with_type.yaml" ;
411
+ const std::string overriding_test_file_path =
412
+ ament_index_cpp::get_package_prefix (" controller_manager" ) +
413
+ " /test/test_controller_overriding_parameters.yaml" ;
414
+
415
+ ControllerManagerRunner cm_runner (this );
416
+ EXPECT_EQ (
417
+ call_spawner (
418
+ " ctrl_with_parameters_and_type --load-only -c "
419
+ " test_controller_manager -p " +
420
+ main_test_file_path + " -p " + overriding_test_file_path),
421
+ 0 );
422
+
423
+ ASSERT_EQ (cm_->get_loaded_controllers ().size (), 1ul );
424
+
425
+ auto ctrl_with_parameters_and_type = cm_->get_loaded_controllers ()[0 ];
426
+ ASSERT_EQ (ctrl_with_parameters_and_type.info .name , " ctrl_with_parameters_and_type" );
427
+ ASSERT_EQ (ctrl_with_parameters_and_type.info .type , test_controller::TEST_CONTROLLER_CLASS_NAME);
428
+ ASSERT_EQ (
429
+ ctrl_with_parameters_and_type.c ->get_lifecycle_state ().id (),
430
+ lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED);
431
+ ASSERT_THAT (
432
+ cm_->get_parameter (" ctrl_with_parameters_and_type.params_file" ).as_string_array (),
433
+ std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
434
+ auto ctrl_node = ctrl_with_parameters_and_type.c ->get_node ();
435
+ ASSERT_THAT (
436
+ ctrl_with_parameters_and_type.info .parameters_files ,
437
+ std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
438
+ if (!ctrl_node->has_parameter (" joint_names" ))
439
+ {
440
+ ctrl_node->declare_parameter (" joint_names" , std::vector<std::string>({" random_joint" }));
441
+ }
442
+ ASSERT_THAT (
443
+ ctrl_node->get_parameter (" joint_names" ).as_string_array (),
444
+ std::vector<std::string>({" joint10" }));
445
+
446
+ if (!ctrl_node->has_parameter (" interface_name" ))
447
+ {
448
+ ctrl_node->declare_parameter (" interface_name" , " invalid_interface" );
449
+ }
450
+ ASSERT_EQ (ctrl_node->get_parameter (" interface_name" ).as_string (), " impedance" )
451
+ << " The parameter should be overridden" ;
452
+
453
+ if (!ctrl_node->has_parameter (" joint_offset" ))
454
+ {
455
+ ctrl_node->declare_parameter (" joint_offset" , -M_PI);
456
+ }
457
+ ASSERT_EQ (ctrl_node->get_parameter (" joint_offset" ).as_double (), 0.2 );
458
+ }
459
+
460
+ TEST_F (TestLoadController, spawner_test_to_check_parameter_overriding_reverse)
461
+ {
462
+ const std::string main_test_file_path =
463
+ ament_index_cpp::get_package_prefix (" controller_manager" ) +
464
+ " /test/test_controller_overriding_parameters.yaml" ;
465
+ const std::string overriding_test_file_path =
466
+ ament_index_cpp::get_package_prefix (" controller_manager" ) +
467
+ " /test/test_controller_spawner_with_type.yaml" ;
468
+
469
+ ControllerManagerRunner cm_runner (this );
470
+ EXPECT_EQ (
471
+ call_spawner (
472
+ " ctrl_with_parameters_and_type --load-only -c "
473
+ " test_controller_manager -p " +
474
+ main_test_file_path + " -p " + overriding_test_file_path),
475
+ 0 );
476
+
477
+ ASSERT_EQ (cm_->get_loaded_controllers ().size (), 1ul );
478
+
479
+ auto ctrl_with_parameters_and_type = cm_->get_loaded_controllers ()[0 ];
480
+ ASSERT_EQ (ctrl_with_parameters_and_type.info .name , " ctrl_with_parameters_and_type" );
481
+ ASSERT_EQ (ctrl_with_parameters_and_type.info .type , test_controller::TEST_CONTROLLER_CLASS_NAME);
482
+ ASSERT_EQ (
483
+ ctrl_with_parameters_and_type.c ->get_lifecycle_state ().id (),
484
+ lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED);
485
+ ASSERT_THAT (
486
+ cm_->get_parameter (" ctrl_with_parameters_and_type.params_file" ).as_string_array (),
487
+ std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
488
+ auto ctrl_node = ctrl_with_parameters_and_type.c ->get_node ();
489
+ ASSERT_THAT (
490
+ ctrl_with_parameters_and_type.info .parameters_files ,
491
+ std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
492
+ if (!ctrl_node->has_parameter (" joint_names" ))
493
+ {
494
+ ctrl_node->declare_parameter (" joint_names" , std::vector<std::string>({" random_joint" }));
495
+ }
496
+ ASSERT_THAT (
497
+ ctrl_node->get_parameter (" joint_names" ).as_string_array (),
498
+ std::vector<std::string>({" joint0" }));
499
+
500
+ if (!ctrl_node->has_parameter (" interface_name" ))
501
+ {
502
+ ctrl_node->declare_parameter (" interface_name" , " invalid_interface" );
503
+ }
504
+ ASSERT_EQ (ctrl_node->get_parameter (" interface_name" ).as_string (), " position" )
505
+ << " The parameter should be overridden" ;
506
+
507
+ if (!ctrl_node->has_parameter (" joint_offset" ))
508
+ {
509
+ ctrl_node->declare_parameter (" joint_offset" , -M_PI);
510
+ }
511
+ ASSERT_EQ (ctrl_node->get_parameter (" joint_offset" ).as_double (), 0.2 );
512
+ }
513
+
400
514
TEST_F (TestLoadController, spawner_test_fallback_controllers)
401
515
{
402
516
const std::string test_file_path = ament_index_cpp::get_package_prefix (" controller_manager" ) +
0 commit comments