Skip to content
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

Ndt map visualization #453

Merged
merged 24 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ce99980
Update README (test commit)
Fernando-Sanz Nov 6, 2024
cea0e81
Initial map visualization
Fernando-Sanz Dec 2, 2024
5e2c033
Complete ndt map visualization publisher
Fernando-Sanz Dec 3, 2024
68d9554
Suggested changes
Fernando-Sanz Dec 3, 2024
d383820
Suggested changes
Fernando-Sanz Dec 4, 2024
330f8a9
Use covariance matrix for rotation and scale
Fernando-Sanz Dec 5, 2024
a46ddbd
Fix error and suggested changes
Fernando-Sanz Dec 9, 2024
3eef273
Add documentation
Fernando-Sanz Dec 9, 2024
1c62da9
Add eigen error handling
Fernando-Sanz Dec 10, 2024
72aeac3
Scale factor and other suggested changes
Fernando-Sanz Dec 11, 2024
679a70d
Update documentation and eigen solver usage
Fernando-Sanz Dec 12, 2024
36dd062
Boolean function and suggested changes
Fernando-Sanz Dec 12, 2024
1d30dcf
isApprox function
Fernando-Sanz Dec 12, 2024
57e2514
Warning message, scale factor and other suggested changes
Fernando-Sanz Dec 13, 2024
c28940f
Change to LifecyclePublisher
Fernando-Sanz Jan 7, 2025
8f398f6
Create .cpp file
Fernando-Sanz Jan 8, 2025
f2c4fb8
Separate creation, loading and publishing
Fernando-Sanz Jan 8, 2025
3c0516e
Change permutation order
Fernando-Sanz Jan 8, 2025
6421a3f
Fix linter errors
Fernando-Sanz Jan 10, 2025
3951e55
Suggested changes
Fernando-Sanz Jan 21, 2025
4bfacf0
Fix CI errors
Fernando-Sanz Jan 21, 2025
66db8c0
Docstrings and detail namespace
Fernando-Sanz Jan 22, 2025
db07439
Fix docstring error
Fernando-Sanz Jan 22, 2025
6d4f8aa
Fix linter errors
Fernando-Sanz Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions beluga_amcl/src/ndt_amcl_node_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ void NdtAmclNode3D::do_activate(const rclcpp_lifecycle::State&) {
qos_profile.reliable();
qos_profile.durability(rclcpp::DurabilityPolicy::TransientLocal);

map_visualization_pub_ =
create_publisher<visualization_msgs::msg::MarkerArray>("obstacle_markers", qos_profile);
map_visualization_pub_ = create_publisher<visualization_msgs::msg::MarkerArray>("obstacle_markers", qos_profile);

particle_filter_ = make_particle_filter();
{
Expand Down Expand Up @@ -257,15 +256,13 @@ beluga::NDTSensorModel<NDTMapRepresentation> NdtAmclNode3D::get_sensor_model() c
RCLCPP_INFO(get_logger(), "Loading map from %s.", map_path.c_str());

// Load the map from hdf5 file
const auto map =
beluga::io::load_from_hdf5<NDTMapRepresentation>(get_parameter("map_path").as_string());
const auto map = beluga::io::load_from_hdf5<NDTMapRepresentation>(get_parameter("map_path").as_string());

// Publish markers for map visualization
beluga_ros::msg::MarkerArray obstacle_markers = beluga_ros::assign_obstacle_map(map);
map_visualization_pub_->publish(obstacle_markers);

return beluga::NDTSensorModel<NDTMapRepresentation>{
params, map};
return beluga::NDTSensorModel<NDTMapRepresentation>{params, map};
}
auto NdtAmclNode3D::make_particle_filter() const -> std::unique_ptr<NdtAmclVariant> {
auto amcl = std::visit(
Expand Down
56 changes: 43 additions & 13 deletions beluga_ros/include/beluga_ros/ndt_ellipsoid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@

#include <beluga_ros/messages.hpp>


/**
* \file
* \brief Utilities for NDT I/O over ROS interfaces.
*/

namespace beluga_ros {

///
///
template <typename MapType, int NDim>
beluga_ros::msg::MarkerArray assign_obstacle_map(const beluga::SparseValueGrid<MapType, NDim>& grid){

beluga_ros::msg::MarkerArray assign_obstacle_map(const beluga::SparseValueGrid<MapType, NDim>& grid) {
// Get data from the grid
auto& map = grid.data();

// Clean up the message
beluga_ros::msg::MarkerArray message{};
{
beluga_ros::msg::Marker marker;
marker.ns = "obstacles";
marker.action = beluga_ros::msg::Marker::DELETE;
marker.action = beluga_ros::msg::Marker::DELETEALL;
message.markers.push_back(marker);
}

int idCount = 0;
for (const auto& [key, cell] : map)
{
for (const auto& [key, cell] : map) {
beluga_ros::msg::Marker marker;
marker.header.frame_id = "map";
marker.id = idCount++;
Expand All @@ -54,14 +53,45 @@ beluga_ros::msg::MarkerArray assign_obstacle_map(const beluga::SparseValueGrid<M
marker.pose.position.y = cell.mean[1];
marker.pose.position.z = cell.mean[2];

// Set the scale based on the covariance
marker.scale.x = 0.5f;
marker.scale.y = 0.5f;
marker.scale.z = 0.5f;
// Compute the rotation based on the covariance matrix
const auto eigenSolver = Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 3, 3>>{cell.covariance};
assert(eigenSolver.info() == Eigen::Success);
const auto eigenvectors = eigenSolver.eigenvectors().real();
const auto eigenvalues = eigenSolver.eigenvalues();

// TODO: Discuss a better way to do this (threshold and permutation)
Eigen::Matrix3d rotationMatrix;
rotationMatrix << eigenvectors.col(0), eigenvectors.col(1), eigenvectors.col(2);
const auto scalevector = Eigen::Vector3d{eigenvalues.x(), eigenvalues.y(), eigenvalues.z()};

// Permutation
if (std::abs(rotationMatrix.determinant() - 1.0) > 1e-6) {
rotationMatrix << eigenvectors.col(1), eigenvectors.col(0), eigenvectors.col(2);
scalevector = Eigen::Vector3d{eigenvalues.y(), eigenvalues.x(), eigenvalues.z()};

if (std::abs(rotationMatrix.determinant() - 1.0) > 1e-6) {
rotationMatrix << eigenvectors.col(0), eigenvectors.col(2), eigenvectors.col(1);
scalevector = Eigen::Vector3d{eigenvalues.x(), eigenvalues.z(), eigenvalues.y()};
}
}

Eigen::Quaterniond rotation;
if (std::abs(rotationMatrix.determinant() - 1.0) < 1e-6) {
rotation = Eigen::Quaterniond{rotationMatrix};
}

marker.pose.orientation.x = rotation.x();
marker.pose.orientation.y = rotation.y();
marker.pose.orientation.z = rotation.z();
marker.pose.orientation.w = rotation.w();

marker.scale.x = scalevector.x();
marker.scale.y = scalevector.y();
marker.scale.z = scalevector.z();

marker.color.r = 0.0f;
marker.color.g = 0.0f;
marker.color.b = 1.0f;
marker.color.g = 1.0f;
marker.color.b = 0.0f;
marker.color.a = 1.0f;

// Add the marker
Expand Down