GoalReachedMonitor.cpp
Go to the documentation of this file.
2
3#include <VirtualRobot/Robot.h> // IWYU pragma: keep
4
7
10
12{
13
15 const core::Scene& scene,
16 const GoalReachedMonitorConfig& config) :
17 goal_(goal), scene(scene), config(config), reachedCount(0)
18 {
19 //ARMARX_CHECK(not waypoints.empty());
20 }
21
22 bool
23 GoalReachedMonitor::goalReached(const bool filter) const noexcept
24 {
26
27 const core::Pose world_T_robot(scene.robot->getGlobalPose());
28 const core::Pose& world_T_goal(goal_);
29
30 const core::Pose robot_T_goal = world_T_robot.inverse() * world_T_goal;
31
32 ARMARX_VERBOSE << "Position error: " << robot_T_goal.translation().head<2>().norm();
33 ARMARX_VERBOSE << "Rotation error: " << Eigen::AngleAxisf(robot_T_goal.linear()).angle();
34
35 const bool posReached = robot_T_goal.translation().head<2>().norm() <= config.posTh;
36 const bool oriReached = Eigen::AngleAxisf(robot_T_goal.linear()).angle() <= config.oriTh;
37
38 if (posReached)
39 {
40 ARMARX_DEBUG << "Position goal `" << robot_T_goal.translation().head<2>()
41 << "` reached";
42 }
43
44 if (oriReached)
45 {
46 ARMARX_DEBUG << "Orientation goal reached";
47 }
48
49 const bool linearVelocityLow = scene.platformVelocity.linear.norm() < config.linearVelTh;
50 const bool angularVelocityLow = scene.platformVelocity.angular.norm() < config.angularVelTh;
51
52 const bool velocityLow = linearVelocityLow and angularVelocityLow;
53
54 if (velocityLow)
55 {
56 ARMARX_DEBUG << "Robot has come to rest.";
57 }
58
59 bool reached = posReached and oriReached and velocityLow;
60
61 if (reached)
62 {
63 reachedCount++;
64 ARMARX_DEBUG << "Goal reached! reachedCount: " << reachedCount;
65 return !filter || (reachedCount >= config.filterCount);
66 }
67 else
68 {
69 reachedCount = 0;
70 return false;
71 }
72 }
73
74 const core::Pose&
75 GoalReachedMonitor::goal() const noexcept
76 {
77 return goal_;
78 }
79
81 {
82 const core::Pose world_T_robot(scene.robot->getGlobalPose());
83 const core::Pose& world_T_goal(goal_);
84
85 const core::Pose robot_T_goal = world_T_robot.inverse() * world_T_goal;
86
87 const float posError = robot_T_goal.translation().head<2>().norm();
88 const float oriError = Eigen::AngleAxisf(robot_T_goal.linear()).angle();
89
90 return Status{.posError = posError, .oriError = oriError};
91 }
92
94 goal_{other.goal_}, scene{other.scene}, config(other.config), reachedCount(other.reachedCount)
95 {
96 }
97
98 GoalReachedMonitor&
100 {
101 if (this != &other)
102 {
103 goal_ = std::move(other.goal_);
104 reachedCount = other.reachedCount;
105 // scene is a const reference — cannot be rebound; must refer to the same scene object
106 // config is const — cannot be reassigned
107 }
108 return *this;
109 }
110
113 {
114 return this->config;
115 }
116
117 void
119 {
120 goal_ = newGoal;
121 }
122} // namespace armarx::navigation::server
bool goalReached(bool filter=true) const noexcept
GoalReachedMonitor & operator=(GoalReachedMonitor &&) noexcept
GoalReachedMonitor(const core::Pose &goal, const core::Scene &scene, const GoalReachedMonitorConfig &config)
const GoalReachedMonitorConfig getConfig() const
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
Eigen::Isometry3f Pose
Definition basic_types.h:31
This file is part of ArmarX.
core::GoalReachedConfig GoalReachedMonitorConfig
double norm(const Point &a)
Definition point.hpp:102
#define ARMARX_TRACE
Definition trace.h:77