GazeController.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <cstddef>
6#include <memory>
7#include <string>
8#include <vector>
9
10#include <Ice/Current.h>
11#include <Ice/Object.h>
12#include <IceUtil/Time.h>
13
14#include <VirtualRobot/VirtualRobot.h>
15
18
21#include <RobotAPI/interface/aron/Aron.h>
22#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
23
24#include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
25#include <armarx/view_selection/gaze_controller/ice/GazeControllerStatus.h>
29
30namespace armarx
31{
32 class ControlTarget1DoFActuatorPosition;
33}
34
36{
38
39 struct Params
40 {
41 std::string nodeSetName;
44 std::size_t maxLoops;
46 };
47
48 struct Config
49 {
51
53
54 /// Identifies this control target; echoed back in the status reports.
55 std::int64_t targetId = -1;
56 };
57
58 using ControlTarget = std::vector<float>;
59
60 /**
61 * @defgroup Component-GazeControl GazeControl
62 * @ingroup ActiveVision-Components
63 * A description of the component GazeControl.
64 *
65 * @class GazeControl
66 * @ingroup Component-GazeControl
67 * @brief Brief description of class GazeControl.
68 *
69 * Detailed description of class GazeControl.
70 */
72 virtual public NJointControllerWithTripleBuffer<ControlTarget>,
73 virtual public armarx::control::ConfigurableNJointControllerInterface
74 {
75 public:
76 using ConfigPtrT = control::ConfigurableNJointControllerConfigPtr;
77
79 const NJointControllerConfigPtr& config,
80 const VirtualRobot::RobotPtr& robot);
81
82 ~GazeController() override;
83
84 void updateConfig(const ::armarx::aron::data::dto::DictPtr& dto,
85 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
86
88 getConfig(const ::Ice::Current& = ::Ice::emptyCurrent) override;
89
90 protected:
91 // NJointControllerInterface interface
92 void onInitNJointController() override;
93
94 // NJointControllerInterface interface
95 void onConnectNJointController() override;
96
97 // NJointControllerInterface interface
98 std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
99
100 // NJointController interface
101 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
102 const IceUtil::Time& timeSinceLastIteration) override;
103
104 // NJointController interface
105 void onPublish(const SensorAndControl&,
107 const DebugObserverInterfacePrx&) override;
108
109 void rtPreActivateController() override;
110
111 void rtPostDeactivateController() override;
112
113 private:
114 // void publishTarget(const armarx::view_selection::gaze_targets::GazeTarget& target);
115 void removeTarget();
116 void additionalTask();
117
118 // rt variables
119 VirtualRobot::RobotPtr _rtRobot;
120
121 struct RobotState
122 {
123 std::vector<float> jointValues;
124 // armarx::NameValueMap jointPositions;
125 Eigen::Matrix4f globalRobotPose;
126 };
127
128 TripleBuffer<RobotState> _robotStateBuffer_rtToAdditionalTask;
129 TripleBuffer<Config> _configBuffer_updateConfigToAdditionalTask;
130 VirtualRobot::RobotPtr _robotAdditionalTask;
131 VirtualRobot::RobotNodePrismaticPtr _virtualPrismaticJoint;
132 VirtualRobot::RobotNodeSetPtr _headNodeSet;
133 std::unique_ptr<VirtualRobot::GazeIK> _gazeIK;
134
135 std::vector<VirtualRobot::RobotNodePtr> _rtRobotNodes;
136
137 // node names for RobotState::jointValues
138 std::vector<std::string> _additionalTaskRobotNodeNames;
139
140 std::vector<armarx::ControlTarget1DoFActuatorPosition*> _rtCtrlTargets;
141
142 // publishing
144 _gazeTarget_rtRunToPublishing;
145
146 StatusReporter _statusReporter;
147
148 GazeControllerStatusListenerPrx _statusTopic;
149
150 std::atomic<float> _publishAngularError = 0.0;
151 std::atomic<float> _publishLateralError = 0.0;
152
153 std::atomic<float> _publishCurrentPitchAngle = 0.0;
154 std::atomic<float> _publishCurrentYawAngle = 0.0;
155 std::atomic<float> _publishTargetPitchAngle = 0.0;
156 std::atomic<float> _publishTargetYawAngle = 0.0;
157
158 std::atomic_bool rtReady = false;
159 };
160} // namespace armarx::view_selection::gaze_controller::gaze_ik
#define TYPEDEF_PTRS_HANDLE(T)
NJointControllerWithTripleBuffer(const ControlTarget &initialCommands=ControlTarget())
A simple triple buffer for lockfree comunication between a single writer and a single reader.
Collects the gaze residual on the control side and reports it on a topic.
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
::armarx::aron::data::dto::DictPtr getConfig(const ::Ice::Current &=::Ice::emptyCurrent) override
GazeController(RobotUnitPtr robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &robot)
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
void rtPreActivateController() override
This function is called before the controller is activated.
control::ConfigurableNJointControllerConfigPtr ConfigPtrT
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
::IceInternal::Handle< Dict > DictPtr
::armarx::view_selection::gaze_targets::GazeTarget Target
Definition types.h:8
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl
armarx::view_selection::gaze_controller::Target target
std::int64_t targetId
Identifies this control target; echoed back in the status reports.