person.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 #ifndef HRI_PERSON_H
30 #define HRI_PERSON_H
31 
32 #include <geometry_msgs/TransformStamped.h>
33 #include <functional>
34 #include <memory>
35 
36 #include "base.h"
37 #include "face.h"
38 #include "body.h"
39 #include "voice.h"
40 
41 #include <hri_msgs/EngagementLevel.h>
42 #include <std_msgs/Float32.h>
43 
45 #include "tf2_ros/message_filter.h"
47 
48 
49 namespace hri
50 {
51 const static std::string PERSON_TF_PREFIX("person_");
52 const static ros::Duration PERSON_TF_TIMEOUT(0.01);
53 
55 {
56  // disengaged: the human has not looked in the direction of the robot
58  // engaging: the human has started to look in the direction of the robot
59  ENGAGING = 2,
60  // engaged: the human is fully engaged with the robot
61  ENGAGED = 3,
62  // disengaging: the human has started to look away from the robot
64 };
65 
66 
67 class HRIListener;
68 
69 
70 class Person : public FeatureTracker
71 {
72 public:
73  Person(ID id, const HRIListener* listener, ros::NodeHandle& nh,
74  tf2_ros::Buffer* tf_buffer_ptr, const std::string& reference_frame);
75 
76  virtual ~Person();
77 
78  std::string frame() const
79  {
80  return PERSON_TF_PREFIX + id_;
81  }
82 
83  /* returns a (weak, constant) pointer to the face of this person, or
84  * a nullptr if this person is currently not associated to any detected face.
85  */
86  FaceWeakConstPtr face() const;
87 
88  /* returns a (weak, constant) pointer to the body of this person, or
89  * a nullptr if this person is currently not associated to any detected body.
90  */
91  BodyWeakConstPtr body() const;
92 
93  /* returns a (weak, constant) pointer to the voice of this person, or
94  * a nullptr if this person is currently not associated to any detected voice.
95  */
96  VoiceWeakConstPtr voice() const;
97 
98 
99  bool anonymous() const
100  {
101  return _anonymous;
102  }
103 
104  ID alias() const
105  {
106  return _alias;
107  }
108 
109  boost::optional<EngagementLevel> engagement_status() const;
110 
111  float location_confidence() const
112  {
113  return _loc_confidence;
114  }
115 
116  boost::optional<geometry_msgs::TransformStamped> transform() const;
117 
118  void init() override;
122 
123 
124 protected:
125  // we use a raw pointer here. `this` is owned by the pointed HRIListener, so
126  // `this` would normally be destroyed before HRIListener (in reality, a
127  // pointer to `this` *might* outlive `HRIListener` -- make sure HRIListener
128  // is destroyed after all pointers to this person are released.
130 
131  void tfCallback(const geometry_msgs::TransformStampedConstPtr& transform_ptr)
132  {
133  ROS_WARN("got tf transform!");
134  }
135 
136  // if non-empty, this person 'does not exist' and is instead an alias to
137  // another person. hri::getPersons and hri::getTrackedPersons will returns
138  // pointers to the aliased person.
140 
142 
143  hri_msgs::EngagementLevelConstPtr _engagement_status;
144 
146 
147  std::string _reference_frame;
148 
156 
158 };
159 
160 typedef std::shared_ptr<Person> PersonPtr;
161 typedef std::shared_ptr<const Person> PersonConstPtr;
162 typedef std::weak_ptr<Person> PersonWeakPtr;
163 typedef std::weak_ptr<const Person> PersonWeakConstPtr;
164 
165 
166 } // namespace hri
167 
168 #endif
std::shared_ptr< Person > PersonPtr
Definition: person.h:160
void init() override
Definition: person.cpp:61
hri_msgs::EngagementLevelConstPtr _engagement_status
Definition: person.h:143
ID voice_id
Definition: person.h:121
std::weak_ptr< const Voice > VoiceWeakConstPtr
Definition: voice.h:150
std::weak_ptr< Person > PersonWeakPtr
Definition: person.h:162
ros::Subscriber face_id_subscriber_
Definition: person.h:149
boost::optional< geometry_msgs::TransformStamped > transform() const
Definition: person.cpp:142
EngagementLevel
Definition: person.h:54
tf2_ros::Buffer * _tf_buffer_ptr
Definition: person.h:157
std::weak_ptr< const Face > FaceWeakConstPtr
Definition: face.h:209
float _loc_confidence
Definition: person.h:145
std::weak_ptr< const Body > BodyWeakConstPtr
Definition: body.h:138
#define ROS_WARN(...)
ros::Subscriber loc_confidence_subscriber_
Definition: person.h:155
virtual ~Person()
Definition: person.cpp:56
boost::optional< EngagementLevel > engagement_status() const
Definition: person.cpp:116
ros::Subscriber engagement_subscriber_
Definition: person.h:154
ros::Subscriber alias_subscriber_
Definition: person.h:153
bool anonymous() const
Definition: person.h:99
void tfCallback(const geometry_msgs::TransformStampedConstPtr &transform_ptr)
Definition: person.h:131
VoiceWeakConstPtr voice() const
Definition: person.cpp:108
BodyWeakConstPtr body() const
Definition: person.cpp:100
std::shared_ptr< const Person > PersonConstPtr
Definition: person.h:161
const HRIListener * listener_
Definition: person.h:129
ros::Subscriber anonymous_subscriber_
Definition: person.h:152
ros::Subscriber voice_id_subscriber_
Definition: person.h:151
ID _alias
Definition: person.h:139
std::weak_ptr< const Person > PersonWeakConstPtr
Definition: person.h:163
Person(ID id, const HRIListener *listener, ros::NodeHandle &nh, tf2_ros::Buffer *tf_buffer_ptr, const std::string &reference_frame)
Definition: person.cpp:42
std::string _reference_frame
Definition: person.h:147
bool _anonymous
Definition: person.h:141
Definition: base.h:38
std::string frame() const
Definition: person.h:78
static const ros::Duration PERSON_TF_TIMEOUT(0.01)
ros::Subscriber body_id_subscriber_
Definition: person.h:150
ID alias() const
Definition: person.h:104
ID body_id
Definition: person.h:120
Main entry point to libhri. This is most likely what you want to use. Use example: ...
Definition: hri.h:70
FaceWeakConstPtr face() const
Definition: person.cpp:92
static const std::string PERSON_TF_PREFIX("person_")
ID face_id
Definition: person.h:119
std::string ID
Definition: base.h:40
float location_confidence() const
Definition: person.h:111


libhri
Author(s): Séverin Lemaignan
autogenerated on Wed Apr 19 2023 02:30:41