33#include <RobotAPI/interface/core/RobotState.h>
44 widget.verticalLayoutImage->addWidget(_turnOnClick);
61 _dialog->addProxyFinder<visionx::ImageProviderInterfacePrx>(
62 "ImageProvider",
"ImageProvider",
"Image*|*Provider");
64 "rsc",
"Robot State Component",
"*Component");
65 _dialog->addProxyFinder<KinematicUnitInterfacePrx>(
66 "KinematicUnitInterface",
"Kinematic Unit Interface",
"*KinematicUnit");
67 _dialog->addLineEdit(
"pitch",
"Pitch Joint (empty = autodetect)",
"");
68 _dialog->addLineEdit(
"yaw",
"Yaw Joint (empty = autodetect)",
"");
70 return qobject_cast<SimpleConfigDialog*>(_dialog);
76 _imageProviderName = settings->value(
"_imageProviderName").toString().toStdString();
77 _robotStateUnitComponentName = settings->value(
"rsc").toString().toStdString();
78 _kinematicUnitInterfaceName =
79 settings->value(
"KinematicUnitInterface").toString().toStdString();
80 _pitchJointName = settings->value(
"pitch").toString().toStdString();
81 _yawJointName = settings->value(
"yaw").toString().toStdString();
82 _inverseYaw = settings->value(
"inverseYaw").toFloat();
84 widget.doubleSpinBoxFactorPitch->setValue(settings->value(
"pitchFactor").toDouble());
85 widget.doubleSpinBoxFactorYaw->setValue(settings->value(
"yawFactor").toDouble());
91 settings->setValue(
"_imageProviderName", QString::fromStdString(_imageProviderName));
95 settings->setValue(
"KinematicUnitInterface",
96 QString::fromStdString(_kinematicUnitInterfaceName));
97 settings->setValue(
"pitch", QString::fromStdString(_pitchJointName));
98 settings->setValue(
"yaw", QString::fromStdString(_yawJointName));
99 settings->setValue(
"inverseYaw", _inverseYaw);
101 settings->setValue(
"pitchFactor", widget.doubleSpinBoxFactorPitch->value());
102 settings->setValue(
"yawFactor", widget.doubleSpinBoxFactorPitch->value());
113 LookAtClickWidgetController::autoDetectRobotSpecificVariables()
116 if (_yawJointName ==
"")
118 if (_robot->getName() ==
"Armar6")
121 _yawJointName =
"Neck_1_Yaw";
123 else if (_robot->getName() ==
"Armar3")
126 _yawJointName =
"Neck_3_Yaw";
130 throw std::invalid_argument(
"Could not autodetect yaw!");
133 if (_pitchJointName ==
"")
135 if (_robot->getName() ==
"Armar6")
137 _pitchJointName =
"Neck_2_Pitch";
139 else if (_robot->getName() ==
"Armar3")
141 _pitchJointName =
"Neck_1_Pitch";
145 throw std::invalid_argument(
"Could not autodetect pitch!");
153 _robot =
addRobot(
"state robot", VirtualRobot::RobotIO::eStructure);
156 autoDetectRobotSpecificVariables();
162 getProxy(kinematicUnitInterfacePrx, _kinematicUnitInterfaceName);
166 _imageProvider = _imageProviderInfo.proxy;
170 _providerImagesOwner.reserve(_imageProviderInfo.numberImages);
171 _providerImages.reserve(_imageProviderInfo.numberImages);
172 for (
int i = 0; i < _imageProviderInfo.numberImages; ++i)
174 _providerImagesOwner.emplace_back(
176 _providerImages.emplace_back(
177 static_cast<void*
>(_providerImagesOwner.back()->pixels));
179 _numberOfImages = _imageProviderInfo.numberImages;
191 const CByteImage& img = *(_providerImagesOwner.at(_imageIndex));
193 std::lock_guard<std::mutex> guard{_currentImageMutex};
194 _currentImage = QImage(img.width, img.height, QImage::Format_RGB888);
197 std::memcpy(_currentImage.bits(), img.pixels, 3 * img.width * img.height);
198 _currentImageDirty =
true;
205 _imageProviderName = _dialog->getProxyName(
"ImageProvider");
206 _pitchJointName = _dialog->getLineEditText(
"pitch");
207 _yawJointName = _dialog->getLineEditText(
"yaw");
208 _kinematicUnitInterfaceName = _dialog->getProxyName(
"KinematicUnitInterface");
212 LookAtClickWidgetController::refreshWidgetData(
float* factorPitch,
float* factorYaw)
214 *factorPitch = widget.doubleSpinBoxFactorPitch->value();
215 *factorYaw = widget.doubleSpinBoxFactorYaw->value();
219 LookAtClickWidgetController::determineNewAngles(
const QPoint& offset,
220 NameValueMap& jointAngles,
221 NameControlModeMap& jointModes,
225 jointModes[_pitchJointName] = ePositionControl;
226 jointModes[_yawJointName] = ePositionControl;
227 ARMARX_INFO << _robot->getRobotNode(_pitchJointName)->getJointValue();
228 ARMARX_INFO << _robot->getRobotNode(_yawJointName)->getJointValue();
229 auto pitch = _robot->getRobotNode(_pitchJointName);
230 auto yaw = _robot->getRobotNode(_yawJointName);
231 const float pitchValue = offset.y() * factorPitch + pitch->getJointValue();
232 const float yawValue = _inverseYaw * offset.x() * factorYaw + yaw->getJointValue();
233 jointAngles[_pitchJointName] =
234 std::clamp(pitchValue, pitch->getJointLimitLo(), pitch->getJointLimitHi());
235 jointAngles[_yawJointName] =
236 std::clamp(yawValue, yaw->getJointLimitLo(), yaw->getJointLimitHi());
237 ARMARX_INFO <<
"pitch value: " << jointAngles[_pitchJointName]
238 <<
"yaw value: " << jointAngles[_yawJointName];
245 float factorPitch, factorYaw;
246 NameValueMap jointAngles;
247 NameControlModeMap jointModes;
249 refreshWidgetData(&factorPitch, &factorYaw);
251 determineNewAngles(offset, jointAngles, jointModes, factorPitch, factorYaw);
254 kinematicUnitInterfacePrx->switchControlMode(jointModes);
255 kinematicUnitInterfacePrx->setJointAngles(jointAngles);
267 if (!_currentImageDirty)
272 std::lock_guard<std::mutex> guard{_currentImageMutex};
273 _turnOnClick->drawBackground(_currentImage);
274 _currentImageDirty =
false;
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
const RobotStateComponentPlugin & getRobotStateComponentPlugin() const
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
A config-dialog containing one (or multiple) proxy finders.
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
bool waitForImages(int milliseconds=1000)
Wait for new images.
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
int getImages(CByteImage **ppImages)
Poll images from provider.
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
#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_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx