26#include <VirtualRobot/CollisionDetection/CollisionModel.h>
27#include <VirtualRobot/MathTools.h>
28#include <VirtualRobot/Nodes/RobotNode.h>
29#include <VirtualRobot/Robot.h>
30#include <VirtualRobot/RobotNodeSet.h>
31#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
32#include <VirtualRobot/Visualization/VisualizationFactory.h>
33#include <VirtualRobot/XML/RobotIO.h>
55#include <Inventor/Qt/SoQt.h>
56#include <Inventor/SoDB.h>
69#define ROBOTSTATE_NAME_DEFAULT "RobotStateComponent"
85 "Joint Configuration",
86 "Framed Position (TCP)",
87 "Framed Orientation (TCP)",
102 QComboBox* outputTypes =
ui.outputTypeComboBox;
106 outputTypes->addItem(typeName);
108 outputTypes->setCurrentIndex(0);
114 bool createDebugDrawer =
true;
127 if (createDebugDrawer)
129 std::string debugDrawerComponentName =
"RobotViewerGUIDebugDrawer_" +
getName();
130 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
148 std::unique_lock lock(*
mutex3D);
172 Ice::StringSeq includePaths;
182 for (
const std::string& projectName : packages)
184 if (projectName.empty())
190 auto pathsString = project.getDataDir();
191 ARMARX_VERBOSE <<
"Data paths of ArmarX package " << projectName <<
": " << pathsString;
192 Ice::StringSeq projectIncludePaths =
Split(pathsString,
";,",
true,
true);
193 ARMARX_VERBOSE <<
"Result: Data paths of ArmarX package " << projectName <<
": "
194 << projectIncludePaths;
196 includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
211 ARMARX_INFO <<
"Loading robot from file " << rfile;
212 robot = loadRobotFile(rfile);
228 std::cout <<
"returning" << std::endl;
236 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
245 ui.kinematicChainComboBox->addItem(
"<All Nodes>");
249 ui.kinematicChainComboBox->addItem(QString::fromStdString(nodeSetName));
251 ui.kinematicChainComboBox->setCurrentIndex(0);
252 ui.tcpComboBox->addItem(
"<default>");
253 for (
auto& node : sharedRobot->getRobotNodes())
255 ui.tcpComboBox->addItem(QString::fromStdString(node));
257 ui.tcpComboBox->setCurrentIndex(0);
259 ui.frameComboBox->addItem(
"<Global>");
263 ui.frameComboBox->addItem(QString::fromStdString(nodeName));
265 ui.frameComboBox->setCurrentIndex(0);
281 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
285 ARMARX_INFO <<
"Disconnecting component: timer stopped";
290 std::unique_lock lock(*
mutex3D);
294 ARMARX_INFO <<
"Disconnecting component: removing visu";
300 ARMARX_INFO <<
"Disconnecting component: finished";
309 std::unique_lock lock(*
mutex3D);
350 {
"RobotStateComponent",
"",
"RobotState*"});
352 return qobject_cast<SimpleConfigDialog*>(dialog);
369 bool showRob = settings->value(
"showRobot", QVariant(
true)).toBool();
370 bool fullMod = settings->value(
"fullModel", QVariant(
true)).toBool();
371 ui.cbRobot->setChecked(showRob);
372 ui.radioButtonFull->setChecked(fullMod);
373 ui.radioButtonCol->setChecked(!fullMod);
380 settings->setValue(
"showRobot",
ui.cbRobot->isChecked());
381 settings->setValue(
"fullModel",
ui.radioButtonFull->isChecked());
394 std::unique_lock lock(*
mutex3D);
396 VirtualRobot::SceneObject::VisualizationType v = VirtualRobot::SceneObject::Full;
400 v = VirtualRobot::SceneObject::Collision;
405 if (robotViewerVisualization)
407 robotVisu->addChild(robotViewerVisualization->getCoinVisualization());
439 std::string poseName(
"root");
443 Eigen::Matrix4f gp = Eigen::Matrix4f::Identity();
461 std::unique_lock lock(*
mutex3D);
497 connect(
ui.cbDebugLayer,
498 SIGNAL(toggled(
bool)),
501 Qt::QueuedConnection);
502 connect(
ui.cbRoot, SIGNAL(toggled(
bool)),
this, SLOT(
showRoot(
bool)), Qt::QueuedConnection);
503 connect(
ui.cbRobot, SIGNAL(toggled(
bool)),
this, SLOT(
showRobot(
bool)), Qt::QueuedConnection);
505 ui.radioButtonCol, SIGNAL(toggled(
bool)),
this, SLOT(
colModel(
bool)), Qt::QueuedConnection);
506 connect(
ui.radioButtonFull,
507 SIGNAL(toggled(
bool)),
510 Qt::QueuedConnection);
511 connect(
ui.horizontalSliderCollisionModelInflation,
512 SIGNAL(sliderMoved(
int)),
515 Qt::QueuedConnection);
518 connect(
ui.kinematicChainComboBox,
519 SIGNAL(currentIndexChanged(
int)),
524 connect(
ui.outputTypeComboBox,
525 SIGNAL(currentIndexChanged(
int)),
528 connect(
ui.copyToClipboardButton, SIGNAL(clicked()),
this, SLOT(
copyToClipboard()));
534 Qt::QueuedConnection);
538RobotViewerWidgetController::loadRobotFile(std::string fileName)
544 ARMARX_INFO <<
"Could not find Robot XML file with name " << fileName;
547 robot = RobotIO::loadRobot(fileName);
551 ARMARX_INFO <<
"Could not find Robot XML file with name " << fileName;
562 if (
ui.radioButtonCol->isChecked())
566 ui.horizontalSliderCollisionModelInflation->setEnabled(
ui.radioButtonCol->isChecked());
580 QClipboard* clipboard = QApplication::clipboard();
583 QString currentText =
ui.previewTextBox->document()->toPlainText();
584 clipboard->setText(currentText);
593writeJointConfigurationToJson(VirtualRobot::Robot& robot,
594 VirtualRobot::RobotNodeSetPtr
const& robotNodeSet)
598 writer.startObject();
602 for (RobotNodePtr
const& node : *robotNodeSet)
604 writer.writeKey(node->getName());
605 writer.writeRawValue(
to_string(node->getJointValue()));
610 for (RobotNodePtr
const& node : robot.getRobotNodes())
612 if (node->isRotationalJoint() || node->isTranslationalJoint())
614 writer.writeKey(node->getName());
615 writer.writeRawValue(
to_string(node->getJointValue()));
621 return writer.toString();
624template <
typename FrameType>
627 VirtualRobot::RobotNodeSetPtr
const& nodeSet,
628 std::string
const& frameName,
629 const std::string& tcpName)
633 auto tcp = tcpName.empty() ? nodeSet->getTCP() : robot->getRobotNode(tcpName);
634 Eigen::Matrix4f tcpMatrix = tcp->getPoseInRootFrame();
635 IceInternal::Handle<FrameType> position =
636 new FrameType(tcpMatrix, robot->getRootNode()->getName(), robot->getName());
637 position->changeFrame(robot, frameName);
641 return object->asString(
true);
657 std::string kinematicChainName =
ui.kinematicChainComboBox->currentText().toStdString();
658 VirtualRobot::RobotNodeSetPtr robotNodeSet;
659 if (
ui.kinematicChainComboBox->currentIndex() > 0)
661 robotNodeSet =
robot->getRobotNodeSet(kinematicChainName);
664 std::string frameName =
ui.frameComboBox->currentText().toStdString();
665 if (
ui.frameComboBox->currentIndex() <= 0)
667 frameName =
"Global";
670 int selectedOutputType =
ui.outputTypeComboBox->currentIndex();
678 const char* oldLocale = std::setlocale(LC_ALL,
"en_US.UTF-8");
679 std::string tcpName =
680 ui.tcpComboBox->currentIndex() == 0 ?
"" :
ui.tcpComboBox->currentText().toStdString();
685 output = writeJointConfigurationToJson(*
robot, robotNodeSet);
689 output = writeFramedTCP<FramedPosition>(
robot, robotNodeSet, frameName, tcpName);
693 output = writeFramedTCP<FramedOrientation>(
robot, robotNodeSet, frameName, tcpName);
697 output = writeFramedTCP<FramedPose>(
robot, robotNodeSet, frameName, tcpName);
701 ARMARX_ERROR <<
"Output type not supported: " << outputType;
705 QString jsonOutput = QString::fromStdString(output);
706 QPlainTextEdit* previewTextBox =
ui.previewTextBox;
707 QTextDocument* document = previewTextBox->document();
708 if (document->toPlainText() != jsonOutput)
710 QScrollBar* scrollBar = previewTextBox->verticalScrollBar();
711 int oldScrollValue = scrollBar->value();
713 document->setPlainText(jsonOutput);
715 int newScrollValue = std::min(oldScrollValue, scrollBar->maximum());
716 scrollBar->setValue(newScrollValue);
719 std::setlocale(LC_ALL, oldLocale);
725 if (
ui.autoUpdateCheckBox->isChecked())
734 std::unique_lock lock(*
mutex3D);
751 Eigen::Matrix4f gp =
robot->getGlobalPose();
752 QString roboInfo(
"Robot Pose (global): pos: ");
753 roboInfo += QString::number(gp(0, 3),
'f', 2);
754 roboInfo += QString(
", ");
755 roboInfo += QString::number(gp(1, 3),
'f', 2);
756 roboInfo += QString(
", ");
757 roboInfo += QString::number(gp(2, 3),
'f', 2);
758 roboInfo += QString(
", rot:");
760 VirtualRobot::MathTools::eigen4f2rpy(gp, rpy);
761 roboInfo += QString::number(rpy(0),
'f', 2);
762 roboInfo += QString(
", ");
763 roboInfo += QString::number(rpy(1),
'f', 2);
764 roboInfo += QString(
", ");
765 roboInfo += QString::number(rpy(2),
'f', 2);
766 ui.leRobotInfo->setText(roboInfo);
774 std::unique_lock lock(*
mutex3D);
776 for (
auto& model :
robot->getCollisionModels())
778 model->inflateModel(inflationValueMM);
780 ui.label_collisionModelInflationValue->setText(QString::number(inflationValueMM) +
" mm");
802 std::unique_lock lock(*
mutex3D);
807 Eigen::Matrix4f newPose = PosePtr::dynamicCast(pose)->toEigen();
809 if (!
robot->getGlobalPose().isApprox(newPose))
811 robot->setGlobalPose(newPose);
821 std::unique_lock lock(*
mutex3D);
827 robot->setJointValues(jointAngles);
#define ROBOTSTATE_NAME_DEFAULT
@ eRobotStateOutputTypeSize
const QString ROBOT_STATE_OUTPUT_TYPE_NAMES[eRobotStateOutputTypeSize]
void serializeIceObject(const SerializablePtr &obj)
static const std::string & GetProjectName()
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
The JSONObject class is used to represent and (de)serialize JSON objects.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
ArmarXObjectSchedulerPtr getObjectScheduler() const
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
A config-dialog containing one (or multiple) proxy finders.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::shared_ptr< class Robot > RobotPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< ArmarXManager > ArmarXManagerPtr
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceInternal::Handle< Pose > PosePtr
IceInternal::Handle< JSONObject > JSONObjectPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
const std::string & to_string(const std::string &s)
boost::shared_ptr< VirtualRobot::CoinVisualization > CoinVisualizationPtr