base.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_BASE_H
31 #define HRI_BASE_H
32 
33 #include <memory>
34 #include <optional>
35 #include <string>
36 #include <ros/ros.h>
37 
38 namespace hri
39 {
40 typedef std::string ID;
41 
43 {
44  invalid = 0,
45  person = (1u << 0), // all known persons, whether or not they are currently seen
46  tracked_person = (1u << 1), // only the actively tracked persons
47  face = (1u << 2),
48  body = (1u << 3),
49  voice = (1u << 4)
50 }; // note that FeatureType values can also be used as bitmasks
51 
53 {
54 public:
55  /* creates a new feature tracker (eg, a face, body or voice tracker).
56  *
57  * This constructor should not be called directly. Instead, use one of the
58  * specialisation: hri::Face, hri::Body, hri::Voice.
59  *
60  * Note however that instances would normally be automatically created, and accessed via
61  * the methods exposed by hri::HRIListener.
62  *
63  * Note that the resulting instance is non-copyable, as it includes
64  * non-trivial, and typically non-reentrant, logic to subscribe/unsubcribe
65  * HRI-related topics.
66  */
67  FeatureTracker(ID id, const ros::NodeHandle& nh) : id_(id), node_(nh), ns_("")
68  {
69  }
70 
71  virtual ~FeatureTracker()
72  {
73  }
74 
75  // forbids copies of our 'feature trackers', as we need to internally manage
76  // if/when they disappear. Instead, access them via weak pointers (cf HRIListener API).
77 
78  // TODO: ask a C++ expert how to enable that while avoid compilation errors when
79  // building/moving a FeatureTracker into a container (in HRIListener)
80  FeatureTracker(const FeatureTracker&) = delete;
81 
82 
83  /* returns the unique ID of this feature.
84  *
85  * :see: FeatureTracker::getNamespace, to access the fully-qualified topic
86  * namespace under which this feature is published.
87  */
88  ID id() const
89  {
90  return id_;
91  }
92 
93  /* returns the topic namespace under which this feature is advertised.
94  */
95  std::string getNamespace() const
96  {
97  return ns_;
98  }
99 
100  /* alias for FeatureTracker::getNamespace
101  */
102  std::string ns() const
103  {
104  return getNamespace();
105  }
106 
107  bool operator<(const FeatureTracker& other) const
108  {
109  return id_ < other.id();
110  }
111 
112 
113  virtual void init() = 0;
114 
115 protected:
117 
118  // topic namespace under which this feature is advertised
119  std::string ns_;
120 
122 };
123 
124 } // namespace hri
125 
126 #endif
hri::FeatureTracker::id
ID id() const
Definition: base.h:88
hri
Definition: base.h:38
hri::FeatureTracker
Definition: base.h:52
hri::FeatureTracker::FeatureTracker
FeatureTracker(ID id, const ros::NodeHandle &nh)
Definition: base.h:67
ros.h
hri::body
@ body
Definition: base.h:48
hri::FeatureTracker::getNamespace
std::string getNamespace() const
Definition: base.h:95
hri::FeatureTracker::ns
std::string ns() const
Definition: base.h:102
hri::tracked_person
@ tracked_person
Definition: base.h:46
hri::invalid
@ invalid
Definition: base.h:44
hri::FeatureTracker::operator<
bool operator<(const FeatureTracker &other) const
Definition: base.h:107
hri::face
@ face
Definition: base.h:47
hri::voice
@ voice
Definition: base.h:49
hri::ID
std::string ID
Definition: base.h:40
hri::FeatureTracker::init
virtual void init()=0
hri::FeatureTracker::~FeatureTracker
virtual ~FeatureTracker()
Definition: base.h:71
hri::FeatureTracker::ns_
std::string ns_
Definition: base.h:119
hri::person
@ person
Definition: base.h:45
hri::FeatureType
FeatureType
Definition: base.h:42
ros::NodeHandle
hri::FeatureTracker::node_
ros::NodeHandle node_
Definition: base.h:121
hri::FeatureTracker::id_
ID id_
Definition: base.h:116


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