Skip to content

Conversation

Amronos
Copy link
Contributor

@Amronos Amronos commented Oct 7, 2025

Adds a new semantic component for magnetometers/magnetic_field_sensors.
I plan to add support for magnetometers to the imu_broadcaster (this will come with a has_magnetometer parameter), as many IMUs have built-in magnetometers.
Alongside this, I also plan on adding support for filtering to the broadcaster through the filters present in imu_tools.
Please review this PR and tell me if you are okay with the above.

Comment on lines 55 to 65
void update_data_from_interfaces() const
{
for (auto i = 0u; i < data_.size(); ++i)
{
const auto data = state_interfaces_[i].get().get_optional();
if (data.has_value())
{
data_[i] = data.value();
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to have this as const?

The function name itself does the contrary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cab54b5.

}

// Array to store the data of the magnetic field sensor
mutable std::array<double, 3> data_{{0.0, 0.0, 0.0}};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's right that the only variable you have is mutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cab54b5.

Comment on lines 39 to 42
bool get_values_as_message(sensor_msgs::msg::MagneticField & message) const
{
update_data_from_interfaces();
message.magnetic_field.x = data_[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need it here too?

It is weird that it is compiling when calling a non const method from a const method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8d8718a.

@Amronos Amronos requested a review from saikishor October 8, 2025 07:06
Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you please add a line to the release notes that this component was added?

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, the test is not added to the CMakeLists.txt, please add it there!

@Amronos
Copy link
Contributor Author

Amronos commented Oct 9, 2025

Thanks for the reviews! Everything is fixed except the release notes. I will fix them once #2646 is merged, to avoid merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants