@@ -79,6 +79,112 @@ TEST_F(SteeringControllersLibraryTest, check_exported_interfaces)
7979 }
8080}
8181
82+ // TF prefix tests
83+ TEST_F (SteeringControllersLibraryTest, configure_succeeds_tf_prefix_no_namespace)
84+ {
85+ std::string odom_id = " odom" ;
86+ std::string base_link_id = " base_link" ;
87+ std::string frame_prefix = " test_prefix" ;
88+
89+ auto node_options = controller_->define_custom_node_options ();
90+ node_options.append_parameter_override (" tf_frame_prefix" , rclcpp::ParameterValue (frame_prefix));
91+ node_options.append_parameter_override (" odom_frame_id" , rclcpp::ParameterValue (odom_id));
92+ node_options.append_parameter_override (" base_frame_id" , rclcpp::ParameterValue (base_link_id));
93+
94+ SetUpController (" test_steering_controllers_library" , node_options);
95+
96+ ASSERT_EQ (controller_->on_configure (rclcpp_lifecycle::State ()), NODE_SUCCESS);
97+
98+ auto odometry_message = controller_->odom_state_msg_ ;
99+ std::string test_odom_frame_id = odometry_message.header .frame_id ;
100+ std::string test_base_frame_id = odometry_message.child_frame_id ;
101+
102+ // frame_prefix is not blank so should be prepended to the frame id's
103+ ASSERT_EQ (test_odom_frame_id, frame_prefix + " /" + odom_id);
104+ ASSERT_EQ (test_base_frame_id, frame_prefix + " /" + base_link_id);
105+ }
106+ TEST_F (SteeringControllersLibraryTest, configure_succeeds_tf_blank_prefix_no_namespace)
107+ {
108+ std::string odom_id = " odom" ;
109+ std::string base_link_id = " base_link" ;
110+ std::string frame_prefix = " " ;
111+
112+ auto node_options = controller_->define_custom_node_options ();
113+ node_options.append_parameter_override (" tf_frame_prefix" , rclcpp::ParameterValue (frame_prefix));
114+ node_options.append_parameter_override (" odom_frame_id" , rclcpp::ParameterValue (odom_id));
115+ node_options.append_parameter_override (" base_frame_id" , rclcpp::ParameterValue (base_link_id));
116+
117+ SetUpController (" test_steering_controllers_library" , node_options);
118+
119+ ASSERT_EQ (controller_->on_configure (rclcpp_lifecycle::State ()), NODE_SUCCESS);
120+
121+ auto odometry_message = controller_->odom_state_msg_ ;
122+ std::string test_odom_frame_id = odometry_message.header .frame_id ;
123+ std::string test_base_frame_id = odometry_message.child_frame_id ;
124+
125+ // frame_prefix is blank so nothing added to the frame id's
126+ ASSERT_EQ (test_odom_frame_id, odom_id);
127+ ASSERT_EQ (test_base_frame_id, base_link_id);
128+ }
129+ TEST_F (SteeringControllersLibraryTest, configure_succeeds_tf_prefix_set_namespace)
130+ {
131+ std::string test_namespace = " /test_namespace" ;
132+
133+ std::string odom_id = " odom" ;
134+ std::string base_link_id = " base_link" ;
135+ std::string frame_prefix = " test_prefix" ;
136+
137+ auto node_options = controller_->define_custom_node_options ();
138+ node_options.append_parameter_override (" tf_frame_prefix" , rclcpp::ParameterValue (frame_prefix));
139+ node_options.append_parameter_override (" odom_frame_id" , rclcpp::ParameterValue (odom_id));
140+ node_options.append_parameter_override (" base_frame_id" , rclcpp::ParameterValue (base_link_id));
141+ node_options.append_parameter_override (
142+ " traction_joints_names" , std::vector<std::string>{" joint1" , " joint2" });
143+ node_options.append_parameter_override (
144+ " steering_joints_names" , std::vector<std::string>{" joint3" , " joint4" });
145+
146+ SetUpController (" test_steering_controllers_library" , node_options, test_namespace);
147+
148+ ASSERT_EQ (controller_->on_configure (rclcpp_lifecycle::State ()), NODE_SUCCESS);
149+
150+ auto odometry_message = controller_->odom_state_msg_ ;
151+ std::string test_odom_frame_id = odometry_message.header .frame_id ;
152+ std::string test_base_frame_id = odometry_message.child_frame_id ;
153+
154+ // frame_prefix is not blank so should be prepended to the frame id's instead of the namespace
155+ ASSERT_EQ (test_odom_frame_id, frame_prefix + " /" + odom_id);
156+ ASSERT_EQ (test_base_frame_id, frame_prefix + " /" + base_link_id);
157+ }
158+ TEST_F (SteeringControllersLibraryTest, configure_succeeds_tf_tilde_prefix_set_namespace)
159+ {
160+ std::string test_namespace = " /test_namespace" ;
161+ std::string odom_id = " odom" ;
162+ std::string base_link_id = " base_link" ;
163+ std::string frame_prefix = " ~" ;
164+
165+ auto node_options = controller_->define_custom_node_options ();
166+ node_options.append_parameter_override (" tf_frame_prefix" , rclcpp::ParameterValue (frame_prefix));
167+ node_options.append_parameter_override (" odom_frame_id" , rclcpp::ParameterValue (odom_id));
168+ node_options.append_parameter_override (" base_frame_id" , rclcpp::ParameterValue (base_link_id));
169+ node_options.append_parameter_override (
170+ " traction_joints_names" , std::vector<std::string>{" joint1" , " joint2" });
171+ node_options.append_parameter_override (
172+ " steering_joints_names" , std::vector<std::string>{" joint3" , " joint4" });
173+
174+ SetUpController (" test_steering_controllers_library" , node_options, test_namespace);
175+
176+ ASSERT_EQ (controller_->on_configure (rclcpp_lifecycle::State ()), NODE_SUCCESS);
177+
178+ auto odometry_message = controller_->odom_state_msg_ ;
179+ std::string test_odom_frame_id = odometry_message.header .frame_id ;
180+ std::string test_base_frame_id = odometry_message.child_frame_id ;
181+ std::string ns_prefix = test_namespace.erase (0 , 1 ) + " /" ;
182+
183+ // frame_prefix has tilde (~) character so node namespace should be prepended to the frame id's
184+ ASSERT_EQ (test_odom_frame_id, ns_prefix + odom_id);
185+ ASSERT_EQ (test_base_frame_id, ns_prefix + base_link_id);
186+ }
187+
82188// Tests controller update_reference_from_subscribers and
83189// for position_feedback behavior
84190// when too old msg is sent i.e age_of_last_command > ref_timeout case
0 commit comments