GazeController.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <mutex>
6#include <optional>
7#include <string>
8
9#include <Ice/Current.h>
10#include <Ice/Object.h>
11#include <IceUtil/Time.h>
12
13#include <VirtualRobot/VirtualRobot.h>
14
17
20#include <RobotAPI/interface/aron/Aron.h>
21#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
22
23#include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
24#include <armarx/view_selection/gaze_controller/ice/GazeControllerStatus.h>
28
29namespace armarx
30{
31 class ControlTarget1DoFActuatorPosition;
32}
33
35{
37
38 struct Params
39 {
40 std::string yawNodeName;
41 std::string pitchNodeName;
42 std::string cameraNodeName;
43 std::string gazeRootNodeName;
44 };
45
46 struct Config
47 {
49
51
52 /// Identifies this control target; echoed back in the status reports.
53 std::int64_t targetId = -1;
54 };
55
56 /**
57 * @defgroup Component-GazeControl GazeControl
58 * @ingroup ActiveVision-Components
59 * A description of the component GazeControl.
60 *
61 * @class GazeControl
62 * @ingroup Component-GazeControl
63 * @brief Brief description of class GazeControl.
64 *
65 * Detailed description of class GazeControl.
66 */
68 virtual public NJointControllerWithTripleBuffer<Config>,
69 virtual public armarx::control::ConfigurableNJointControllerInterface
70 {
71 public:
72 using ConfigPtrT = control::ConfigurableNJointControllerConfigPtr;
73
75 const NJointControllerConfigPtr& config,
76 const VirtualRobot::RobotPtr& robot);
77
78 ~GazeController() override;
79
80 void updateConfig(const ::armarx::aron::data::dto::DictPtr& dto,
81 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
82
84 getConfig(const ::Ice::Current& = ::Ice::emptyCurrent) override;
85
86 protected:
87 // NJointControllerInterface interface
88 void onInitNJointController() override;
89
90 // NJointControllerInterface interface
91 void onConnectNJointController() override;
92
93 // NJointControllerInterface interface
94 std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
95
96 // NJointController interface
97 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
98 const IceUtil::Time& timeSinceLastIteration) override;
99
100 // NJointController interface
101 void onPublish(const SensorAndControl&,
103 const DebugObserverInterfacePrx&) override;
104
105 void rtPreActivateController() override;
106 void rtPostDeactivateController() override;
107
108 private:
109 // void publishTarget(const armarx::view_selection::gaze_targets::GazeTarget& target);
110 void removeTarget();
111
112 // rt variables
113 VirtualRobot::RobotPtr _rtRobot;
114 std::string _rtGazeNodeName;
115 VirtualRobot::RobotNodePtr _rtYawNode;
116 VirtualRobot::RobotNodePtr _rtPitchNode;
117 VirtualRobot::RobotNodePtr _rtCameraNode;
118 // VirtualRobot::RobotNodePtr _rtTorsoNode;
119
120 armarx::ControlTarget1DoFActuatorPosition* _rtPitchCtrlTarget;
121 armarx::ControlTarget1DoFActuatorPosition* _rtYawCtrlTarget;
122 float* _rtPitchCtrlPos;
123 float* _rtYawCtrlPos;
124
125 // publishing
126 mutable std::recursive_mutex _tripRt2NonRtMutex;
128
129 StatusReporter _statusReporter;
130
131 GazeControllerStatusListenerPrx _statusTopic;
132
133 std::atomic<float> _publishCurrentPitchAngle = 0.0;
134 std::atomic<float> _publishCurrentYawAngle = 0.0;
135 std::atomic<float> _publishTargetPitchAngle = 0.0;
136 std::atomic<float> _publishTargetYawAngle = 0.0;
137 std::atomic<float> _publishAngularError = 0.0;
138 std::atomic<float> _publishLateralError = 0.0;
139 };
140} // namespace armarx::view_selection::gaze_controller::atan2
#define TYPEDEF_PTRS_HANDLE(T)
NJointControllerWithTripleBuffer(const Config &initialCommands=Config())
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.