Multi-robot Playground
IntegratedGlobalPlannerNode.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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 <stdio.h>
47 #include <queue>
48 #include "ros/ros.h"
49 #include "tf/tf.h"
50 
51 /*
52  * Messages
53  */
54 #include "std_msgs/Bool.h"
55 #include "std_msgs/String.h"
56 #include "std_msgs/Float32.h"
57 #include "nav_msgs/Path.h"
58 #include "nav_msgs/OccupancyGrid.h"
59 #include "visualization_msgs/Marker.h"
60 #include "geometry_msgs/PoseStamped.h"
61 #include "multirobotsimulations/CustomPose.h"
62 
63 /*
64  * Helpers
65  */
66 #include "SearchAlgorithms.h"
67 #include "Common.h"
68 
69 typedef enum {
72 } SubGoalState;
73 
75  public:
78 
79  private:
80  void CreateMarker(visualization_msgs::Marker& input, const char* ns, const int& id, const int& seq);
82  nav_msgs::OccupancyGrid& cspace,
83  Vec2i& occpos,
84  Vec2i& source,
85  Vec2i& closest,
86  std::list<Vec2i>& outpath);
87  void ChangeState(const SubGoalState& newState);
88  void CSpaceCallback(nav_msgs::OccupancyGrid::ConstPtr msg);
89  void PoseCallback(multirobotsimulations::CustomPose::ConstPtr msg);
90  void AverageVelocityCallback(std_msgs::Float32::ConstPtr msg);
91  void GoalCallback(geometry_msgs::Pose::ConstPtr msg);
92  void StopCallBack(std_msgs::String::ConstPtr msg);
93  void Update();
94 
95  /*
96  * Control variables
97  */
99  int aId;
100  int aSeq;
102  bool aHasPose;
103  bool aHasOcc;
105  double aRate;
106  double aDistance;
109  double aStuckTime;
111  std::string aNamespace;
112 
113  /*
114  * Routines
115  */
116  std::vector<ros::Timer> aTimers;
117 
118  /*
119  * Subscribers
120  */
121  std::vector<ros::Subscriber> aSubscribers;
122 
123  /*
124  * Advertisers
125  */
126  ros::Publisher aPathMarkerPublisher;
127  ros::Publisher aFinishEventPublisher;
128  ros::Publisher aCurrentPathPublisher;
129 
130  /*
131  * Messages
132  */
133  nav_msgs::Path aPathMsg;
134  std_msgs::String aStrMsg;
135  visualization_msgs::Marker aPathMarkerMsg;
136  nav_msgs::OccupancyGrid aCspace;
137 
138  /*
139  * Helpers
140  */
141  ros::Time last_time;
142  std::list<Vec2i> aWaypoints;
143  tf::Vector3 aLastPos;
144  tf::Vector3 aWorldPos;
145  tf::Vector3 aCurrentGoal;
148 };
IntegratedGlobalPlannerNode::aDeltaTimeSec
int aDeltaTimeSec
Definition: IntegratedGlobalPlannerNode.h:101
IntegratedGlobalPlannerNode::aId
int aId
Definition: IntegratedGlobalPlannerNode.h:99
SearchAlgorithms.h
IntegratedGlobalPlannerNode::aWorldPos
tf::Vector3 aWorldPos
Definition: IntegratedGlobalPlannerNode.h:144
IntegratedGlobalPlannerNode::aHasAverageVelocity
bool aHasAverageVelocity
Definition: IntegratedGlobalPlannerNode.h:104
IntegratedGlobalPlannerNode::aCurrentState
SubGoalState aCurrentState
Definition: IntegratedGlobalPlannerNode.h:147
IntegratedGlobalPlannerNode::Update
void Update()
state_idle
@ state_idle
Definition: IntegratedGlobalPlannerNode.h:70
IntegratedGlobalPlannerNode::aSubscribers
std::vector< ros::Subscriber > aSubscribers
Definition: IntegratedGlobalPlannerNode.h:121
Vec2i
Definition: Common.h:59
IntegratedGlobalPlannerNode::aPathMarkerMsg
visualization_msgs::Marker aPathMarkerMsg
Definition: IntegratedGlobalPlannerNode.h:135
IntegratedGlobalPlannerNode::aPathMsg
nav_msgs::Path aPathMsg
Definition: IntegratedGlobalPlannerNode.h:133
IntegratedGlobalPlannerNode::last_time
ros::Time last_time
Definition: IntegratedGlobalPlannerNode.h:141
IntegratedGlobalPlannerNode::~IntegratedGlobalPlannerNode
~IntegratedGlobalPlannerNode()
IntegratedGlobalPlannerNode
Definition: IntegratedGlobalPlannerNode.h:74
IntegratedGlobalPlannerNode::aWaypoints
std::list< Vec2i > aWaypoints
Definition: IntegratedGlobalPlannerNode.h:142
IntegratedGlobalPlannerNode::GoalCallback
void GoalCallback(geometry_msgs::Pose::ConstPtr msg)
IntegratedGlobalPlannerNode::aCurrentPathPublisher
ros::Publisher aCurrentPathPublisher
Definition: IntegratedGlobalPlannerNode.h:128
SubGoalState
SubGoalState
Definition: IntegratedGlobalPlannerNode.h:69
IntegratedGlobalPlannerNode::CreateMarker
void CreateMarker(visualization_msgs::Marker &input, const char *ns, const int &id, const int &seq)
IntegratedGlobalPlannerNode::aPathMarkerPublisher
ros::Publisher aPathMarkerPublisher
Definition: IntegratedGlobalPlannerNode.h:126
IntegratedGlobalPlannerNode::StopCallBack
void StopCallBack(std_msgs::String::ConstPtr msg)
IntegratedGlobalPlannerNode::CSpaceCallback
void CSpaceCallback(nav_msgs::OccupancyGrid::ConstPtr msg)
IntegratedGlobalPlannerNode::IntegratedGlobalPlannerNode
IntegratedGlobalPlannerNode()
IntegratedGlobalPlannerNode::aDistance
double aDistance
Definition: IntegratedGlobalPlannerNode.h:106
IntegratedGlobalPlannerNode::aStuckTime
double aStuckTime
Definition: IntegratedGlobalPlannerNode.h:109
IntegratedGlobalPlannerNode::PoseCallback
void PoseCallback(multirobotsimulations::CustomPose::ConstPtr msg)
IntegratedGlobalPlannerNode::AverageVelocityCallback
void AverageVelocityCallback(std_msgs::Float32::ConstPtr msg)
IntegratedGlobalPlannerNode::aHasOcc
bool aHasOcc
Definition: IntegratedGlobalPlannerNode.h:103
IntegratedGlobalPlannerNode::aCurrentGoal
tf::Vector3 aCurrentGoal
Definition: IntegratedGlobalPlannerNode.h:145
IntegratedGlobalPlannerNode::aLastPos
tf::Vector3 aLastPos
Definition: IntegratedGlobalPlannerNode.h:143
IntegratedGlobalPlannerNode::aStrMsg
std_msgs::String aStrMsg
Definition: IntegratedGlobalPlannerNode.h:134
IntegratedGlobalPlannerNode::aRate
double aRate
Definition: IntegratedGlobalPlannerNode.h:105
Common.h
IntegratedGlobalPlannerNode::aCspace
nav_msgs::OccupancyGrid aCspace
Definition: IntegratedGlobalPlannerNode.h:136
IntegratedGlobalPlannerNode::aQueueSize
int aQueueSize
Definition: IntegratedGlobalPlannerNode.h:98
IntegratedGlobalPlannerNode::aHasPose
bool aHasPose
Definition: IntegratedGlobalPlannerNode.h:102
IntegratedGlobalPlannerNode::aNamespace
std::string aNamespace
Definition: IntegratedGlobalPlannerNode.h:111
IntegratedGlobalPlannerNode::aAverageVelocity
double aAverageVelocity
Definition: IntegratedGlobalPlannerNode.h:110
IntegratedGlobalPlannerNode::aOccPos
Vec2i aOccPos
Definition: IntegratedGlobalPlannerNode.h:146
IntegratedGlobalPlannerNode::ChangeState
void ChangeState(const SubGoalState &newState)
IntegratedGlobalPlannerNode::aStuckTimeThreshold
double aStuckTimeThreshold
Definition: IntegratedGlobalPlannerNode.h:108
state_executing_path
@ state_executing_path
Definition: IntegratedGlobalPlannerNode.h:71
IntegratedGlobalPlannerNode::aFinishEventPublisher
ros::Publisher aFinishEventPublisher
Definition: IntegratedGlobalPlannerNode.h:127
IntegratedGlobalPlannerNode::aTimers
std::vector< ros::Timer > aTimers
Definition: IntegratedGlobalPlannerNode.h:116
IntegratedGlobalPlannerNode::aSeq
int aSeq
Definition: IntegratedGlobalPlannerNode.h:100
IntegratedGlobalPlannerNode::aSubGoalReachThreshold
double aSubGoalReachThreshold
Definition: IntegratedGlobalPlannerNode.h:107
IntegratedGlobalPlannerNode::DepthFirstSearchFreePath
void DepthFirstSearchFreePath(nav_msgs::OccupancyGrid &cspace, Vec2i &occpos, Vec2i &source, Vec2i &closest, std::list< Vec2i > &outpath)