hri.h
Go to the documentation of this file.
1 // Copyright 2022 PAL Robotics S.L.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 //
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // * Neither the name of the PAL Robotics S.L. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 
29 
30 #ifndef HRI_HRI_H
31 #define HRI_HRI_H
32 
33 #include <ros/ros.h>
34 #include <hri_msgs/IdsList.h>
35 
36 #include <functional>
37 #include <map>
38 #include <memory>
39 
40 #include "base.h"
41 #include "face.h"
42 #include "body.h"
43 #include "voice.h"
44 #include "person.h"
45 #include "ros/subscriber.h"
46 
47 
48 namespace hri
49 {
71 {
72 public:
73  HRIListener();
74 
75  ~HRIListener();
76 
81  std::map<ID, FaceWeakConstPtr> getFaces() const;
82 
86  void onFace(std::function<void(FaceWeakConstPtr)> callback)
87  {
88  face_callbacks.push_back(callback);
89  }
90 
94  void onFaceLost(std::function<void(ID)> callback)
95  {
96  face_lost_callbacks.push_back(callback);
97  }
98 
99 
104  std::map<ID, BodyWeakConstPtr> getBodies() const;
105 
109  void onBody(std::function<void(BodyWeakConstPtr)> callback)
110  {
111  body_callbacks.push_back(callback);
112  }
113 
117  void onBodyLost(std::function<void(ID)> callback)
118  {
119  body_lost_callbacks.push_back(callback);
120  }
121 
122 
127  std::map<ID, VoiceWeakConstPtr> getVoices() const;
128 
132  void onVoice(std::function<void(VoiceWeakPtr)> callback)
133  {
134  voice_callbacks.push_back(callback);
135  }
136 
140  void onVoiceLost(std::function<void(ID)> callback)
141  {
142  voice_lost_callbacks.push_back(callback);
143  }
144 
145 
146 
156  std::map<ID, PersonWeakConstPtr> getPersons() const;
157 
161  void onPerson(std::function<void(PersonWeakConstPtr)> callback)
162  {
163  person_callbacks.push_back(callback);
164  }
165 
170  void onPersonLost(std::function<void(ID)> callback)
171  {
172  person_lost_callbacks.push_back(callback);
173  }
174 
181  std::map<ID, PersonWeakConstPtr> getTrackedPersons() const;
182 
183 
187  void onTrackedPerson(std::function<void(PersonWeakConstPtr)> callback)
188  {
189  person_tracked_callbacks.push_back(callback);
190  }
191 
195  void onTrackedPersonLost(std::function<void(ID)> callback)
196  {
197  person_tracked_lost_callbacks.push_back(callback);
198  }
199 
200 
206  void setReferenceFrame(const std::string& frame)
207  {
208  _reference_frame = frame;
209  }
210 
211 private:
213 
214  void init();
215 
216  void onTrackedFeature(FeatureType feature, hri_msgs::IdsListConstPtr tracked);
217 
218  std::map<FeatureType, ros::Subscriber> feature_subscribers_;
219 
220  std::map<ID, FaceConstPtr> faces;
221  std::vector<std::function<void(FaceWeakConstPtr)>> face_callbacks;
222  std::vector<std::function<void(ID)>> face_lost_callbacks;
223 
224  std::map<ID, BodyConstPtr> bodies;
225  std::vector<std::function<void(BodyWeakConstPtr)>> body_callbacks;
226  std::vector<std::function<void(ID)>> body_lost_callbacks;
227 
228  std::map<ID, VoiceConstPtr> voices;
229  // VoiceWeakPtr (and not VoiceWeakConstPtr) as user might
230  // register callbacks on the returned Voice
231  std::vector<std::function<void(VoiceWeakPtr)>> voice_callbacks;
232  std::vector<std::function<void(ID)>> voice_lost_callbacks;
233 
234  std::map<ID, PersonConstPtr> persons;
235  std::vector<std::function<void(PersonConstPtr)>> person_callbacks;
236  std::vector<std::function<void(ID)>> person_lost_callbacks;
237  std::map<ID, PersonConstPtr> tracked_persons;
238  std::vector<std::function<void(PersonConstPtr)>> person_tracked_callbacks;
239  std::vector<std::function<void(ID)>> person_tracked_lost_callbacks;
240 
241  std::string _reference_frame;
244 };
245 
246 } // namespace hri
247 
248 
249 
250 #endif // HRI_HRI_H
hri::HRIListener::person_callbacks
std::vector< std::function< void(PersonConstPtr)> > person_callbacks
Definition: hri.h:235
hri
Definition: base.h:38
hri::HRIListener::faces
std::map< ID, FaceConstPtr > faces
Definition: hri.h:220
hri::HRIListener::body_callbacks
std::vector< std::function< void(BodyWeakConstPtr)> > body_callbacks
Definition: hri.h:225
face.h
hri::HRIListener::tracked_persons
std::map< ID, PersonConstPtr > tracked_persons
Definition: hri.h:237
hri::HRIListener::body_lost_callbacks
std::vector< std::function< void(ID)> > body_lost_callbacks
Definition: hri.h:226
ros.h
hri::HRIListener::person_lost_callbacks
std::vector< std::function< void(ID)> > person_lost_callbacks
Definition: hri.h:236
hri::HRIListener::person_tracked_lost_callbacks
std::vector< std::function< void(ID)> > person_tracked_lost_callbacks
Definition: hri.h:239
hri::HRIListener::persons
std::map< ID, PersonConstPtr > persons
Definition: hri.h:234
hri::HRIListener::~HRIListener
~HRIListener()
Definition: hri.cpp:49
hri::VoiceWeakPtr
std::weak_ptr< Voice > VoiceWeakPtr
Definition: voice.h:148
base.h
hri::HRIListener::HRIListener
HRIListener()
Definition: hri.cpp:44
hri::HRIListener::onFaceLost
void onFaceLost(std::function< void(ID)> callback)
Registers a callback function, to be invoked everytime a previously tracked face is lost (eg,...
Definition: hri.h:94
hri::HRIListener::bodies
std::map< ID, BodyConstPtr > bodies
Definition: hri.h:224
hri::HRIListener::getBodies
std::map< ID, BodyWeakConstPtr > getBodies() const
Returns the list of currently detected bodies, mapped to their IDs.
Definition: hri.cpp:76
hri::HRIListener::getPersons
std::map< ID, PersonWeakConstPtr > getPersons() const
Returns the list of all known persons, whether or not they are currently actively detected (eg,...
Definition: hri.cpp:104
hri::HRIListener::onTrackedPerson
void onTrackedPerson(std::function< void(PersonWeakConstPtr)> callback)
Registers a callback function, to be invoked everytime a new person is detected and actively tracked ...
Definition: hri.h:187
hri::HRIListener::getTrackedPersons
std::map< ID, PersonWeakConstPtr > getTrackedPersons() const
Returns the list of currently detected persons, mapped to their IDs.
Definition: hri.cpp:139
tf2_ros::TransformListener
hri::PersonConstPtr
std::shared_ptr< const Person > PersonConstPtr
Definition: person.h:162
hri::HRIListener::_tf_listener
tf2_ros::TransformListener _tf_listener
Definition: hri.h:243
hri::HRIListener::node_
ros::NodeHandle node_
Definition: hri.h:212
hri::FaceWeakConstPtr
std::weak_ptr< const Face > FaceWeakConstPtr
Definition: face.h:211
hri::HRIListener::person_tracked_callbacks
std::vector< std::function< void(PersonConstPtr)> > person_tracked_callbacks
Definition: hri.h:238
subscriber.h
hri::HRIListener::onVoiceLost
void onVoiceLost(std::function< void(ID)> callback)
Registers a callback function, to be invoked everytime a previously tracked voice is lost (eg,...
Definition: hri.h:140
hri::HRIListener::_reference_frame
std::string _reference_frame
Definition: hri.h:241
hri::HRIListener::onBody
void onBody(std::function< void(BodyWeakConstPtr)> callback)
Registers a callback function, to be invoked everytime a new body is detected.
Definition: hri.h:109
hri::HRIListener::onFace
void onFace(std::function< void(FaceWeakConstPtr)> callback)
Registers a callback function, to be invoked everytime a new face is detected.
Definition: hri.h:86
hri::BodyWeakConstPtr
std::weak_ptr< const Body > BodyWeakConstPtr
Definition: body.h:139
hri::HRIListener::face_callbacks
std::vector< std::function< void(FaceWeakConstPtr)> > face_callbacks
Definition: hri.h:221
tf2_ros::Buffer
hri::HRIListener::voice_lost_callbacks
std::vector< std::function< void(ID)> > voice_lost_callbacks
Definition: hri.h:232
hri::HRIListener::onPersonLost
void onPersonLost(std::function< void(ID)> callback)
Registers a callback function, to be invoked everytime a person is lost. This can only happen for ano...
Definition: hri.h:170
hri::HRIListener::onBodyLost
void onBodyLost(std::function< void(ID)> callback)
Registers a callback function, to be invoked everytime a previously tracked body is lost (eg,...
Definition: hri.h:117
body.h
hri::HRIListener::onPerson
void onPerson(std::function< void(PersonWeakConstPtr)> callback)
Registers a callback function, to be invoked everytime a new person is detected.
Definition: hri.h:161
hri::PersonWeakConstPtr
std::weak_ptr< const Person > PersonWeakConstPtr
Definition: person.h:164
hri::HRIListener::getFaces
std::map< ID, FaceWeakConstPtr > getFaces() const
Returns the list of currently detected faces, mapped to their IDs.
Definition: hri.cpp:62
hri::HRIListener::feature_subscribers_
std::map< FeatureType, ros::Subscriber > feature_subscribers_
Definition: hri.h:218
hri::HRIListener
Main entry point to libhri. This is most likely what you want to use. Use example:
Definition: hri.h:70
hri::HRIListener::onTrackedPersonLost
void onTrackedPersonLost(std::function< void(ID)> callback)
Registers a callback function, to be invoked everytime a previously tracked person is lost.
Definition: hri.h:195
hri::HRIListener::init
void init()
Definition: hri.cpp:174
hri::ID
std::string ID
Definition: base.h:40
hri::HRIListener::getVoices
std::map< ID, VoiceWeakConstPtr > getVoices() const
Returns the list of currently detected voices, mapped to their IDs.
Definition: hri.cpp:90
hri::HRIListener::_tf_buffer
tf2_ros::Buffer _tf_buffer
Definition: hri.h:242
hri::HRIListener::face_lost_callbacks
std::vector< std::function< void(ID)> > face_lost_callbacks
Definition: hri.h:222
hri::HRIListener::voice_callbacks
std::vector< std::function< void(VoiceWeakPtr)> > voice_callbacks
Definition: hri.h:231
voice.h
hri::HRIListener::voices
std::map< ID, VoiceConstPtr > voices
Definition: hri.h:228
hri::HRIListener::onVoice
void onVoice(std::function< void(VoiceWeakPtr)> callback)
Registers a callback function, to be invoked everytime a new voice is detected.
Definition: hri.h:132
hri::HRIListener::onTrackedFeature
void onTrackedFeature(FeatureType feature, hri_msgs::IdsListConstPtr tracked)
Definition: hri.cpp:200
person.h
hri::HRIListener::setReferenceFrame
void setReferenceFrame(const std::string &frame)
Definition: hri.h:206
hri::FeatureType
FeatureType
Definition: base.h:42
ros::NodeHandle


libhri
Author(s): Séverin Lemaignan
autogenerated on Thu Jul 6 2023 02:43:58