Human.cpp
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 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2022
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#include "Human.h"
23
24#include <optional>
25#include <string>
26
29
31
33{
34
36 const Eigen::Vector3f& robotPosition,
37 const Params& params) :
38 human_(human), robotPosition_(robotPosition), params_(params)
39 {
40 }
41
42 std::optional<gaze_targets::GazeTarget>
44 {
45 ARMARX_CHECK(human_.humanTrackingId.has_value())
46 << "A tracking id is required. Otherwise, the name will be ambiguous";
47
48 // at the moment, we assume the azure kinect model
51
52 if (not(human_.keypoints.count(headKey) > 0))
53 {
54 ARMARX_VERBOSE << "head keypoint `" << headKey << "` not available";
55 return std::nullopt;
56 }
57
58 const auto globalPosition = human_.keypoints.at(headKey).positionGlobal;
59 if (not globalPosition.has_value())
60 {
61 ARMARX_VERBOSE << "global position not available";
62 return std::nullopt;
63 }
64
66
67 {
68 target.name = "human_" + human_.humanTrackingId.value();
69 target.position = armarx::FramedPosition(globalPosition->toEigen(), GlobalFrame, "");
70
72 priority(globalPosition->toEigen()));
73 target.duration = armarx::Duration::Seconds(1);
74 target.creationTimestamp = armarx::Clock::Now();
75 }
76
77 return target;
78 }
79
80 double
81 Human::priority(const Eigen::Vector3f& globalHeadPosition) const
82 {
83 const double distance = (globalHeadPosition - robotPosition_).norm();
84 return 1 - (distance - params_.distanceMin) / (params_.distanceMax - params_.distanceMin);
85 }
86
87
88} // namespace armarx::view_selection::targets
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
The FramedPosition class.
Definition FramedPose.h:158
Business Object (BO) class of GazeTarget.
Definition GazeTarget.h:23
Human(const armem::human::HumanPose &human, const Eigen::Vector3f &robotPosition, const Params &params)
Definition Human.cpp:35
std::optional< gaze_targets::GazeTarget > asGazeTarget() const
Definition Human.cpp:43
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
const simox::meta::EnumNames< Joints > JointNames
Names of the joints as defined in the body model.
@ TaskDriven
Task-Driven attention has highest priority.
This file is part of ArmarX.
Definition Human.cpp:33
double norm(const Point &a)
Definition point.hpp:102
double distance(const Point &a, const Point &b)
Definition point.hpp:95