24
24
25
25
#include " geometry_msgs/msg/wrench_stamped.hpp"
26
26
#include " hardware_interface/loaned_state_interface.hpp"
27
+ #include " lifecycle_msgs/msg/state.hpp"
27
28
#include " rclcpp/executor.hpp"
28
29
#include " rclcpp/executors.hpp"
29
30
#include " rclcpp/utilities.hpp"
30
-
31
31
using hardware_interface::LoanedStateInterface;
32
32
using testing::IsEmpty;
33
33
using testing::SizeIs;
@@ -40,15 +40,43 @@ constexpr auto NODE_ERROR = controller_interface::CallbackReturn::ERROR;
40
40
41
41
void ForceTorqueSensorBroadcasterTest::SetUpTestCase () {}
42
42
43
- void ForceTorqueSensorBroadcasterTest::TearDownTestCase () {}
43
+ void ForceTorqueSensorBroadcasterTest::TearDownTestCase ()
44
+ {
45
+ // Ensure all nodes are properly shutdown
46
+ rclcpp::shutdown ();
47
+ // Add a small delay to allow proper cleanup
48
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
49
+ }
44
50
45
51
void ForceTorqueSensorBroadcasterTest::SetUp ()
46
52
{
47
53
// initialize controller
48
54
fts_broadcaster_ = std::make_unique<FriendForceTorqueSensorBroadcaster>();
49
55
}
50
56
51
- void ForceTorqueSensorBroadcasterTest::TearDown () { fts_broadcaster_.reset (nullptr ); }
57
+ void ForceTorqueSensorBroadcasterTest::TearDown ()
58
+ {
59
+ // Reset the broadcaster with proper cleanup
60
+ if (fts_broadcaster_)
61
+ {
62
+ if (
63
+ fts_broadcaster_->get_lifecycle_state ().id () !=
64
+ lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
65
+ {
66
+ if (
67
+ fts_broadcaster_->get_lifecycle_state ().id () ==
68
+ lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
69
+ {
70
+ ASSERT_EQ (fts_broadcaster_->on_deactivate (rclcpp_lifecycle::State ()), NODE_SUCCESS);
71
+ }
72
+ // Clean up the broadcaster
73
+ ASSERT_EQ (fts_broadcaster_->on_cleanup (rclcpp_lifecycle::State ()), NODE_SUCCESS);
74
+ }
75
+ fts_broadcaster_.reset (nullptr );
76
+ }
77
+ // Add a small delay between tests
78
+ std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
79
+ }
52
80
53
81
void ForceTorqueSensorBroadcasterTest::SetUpFTSBroadcaster ()
54
82
{
0 commit comments