Multi-robot Playground
RelativePoseEstimatorNode.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 <stdio.h>
47 #include <vector>
48 #include "ros/ros.h"
49 #include "tf/tf.h"
50 
51 /*
52  * Messages
53  */
54 #include "std_msgs/Float64MultiArray.h"
55 #include "geometry_msgs/Pose.h"
56 #include "geometry_msgs/PoseArray.h"
57 #include "std_msgs/Int8MultiArray.h"
58 #include "visualization_msgs/Marker.h"
59 #include "visualization_msgs/MarkerArray.h"
60 #include "multirobotsimulations/CustomPose.h"
61 #include "multirobotsimulations/MockPackage.h"
62 
63 /*
64  * Helpers
65  */
66 #include "Common.h"
67 
69  public:
72 
73  private:
74  void LoadRelativePoses(ros::NodeHandle& nodeHandle);
75  void PrepareMarkers(visualization_msgs::Marker& input, const char* ns, const int& id, const int& seq);
76  void SetNear(visualization_msgs::Marker& input);
77  void SetFar(visualization_msgs::Marker& input);
78  void CommCallback(std_msgs::Int8MultiArray::ConstPtr msg);
79  void Update();
80 
81  /*
82  * Control variables
83  */
84  int aRobots;
85  int aId;
87  int aSeq;
88  double aRate;
89  std::string aNamespace;
90 
91  /*
92  * Routines
93  */
94  std::vector<ros::Timer> aTimers;
95 
96  /*
97  * Subscribers
98  */
99  std::vector<ros::Subscriber> aSubscribers;
100 
101  /*
102  * Advertisers
103  */
105  ros::Publisher aRelativePosesPublisher;
106  ros::Publisher aDistancesPublisher;
107  ros::Publisher aNearMarkerPublisher;
108  ros::Publisher aFarMarkerPublisher;
109 
110  /*
111  * Messages
112  */
113  geometry_msgs::PoseArray aRobotsRelStartingPosMsg;
114  geometry_msgs::PoseArray aRobotsRelativePosesMsg;
115  visualization_msgs::Marker aClusterMarkerMsg;
116  visualization_msgs::Marker aClusterMarkerFarMsg;
117  std_msgs::Float64MultiArray aRobotsRelativeDistancesMsg;
118  std_msgs::Int8MultiArray aRobotsInCommMsg;
119 
120  /*
121  * Helpers
122  */
123  std::vector<geometry_msgs::Pose> aRobotsWorldPoses;
124  std::vector<bool> aReceivedPoses;
125  std::vector<tf::Vector3> aRelativePoses;
126 };
RelativePoseEstimatorNode::aQueueSize
int aQueueSize
Definition: RelativePoseEstimatorNode.h:86
RelativePoseEstimatorNode::LoadRelativePoses
void LoadRelativePoses(ros::NodeHandle &nodeHandle)
RelativePoseEstimatorNode::aFarMarkerPublisher
ros::Publisher aFarMarkerPublisher
Definition: RelativePoseEstimatorNode.h:108
RelativePoseEstimatorNode::PrepareMarkers
void PrepareMarkers(visualization_msgs::Marker &input, const char *ns, const int &id, const int &seq)
RelativePoseEstimatorNode::aClusterMarkerMsg
visualization_msgs::Marker aClusterMarkerMsg
Definition: RelativePoseEstimatorNode.h:115
RelativePoseEstimatorNode::aClusterMarkerFarMsg
visualization_msgs::Marker aClusterMarkerFarMsg
Definition: RelativePoseEstimatorNode.h:116
RelativePoseEstimatorNode::aReceivedPoses
std::vector< bool > aReceivedPoses
Definition: RelativePoseEstimatorNode.h:124
RelativePoseEstimatorNode::aRate
double aRate
Definition: RelativePoseEstimatorNode.h:88
RelativePoseEstimatorNode::aNearMarkerPublisher
ros::Publisher aNearMarkerPublisher
Definition: RelativePoseEstimatorNode.h:107
RelativePoseEstimatorNode::aNamespace
std::string aNamespace
Definition: RelativePoseEstimatorNode.h:89
RelativePoseEstimatorNode::SetNear
void SetNear(visualization_msgs::Marker &input)
RelativePoseEstimatorNode::aRobotsInCommMsg
std_msgs::Int8MultiArray aRobotsInCommMsg
Definition: RelativePoseEstimatorNode.h:118
RelativePoseEstimatorNode::RelativePoseEstimatorNode
RelativePoseEstimatorNode()
RelativePoseEstimatorNode::aRelativePosesPublisher
ros::Publisher aRelativePosesPublisher
Definition: RelativePoseEstimatorNode.h:105
RelativePoseEstimatorNode::aDistancesPublisher
ros::Publisher aDistancesPublisher
Definition: RelativePoseEstimatorNode.h:106
RelativePoseEstimatorNode::aRobotsWorldPoses
std::vector< geometry_msgs::Pose > aRobotsWorldPoses
Definition: RelativePoseEstimatorNode.h:123
RelativePoseEstimatorNode::aRobotsRelativeDistancesMsg
std_msgs::Float64MultiArray aRobotsRelativeDistancesMsg
Definition: RelativePoseEstimatorNode.h:117
RelativePoseEstimatorNode::~RelativePoseEstimatorNode
~RelativePoseEstimatorNode()
RelativePoseEstimatorNode::aTimers
std::vector< ros::Timer > aTimers
Definition: RelativePoseEstimatorNode.h:94
RelativePoseEstimatorNode::CommCallback
void CommCallback(std_msgs::Int8MultiArray::ConstPtr msg)
RelativePoseEstimatorNode::aId
int aId
Definition: RelativePoseEstimatorNode.h:85
Common.h
RelativePoseEstimatorNode::aStartRelativePosesPublisher
ros::Publisher aStartRelativePosesPublisher
Definition: RelativePoseEstimatorNode.h:104
RelativePoseEstimatorNode::SetFar
void SetFar(visualization_msgs::Marker &input)
RelativePoseEstimatorNode::Update
void Update()
RelativePoseEstimatorNode::aRobotsRelStartingPosMsg
geometry_msgs::PoseArray aRobotsRelStartingPosMsg
Definition: RelativePoseEstimatorNode.h:113
RelativePoseEstimatorNode::aRobotsRelativePosesMsg
geometry_msgs::PoseArray aRobotsRelativePosesMsg
Definition: RelativePoseEstimatorNode.h:114
RelativePoseEstimatorNode::aSubscribers
std::vector< ros::Subscriber > aSubscribers
Definition: RelativePoseEstimatorNode.h:99
RelativePoseEstimatorNode::aSeq
int aSeq
Definition: RelativePoseEstimatorNode.h:87
RelativePoseEstimatorNode
Definition: RelativePoseEstimatorNode.h:68
RelativePoseEstimatorNode::aRelativePoses
std::vector< tf::Vector3 > aRelativePoses
Definition: RelativePoseEstimatorNode.h:125
RelativePoseEstimatorNode::aRobots
int aRobots
Definition: RelativePoseEstimatorNode.h:84