28
28
#include " lifecycle_msgs/msg/state.hpp"
29
29
#include " rclcpp_lifecycle/state.hpp"
30
30
#include " ros2_control_test_assets/descriptions.hpp"
31
+ #include " ros2_control_test_assets/test_hardware_interface_constants.hpp"
31
32
32
33
using ros2_control_test_assets::TEST_ACTUATOR_HARDWARE_COMMAND_INTERFACES;
33
34
using ros2_control_test_assets::TEST_ACTUATOR_HARDWARE_NAME;
@@ -1538,6 +1539,122 @@ class ResourceManagerTestReadWriteError : public ResourceManagerTest
1538
1539
}
1539
1540
}
1540
1541
1542
+ void check_read_or_write_deactivate (
1543
+ FunctionT method_that_deactivates, FunctionT other_method, const double deactivate_value)
1544
+ {
1545
+ // define state to set components to
1546
+ rclcpp_lifecycle::State state_active (
1547
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE,
1548
+ hardware_interface::lifecycle_state_names::ACTIVE);
1549
+
1550
+ // deactivate for TEST_ACTUATOR_HARDWARE_NAME
1551
+ claimed_itfs[0 ].set_value (deactivate_value);
1552
+ claimed_itfs[1 ].set_value (deactivate_value - 10.0 );
1553
+ {
1554
+ // deactivate on error
1555
+ auto [ok, failed_hardware_names] = method_that_deactivates (time, duration);
1556
+ EXPECT_TRUE (ok);
1557
+ EXPECT_TRUE (failed_hardware_names.empty ());
1558
+ auto status_map = rm->get_components_status ();
1559
+ EXPECT_EQ (
1560
+ status_map[TEST_ACTUATOR_HARDWARE_NAME].state .id (),
1561
+ lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE);
1562
+ EXPECT_EQ (
1563
+ status_map[TEST_SYSTEM_HARDWARE_NAME].state .id (),
1564
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1565
+ check_if_interface_available (true , true );
1566
+
1567
+ // reactivate
1568
+ rm->set_component_state (TEST_ACTUATOR_HARDWARE_NAME, state_active);
1569
+ status_map = rm->get_components_status ();
1570
+ EXPECT_EQ (
1571
+ status_map[TEST_ACTUATOR_HARDWARE_NAME].state .id (),
1572
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1573
+ EXPECT_EQ (
1574
+ status_map[TEST_SYSTEM_HARDWARE_NAME].state .id (),
1575
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1576
+ check_if_interface_available (true , true );
1577
+ }
1578
+ // write is sill OK
1579
+ {
1580
+ auto [ok, failed_hardware_names] = other_method (time, duration);
1581
+ EXPECT_TRUE (ok);
1582
+ EXPECT_TRUE (failed_hardware_names.empty ());
1583
+ check_if_interface_available (true , true );
1584
+ }
1585
+
1586
+ // deactivate for TEST_SYSTEM_HARDWARE_NAME
1587
+ claimed_itfs[0 ].set_value (deactivate_value - 10.0 );
1588
+ claimed_itfs[1 ].set_value (deactivate_value);
1589
+ {
1590
+ // deactivate on flag
1591
+ auto [ok, failed_hardware_names] = method_that_deactivates (time, duration);
1592
+ EXPECT_TRUE (ok);
1593
+ EXPECT_TRUE (failed_hardware_names.empty ());
1594
+ auto status_map = rm->get_components_status ();
1595
+ EXPECT_EQ (
1596
+ status_map[TEST_ACTUATOR_HARDWARE_NAME].state .id (),
1597
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1598
+ EXPECT_EQ (
1599
+ status_map[TEST_SYSTEM_HARDWARE_NAME].state .id (),
1600
+ lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE);
1601
+ check_if_interface_available (true , true );
1602
+ // re-activate
1603
+ rm->set_component_state (TEST_SYSTEM_HARDWARE_NAME, state_active);
1604
+ status_map = rm->get_components_status ();
1605
+ EXPECT_EQ (
1606
+ status_map[TEST_ACTUATOR_HARDWARE_NAME].state .id (),
1607
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1608
+ EXPECT_EQ (
1609
+ status_map[TEST_SYSTEM_HARDWARE_NAME].state .id (),
1610
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1611
+ check_if_interface_available (true , true );
1612
+ }
1613
+ // write is sill OK
1614
+ {
1615
+ auto [ok, failed_hardware_names] = other_method (time, duration);
1616
+ EXPECT_TRUE (ok);
1617
+ EXPECT_TRUE (failed_hardware_names.empty ());
1618
+ check_if_interface_available (true , true );
1619
+ }
1620
+
1621
+ // deactivate both, TEST_ACTUATOR_HARDWARE_NAME and TEST_SYSTEM_HARDWARE_NAME
1622
+ claimed_itfs[0 ].set_value (deactivate_value);
1623
+ claimed_itfs[1 ].set_value (deactivate_value);
1624
+ {
1625
+ // deactivate on flag
1626
+ auto [ok, failed_hardware_names] = method_that_deactivates (time, duration);
1627
+ EXPECT_TRUE (ok);
1628
+ EXPECT_TRUE (failed_hardware_names.empty ());
1629
+ auto status_map = rm->get_components_status ();
1630
+ EXPECT_EQ (
1631
+ status_map[TEST_ACTUATOR_HARDWARE_NAME].state .id (),
1632
+ lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE);
1633
+ EXPECT_EQ (
1634
+ status_map[TEST_SYSTEM_HARDWARE_NAME].state .id (),
1635
+ lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE);
1636
+ check_if_interface_available (true , true );
1637
+ // re-activate
1638
+ rm->set_component_state (TEST_ACTUATOR_HARDWARE_NAME, state_active);
1639
+ rm->set_component_state (TEST_SYSTEM_HARDWARE_NAME, state_active);
1640
+ status_map = rm->get_components_status ();
1641
+ EXPECT_EQ (
1642
+ status_map[TEST_ACTUATOR_HARDWARE_NAME].state .id (),
1643
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1644
+ EXPECT_EQ (
1645
+ status_map[TEST_SYSTEM_HARDWARE_NAME].state .id (),
1646
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
1647
+ check_if_interface_available (true , true );
1648
+ }
1649
+ // write is sill OK
1650
+ {
1651
+ auto [ok, failed_hardware_names] = other_method (time, duration);
1652
+ EXPECT_TRUE (ok);
1653
+ EXPECT_TRUE (failed_hardware_names.empty ());
1654
+ check_if_interface_available (true , true );
1655
+ }
1656
+ }
1657
+
1541
1658
public:
1542
1659
std::shared_ptr<TestableResourceManager> rm;
1543
1660
std::vector<hardware_interface::LoanedCommandInterface> claimed_itfs;
@@ -1546,8 +1663,6 @@ class ResourceManagerTestReadWriteError : public ResourceManagerTest
1546
1663
const rclcpp::Duration duration = rclcpp::Duration::from_seconds(0.01 );
1547
1664
1548
1665
// values to set to hardware to simulate failure on read and write
1549
- static constexpr double READ_FAIL_VALUE = 28282828.0 ;
1550
- static constexpr double WRITE_FAIL_VALUE = 23232323.0 ;
1551
1666
};
1552
1667
1553
1668
TEST_F (ResourceManagerTestReadWriteError, handle_error_on_hardware_read)
@@ -1558,7 +1673,7 @@ TEST_F(ResourceManagerTestReadWriteError, handle_error_on_hardware_read)
1558
1673
// check read methods failures
1559
1674
check_read_or_write_failure (
1560
1675
std::bind (&TestableResourceManager::read, rm, _1, _2),
1561
- std::bind (&TestableResourceManager::write, rm, _1, _2), READ_FAIL_VALUE);
1676
+ std::bind (&TestableResourceManager::write, rm, _1, _2), test_constants:: READ_FAIL_VALUE);
1562
1677
}
1563
1678
1564
1679
TEST_F (ResourceManagerTestReadWriteError, handle_error_on_hardware_write)
@@ -1569,7 +1684,29 @@ TEST_F(ResourceManagerTestReadWriteError, handle_error_on_hardware_write)
1569
1684
// check write methods failures
1570
1685
check_read_or_write_failure (
1571
1686
std::bind (&TestableResourceManager::write, rm, _1, _2),
1572
- std::bind (&TestableResourceManager::read, rm, _1, _2), WRITE_FAIL_VALUE);
1687
+ std::bind (&TestableResourceManager::read, rm, _1, _2), test_constants::WRITE_FAIL_VALUE);
1688
+ }
1689
+
1690
+ TEST_F (ResourceManagerTestReadWriteError, handle_deactivate_on_hardware_read)
1691
+ {
1692
+ setup_resource_manager_and_do_initial_checks ();
1693
+
1694
+ using namespace std ::placeholders;
1695
+ // check read methods failures
1696
+ check_read_or_write_deactivate (
1697
+ std::bind (&TestableResourceManager::read, rm, _1, _2),
1698
+ std::bind (&TestableResourceManager::write, rm, _1, _2), test_constants::READ_DEACTIVATE_VALUE);
1699
+ }
1700
+
1701
+ TEST_F (ResourceManagerTestReadWriteError, handle_deactivate_on_hardware_write)
1702
+ {
1703
+ setup_resource_manager_and_do_initial_checks ();
1704
+
1705
+ using namespace std ::placeholders;
1706
+ // check write methods failures
1707
+ check_read_or_write_deactivate (
1708
+ std::bind (&TestableResourceManager::write, rm, _1, _2),
1709
+ std::bind (&TestableResourceManager::read, rm, _1, _2), test_constants::WRITE_DEACTIVATE_VALUE);
1573
1710
}
1574
1711
1575
1712
TEST_F (ResourceManagerTest, test_caching_of_controllers_to_hardware)
0 commit comments