HumanObstacleDetection.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package Armar6Skills::ArmarXObjects::HumanAvoidance
17  * @author Christian R. G. Dreher <c.dreher@kit.edu>
18  * @author Fabian Peller
19  * @date 2019
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 
25 #pragma once
26 
27 
28 // STD/STL
29 #include <array>
30 #include <string>
31 #include <tuple>
32 #include <vector>
33 
34 // Eigen
35 #include <Eigen/Core>
36 
37 // Ice
38 #include <Ice/Current.h>
39 
40 // ArmarX
44 
45 // Interface
46 #include <RobotComponents/interface/components/ObstacleDetection/HumanObstacleDetectionInterface.h>
47 
48 // ObstacleAvoidance
49 #include <RobotAPI/interface/components/ObstacleAvoidance/DynamicObstacleManagerInterface.h>
50 
51 namespace armarx
52 {
53 
55  virtual public armarx::Component,
56  virtual public armarx::HumanObstacleDetectionInterface
57  {
58 
59  private:
60 
61  struct OpenPoseResult
62  {
63  bool valid = false;
64  unsigned int index;
65  float distance;
66  float confidence;
67  Eigen::Vector3f mean_position;
68  armarx::Keypoint3DMap keypoints;
69  IceUtil::Time timestamp;
70  };
71 
72  struct HumanApproximation
73  {
74  bool valid = false;
75  std::map<std::string, std::pair<IceUtil::Time, Eigen::Vector2f>> transformed_keypoints;
76  double posX;
77  double posY;
78  double yaw;
79  double axisLengthX;
80  double axisLengthY;
81  IceUtil::Time timestamp;
82  };
83 
84  public:
85 
86  HumanObstacleDetection() noexcept;
87 
88  std::string getDefaultName() const override;
89 
90  void setEnabled(bool enable, const Ice::Current& = Ice::emptyCurrent) override;
91  void enable(const Ice::Current& = Ice::emptyCurrent) override;
92  void disable(const Ice::Current& = Ice::emptyCurrent) override;
93  void report3DKeypoints(const armarx::HumanPose3DMap& kpml, long timestamp, const Ice::Current& = Ice::emptyCurrent) override;
94 
95  void checkHumanVisibility();
96 
97  protected:
98 
99  void onInitComponent() override;
100 
101  void onConnectComponent() override;
102 
103  void onDisconnectComponent() override;
104 
105  void onExitComponent() override;
106 
108 
109  private:
110 
111  OpenPoseResult
112  find_closest_human(const std::vector<armarx::Keypoint3DMap>& kpml, const IceUtil::Time& time);
113 
114  HumanApproximation
115  approximate_human(const OpenPoseResult& human);
116 
117  public:
118 
119  static const std::string default_name;
120 
121  private:
122 
123  bool m_enabled;
124  int m_onlyUseFirstNResults;
125 
126  unsigned int m_warn_distance;
127 
128  float m_human_confidence_filter_value;
129  float m_min_velocity_treshold;
130  IceUtil::Time m_keypoint_after;
131 
132  unsigned int m_pose_buffer_fillctr = 0;
133  unsigned int m_pose_buffer_index = 0;
135 
137 
138  HumanApproximation last_human_approximation;
139 
140 
142 
143  std::mutex m_human_mutex;
144  std::mutex m_enabled_mutex;
145 
146  };
147 
148 }
armarx::HumanObstacleDetection::disable
void disable(const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:435
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::HumanObstacleDetection::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: HumanObstacleDetection.cpp:443
armarx::HumanObstacleDetection
Definition: HumanObstacleDetection.h:54
armarx::HumanObstacleDetection::enable
void enable(const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:427
armarx::HumanObstacleDetection::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: HumanObstacleDetection.cpp:102
armarx::HumanObstacleDetection::HumanObstacleDetection
HumanObstacleDetection() noexcept
Definition: HumanObstacleDetection.cpp:54
PeriodicTask.h
armarx::HumanObstacleDetection::checkHumanVisibility
void checkHumanVisibility()
Definition: HumanObstacleDetection.cpp:402
armarx::HumanObstacleDetection::setEnabled
void setEnabled(bool enable, const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:419
armarx::HumanObstacleDetection::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: HumanObstacleDetection.cpp:76
armarx::HumanObstacleDetection::default_name
static const std::string default_name
Definition: HumanObstacleDetection.h:119
armarx::HumanObstacleDetection::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: HumanObstacleDetection.cpp:91
armarx::HumanObstacleDetection::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: HumanObstacleDetection.cpp:67
armarx::HumanObstacleDetection::report3DKeypoints
void report3DKeypoints(const armarx::HumanPose3DMap &kpml, long timestamp, const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:110
armarx::ProxyType
ProxyType
Definition: ProxyPropertyDefinition.h:41
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::HumanObstacleDetection::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HumanObstacleDetection.cpp:451
TripleBuffer.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::WriteBufferedTripleBuffer
Same as the TripleBuffer, but partial writes of the data structure are ok. The write operation may be...
Definition: TripleBuffer.h:267
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28