7#include <Ice/Current.h>
8#include <IceUtil/Time.h>
10#include <VirtualRobot/Nodes/RobotNode.h>
11#include <VirtualRobot/Robot.h>
12#include <VirtualRobot/RobotNodeSet.h>
13#include <VirtualRobot/VirtualRobot.h>
17#include <ArmarXCore/interface/observers/ObserverInterface.h>
18#include <ArmarXCore/interface/observers/VariantBase.h>
26#include <RobotAPI/interface/aron/Aron.h>
27#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
28#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
33#include <armarx/view_selection/gaze_controller/atan2/aron/ControllerConfig.aron.generated.h>
44 const NJointControllerConfigPtr& config,
49 ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
55 const armarx::view_selection::gaze_controller::atan2::arondto::Config configData =
56 arondto::Config::FromAron(cfg->config);
62 _rtRobot->setThreadsafe(
false);
65 _rtGazeNodeName = configData.params.gazeRootNodeName;
66 _rtCameraNode = _rtRobot->getRobotNode(configData.params.cameraNodeName);
67 _rtPitchNode = _rtRobot->getRobotNode(configData.params.pitchNodeName);
68 _rtYawNode = _rtRobot->getRobotNode(configData.params.yawNodeName);
76 configData.params.pitchNodeName, ControlModes::Position1DoF);
80 configData.params.yawNodeName, ControlModes::Position1DoF);
94 auto updateConfigDto = arondto::Config::FromAron(dto);
122 const IceUtil::Time& )
124 const float currentYawAngle = _rtYawNode->getJointValue();
125 const float currentPitchAngle = _rtPitchNode->getJointValue();
128 _publishCurrentYawAngle = currentYawAngle;
129 _publishCurrentPitchAngle = currentPitchAngle;
132 auto target = gazeTarget.position;
133 if (target.frame.empty())
138 target.changeFrame(_rtRobot, _rtGazeNodeName);
139 Eigen::Vector3f targetPoint = target.toEigen();
142 float targetYawAngle = -std::atan2(targetPoint.x(), targetPoint.y());
148 targetPoint = Eigen::AngleAxisf(-targetYawAngle, Eigen::Vector3f::UnitZ()) * targetPoint;
151 const bool yawTargetReachable = _rtYawNode->checkJointLimits(targetYawAngle);
152 if (not yawTargetReachable)
154 targetYawAngle = std::clamp(
155 targetYawAngle, _rtYawNode->getJointLimitLow(), _rtYawNode->getJointLimitHigh());
158 float targetPitchAngle = -std::atan2(targetPoint.z(), targetPoint.y());
161 const bool pitchTargetReachable = _rtPitchNode->checkJointLimits(targetPitchAngle);
162 if (not pitchTargetReachable)
164 targetPitchAngle = std::clamp(targetPitchAngle,
165 _rtPitchNode->getJointLimitLow(),
166 _rtPitchNode->getJointLimitHigh());
170 _publishTargetYawAngle = targetYawAngle;
171 _publishTargetPitchAngle = targetPitchAngle;
174 _rtYawCtrlTarget->position = targetYawAngle;
175 _rtPitchCtrlTarget->position = targetPitchAngle;
195 const float currentPitchAngle = _publishCurrentPitchAngle;
196 const float currentYawAngle = _publishCurrentYawAngle;
197 const float targetPitchAngle = _publishTargetPitchAngle;
198 const float targetYawAngle = _publishTargetYawAngle;
201 datafields[
"currentPitchAngle"] =
new Variant(currentPitchAngle);
202 datafields[
"currentYawAngle"] =
new Variant(currentYawAngle);
203 datafields[
"targetPitchAngle"] =
new Variant(targetPitchAngle);
204 datafields[
"targetYawAngle"] =
new Variant(targetYawAngle);
206 if (_tripRt2NonRt.updateReadBuffer())
#define ARMARX_RT_LOGF(...)
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
std::string getInstanceName(const Ice::Current &=Ice::emptyCurrent) const final override
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
const Config & rtGetControlStruct() const
void setControlStruct(const Config &newStruct)
The Variant class is described here: Variants.
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 onInitNJointController() override
~GazeController() 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 onConnectNJointController() override
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
Business Object (BO) class of GazeTarget.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
std::string const GlobalFrame
Variable of the global coordinate system.
std::shared_ptr< class Robot > RobotPtr
::IceInternal::Handle< Dict > DictPtr
const simox::meta::EnumNames< ControllerType > ControllerTypeNames
const armarx::NJointControllerRegistration< GazeController > RegistrationControllerGazeController(common::ControllerTypeNames.to_name(common::ControllerType::GazeControllerAtan2))
void fromAron(const arondto::Config &dto, Config &bo)
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class RobotUnit > RobotUnitPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl