Multi-robot Playground
RandomizedSocialWelfareNode.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 <random>
48 #include "ros/ros.h"
49 
50 /*
51  * Messages
52  */
53 #include "nav_msgs/OccupancyGrid.h"
54 #include "std_msgs/String.h"
55 #include "std_msgs/Int8MultiArray.h"
56 #include "multirobotsimulations/CustomPose.h"
57 #include "multirobotsimulations/Frontiers.h"
58 #include "visualization_msgs/Marker.h"
59 
60 /*
61  * Helpers
62  */
63 #include "Common.h"
64 
65 typedef enum {
68  state_idle = 11,
77 
79  public:
82 
83  private:
84  void EstimatePoseCallback(multirobotsimulations::CustomPose::ConstPtr msg);
85  void ClustersCallback(multirobotsimulations::Frontiers::ConstPtr msg);
86  void SubGoalFinishCallback(std_msgs::String::ConstPtr msg);
87  void CSpaceCallback(nav_msgs::OccupancyGrid::ConstPtr msg);
88  void SetExploringCallback(std_msgs::String::ConstPtr msg);
89  void SetBasestationCallback(std_msgs::String::ConstPtr msg);
90  void SetIdleCallback(std_msgs::String::ConstPtr msg);
91 
92  void ChangeState(const ExplorerState& newState);
93  int SelectFrontier(multirobotsimulations::Frontiers& centroids, tf::Vector3& selectFrontierWorld);
94  void CreateMarker(visualization_msgs::Marker& input, const char* ns, const int& id, const int& seq);
95  void SetGoal(const tf::Vector3& goal);
96  void Update();
97 
98  /*
99  * Control variables
100  */
102  int aRate;
103  int aRobots;
104  int aId;
105  bool aHasPose;
106  bool aHasOcc;
107  bool aDirty;
108  bool aFirst;
109  double aDeltaTime;
111  ros::Time aLastTime;
112  tf::Vector3 aWorldPos;
113  tf::Vector3 aGoalFrontier;
114  tf::Vector3 aGoalBasestation;
115  std::string aNamespace;
117 
118  /*
119  * Routines
120  */
121  std::vector<ros::Timer> aTimers;
122 
123  /*
124  * Subscribers
125  */
126  std::vector<ros::Subscriber> aSubscribers;
127 
128  /*
129  * Advertisers
130  */
131  ros::Publisher aGoalPublisher;
133 
134  /*
135  * Messages
136  */
137  multirobotsimulations::Frontiers aFrontierCentroidsMsg;
138  nav_msgs::OccupancyGrid aCSpaceMsg;
139 
140  /*
141  * Extension from Yamauchi-based policy
142  */
143  bool CheckNear();
144  int RandomizedFrontierSelection(multirobotsimulations::Frontiers& centroids, tf::Vector3& selectFrontierWorld);
145  void CommCallback(std_msgs::Int8MultiArray::ConstPtr msg);
146 
147  // extension control
148  bool aHasComm;
149 
150  // extension messages
151  std_msgs::Int8MultiArray aCommMsg;
152 
153  // extension helpers
154  std::unique_ptr<std::mt19937> aRandomNumberGenerator;
155  std::random_device aRandomNumberDevice;
156 };
RandomizedSocialWelfareNode::aRobots
int aRobots
Definition: RandomizedSocialWelfareNode.h:103
RandomizedSocialWelfareNode::aCSpaceMsg
nav_msgs::OccupancyGrid aCSpaceMsg
Definition: RandomizedSocialWelfareNode.h:138
RandomizedSocialWelfareNode::aFirst
bool aFirst
Definition: RandomizedSocialWelfareNode.h:108
state_idle
@ state_idle
Definition: RandomizedSocialWelfareNode.h:68
RandomizedSocialWelfareNode::aTimers
std::vector< ros::Timer > aTimers
Definition: RandomizedSocialWelfareNode.h:121
RandomizedSocialWelfareNode::CommCallback
void CommCallback(std_msgs::Int8MultiArray::ConstPtr msg)
RandomizedSocialWelfareNode::ChangeState
void ChangeState(const ExplorerState &newState)
state_back_to_base
@ state_back_to_base
Definition: RandomizedSocialWelfareNode.h:70
RandomizedSocialWelfareNode::SelectFrontier
int SelectFrontier(multirobotsimulations::Frontiers &centroids, tf::Vector3 &selectFrontierWorld)
ExplorerState
ExplorerState
Definition: RandomizedSocialWelfareNode.h:65
state_back_to_base_finished
@ state_back_to_base_finished
Definition: RandomizedSocialWelfareNode.h:71
RandomizedSocialWelfareNode::aHasOcc
bool aHasOcc
Definition: RandomizedSocialWelfareNode.h:106
RandomizedSocialWelfareNode::aGoalPublisher
ros::Publisher aGoalPublisher
Definition: RandomizedSocialWelfareNode.h:131
Vec2i
Definition: Common.h:59
RandomizedSocialWelfareNode::aNamespace
std::string aNamespace
Definition: RandomizedSocialWelfareNode.h:115
RandomizedSocialWelfareNode::SetBasestationCallback
void SetBasestationCallback(std_msgs::String::ConstPtr msg)
RandomizedSocialWelfareNode::aRate
int aRate
Definition: RandomizedSocialWelfareNode.h:102
RandomizedSocialWelfareNode::RandomizedSocialWelfareNode
RandomizedSocialWelfareNode()
RandomizedSocialWelfareNode::Update
void Update()
state_set_back_to_base
@ state_set_back_to_base
Definition: RandomizedSocialWelfareNode.h:74
RandomizedSocialWelfareNode::RandomizedFrontierSelection
int RandomizedFrontierSelection(multirobotsimulations::Frontiers &centroids, tf::Vector3 &selectFrontierWorld)
RandomizedSocialWelfareNode::ClustersCallback
void ClustersCallback(multirobotsimulations::Frontiers::ConstPtr msg)
RandomizedSocialWelfareNode::CheckNear
bool CheckNear()
RandomizedSocialWelfareNode::EstimatePoseCallback
void EstimatePoseCallback(multirobotsimulations::CustomPose::ConstPtr msg)
RandomizedSocialWelfareNode::aOccPos
Vec2i aOccPos
Definition: RandomizedSocialWelfareNode.h:110
RandomizedSocialWelfareNode::aDeltaTime
double aDeltaTime
Definition: RandomizedSocialWelfareNode.h:109
RandomizedSocialWelfareNode::aFrontierComputePublisher
ros::Publisher aFrontierComputePublisher
Definition: RandomizedSocialWelfareNode.h:132
RandomizedSocialWelfareNode::~RandomizedSocialWelfareNode
~RandomizedSocialWelfareNode()
RandomizedSocialWelfareNode::aGoalBasestation
tf::Vector3 aGoalBasestation
Definition: RandomizedSocialWelfareNode.h:114
RandomizedSocialWelfareNode::aCurrentState
ExplorerState aCurrentState
Definition: RandomizedSocialWelfareNode.h:116
RandomizedSocialWelfareNode::aLastTime
ros::Time aLastTime
Definition: RandomizedSocialWelfareNode.h:111
state_waiting_centroids
@ state_waiting_centroids
Definition: RandomizedSocialWelfareNode.h:73
RandomizedSocialWelfareNode::SetExploringCallback
void SetExploringCallback(std_msgs::String::ConstPtr msg)
RandomizedSocialWelfareNode
Definition: RandomizedSocialWelfareNode.h:78
ExplorerState
ExplorerState
Definition: Alysson2024Node.h:68
state_planning
@ state_planning
Definition: RandomizedSocialWelfareNode.h:75
RandomizedSocialWelfareNode::aId
int aId
Definition: RandomizedSocialWelfareNode.h:104
RandomizedSocialWelfareNode::aGoalFrontier
tf::Vector3 aGoalFrontier
Definition: RandomizedSocialWelfareNode.h:113
Common.h
RandomizedSocialWelfareNode::aDirty
bool aDirty
Definition: RandomizedSocialWelfareNode.h:107
RandomizedSocialWelfareNode::aHasComm
bool aHasComm
Definition: RandomizedSocialWelfareNode.h:148
RandomizedSocialWelfareNode::aFrontierCentroidsMsg
multirobotsimulations::Frontiers aFrontierCentroidsMsg
Definition: RandomizedSocialWelfareNode.h:137
state_exploring
@ state_exploring
Definition: RandomizedSocialWelfareNode.h:67
RandomizedSocialWelfareNode::aWorldPos
tf::Vector3 aWorldPos
Definition: RandomizedSocialWelfareNode.h:112
RandomizedSocialWelfareNode::SetIdleCallback
void SetIdleCallback(std_msgs::String::ConstPtr msg)
RandomizedSocialWelfareNode::CreateMarker
void CreateMarker(visualization_msgs::Marker &input, const char *ns, const int &id, const int &seq)
RandomizedSocialWelfareNode::SetGoal
void SetGoal(const tf::Vector3 &goal)
RandomizedSocialWelfareNode::aHasPose
bool aHasPose
Definition: RandomizedSocialWelfareNode.h:105
state_compute_centroids
@ state_compute_centroids
Definition: RandomizedSocialWelfareNode.h:72
state_select_frontier
@ state_select_frontier
Definition: RandomizedSocialWelfareNode.h:66
RandomizedSocialWelfareNode::aRandomNumberDevice
std::random_device aRandomNumberDevice
Definition: RandomizedSocialWelfareNode.h:155
RandomizedSocialWelfareNode::aRandomNumberGenerator
std::unique_ptr< std::mt19937 > aRandomNumberGenerator
Definition: RandomizedSocialWelfareNode.h:154
state_exploration_finished
@ state_exploration_finished
Definition: RandomizedSocialWelfareNode.h:69
RandomizedSocialWelfareNode::aSubscribers
std::vector< ros::Subscriber > aSubscribers
Definition: RandomizedSocialWelfareNode.h:126
RandomizedSocialWelfareNode::aQueueSize
int aQueueSize
Definition: RandomizedSocialWelfareNode.h:101
RandomizedSocialWelfareNode::aCommMsg
std_msgs::Int8MultiArray aCommMsg
Definition: RandomizedSocialWelfareNode.h:151
RandomizedSocialWelfareNode::SubGoalFinishCallback
void SubGoalFinishCallback(std_msgs::String::ConstPtr msg)
RandomizedSocialWelfareNode::CSpaceCallback
void CSpaceCallback(nav_msgs::OccupancyGrid::ConstPtr msg)