27 #include <RobotAPI/interface/core/RobotState.h>
44 widget.verticalLayoutImage->addWidget(_turnOnClick);
46 connect(_turnOnClick, SIGNAL(
clickedAt(
const QPoint&)),
this, SLOT(
clickedAt(
const QPoint&)));
63 _dialog->addProxyFinder<visionx::ImageProviderInterfacePrx>(
"ImageProvider",
"ImageProvider",
"Image*|*Provider");
65 _dialog->addProxyFinder<KinematicUnitInterfacePrx>(
"KinematicUnitInterface",
"Kinematic Unit Interface",
"*KinematicUnit");
66 _dialog->addLineEdit(
"pitch",
"Pitch Joint (empty = autodetect)",
"");
67 _dialog->addLineEdit(
"yaw",
"Yaw Joint (empty = autodetect)",
"");
69 return qobject_cast<SimpleConfigDialog*>(_dialog);
74 _imageProviderName = settings->value(
"_imageProviderName").toString().toStdString();
75 _robotStateUnitComponentName = settings->value(
"rsc").toString().toStdString();
76 _kinematicUnitInterfaceName = settings->value(
"KinematicUnitInterface").toString().toStdString();
77 _pitchJointName = settings->value(
"pitch").toString().toStdString();
78 _yawJointName = settings->value(
"yaw").toString().toStdString();
79 _inverseYaw = settings->value(
"inverseYaw").toFloat();
81 widget.doubleSpinBoxFactorPitch->setValue(settings->value(
"pitchFactor").toDouble());
82 widget.doubleSpinBoxFactorYaw->setValue(settings->value(
"yawFactor").toDouble());
87 settings->setValue(
"_imageProviderName", QString::fromStdString(_imageProviderName));
89 settings->setValue(
"KinematicUnitInterface", QString::fromStdString(_kinematicUnitInterfaceName));
90 settings->setValue(
"pitch", QString::fromStdString(_pitchJointName));
91 settings->setValue(
"yaw", QString::fromStdString(_yawJointName));
92 settings->setValue(
"inverseYaw", _inverseYaw);
94 settings->setValue(
"pitchFactor", widget.doubleSpinBoxFactorPitch->value());
95 settings->setValue(
"yawFactor", widget.doubleSpinBoxFactorPitch->value());
105 void LookAtClickWidgetController::autoDetectRobotSpecificVariables()
108 if (_yawJointName ==
"")
110 if (_robot->getName() ==
"Armar6")
113 _yawJointName =
"Neck_1_Yaw";
115 else if (_robot->getName() ==
"Armar3")
118 _yawJointName =
"Neck_3_Yaw";
122 throw std::invalid_argument(
"Could not autodetect yaw!");
125 if (_pitchJointName ==
"")
127 if (_robot->getName() ==
"Armar6")
129 _pitchJointName =
"Neck_2_Pitch";
131 else if (_robot->getName() ==
"Armar3")
133 _pitchJointName =
"Neck_1_Pitch";
137 throw std::invalid_argument(
"Could not autodetect pitch!");
144 _robot =
addRobot(
"state robot", VirtualRobot::RobotIO::eStructure);
147 autoDetectRobotSpecificVariables();
153 getProxy(kinematicUnitInterfacePrx, _kinematicUnitInterfaceName);
157 _imageProvider = _imageProviderInfo.
proxy;
161 _providerImagesOwner.reserve(_imageProviderInfo.
numberImages);
162 _providerImages.reserve(_imageProviderInfo.
numberImages);
163 for (
int i = 0; i < _imageProviderInfo.
numberImages; ++i)
166 _providerImages.emplace_back(
static_cast<void*
>(_providerImagesOwner.back()->pixels));
179 const CByteImage& img = *(_providerImagesOwner.at(_imageIndex));
181 std::lock_guard<std::mutex> guard {_currentImageMutex};
182 _currentImage = QImage(img.width, img.height, QImage::Format_RGB888);
185 std::memcpy(_currentImage.bits(), img.pixels, 3 * img.width * img.height);
186 _currentImageDirty =
true;
192 _imageProviderName = _dialog->getProxyName(
"ImageProvider");
193 _pitchJointName = _dialog->getLineEditText(
"pitch");
194 _yawJointName = _dialog->getLineEditText(
"yaw");
195 _kinematicUnitInterfaceName = _dialog->getProxyName(
"KinematicUnitInterface");
198 void LookAtClickWidgetController::refreshWidgetData(
float* factorPitch,
float* factorYaw)
200 *factorPitch = widget.doubleSpinBoxFactorPitch->value();
201 *factorYaw = widget.doubleSpinBoxFactorYaw->value();
205 void LookAtClickWidgetController::determineNewAngles(
const QPoint& offset,
NameValueMap&
jointAngles, NameControlModeMap& jointModes,
float factorPitch,
float factorYaw)
207 jointModes[_pitchJointName] = ePositionControl;
208 jointModes[_yawJointName] = ePositionControl;
209 ARMARX_INFO << _robot->getRobotNode(_pitchJointName)->getJointValue();
210 ARMARX_INFO << _robot->getRobotNode(_yawJointName)->getJointValue();
211 auto pitch = _robot->getRobotNode(_pitchJointName);
212 auto yaw = _robot->getRobotNode(_yawJointName);
213 const float pitchValue = offset.y() * factorPitch + pitch->getJointValue();
214 const float yawValue = _inverseYaw * offset.x() * factorYaw + yaw->getJointValue();
215 jointAngles[_pitchJointName] =
std::clamp(pitchValue, pitch->getJointLimitLo(), pitch->getJointLimitHi());
223 float factorPitch, factorYaw;
225 NameControlModeMap jointModes;
227 refreshWidgetData(&factorPitch, &factorYaw);
229 determineNewAngles(offset,
jointAngles, jointModes, factorPitch, factorYaw);
232 kinematicUnitInterfacePrx->switchControlMode(jointModes);
233 kinematicUnitInterfacePrx->setJointAngles(
jointAngles);
245 if (!_currentImageDirty)
250 std::lock_guard<std::mutex> guard {_currentImageMutex};
252 _currentImageDirty =
false;