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  struct OpenPoseResult
61  {
62  bool valid = false;
63  unsigned int index;
64  float distance;
65  float confidence;
66  Eigen::Vector3f mean_position;
67  armarx::Keypoint3DMap keypoints;
69  };
70 
71  struct HumanApproximation
72  {
73  bool valid = false;
74  std::map<std::string, std::pair<IceUtil::Time, Eigen::Vector2f>> transformed_keypoints;
75  double posX;
76  double posY;
77  double yaw;
78  double axisLengthX;
79  double axisLengthY;
81  };
82 
83  public:
84  HumanObstacleDetection() noexcept;
85 
86  std::string getDefaultName() const override;
87 
88  void setEnabled(bool enable, const Ice::Current& = Ice::emptyCurrent) override;
89  void enable(const Ice::Current& = Ice::emptyCurrent) override;
90  void disable(const Ice::Current& = Ice::emptyCurrent) override;
91  void report3DKeypoints(const armarx::HumanPose3DMap& kpml,
92  long timestamp,
93  const Ice::Current& = Ice::emptyCurrent) override;
94 
95  void checkHumanVisibility();
96 
97  protected:
98  void onInitComponent() override;
99 
100  void onConnectComponent() override;
101 
102  void onDisconnectComponent() override;
103 
104  void onExitComponent() override;
105 
107 
108  private:
109  OpenPoseResult find_closest_human(const std::vector<armarx::Keypoint3DMap>& kpml,
110  const IceUtil::Time& time);
111 
112  HumanApproximation approximate_human(const OpenPoseResult& human);
113 
114  public:
115  static const std::string default_name;
116 
117  private:
118  bool m_enabled;
119  int m_onlyUseFirstNResults;
120 
121  unsigned int m_warn_distance;
122 
123  float m_human_confidence_filter_value;
124  float m_min_velocity_treshold;
125  IceUtil::Time m_keypoint_after;
126 
127  unsigned int m_pose_buffer_fillctr = 0;
128  unsigned int m_pose_buffer_index = 0;
130 
132 
133  HumanApproximation last_human_approximation;
134 
135 
137 
138  std::mutex m_human_mutex;
139  std::mutex m_enabled_mutex;
140  };
141 
142 } // namespace armarx
armarx::HumanObstacleDetection::disable
void disable(const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:431
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::HumanObstacleDetection::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: HumanObstacleDetection.cpp:438
armarx::HumanObstacleDetection
Definition: HumanObstacleDetection.h:54
armarx::HumanObstacleDetection::enable
void enable(const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:424
armarx::HumanObstacleDetection::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: HumanObstacleDetection.cpp:95
armarx::HumanObstacleDetection::HumanObstacleDetection
HumanObstacleDetection() noexcept
Definition: HumanObstacleDetection.cpp:53
PeriodicTask.h
armarx::HumanObstacleDetection::checkHumanVisibility
void checkHumanVisibility()
Definition: HumanObstacleDetection.cpp:400
armarx::HumanObstacleDetection::setEnabled
void setEnabled(bool enable, const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:417
armarx::HumanObstacleDetection::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: HumanObstacleDetection.cpp:72
armarx::HumanObstacleDetection::default_name
static const std::string default_name
Definition: HumanObstacleDetection.h:115
armarx::HumanObstacleDetection::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: HumanObstacleDetection.cpp:85
armarx::HumanObstacleDetection::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: HumanObstacleDetection.cpp:64
armarx::HumanObstacleDetection::report3DKeypoints
void report3DKeypoints(const armarx::HumanPose3DMap &kpml, long timestamp, const Ice::Current &=Ice::emptyCurrent) override
Definition: HumanObstacleDetection.cpp:103
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::ProxyType
ProxyType
Definition: ProxyPropertyDefinition.h:40
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:91
armarx::HumanObstacleDetection::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HumanObstacleDetection.cpp:444
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:312
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:95
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27