Skip to content

Commit

Permalink
Merge branch 'semantic' into neighbours
Browse files Browse the repository at this point in the history
  • Loading branch information
smarnav2904 authored Nov 22, 2023
2 parents 227e856 + f05249a commit 0b71f59
Show file tree
Hide file tree
Showing 8 changed files with 91,985 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ add_service_files(
FILES
GetPath.srv
SetAlgorithm.srv
GetSemanticGrid.srv
)

## Generate added messages and services with any dependencies listed here
Expand Down Expand Up @@ -193,6 +194,7 @@ if(BUILD_ROS_SUPPORT)

catkin_install_python(PROGRAMS scripts/test_algorithms.py
scripts/test_algorithms_compare.py
scripts/grid3d_class.py
scripts/test_algorithms_performance.py
scripts/test_algorithms_pseudo_random_paths.py
scripts/compare_trajectories_rviz.py
Expand Down
59 changes: 56 additions & 3 deletions include/Grid3D/grid3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <octomap/OcTree.h>
#include <nav_msgs/OccupancyGrid.h>
#include <std_msgs/Float32.h>
#include <std_msgs/Int32MultiArray.h>
#include <IfcGrid/GetSemanticGrid.h>
#include <stdio.h>
// PCL
#include <pcl/point_cloud.h>
Expand Down Expand Up @@ -63,7 +65,12 @@ class Grid3d
sensor_msgs::PointCloud2 m_pcMsg;
ros::Publisher m_pcPub, percent_computed_pub_;
ros::Timer mapTimer;

// Semantic Grid

std_msgs::Int32MultiArray semantic_grid;
std::vector<int> semanticGrid;

// Visualization of a grid slice as 2D grid map msg
nav_msgs::OccupancyGrid m_gridSliceMsg;
ros::Publisher m_gridSlicePub;
Expand Down Expand Up @@ -105,6 +112,9 @@ class Grid3d
m_octomap = NULL;
m_grid = NULL;

if(loadSemanticGrid()){
std::cout<< "Grid Loaded";
}
if(loadOctomap(m_mapPath))
{
// Compute the point-cloud associated to the ocotmap
Expand Down Expand Up @@ -216,6 +226,16 @@ class Grid3d

return m_grid[index].prob;
}

float getCellSemantic(const float &_x, const float &_y, const float &_z){

if( !isIntoMap(_x, _y, _z) )
return 0;

int index = point2grid(_x, _y, _z);

return m_grid[index].semantic;
}

std::pair<Planners::utils::Vec3i, double> getClosestObstacle(const Planners::utils::Vec3i& _coords){

Expand Down Expand Up @@ -246,6 +266,39 @@ class Grid3d

protected:

bool loadSemanticGrid() {
ros::NodeHandle n;

// Define a ROS service client
ros::ServiceClient client = n.serviceClient<IfcGrid::GetSemanticGrid>("get_semantic_grid");

IfcGrid::GetSemanticGrid srv;

// Wait for the service to become available
if (!client.waitForExistence(ros::Duration(40.0))) {
ROS_ERROR("Service get_semantic_grid unavailable");
return false;
}

// Call the service
if (client.call(srv)) {
// Process the response
// The shape and semantic grid are available in srv.response.shape and srv.response.semantic_grid
std::vector<short int> shape = srv.response.shape;
std::vector<int> int_shape(shape.begin(), shape.end());

semanticGrid = srv.response.semantic_grid;

return !semanticGrid.empty();
} else {
ROS_ERROR("Failed to call service get_semantic_grid");
return false;
}
}




#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void publishMapPointCloudTimer(const ros::TimerEvent& event)
Expand Down Expand Up @@ -530,16 +583,16 @@ class Grid3d
// m_grid[index].prob = prob;
// m_grid[index].prob = 100-dist;
m_grid[index].prob = dist;
m_grid[index].semantic = semanticGrid[index];
}
}
else{
// std::cout << "dist: " << dist << std::endl;
// m_grid[index].dist = -1.0;
m_grid[index].dist = 90.0;
m_grid[index].prob = 0.0;

}


}
else
{
Expand Down Expand Up @@ -598,4 +651,4 @@ class Grid3d
};


#endif
#endif
1 change: 0 additions & 1 deletion include/Planners/AlgorithmBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ namespace Planners
* @param _resolution resolution to save inside the world object
*/
void setWorldSize(const Vec3i &worldSize_,const double _resolution);

/**
* @brief Get the World Size, it simply call the getWorldSize method from the
* discrete world internal object
Expand Down
4 changes: 3 additions & 1 deletion include/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace Planners
{
float dist{0};
float prob{0};
int semantic{0};
};
/**
* @brief
Expand Down Expand Up @@ -221,12 +222,13 @@ namespace Planners

Planners::utils::Vec3i coordinates;

unsigned int G{0}, H{0}, C{0};
unsigned int G{0}, H{0}, C{0}, S{0};

unsigned int gplush{0};
unsigned int world_index{0};

double cost{0};
int semantic{0};

bool occuppied{false};
bool isInOpenList{false};
Expand Down
8 changes: 8 additions & 0 deletions launch/grid3d.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<launch>
<node name="semantic_grid" pkg="heuristic_planners" type="grid3d_class.py">
<param name="world_size_x" value="220" />
<param name="world_size_y" value="220" />
<param name="world_size_z" value="20" />
<param name="resolution" value="0.2" />
</node>
</launch>
Loading

0 comments on commit 0b71f59

Please sign in to comment.