ppplanner.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2019, SEAOS, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the <organization> nor the
16  * names of its contributors may be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Author: t-ogata@seaos.co.jp
31  *********************************************************************/
32 #ifndef PIPELINEPLANNER_H
33 #define PIPELINEPLANNER_H
34 #include <ros/ros.h>
35 #include <costmap_2d/costmap_2d.h>
36 #include <geometry_msgs/PoseStamped.h>
37 #include <geometry_msgs/PoseArray.h>
38 #include <geometry_msgs/Pose.h>
39 #include <geometry_msgs/Point.h>
40 #include <nav_msgs/Path.h>
41 #include <tf/transform_datatypes.h>
42 #include <vector>
44 #include <nav_msgs/GetPlan.h>
45 #include <dynamic_reconfigure/server.h>
46 //#include <dynamic_reconfigure/IntParameter.h>
47 //#include <dynamic_reconfigure/Reconfigure.h>
48 //#include <dynamic_reconfigure/Config.h>
49 //#include <dynamic_reconfigure/client.h>
50 //#include <global_planner/planner_core.h>
51 #include <pipeline_planner/PipelinePlannerConfig.h>
52 #include <pipeline_planner/RobotPosition.h>
53 #include <pipeline_planner/SegmentInfo.h>
54 #include <std_msgs/UInt32.h>
55 #include <std_msgs/Float32.h>
56 #include <std_msgs/Bool.h>
57 #include <pipeline_planner/GetReadStatus.h>
58 #include <pipeline_planner/GetRobotStatus.h>
59 #include <pipeline_planner/GetCheckpoints.h>
60 #include <pipeline_planner/GetNumofCheckpoints.h>
61 #include <pipeline_planner/InquireSegments.h>
62 #include <pipeline_planner/ReceiveCheckpoints.h>
63 #include <pipeline_planner/SetARadius.h>
64 #include <pipeline_planner/SetARightshift.h>
65 #include <navfn/navfn_ros.h>
66 #include <move_base_msgs/MoveBaseAction.h>
67 #include <boost/thread.hpp>
68 
69 namespace pipeline_planner {
70 
76  public:
86  PipelinePlanner(std::string name, costmap_2d::Costmap2D* costmap, std::string frame_id);
87 
92 
98  void initialize(std::string name, costmap_2d::Costmap2DROS* costmap_ros);
105  bool initialize(std::string name, costmap_2d::Costmap2D* costmap, std::string frame_id);
106 
113  bool ReceiveCheckpoints(pipeline_planner::ReceiveCheckpoints::Request &req,pipeline_planner::ReceiveCheckpoints::Response &res);
114 
118  void setPipeRadius(float radius);
119 // void setPipeRadius(float radius){
120 // pipe_radius_float=radius;
121 // pipe_radius_=(double)pipe_radius_float;
122 // }
123 
124  void setLethal(unsigned char lethal_cost){
125  lethal_cost_ = lethal_cost;
126  }
127 
128  void setWeight(float centre_weight){
129  centre_weight_= centre_weight;
130  }
131 
132 #if MODE==MODE_GPU
133  void setNumThread(float num_threads){
134  num_threads_= num_threads;
135  }
136 #endif
137 
138  void setStraight(bool use_straight){
139  use_straight_ = use_straight;
140  }
141 
142  void setCharge(bool charge){
143  charge_= charge;
144  }
145 
146  void setTimeDisplay(bool time_display){
147  time_display_ = time_display;
148  }
149 
150  void setTorchArea(bool use_torch,float torch_area_x,float torch_area_y){
151  use_torch_=use_torch;
152  torch_area_x_=torch_area_x;
153  torch_area_y_=torch_area_y;
154  }
155 
156 
164  bool makePlan(const geometry_msgs::PoseStamped& start,
165  const geometry_msgs::PoseStamped& goal,
166  std::vector<geometry_msgs::PoseStamped>& plan);
167 
168  private:
169 
175  void reconfigureCB(pipeline_planner::PipelinePlannerConfig &config,uint32_t level);
176 
183  bool getReadStatus(pipeline_planner::GetReadStatus::Request &req,pipeline_planner::GetReadStatus::Response &res){
184  res.read_status=read_status_.data;
185  return true;
186  }
187 
194  bool getRobotStatus(pipeline_planner::GetRobotStatus::Request &req,pipeline_planner::GetRobotStatus::Response &res){
195  res.robot_status=robot_status_.data;
196  return true;
197  }
198 
205  bool getCheckpoints(pipeline_planner::GetCheckpoints::Request &req,pipeline_planner::GetCheckpoints::Response &res){
206  int i,size;
207  size=check_points_.size();
208  res.checkpoints.resize(size);
209  for(i=0;i<size;i++){
210  res.checkpoints[i]=check_points_.at(i);
211  };
212  if(openclose_==1){
213  res.openclose=1;
214  } else if(openclose_==2){
215  res.openclose=2;
216  } else {
217  res.openclose=3;
218  };
219  return true;
220  }
221 
228  bool getNumofCheckpoints(pipeline_planner::GetNumofCheckpoints::Request &req,pipeline_planner::GetNumofCheckpoints::Response &res){
229  //res.num_checkpoints=read_status_.data;
230  res.num_checkpoints=check_points_.size();
231  return true;
232  }
233 
240  bool InquireSegments(pipeline_planner::InquireSegments::Request &req,pipeline_planner::InquireSegments::Response &res);
241 
257  bool SetARadius(pipeline_planner::SetARadius::Request &req,pipeline_planner::SetARadius::Response &res);
258 
270  bool SetARightshift(pipeline_planner::SetARightshift::Request &req,pipeline_planner::SetARightshift::Response &res);
271 
278  //void SubscribeCheckpoints(const geometry_msgs::PoseArray::ConstPtr& checkpoints);
279 
284  void PublishCheckpointsResult(std_msgs::UInt32 result);
285 
296  bool InPipeSegment(const geometry_msgs::PoseStamped& pose,double radius,double start_edge_radius,double end_edge_radius,double tolerance,int index);
297 
305  bool isBehindInaSegment(int idx,
306  const geometry_msgs::PoseStamped& start,
307  const geometry_msgs::PoseStamped& goal);
308 
315  bool hasNoCross(const int endpoint,const std::vector<geometry_msgs::PoseStamped> check_points);
316 
325  int costCheck(int endpoint);
326 
332  bool DistanceFromCentre(int endpoint);
333 
340  bool InitSegInfo();
341 
350  bool VeilCostmap(const std::vector<int> segids,const int startindex,
351  const int goalindex,const geometry_msgs::PoseStamped& start);
352 
361  bool ConnectPoints(const geometry_msgs::PoseStamped& start,const geometry_msgs::PoseStamped& goal,
362  const std::vector<int> segids,std::vector<geometry_msgs::PoseStamped>& plan);
363 
371  bool DrawOpenSegment(const geometry_msgs::PoseStamped init_point,
372  const geometry_msgs::PoseStamped end_point,
373  std::vector<geometry_msgs::PoseStamped>& plan);
374 
375  std::vector<double> dist_from_pipe_centre_;
376 
377  dynamic_reconfigure::Server<pipeline_planner::PipelinePlannerConfig> *dsrv_;
378 
386  bool knowRobotPosition(const geometry_msgs::Pose pose,int& ID,
387  double& distance);
388  //struct used in the knowRobotPosition function
389  struct asegment {
390  int id; int part; double dist; bool in;
391  };
392 
405  bool whereInaPipeSegment(const geometry_msgs::Pose pose,const int id,const double radius,const double sradius,const double eradius,int& part,double &dist,double tolerance);
406 
411  void publishPlan(const std::vector<geometry_msgs::PoseStamped>& path);
412 
420  void makePipeline();
421  void makePipeline(bool legal);
422 
426  void calcPipeline(const int numcheckpoints,const double *stonex,const double *stoney,const bool isClose,const double *radii,const double *sradii,const double *eradii,const double origin_x,const double origin_y,const unsigned int costsizex,const unsigned int costsizey,const double resolution,int *data);
427 
432  void callbackgoal(const move_base_msgs::MoveBaseActionGoal::ConstPtr& goal);
433 
438  void callbackRobotPose(const geometry_msgs::Pose::ConstPtr& pose);
439 
443  void informRobotPose();
444 
450  void TimeDisplay(const bool time_display,const double duration);
451 
469  bool TakeLocalGoal(const geometry_msgs::PoseStamped& start,
470  const geometry_msgs::PoseStamped& goal,
471  geometry_msgs::PoseStamped& local_goal,int& err);
472 
489  int CrossTorchArea(const double tx,const double ty,
490  const double sx,const double sy,
491  const double ex,const double ey,
492  double& bx,double& by);
493 
500  double TakeSegmentRadius(const double contained_radius);
501 
503  std::string gained_frame_id_;
505  std::vector<geometry_msgs::PoseStamped> check_points_;
506  nav_msgs::OccupancyGrid pipeline_;
507  std::vector<double> segment_lengths_;
508  std::vector<pipeline_planner::SegmentInfo> segment_infos_;
509  //ros::Subscriber sub_checkpoints_;
511  //global_planner::GlobalPlanner* global_planner_;
514  std::string name_;
515  // status of reading checkpoints
516  // status is contained in read_status_.data
517  // 1:not yet read, 2:reading now, 3:OK, 4:read but empty,
518  // 5:route overlaps obstacle, 6:out of costmap, 7:openclose flag error,
519  // 8:having a crossing, others:unknown error
520  std_msgs::UInt32 read_status_;
521  // status of a robot
522  // 1:not yet initialised, 2:ready,
523  // 3:the robot is on the way to a goal or reached the goal,
524  // 4:start is out of pipeline, 5:all pipe segments include start,
525  // 6:goal is out of pipeline, 7:all pipe segments include goal,
526  // 8:goal is behind start in a open pipeline,
527  // 9:invalid check points, 10:global planner fails to make a plan,
528  // 11:goal is behind start in one pipe segment
529  // 12:now calculating global path
530  std_msgs::UInt32 robot_status_;
537  double pipe_radius_;
538  //double pipe_radius_float;
539  unsigned char lethal_cost_;
541  //1:close, 2:open
543  double tolerance_;
552  boost::thread* thread_robot_position_;
553 
554  //taking straight line model
556  bool charge_;
557  //fixing pipe radius in each pipe segment or not
559  //whether displaying calculation time or not
562  std_msgs::Float32 consumed_time_;
563  //robot position to inform
564  geometry_msgs::Pose robot_position_;
565  boost::mutex mutex_robot_position_;
566  //Subscription of actionlib
569  //torch model
572 
573  bool debug;
574 
575  //CUDA
576 #if MODE==MODE_GPU
577 
585  bool VeilCostmap_cuda(const std::vector<int> segids,const int startindex,
586  const int goalindex,const geometry_msgs::PoseStamped& start);
587 
593  bool DistanceFromCentre_cuda(int endpoint);
594 
595  void ThreadNumberAdjusment(bool debug);
596 
598 #endif
599 
600  };
601 };
602 #endif
void makePipeline()
To make a pipeline and publish it as a topic Pipeline is constructed from check_points_. Validity of checkpoints_ must be checked in advance. Publication data values 0:in the pipeline, 100:out of the pipeline.
std::vector< pipeline_planner::SegmentInfo > segment_infos_
Definition: ppplanner.h:508
bool ReceiveCheckpoints(pipeline_planner::ReceiveCheckpoints::Request &req, pipeline_planner::ReceiveCheckpoints::Response &res)
Reception of checkpoints.
bool DistanceFromCentre_cuda(int endpoint)
Calculation of cell&#39;s distance from pipe centre.
void initialize(std::string name, costmap_2d::Costmap2DROS *costmap_ros)
Initialisation function for the Planner.
bool VeilCostmap_cuda(const std::vector< int > segids, const int startindex, const int goalindex, const geometry_msgs::PoseStamped &start)
To veil costmap other than that in pipeline segments.
bool InitSegInfo()
Initialisation of segment info.
void TimeDisplay(const bool time_display, const double duration)
Display consumed time on makePlan function.
bool getRobotStatus(pipeline_planner::GetRobotStatus::Request &req, pipeline_planner::GetRobotStatus::Response &res)
Get the status of a robot.
Definition: ppplanner.h:194
int CrossTorchArea(const double tx, const double ty, const double sx, const double sy, const double ex, const double ey, double &bx, double &by)
Whether the line segment crosses the torch area boundary or not.
ros::ServiceServer set_a_radius_srv_
Definition: ppplanner.h:550
void setLethal(unsigned char lethal_cost)
Definition: ppplanner.h:124
void callbackgoal(const move_base_msgs::MoveBaseActionGoal::ConstPtr &goal)
Callback function for reception of actionlib goal.
nav_msgs::OccupancyGrid pipeline_
Definition: ppplanner.h:506
bool isBehindInaSegment(int idx, const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal)
Whether the goal point is behind the start point in a pipe segment.
void setNumThread(float num_threads)
Definition: ppplanner.h:133
void setStraight(bool use_straight)
Definition: ppplanner.h:138
void informRobotPose()
loop for informing the robot position by a thread
ros::ServiceServer set_a_rightshift_srv_
Definition: ppplanner.h:551
std_msgs::UInt32 robot_status_
Definition: ppplanner.h:530
ros::ServiceServer receive_checkpoints_srv_
Definition: ppplanner.h:549
ros::ServiceServer read_state_srv_
Definition: ppplanner.h:544
ros::ServiceServer get_checkpoints_srv_
Definition: ppplanner.h:546
std_msgs::Float32 consumed_time_
Definition: ppplanner.h:562
void callbackRobotPose(const geometry_msgs::Pose::ConstPtr &pose)
Callback function for reception of robot position.
void publishPlan(const std::vector< geometry_msgs::PoseStamped > &path)
To publish a path.
bool hasNoCross(const int endpoint, const std::vector< geometry_msgs::PoseStamped > check_points)
To check whether a sequence of checkpoints has a crossing or not.
Provides a global planner that will make a route along check points gained from topic. This planner uses global_planner.
Definition: ppplanner.h:75
ros::ServiceServer robot_state_srv_
Definition: ppplanner.h:545
ros::Publisher pub_robot_position_
Definition: ppplanner.h:534
navfn::NavfnROS * navfn_planner_
Definition: ppplanner.h:512
void reconfigureCB(pipeline_planner::PipelinePlannerConfig &config, uint32_t level)
Callback function for dynamic reconfiguration.
bool DrawOpenSegment(const geometry_msgs::PoseStamped init_point, const geometry_msgs::PoseStamped end_point, std::vector< geometry_msgs::PoseStamped > &plan)
To substitute the plan along two points.
bool InquireSegments(pipeline_planner::InquireSegments::Request &req, pipeline_planner::InquireSegments::Response &res)
Inquiring segments information.
costmap_2d::Costmap2D * navfn_costmap_
Definition: ppplanner.h:513
bool knowRobotPosition(const geometry_msgs::Pose pose, int &ID, double &distance)
To know the position of a robot in the pipeline.
bool ConnectPoints(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, const std::vector< int > segids, std::vector< geometry_msgs::PoseStamped > &plan)
To substitute plan by connecting start point, checkpoints and goal point.
void setPipeRadius(float radius)
substitute pipe_radius_ value when it is called from dynamic reconfigure
boost::thread * thread_robot_position_
Definition: ppplanner.h:552
bool makePlan(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
Given a goal pose in the world, compute a plan.
PipelinePlanner()
Constructor for the PipelinePlanner.
ros::ServiceServer inquire_segments_srv_
Definition: ppplanner.h:548
dynamic_reconfigure::Server< pipeline_planner::PipelinePlannerConfig > * dsrv_
Definition: ppplanner.h:377
void PublishCheckpointsResult(std_msgs::UInt32 result)
Callback function for subscription of checkpoints data from topic.
geometry_msgs::Pose robot_position_
Definition: ppplanner.h:564
costmap_2d::Costmap2D * costmap_
Definition: ppplanner.h:504
int costCheck(int endpoint)
To check received checkpoints whether it has a problem on costmap or not.
bool getReadStatus(pipeline_planner::GetReadStatus::Request &req, pipeline_planner::GetReadStatus::Response &res)
Get the status of reading checkpoints.
Definition: ppplanner.h:183
ros::Subscriber sub_movebase_goal_
Definition: ppplanner.h:568
void calcPipeline(const int numcheckpoints, const double *stonex, const double *stoney, const bool isClose, const double *radii, const double *sradii, const double *eradii, const double origin_x, const double origin_y, const unsigned int costsizex, const unsigned int costsizey, const double resolution, int *data)
To calculate the pipeline without GPU.
bool getNumofCheckpoints(pipeline_planner::GetNumofCheckpoints::Request &req, pipeline_planner::GetNumofCheckpoints::Response &res)
Get the status of reading checkpoints.
Definition: ppplanner.h:228
ros::ServiceServer get_numof_checkpoints_srv_
Definition: ppplanner.h:547
std::vector< geometry_msgs::PoseStamped > check_points_
Definition: ppplanner.h:505
void setTorchArea(bool use_torch, float torch_area_x, float torch_area_y)
Definition: ppplanner.h:150
std::vector< double > segment_lengths_
Definition: ppplanner.h:507
bool InPipeSegment(const geometry_msgs::PoseStamped &pose, double radius, double start_edge_radius, double end_edge_radius, double tolerance, int index)
Verification of whether the position is in the pipeline segment or not.
bool SetARadius(pipeline_planner::SetARadius::Request &req, pipeline_planner::SetARadius::Response &res)
Service to set a pipeline segment radius.
bool VeilCostmap(const std::vector< int > segids, const int startindex, const int goalindex, const geometry_msgs::PoseStamped &start)
To veil costmap other than that in pipeline segments.
bool DistanceFromCentre(int endpoint)
Calculation of cell&#39;s distance from pipe centre.
bool getCheckpoints(pipeline_planner::GetCheckpoints::Request &req, pipeline_planner::GetCheckpoints::Response &res)
Get check points.
Definition: ppplanner.h:205
bool whereInaPipeSegment(const geometry_msgs::Pose pose, const int id, const double radius, const double sradius, const double eradius, int &part, double &dist, double tolerance)
To know the position of a robot in a pipe segment.
void setTimeDisplay(bool time_display)
Definition: ppplanner.h:146
double TakeSegmentRadius(const double contained_radius)
Taking pipline radius in a given pipeline segment.
bool TakeLocalGoal(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, geometry_msgs::PoseStamped &local_goal, int &err)
To make local goal on torch model.
void setWeight(float centre_weight)
Definition: ppplanner.h:128
bool SetARightshift(pipeline_planner::SetARightshift::Request &req, pipeline_planner::SetARightshift::Response &res)
Service to set a right shift value for a pipeline segment.
std::vector< double > dist_from_pipe_centre_
Definition: ppplanner.h:375
~PipelinePlanner()
Destructor for the planner.


pipeline_planner
Author(s): seaos
autogenerated on Thu Jul 4 2019 19:55:39