-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Humble Backport] tf_prefix param: fix slashes and add to IMU Broadcaster #1102
Changes from 2 commits
79ead8b
38745aa
2c434b1
21eb1b5
765d8f6
577dd30
958976d
18487bc
3c9cf6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,17 +5,19 @@ imu_sensor_broadcaster: | |||||
description: "Defines sensor name used as prefix for its interfaces. | ||||||
Interface names are: ``<sensor_name>/orientation.x, ..., <sensor_name>/angular_velocity.x, ..., | ||||||
<sensor_name>/linear_acceleration.x.``", | ||||||
validation: { | ||||||
not_empty<>: null | ||||||
} | ||||||
# FIXME: Currently does not work with namespace | ||||||
# validation: { | ||||||
# not_empty<>: null | ||||||
# } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain a bit more in what situation it doesn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sure: I don't know exactly what's going on. However, when this is checked it then gets an error: [ERROR] [1713772814.609746661] [test_namespace.test_imu_sensor_broadcaster]: Exception thrown during init stage with message: Invalid value set during initialization for parameter 'sensor_name': Parameter 'sensor_name' cannot be empty The problem is probably that:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you have misinterpreted it. This information is need to get the proper state interfaces within the controller. Please look into the following code
|
||||||
} | ||||||
frame_id: { | ||||||
type: string, | ||||||
default_value: "", | ||||||
description: "Sensor's frame_id in which values are published.", | ||||||
validation: { | ||||||
not_empty<>: null | ||||||
} | ||||||
# FIXME: Currently does not work with namespace | ||||||
# validation: { | ||||||
# not_empty<>: null | ||||||
# } | ||||||
} | ||||||
static_covariance_orientation: { | ||||||
type: double_array, | ||||||
|
@@ -41,3 +43,13 @@ imu_sensor_broadcaster: | |||||
fixed_size<>: [9], | ||||||
} | ||||||
} | ||||||
tf_frame_prefix_enable: { | ||||||
type: bool, | ||||||
default_value: true, | ||||||
description: "Enables or disables appending tf_prefix to tf frame id's.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the need for this new parameter. Can you explain me why it is needed ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the example of diff_drive. I think you can get rid of it. |
||||||
} | ||||||
tf_frame_prefix: { | ||||||
type: string, | ||||||
default_value: "", | ||||||
description: "(optional) Prefix to be appended to the tf frames, will be added to odom_id and base_frame_id before publishing. If the parameter is empty, controller's namespace will be used.", | ||||||
rafal-gorecki marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -54,9 +54,9 @@ void IMUSensorBroadcasterTest::SetUp() | |||
|
||||
void IMUSensorBroadcasterTest::TearDown() { imu_broadcaster_.reset(nullptr); } | ||||
|
||||
void IMUSensorBroadcasterTest::SetUpIMUBroadcaster() | ||||
void IMUSensorBroadcasterTest::SetUpIMUBroadcaster(const std::string & ns) | ||||
{ | ||||
const auto result = imu_broadcaster_->init("test_imu_sensor_broadcaster"); | ||||
const auto result = imu_broadcaster_->init("test_imu_sensor_broadcaster", ns); | ||||
ASSERT_EQ(result, controller_interface::return_type::OK); | ||||
|
||||
std::vector<LoanedStateInterface> state_ifs; | ||||
|
@@ -74,13 +74,14 @@ void IMUSensorBroadcasterTest::SetUpIMUBroadcaster() | |||
imu_broadcaster_->assign_interfaces({}, std::move(state_ifs)); | ||||
} | ||||
|
||||
void IMUSensorBroadcasterTest::subscribe_and_get_message(sensor_msgs::msg::Imu & imu_msg) | ||||
void IMUSensorBroadcasterTest::subscribe_and_get_message( | ||||
sensor_msgs::msg::Imu & imu_msg, const std::string & ns) | ||||
{ | ||||
// create a new subscriber | ||||
rclcpp::Node test_subscription_node("test_subscription_node"); | ||||
rclcpp::Node test_subscription_node("test_subscription_node", ns); | ||||
auto subs_callback = [&](const sensor_msgs::msg::Imu::SharedPtr) {}; | ||||
auto subscription = test_subscription_node.create_subscription<sensor_msgs::msg::Imu>( | ||||
"/test_imu_sensor_broadcaster/imu", 10, subs_callback); | ||||
"test_imu_sensor_broadcaster/imu", 10, subs_callback); | ||||
|
||||
// call update to publish the test value | ||||
// since update doesn't guarantee a published message, republish until received | ||||
|
@@ -208,6 +209,154 @@ TEST_F(IMUSensorBroadcasterTest, SensorName_Publish_Success) | |||
} | ||||
} | ||||
|
||||
TEST_F(IMUSensorBroadcasterTest, NoPrefixNoNamespace) | ||||
{ | ||||
SetUpIMUBroadcaster(); | ||||
|
||||
std::string frame_prefix = "test_prefix"; | ||||
|
||||
// set the params 'sensor_name' and 'frame_id' | ||||
imu_broadcaster_->get_node()->set_parameter({"sensor_name", sensor_name_}); | ||||
imu_broadcaster_->get_node()->set_parameter({"frame_id", frame_id_}); | ||||
|
||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix_enable", false}); | ||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix", frame_prefix}); | ||||
|
||||
ASSERT_EQ(imu_broadcaster_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
ASSERT_EQ(imu_broadcaster_->on_activate(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
|
||||
sensor_msgs::msg::Imu imu_msg; | ||||
subscribe_and_get_message(imu_msg); | ||||
|
||||
EXPECT_EQ(imu_msg.header.frame_id, frame_id_); | ||||
} | ||||
|
||||
TEST_F(IMUSensorBroadcasterTest, PrefixNoNamespace) | ||||
{ | ||||
SetUpIMUBroadcaster(); | ||||
|
||||
std::string frame_prefix = "test_prefix"; | ||||
|
||||
// set the params 'sensor_name' and 'frame_id' | ||||
imu_broadcaster_->get_node()->set_parameter({"sensor_name", sensor_name_}); | ||||
imu_broadcaster_->get_node()->set_parameter({"frame_id", frame_id_}); | ||||
|
||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix_enable", true}); | ||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix", frame_prefix}); | ||||
|
||||
ASSERT_EQ(imu_broadcaster_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
ASSERT_EQ(imu_broadcaster_->on_activate(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
|
||||
sensor_msgs::msg::Imu imu_msg; | ||||
subscribe_and_get_message(imu_msg); | ||||
|
||||
EXPECT_EQ(imu_msg.header.frame_id, frame_prefix + frame_id_); | ||||
} | ||||
|
||||
TEST_F(IMUSensorBroadcasterTest, BlankPrefixNoNamespace) | ||||
{ | ||||
SetUpIMUBroadcaster(); | ||||
|
||||
std::string frame_prefix = ""; | ||||
|
||||
// set the params 'sensor_name' and 'frame_id' | ||||
imu_broadcaster_->get_node()->set_parameter({"sensor_name", sensor_name_}); | ||||
imu_broadcaster_->get_node()->set_parameter({"frame_id", frame_id_}); | ||||
|
||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix_enable", true}); | ||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix", frame_prefix}); | ||||
|
||||
ASSERT_EQ(imu_broadcaster_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
ASSERT_EQ(imu_broadcaster_->on_activate(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
|
||||
sensor_msgs::msg::Imu imu_msg; | ||||
subscribe_and_get_message(imu_msg); | ||||
|
||||
EXPECT_EQ(imu_msg.header.frame_id, frame_id_); | ||||
} | ||||
|
||||
TEST_F(IMUSensorBroadcasterTest, NoPrefixWithNamespace) | ||||
{ | ||||
std::string test_namespace = "test_namespace"; | ||||
|
||||
SetUpIMUBroadcaster(test_namespace); | ||||
|
||||
std::string frame_prefix = "test_prefix"; | ||||
|
||||
// set the params 'sensor_name' and 'frame_id' | ||||
imu_broadcaster_->get_node()->set_parameter({"sensor_name", sensor_name_}); | ||||
imu_broadcaster_->get_node()->set_parameter({"frame_id", frame_id_}); | ||||
|
||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix_enable", false}); | ||||
imu_broadcaster_->get_node()->set_parameter({"tf_frame_prefix", frame_prefix}); | ||||
|
||||
ASSERT_EQ(imu_broadcaster_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
ASSERT_EQ(imu_broadcaster_->on_activate(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
|
||||
sensor_msgs::msg::Imu imu_msg; | ||||
subscribe_and_get_message(imu_msg, test_namespace); | ||||
|
||||
EXPECT_EQ(imu_msg.header.frame_id, frame_id_); | ||||
} | ||||
|
||||
TEST_F(IMUSensorBroadcasterTest, PrefixWithNamespace) | ||||
{ | ||||
std::string test_namespace = "test_namespace"; | ||||
|
||||
SetUpIMUBroadcaster(test_namespace); | ||||
|
||||
std::string frame_prefix = "test_prefix"; | ||||
|
||||
// set the params 'sensor_name' and 'frame_id' | ||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("sensor_name", rclcpp::ParameterValue(sensor_name_))); | ||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("sensor_name", rclcpp::ParameterValue(sensor_name_))); | ||||
imu_broadcaster_->get_node()->set_parameter({"frame_id", frame_id_}); | ||||
|
||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("tf_frame_prefix_enable", rclcpp::ParameterValue(true))); | ||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("tf_frame_prefix", rclcpp::ParameterValue(frame_prefix))); | ||||
|
||||
ASSERT_EQ(imu_broadcaster_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
ASSERT_EQ(imu_broadcaster_->on_activate(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
|
||||
sensor_msgs::msg::Imu imu_msg; | ||||
subscribe_and_get_message(imu_msg, test_namespace); | ||||
|
||||
EXPECT_EQ(imu_msg.header.frame_id, frame_prefix + frame_id_); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't there be a slash in between? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A matter for discussion, but in my opinion the prefix can be arbitrary and the user does not necessarily have to want it to end slash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok if you want it to be prefixed without a '/' at the end, why don't you parse it directly already appending it to the frame_id? This frame_id is only used for the published message. I don't see a point of adding a tf_prefix, if it is not namespaced.
What do you think about this? |
||||
} | ||||
|
||||
TEST_F(IMUSensorBroadcasterTest, BlankPrefixWithNamespace) | ||||
{ | ||||
std::string test_namespace = "test_namespace"; | ||||
|
||||
SetUpIMUBroadcaster(test_namespace); | ||||
|
||||
std::string frame_prefix = ""; | ||||
|
||||
// set the params 'sensor_name' and 'frame_id' | ||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("sensor_name", rclcpp::ParameterValue(sensor_name_))); | ||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("sensor_name", rclcpp::ParameterValue(sensor_name_))); | ||||
imu_broadcaster_->get_node()->set_parameter({"frame_id", frame_id_}); | ||||
|
||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("tf_frame_prefix_enable", rclcpp::ParameterValue(true))); | ||||
imu_broadcaster_->get_node()->set_parameter( | ||||
rclcpp::Parameter("tf_frame_prefix", rclcpp::ParameterValue(frame_prefix))); | ||||
|
||||
ASSERT_EQ(imu_broadcaster_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
ASSERT_EQ(imu_broadcaster_->on_activate(rclcpp_lifecycle::State()), NODE_SUCCESS); | ||||
|
||||
sensor_msgs::msg::Imu imu_msg; | ||||
subscribe_and_get_message(imu_msg, test_namespace); | ||||
|
||||
EXPECT_EQ(imu_msg.header.frame_id, test_namespace + "/" + frame_id_); | ||||
} | ||||
|
||||
int main(int argc, char ** argv) | ||||
{ | ||||
::testing::InitGoogleMock(&argc, argv); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you always want to erase the first character? If the prefix is parsed without '/' then it removes the wrong character right?
I see that you did that when you are using node namespace, however, I think you need to correct the users tf_prefix as well, if he adds a '/' as well. Try to do same logic as done in #1060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense