-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic action server and grid_visualization class
- Loading branch information
Showing
5 changed files
with
225 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
mission/landmarks/include/landmarks/grid_visualization.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef GRID_VISUALIZATION_HPP | ||
#define GRID_VISUALIZATION_HPP | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <nav_msgs/msg/occupancy_grid.hpp> | ||
#include <vortex_msgs/msg/landmark_array.hpp> | ||
#include <geometry_msgs/msg/pose_array.hpp> | ||
|
||
namespace grid_visualization { | ||
|
||
class GridVisualization { | ||
public: | ||
explicit GridVisualization(); | ||
|
||
~GridVisualization() {}; | ||
|
||
/** | ||
* @brief Creates an occupancy grid. | ||
* | ||
* @return The created occupancy grid. | ||
*/ | ||
nav_msgs::msg::OccupancyGrid createGrid(const vortex_msgs::msg::LandmarkArray &landmarkArray); | ||
|
||
geometry_msgs::msg::PoseArray poseArrayCreater(vortex_msgs::msg::LandmarkArray landmarks); | ||
|
||
|
||
|
||
|
||
}; | ||
|
||
} // namespace GRID_VISUALIZATION | ||
|
||
#endif // GRID_VISUALIZATION_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <landmarks/grid_visualization.hpp> | ||
|
||
namespace grid_visualization { | ||
|
||
GridVisualization::GridVisualization() {} | ||
|
||
nav_msgs::msg::OccupancyGrid GridVisualization::createGrid( | ||
const vortex_msgs::msg::LandmarkArray &landmarkArray) { | ||
// Assuming some parameters for the occupancy grid | ||
int grid_width = 100; | ||
int grid_height = 100; | ||
|
||
// Initialize the OccupancyGrid message | ||
nav_msgs::msg::OccupancyGrid grid; | ||
grid.header.frame_id = "map"; | ||
grid.info.width = grid_width; | ||
grid.info.height = grid_height; | ||
grid.info.resolution = 0.1; // physical distance between two cells in meters | ||
|
||
// Initialize the data array | ||
grid.data.resize(grid_width * grid_height, | ||
0); // Initialize unoccupied grid | ||
for (const auto &landmark : landmarkArray.landmarks) { | ||
|
||
int x = landmark.odom.pose.pose.position.x / grid.info.resolution; | ||
int y = landmark.odom.pose.pose.position.y / grid.info.resolution; | ||
|
||
// Check bounds | ||
if (x >= 0 && x < grid.info.width && y >= 0 && y < grid.info.height) { | ||
// Increment the grid index | ||
grid.data[x + y * grid.info.width]++; | ||
} | ||
} | ||
|
||
return grid; | ||
} | ||
|
||
geometry_msgs::msg::PoseArray GridVisualization::poseArrayCreater(vortex_msgs::msg::LandmarkArray landmarks) { | ||
geometry_msgs::msg::PoseArray poseArray; | ||
poseArray.header.frame_id = "map"; | ||
for (const auto &landmark : landmarks.landmarks) { | ||
// Convert landmark to pose here... | ||
poseArray.poses.push_back(landmark.odom.pose.pose); | ||
} | ||
return poseArray; | ||
} | ||
|
||
} // namespace grid_visualization |
Oops, something went wrong.