Multi-robot Playground
FrontierDiscoveryNode.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Alysson Ribeiro da Silva
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. All advertising materials mentioning features or use of this software must
16  * display the following acknowledgement:
17  * This product includes software developed by Alysson Ribeiro da Silva.
18  *
19  * 4. Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * 5. The source and the binary form, and any modifications made to them
24  * may not be used for the purpose of training or improving machine learning
25  * algorithms, including but not limited to artificial intelligence, natural
26  * language processing, or data mining. This condition applies to any derivatives,
27  * modifications, or updates based on the Software code. Any usage of the source
28  * or the binary form in an AI-training dataset is considered a breach of
29  * this License.
30  *
31  * THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR
32  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
34  * EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42 
43 /*
44  * Ros and system
45  */
46 #include <vector>
47 #include "ros/ros.h"
48 #include "tf/tf.h"
49 
50 /*
51  * Messages
52  */
53 #include "nav_msgs/OccupancyGrid.h"
54 #include "geometry_msgs/Point.h"
55 #include "geometry_msgs/PoseArray.h"
56 #include "std_msgs/String.h"
57 #include "multirobotsimulations/CustomPose.h"
58 #include "multirobotsimulations/Frontiers.h"
59 #include "visualization_msgs/Marker.h"
60 #include "visualization_msgs/MarkerArray.h"
61 
62 /*
63  * Helpers
64  */
65 #include "Common.h"
66 #include "SearchAlgorithms.h"
67 
68 /*
69  * FrontierDiscoveryNode states
70  */
71 typedef enum{
72  IDLE = 0,
76 
77 /*
78  * Frontier discovery node class
79  */
81  public:
84 
85  private:
86  void Update();
87  void CSpaceCallback(nav_msgs::OccupancyGrid::ConstPtr msg);
88  void EstimatePoseCallback(multirobotsimulations::CustomPose::ConstPtr msg);
89  void ComputeCallback(std_msgs::String::ConstPtr msg);
90  void CreateMarker(visualization_msgs::Marker& input, const char* ns, const int& id, const int& seq);
91  void SetPoseArr(geometry_msgs::PoseArray& arr, const int& seq);
92  void ResetFrontierMsg(multirobotsimulations::Frontiers& msg);
93  double ComputeCentroidValue(nav_msgs::OccupancyGrid& occ, Vec2i& centroid, const double& lidarRange);
94 
95  /*
96  * Control variables
97  */
99  int aId;
100  int aSeq;
103  bool aHasPose;
104  double aRate;
105  double aYaw;
109  std::string aNamespace;
110 
111  /*
112  * Routines
113  */
114  std::vector<ros::Timer> aTimers;
115 
116  /*
117  * Subscribers
118  */
119  std::vector<ros::Subscriber> aSubscribers;
120 
121  /*
122  * Advertisers
123  */
124  ros::Publisher aClusterMarkerPub;
125  ros::Publisher aFrontiersMapPub;
126  ros::Publisher aFrontiersClustersPub;
127 
128  /*
129  * Messages
130  */
131  multirobotsimulations::Frontiers aFrontierMsg;
132  geometry_msgs::PoseArray aPoseArrMsg;
133  geometry_msgs::Pose aWorldPos;
134  nav_msgs::OccupancyGrid aOcc;
135  nav_msgs::OccupancyGrid aFrontiersMap;
136  visualization_msgs::Marker aClusterMarkerMsg;
137 
138  /*
139  * Helpers
140  */
141  std::list<Vec2i> aPath;
142  std::vector<Vec2i> aFrontiers;
143  std::vector<Vec2i> aCentroids;
144  std::vector<Vec2i> aFilteredCentroids;
145  std::vector<std::vector<Vec2i>> aClusters;
146  std::vector<std::vector<Vec2i>> aFilteredClusters;
147 };
FrontierDiscoveryNode::SetPoseArr
void SetPoseArr(geometry_msgs::PoseArray &arr, const int &seq)
FrontierDiscoveryNode::ComputeCentroidValue
double ComputeCentroidValue(nav_msgs::OccupancyGrid &occ, Vec2i &centroid, const double &lidarRange)
SearchAlgorithms.h
FrontierDiscoveryNode::aMaxLidarRange
double aMaxLidarRange
Definition: FrontierDiscoveryNode.h:106
FrontierDiscoveryNode::aClusterMarkerPub
ros::Publisher aClusterMarkerPub
Definition: FrontierDiscoveryNode.h:124
FrontierDiscoveryNode::aRate
double aRate
Definition: FrontierDiscoveryNode.h:104
Vec2i
Definition: Common.h:59
IDLE
@ IDLE
Definition: FrontierDiscoveryNode.h:72
FrontierDiscoveryNode
Definition: FrontierDiscoveryNode.h:80
FrontierDiscoveryNode::aQueueSize
int aQueueSize
Definition: FrontierDiscoveryNode.h:98
FrontierDiscoveryNode::aState
FrontierState aState
Definition: FrontierDiscoveryNode.h:108
FrontierDiscoveryNode::aSeq
int aSeq
Definition: FrontierDiscoveryNode.h:100
FrontierDiscoveryNode::CreateMarker
void CreateMarker(visualization_msgs::Marker &input, const char *ns, const int &id, const int &seq)
FrontierDiscoveryNode::~FrontierDiscoveryNode
~FrontierDiscoveryNode()
FrontierDiscoveryNode::aFrontiers
std::vector< Vec2i > aFrontiers
Definition: FrontierDiscoveryNode.h:142
FrontierDiscoveryNode::aTimers
std::vector< ros::Timer > aTimers
Definition: FrontierDiscoveryNode.h:114
FrontierDiscoveryNode::aPath
std::list< Vec2i > aPath
Definition: FrontierDiscoveryNode.h:141
FINISHED
@ FINISHED
Definition: FrontierDiscoveryNode.h:74
FrontierDiscoveryNode::EstimatePoseCallback
void EstimatePoseCallback(multirobotsimulations::CustomPose::ConstPtr msg)
FrontierDiscoveryNode::aClusterMarkerMsg
visualization_msgs::Marker aClusterMarkerMsg
Definition: FrontierDiscoveryNode.h:136
FrontierDiscoveryNode::aFrontierMsg
multirobotsimulations::Frontiers aFrontierMsg
Definition: FrontierDiscoveryNode.h:131
FrontierDiscoveryNode::aReceivedCSpace
bool aReceivedCSpace
Definition: FrontierDiscoveryNode.h:102
FrontierDiscoveryNode::aClusterDetectionMin
int aClusterDetectionMin
Definition: FrontierDiscoveryNode.h:101
PROCESSING
@ PROCESSING
Definition: FrontierDiscoveryNode.h:73
FrontierDiscoveryNode::aWorldPos
geometry_msgs::Pose aWorldPos
Definition: FrontierDiscoveryNode.h:133
FrontierDiscoveryNode::aFrontiersMapPub
ros::Publisher aFrontiersMapPub
Definition: FrontierDiscoveryNode.h:125
FrontierDiscoveryNode::aPos
Vec2i aPos
Definition: FrontierDiscoveryNode.h:107
FrontierDiscoveryNode::aCentroids
std::vector< Vec2i > aCentroids
Definition: FrontierDiscoveryNode.h:143
FrontierDiscoveryNode::FrontierDiscoveryNode
FrontierDiscoveryNode()
FrontierDiscoveryNode::ComputeCallback
void ComputeCallback(std_msgs::String::ConstPtr msg)
FrontierState
FrontierState
Definition: FrontierDiscoveryNode.h:71
FrontierDiscoveryNode::aFrontiersMap
nav_msgs::OccupancyGrid aFrontiersMap
Definition: FrontierDiscoveryNode.h:135
FrontierDiscoveryNode::aFilteredCentroids
std::vector< Vec2i > aFilteredCentroids
Definition: FrontierDiscoveryNode.h:144
FrontierDiscoveryNode::aFrontiersClustersPub
ros::Publisher aFrontiersClustersPub
Definition: FrontierDiscoveryNode.h:126
Common.h
FrontierDiscoveryNode::aHasPose
bool aHasPose
Definition: FrontierDiscoveryNode.h:103
FrontierDiscoveryNode::ResetFrontierMsg
void ResetFrontierMsg(multirobotsimulations::Frontiers &msg)
FrontierDiscoveryNode::aPoseArrMsg
geometry_msgs::PoseArray aPoseArrMsg
Definition: FrontierDiscoveryNode.h:132
FrontierDiscoveryNode::aNamespace
std::string aNamespace
Definition: FrontierDiscoveryNode.h:109
FrontierDiscoveryNode::aFilteredClusters
std::vector< std::vector< Vec2i > > aFilteredClusters
Definition: FrontierDiscoveryNode.h:146
FrontierDiscoveryNode::aId
int aId
Definition: FrontierDiscoveryNode.h:99
FrontierDiscoveryNode::aOcc
nav_msgs::OccupancyGrid aOcc
Definition: FrontierDiscoveryNode.h:134
FrontierDiscoveryNode::Update
void Update()
FrontierDiscoveryNode::CSpaceCallback
void CSpaceCallback(nav_msgs::OccupancyGrid::ConstPtr msg)
FrontierDiscoveryNode::aYaw
double aYaw
Definition: FrontierDiscoveryNode.h:105
FrontierDiscoveryNode::aClusters
std::vector< std::vector< Vec2i > > aClusters
Definition: FrontierDiscoveryNode.h:145
FrontierDiscoveryNode::aSubscribers
std::vector< ros::Subscriber > aSubscribers
Definition: FrontierDiscoveryNode.h:119