Scheduler.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  * @author VS_CODE_USER_NAME ( VS_CODE_USER_EMAIL )
17  * @date 2023
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <experimental/memory>
25 
26 #include <Eigen/Core>
27 
28 #include <VirtualRobot/VirtualRobot.h>
29 
31 #include <ArmarXCore/core/time.h>
33 
36 
38 
40 
42 {
43 
44  class Scheduler
45  {
46  public:
48  {
52 
54  };
55 
56  struct Params
57  {
58  std::string robotName;
59  Eigen::Vector3f defaultTarget;
60 
63  };
64 
65  Scheduler(const InjectedServices& srv, const Params& params);
66  virtual ~Scheduler() = default;
67 
68  void handleTargetUpdate(const gaze_targets::GazeTarget& memoryTarget);
69  void resetPriorityQueue();
70 
72 
73  // submit next target from queue based on priority and preemption attributes
74  // WARNING: can only be safely called after acquiring the targetLock
75  void scheduleNextTarget();
76 
77  private:
78  VirtualRobot::RobotPtr robot_ = nullptr;
79 
80  //check whether the current target is out of time and reschedule
81  void checkTargetDeadline();
82 
83  void submitControlTarget(const gaze_targets::GazeTarget& target);
84 
85 
86  // an irreplaceable default target with low priority used if no other
87  // targets are submitted
88  void submitIdleTarget();
89 
90 
91  void visualizeActiveTarget();
92 
93  void runPeriodically();
94 
95 
96  const InjectedServices srv;
97  const Params params;
98 
99  void init();
100 
101 
102  // target managemant needs to be synchronized
103  std::mutex targetMutex;
104  std::multiset<gaze_targets::GazeTarget, std::greater<>> requestedTargets;
105 
107  armarx::DateTime currentDeadline = DateTime::Invalid();
109  };
110 
111 
112 } // namespace armarx::view_selection::gaze_scheduler
Client.h
armarx::view_selection::gaze_scheduler::Scheduler::resetPriorityQueue
void resetPriorityQueue()
Definition: Scheduler.cpp:59
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:668
armarx::view_selection::gaze_scheduler::Scheduler
Definition: Scheduler.h:44
armarx::view_selection::gaze_targets::GazeTarget
Business Object (BO) class of GazeTarget.
Definition: GazeTarget.h:39
std::experimental::fundamentals_v2::observer_ptr
Definition: ManagedIceObject.h:53
armarx::view_selection::gaze_scheduler::Scheduler::~Scheduler
virtual ~Scheduler()=default
armarx::view_selection::gaze_scheduler::Scheduler::scheduleNextTarget
void scheduleNextTarget()
Definition: Scheduler.cpp:193
armarx::view_selection::gaze_scheduler::Scheduler::Params
Definition: Scheduler.h:56
armarx::view_selection::gaze_scheduler::Scheduler::InjectedServices::controllerHandler
std::experimental::observer_ptr< ControllerHandlerInterface > controllerHandler
Definition: Scheduler.h:53
armarx::view_selection::gaze_scheduler::Scheduler::Params::targetVizAlpha
int targetVizAlpha
Definition: Scheduler.h:62
armarx::view_selection::gaze_scheduler::Scheduler::Scheduler
Scheduler(const InjectedServices &srv, const Params &params)
Definition: Scheduler.cpp:52
armarx::view_selection::gaze_scheduler::Scheduler::InjectedServices::arviz
std::experimental::observer_ptr< viz::Client > arviz
Definition: Scheduler.h:51
VirtualRobotReader.h
TaskUtil.h
armarx::view_selection::gaze_scheduler::Scheduler::Params::defaultTarget
Eigen::Vector3f defaultTarget
Definition: Scheduler.h:59
armarx::view_selection::gaze_scheduler::Scheduler::Params::robotName
std::string robotName
Definition: Scheduler.h:58
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
TripleBuffer.h
armarx::view_selection::gaze_scheduler
This file is part of ArmarX.
Definition: Component.cpp:57
armarx::view_selection::gaze_scheduler::Scheduler::Params::visuEnabled
bool visuEnabled
Definition: Scheduler.h:61
time.h
armarx::view_selection::gaze_scheduler::Scheduler::InjectedServices
Definition: Scheduler.h:47
armarx::view_selection::gaze_scheduler::Scheduler::InjectedServices::virtualRobotReader
std::experimental::observer_ptr< armem::robot_state::VirtualRobotReader > virtualRobotReader
Definition: Scheduler.h:50
GazeTarget.h
armarx::view_selection::gaze_scheduler::Scheduler::handleTargetUpdate
void handleTargetUpdate(const gaze_targets::GazeTarget &memoryTarget)
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:57
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
ControllerHandlerInterface.h
armarx::TripleBuffer
A simple triple buffer for lockfree comunication between a single writer and a single reader.
Definition: TripleBuffer.h:71
armarx::view_selection::gaze_scheduler::Scheduler::submitToQueue
void submitToQueue(const gaze_targets::GazeTarget &target)
Definition: Scheduler.cpp:171