Skip to content

Commit c611d4b

Browse files
committed
Added EDT querying
1 parent 9662404 commit c611d4b

File tree

4 files changed

+100
-9
lines changed

4 files changed

+100
-9
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ target_link_libraries(pubCamPose ${catkin_LIBRARIES})
4848
add_executable(pcNoise src/pcNoise.cpp)
4949
target_link_libraries(pcNoise ${catkin_LIBRARIES})
5050

51+
add_executable(queryPt src/pubQueryPoint.cpp)
52+
target_link_libraries(queryPt ${catkin_LIBRARIES})
5153

5254

5355

include/FastPlannerOctomap/Map.h

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Map3D
2828
bool ifUpdateMap(Eigen::Vector3d pt1);
2929
void setStartPosition(Eigen::Vector3d pt);
3030
void setMapRange(Eigen::Vector3d pt);
31+
bool isInMap(octomap::point3d pt);
3132
void setMinMax();
3233
void erase();
3334
void getCostMapMarker(visualization_msgs::MarkerArray m, DynamicEDTOctomap *ptr, ros::Publisher pub);
@@ -137,6 +138,16 @@ void Map3D::OctoMapEDT::setMapRange(Eigen::Vector3d pt)
137138

138139
}
139140

141+
/////////////////////////////////////////////////////////////////////////////////////////
142+
/** check if a point lies in map or not **/
143+
bool Map3D::OctoMapEDT::isInMap(octomap::point3d pt)
144+
{
145+
if ( start.x() <= pt.x() <= end.x() && start.y() <= pt.y() <= end.y() && start.z() <= pt.z() <= end.z())
146+
return true;
147+
else
148+
return false;
149+
}
150+
140151

141152
//////////////////////////////////////////////////////////////////////////////////////////
142153
/** publish the costmap obtained from the octree **/

src/Planner.cpp

+43-9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ std::vector<Eigen::Vector3d> prevTraj;
5757
visualization_msgs::MarkerArray costMap_vis;
5858

5959
ros::Publisher queryPointEdt;
60+
octomap::point3d qPt;
61+
bool queryPtUpdated = false;
6062

6163
/**********************************************************************************************************************************************************
6264
* -------------------------------------------------------------------Callbacks---------------------------------------------------------------------------*
@@ -103,14 +105,30 @@ void edt_cb(const geometry_msgs::PoseStamped msg)
103105
{
104106
octomap::point3d queryPt(msg.pose.position.x, msg.pose.position.y, msg.pose.position.z);
105107

106-
float dist = costMap3D.costMap->getDistance(queryPt);
107-
std::cout<<"Distance of queried point "<<queryPt<<" is :-> "<<dist<<std::endl;
108-
108+
std::cout<<"Here "<<std::endl;
109+
qPt = queryPt;
110+
queryPtUpdated = true;
111+
DynamicEDTOctomap costMap(5.0, costMap3D.tree, costMap3D.start, costMap3D.end, false);
112+
113+
// check if the point is in the map
109114
std_msgs::Float64 edt;
110-
edt.data = dist;
115+
if(costMap3D.isInMap(queryPt))
116+
{
117+
std::cout<<costMap3D.start<<" "<<costMap3D.end<<std::endl;
118+
std::cout<<"Inside Map"<<std::endl;
119+
std::cout<<queryPt<<std::endl;
120+
float dist = costMap.getDistance(queryPt);
121+
std::cout<<"Distance of queried point "<<queryPt<<" is :-> "<<dist<<std::endl;
111122

123+
edt.data = dist;
124+
}
125+
126+
else
127+
{
128+
edt.data = 1000;
129+
}
112130
queryPointEdt.publish(edt);
113-
131+
114132
}
115133

116134
///////////////////////////////////////////////////////////////////
@@ -166,9 +184,23 @@ void plan(ros::Publisher path, ros::Publisher map, ros::Publisher pathEDT)
166184
DynamicEDTOctomap DistMap(5.0, costMap3D.tree, costMap3D.start, costMap3D.end, false); // take unknwon region as unoccupied
167185
DistMap.update();
168186

187+
octomap::point3d qp(24.23, 0.0 ,1.25);
188+
189+
169190
// set this as the costMap in the costMap3D object
170191
costMap3D.costMap = &DistMap;
171192

193+
if(queryPtUpdated)
194+
{std::cout<<"--------------------------------------------------------------- Distance is "<<costMap3D.costMap->getDistance(qp)<<std::endl;
195+
std_msgs::Float64 edt;
196+
edt.data = costMap3D.costMap->getDistance(qPt);
197+
queryPointEdt.publish(edt);
198+
queryPtUpdated = false;
199+
200+
}
201+
202+
203+
172204
// set planning range and pass cost map to planner
173205
kAstar.init(costMap3D.start, costMap3D.end, currPose);
174206
kAstar.setEnvironment(&DistMap);
@@ -183,10 +215,12 @@ void plan(ros::Publisher path, ros::Publisher map, ros::Publisher pathEDT)
183215
{
184216
status = kAstar.search(startPose, startVel, startAcc, goalPose, goalVel, true, false, 0.0);
185217
startOver = 0;
218+
ros::spinOnce();
186219
}
187220
else
188221
{
189222
status = kAstar.search(startPose, startVel, startAcc, goalPose, goalVel, false, false, 0.0);
223+
ros::spinOnce();
190224
}
191225

192226
std::cout<<"Planner output status is >>>>> "<<status<<std::endl;
@@ -237,7 +271,7 @@ void plan(ros::Publisher path, ros::Publisher map, ros::Publisher pathEDT)
237271
generatedPathEDT.header.frame_id = "map";
238272
generatedPathEDT.poses.push_back(pEdt);
239273

240-
std::cout<<"Waypoint in current trajectory ..."<<pos<<std::endl;
274+
// std::cout<<"Waypoint in current trajectory ..."<<pos<<std::endl;
241275

242276
if(-INF<pos(0)<INF && -INF<pos(1)<INF && -INF<pos(2)<INF)
243277
{
@@ -323,8 +357,8 @@ int main(int argc, char **argv)
323357
ros::Publisher pathEDT = n.advertise<nav_msgs::Path>("/fastPlanner_path_EDT",1);
324358

325359
/** EDT Subscriber and distance publisher **/
326-
ros::Subscriber queryPoint = n.subscribe<geometry_msgs::PoseStamped>("/query_point_topic", 1, edt_cb);
327-
queryPointEdt = n.advertise<std_msgs::Float64>("/query_point_distance", 1);
360+
ros::Subscriber queryPoint = n.subscribe<geometry_msgs::PoseStamped>("/query_point_topic", 1, edt_cb);
361+
queryPointEdt = n.advertise<std_msgs::Float64>("/query_point_distance", 1);
328362

329363
ros::Rate rate(20);
330364

@@ -333,7 +367,7 @@ int main(int argc, char **argv)
333367

334368
while(!goalReceived)
335369
{
336-
std::cout<<"Waiting for goal ..."<<std::endl;
370+
//std::cout<<"Waiting for goal ..."<<std::endl;
337371
ros::spinOnce();
338372
rate.sleep();
339373

src/pubQueryPoint.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// publish query point for which edt is needed on tje topic "/query_point_topic"
2+
// calculate EDT and publish the distance on the topic "/query_point_distance"
3+
4+
#include"ros/ros.h"
5+
#include"geometry_msgs/PoseStamped.h"
6+
#include"std_msgs/Float64.h"
7+
#include<iostream>
8+
9+
ros::Subscriber edtDistSub;
10+
ros::Publisher edtQueryPub;
11+
12+
void edt_query_cb(std_msgs::Float64 msg)
13+
{
14+
std::cout<<msg.data<<std::endl;
15+
}
16+
17+
18+
int main(int argc, char **argv)
19+
{
20+
ros::init(argc, argv, "EDT_query");
21+
ros::NodeHandle nh;
22+
23+
edtQueryPub = nh.advertise<geometry_msgs::PoseStamped>("/query_point_topic", 1);
24+
edtDistSub = nh.subscribe<std_msgs::Float64>("/query_point_distance", 1, edt_query_cb);
25+
26+
while(ros::ok())
27+
{
28+
if (!ros::ok())
29+
{
30+
break;
31+
}
32+
geometry_msgs::PoseStamped queryPt;
33+
std::cout<<"Enter the query point ";
34+
std::cin>>queryPt.pose.position.x>>queryPt.pose.position.y>>queryPt.pose.position.z;
35+
36+
edtQueryPub.publish(queryPt);
37+
ros::spinOnce();
38+
39+
40+
}
41+
42+
return 0;
43+
44+
}

0 commit comments

Comments
 (0)