GazeController.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstddef>
5#include <memory>
6#include <string>
7#include <vector>
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>
26
27namespace armarx
28{
29 class ControlTarget1DoFActuatorPosition;
30}
31
33{
35
36 struct Params
37 {
38 std::string nodeSetName;
41 std::size_t maxLoops;
43 };
44
50
51 using ControlTarget = std::vector<float>;
52
53 /**
54 * @defgroup Component-GazeControl GazeControl
55 * @ingroup ActiveVision-Components
56 * A description of the component GazeControl.
57 *
58 * @class GazeControl
59 * @ingroup Component-GazeControl
60 * @brief Brief description of class GazeControl.
61 *
62 * Detailed description of class GazeControl.
63 */
65 virtual public NJointControllerWithTripleBuffer<ControlTarget>,
66 virtual public armarx::control::ConfigurableNJointControllerInterface
67 {
68 public:
69 using ConfigPtrT = control::ConfigurableNJointControllerConfigPtr;
70
72 const NJointControllerConfigPtr& config,
73 const VirtualRobot::RobotPtr& robot);
74
75 ~GazeController() override;
76
77 void updateConfig(const ::armarx::aron::data::dto::DictPtr& dto,
78 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
79
81 getConfig(const ::Ice::Current& = ::Ice::emptyCurrent) override;
82
83 protected:
84 // NJointControllerInterface interface
85 void onInitNJointController() override;
86
87 // NJointControllerInterface interface
88 void onConnectNJointController() override;
89
90 // NJointControllerInterface interface
91 std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
92
93 // NJointController interface
94 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
95 const IceUtil::Time& timeSinceLastIteration) override;
96
97 // NJointController interface
98 void onPublish(const SensorAndControl&,
100 const DebugObserverInterfacePrx&) override;
101
102 void rtPreActivateController() override;
103
104 void rtPostDeactivateController() override;
105
106 private:
107 // void publishTarget(const armarx::view_selection::gaze_targets::GazeTarget& target);
108 void removeTarget();
109 void additionalTask();
110
111 // rt variables
112 VirtualRobot::RobotPtr _rtRobot;
113
114 struct RobotState
115 {
116 std::vector<float> jointValues;
117 // armarx::NameValueMap jointPositions;
118 Eigen::Matrix4f globalRobotPose;
119 };
120
121 TripleBuffer<RobotState> _robotStateBuffer_rtToAdditionalTask;
122 TripleBuffer<Config> _configBuffer_updateConfigToAdditionalTask;
123 VirtualRobot::RobotPtr _robotAdditionalTask;
124 VirtualRobot::RobotNodePrismaticPtr _virtualPrismaticJoint;
125 VirtualRobot::RobotNodeSetPtr _headNodeSet;
126 std::unique_ptr<VirtualRobot::GazeIK> _gazeIK;
127
128 std::vector<VirtualRobot::RobotNodePtr> _rtRobotNodes;
129
130 // node names for RobotState::jointValues
131 std::vector<std::string> _additionalTaskRobotNodeNames;
132
133 std::vector<armarx::ControlTarget1DoFActuatorPosition*> _rtCtrlTargets;
134
135 // publishing
137 _gazeTarget_rtRunToPublishing;
138
139 std::atomic<float> _publishCurrentPitchAngle = 0.0;
140 std::atomic<float> _publishCurrentYawAngle = 0.0;
141 std::atomic<float> _publishTargetPitchAngle = 0.0;
142 std::atomic<float> _publishTargetYawAngle = 0.0;
143
144 std::atomic_bool rtReady = false;
145 };
146} // 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.
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