26#include <RobotAPI/gui-plugins/RobotViewerPlugin/ui_RobotViewerGuiPlugin.h>
28#include <VirtualRobot/CollisionDetection/CollisionModel.h>
29#include <VirtualRobot/MathTools.h>
30#include <VirtualRobot/Nodes/RobotNode.h>
31#include <VirtualRobot/Robot.h>
32#include <VirtualRobot/RobotNodeSet.h>
33#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
34#include <VirtualRobot/Visualization/VisualizationFactory.h>
35#include <VirtualRobot/XML/RobotIO.h>
57#include <Inventor/Qt/SoQt.h>
58#include <Inventor/SoDB.h>
71#define ROBOTSTATE_NAME_DEFAULT "RobotStateComponent"
87 "Joint Configuration",
88 "Framed Position (TCP)",
89 "Framed Orientation (TCP)",
103 ui = std::make_unique<Ui::RobotViewerGuiPlugin>();
107 QComboBox* outputTypes =
ui->outputTypeComboBox;
111 outputTypes->addItem(typeName);
113 outputTypes->setCurrentIndex(0);
119 bool createDebugDrawer =
true;
132 if (createDebugDrawer)
134 std::string debugDrawerComponentName =
"RobotViewerGUIDebugDrawer_" +
getName();
135 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
153 std::unique_lock lock(*
mutex3D);
177 Ice::StringSeq includePaths;
187 for (
const std::string& projectName : packages)
189 if (projectName.empty())
195 auto pathsString = project.getDataDir();
196 ARMARX_VERBOSE <<
"Data paths of ArmarX package " << projectName <<
": " << pathsString;
197 Ice::StringSeq projectIncludePaths =
Split(pathsString,
";,",
true,
true);
198 ARMARX_VERBOSE <<
"Result: Data paths of ArmarX package " << projectName <<
": "
199 << projectIncludePaths;
201 includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
216 ARMARX_INFO <<
"Loading robot from file " << rfile;
217 robot = loadRobotFile(rfile);
233 std::cout <<
"returning" << std::endl;
241 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
250 ui->kinematicChainComboBox->addItem(
"<All Nodes>");
254 ui->kinematicChainComboBox->addItem(QString::fromStdString(nodeSetName));
256 ui->kinematicChainComboBox->setCurrentIndex(0);
257 ui->tcpComboBox->addItem(
"<default>");
258 for (
auto& node : sharedRobot->getRobotNodes())
260 ui->tcpComboBox->addItem(QString::fromStdString(node));
262 ui->tcpComboBox->setCurrentIndex(0);
264 ui->frameComboBox->addItem(
"<Global>");
268 ui->frameComboBox->addItem(QString::fromStdString(nodeName));
270 ui->frameComboBox->setCurrentIndex(0);
286 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
290 ARMARX_INFO <<
"Disconnecting component: timer stopped";
295 std::unique_lock lock(*
mutex3D);
299 ARMARX_INFO <<
"Disconnecting component: removing visu";
305 ARMARX_INFO <<
"Disconnecting component: finished";
314 std::unique_lock lock(*
mutex3D);
355 {
"RobotStateComponent",
"",
"RobotState*"});
357 return qobject_cast<SimpleConfigDialog*>(dialog);
374 bool showRob = settings->value(
"showRobot", QVariant(
true)).toBool();
375 bool fullMod = settings->value(
"fullModel", QVariant(
true)).toBool();
376 ui->cbRobot->setChecked(showRob);
377 ui->radioButtonFull->setChecked(fullMod);
378 ui->radioButtonCol->setChecked(!fullMod);
385 settings->setValue(
"showRobot",
ui->cbRobot->isChecked());
386 settings->setValue(
"fullModel",
ui->radioButtonFull->isChecked());
399 std::unique_lock lock(*
mutex3D);
401 VirtualRobot::SceneObject::VisualizationType v = VirtualRobot::SceneObject::Full;
405 v = VirtualRobot::SceneObject::Collision;
410 if (robotViewerVisualization)
412 robotVisu->addChild(robotViewerVisualization->getCoinVisualization());
444 std::string poseName(
"root");
448 Eigen::Matrix4f gp = Eigen::Matrix4f::Identity();
466 std::unique_lock lock(*
mutex3D);
502 connect(
ui->cbDebugLayer,
503 SIGNAL(toggled(
bool)),
506 Qt::QueuedConnection);
507 connect(
ui->cbRoot, SIGNAL(toggled(
bool)),
this, SLOT(
showRoot(
bool)), Qt::QueuedConnection);
508 connect(
ui->cbRobot, SIGNAL(toggled(
bool)),
this, SLOT(
showRobot(
bool)), Qt::QueuedConnection);
510 ui->radioButtonCol, SIGNAL(toggled(
bool)),
this, SLOT(
colModel(
bool)), Qt::QueuedConnection);
511 connect(
ui->radioButtonFull,
512 SIGNAL(toggled(
bool)),
515 Qt::QueuedConnection);
516 connect(
ui->horizontalSliderCollisionModelInflation,
517 SIGNAL(sliderMoved(
int)),
520 Qt::QueuedConnection);
523 connect(
ui->kinematicChainComboBox,
524 SIGNAL(currentIndexChanged(
int)),
529 connect(
ui->outputTypeComboBox,
530 SIGNAL(currentIndexChanged(
int)),
533 connect(
ui->copyToClipboardButton, SIGNAL(clicked()),
this, SLOT(
copyToClipboard()));
539 Qt::QueuedConnection);
543RobotViewerWidgetController::loadRobotFile(std::string fileName)
549 ARMARX_INFO <<
"Could not find Robot XML file with name " << fileName;
552 robot = RobotIO::loadRobot(fileName);
556 ARMARX_INFO <<
"Could not find Robot XML file with name " << fileName;
567 if (
ui->radioButtonCol->isChecked())
571 ui->horizontalSliderCollisionModelInflation->setEnabled(
ui->radioButtonCol->isChecked());
585 QClipboard* clipboard = QApplication::clipboard();
588 QString currentText =
ui->previewTextBox->document()->toPlainText();
589 clipboard->setText(currentText);
598writeJointConfigurationToJson(VirtualRobot::Robot& robot,
599 VirtualRobot::RobotNodeSetPtr
const& robotNodeSet)
603 writer.startObject();
607 for (RobotNodePtr
const& node : *robotNodeSet)
609 writer.writeKey(node->getName());
610 writer.writeRawValue(
to_string(node->getJointValue()));
615 for (RobotNodePtr
const& node : robot.getRobotNodes())
617 if (node->isRotationalJoint() || node->isTranslationalJoint())
619 writer.writeKey(node->getName());
620 writer.writeRawValue(
to_string(node->getJointValue()));
626 return writer.toString();
629template <
typename FrameType>
632 VirtualRobot::RobotNodeSetPtr
const& nodeSet,
633 std::string
const& frameName,
634 const std::string& tcpName)
638 auto tcp = tcpName.empty() ? nodeSet->getTCP() : robot->getRobotNode(tcpName);
639 Eigen::Matrix4f tcpMatrix = tcp->getPoseInRootFrame();
640 IceInternal::Handle<FrameType> position =
641 new FrameType(tcpMatrix, robot->getRootNode()->getName(), robot->getName());
642 position->changeFrame(robot, frameName);
646 return object->asString(
true);
662 std::string kinematicChainName =
ui->kinematicChainComboBox->currentText().toStdString();
663 VirtualRobot::RobotNodeSetPtr robotNodeSet;
664 if (
ui->kinematicChainComboBox->currentIndex() > 0)
666 robotNodeSet =
robot->getRobotNodeSet(kinematicChainName);
669 std::string frameName =
ui->frameComboBox->currentText().toStdString();
670 if (
ui->frameComboBox->currentIndex() <= 0)
672 frameName =
"Global";
675 int selectedOutputType =
ui->outputTypeComboBox->currentIndex();
683 const char* oldLocale = std::setlocale(LC_ALL,
"en_US.UTF-8");
684 std::string tcpName =
685 ui->tcpComboBox->currentIndex() == 0 ?
"" :
ui->tcpComboBox->currentText().toStdString();
690 output = writeJointConfigurationToJson(*
robot, robotNodeSet);
694 output = writeFramedTCP<FramedPosition>(
robot, robotNodeSet, frameName, tcpName);
698 output = writeFramedTCP<FramedOrientation>(
robot, robotNodeSet, frameName, tcpName);
702 output = writeFramedTCP<FramedPose>(
robot, robotNodeSet, frameName, tcpName);
706 ARMARX_ERROR <<
"Output type not supported: " << outputType;
710 QString jsonOutput = QString::fromStdString(output);
711 QPlainTextEdit* previewTextBox =
ui->previewTextBox;
712 QTextDocument* document = previewTextBox->document();
713 if (document->toPlainText() != jsonOutput)
715 QScrollBar* scrollBar = previewTextBox->verticalScrollBar();
716 int oldScrollValue = scrollBar->value();
718 document->setPlainText(jsonOutput);
720 int newScrollValue = std::min(oldScrollValue, scrollBar->maximum());
721 scrollBar->setValue(newScrollValue);
724 std::setlocale(LC_ALL, oldLocale);
730 if (
ui->autoUpdateCheckBox->isChecked())
739 std::unique_lock lock(*
mutex3D);
756 Eigen::Matrix4f gp =
robot->getGlobalPose();
757 QString roboInfo(
"Robot Pose (global): pos: ");
758 roboInfo += QString::number(gp(0, 3),
'f', 2);
759 roboInfo += QString(
", ");
760 roboInfo += QString::number(gp(1, 3),
'f', 2);
761 roboInfo += QString(
", ");
762 roboInfo += QString::number(gp(2, 3),
'f', 2);
763 roboInfo += QString(
", rot:");
765 VirtualRobot::MathTools::eigen4f2rpy(gp, rpy);
766 roboInfo += QString::number(rpy(0),
'f', 2);
767 roboInfo += QString(
", ");
768 roboInfo += QString::number(rpy(1),
'f', 2);
769 roboInfo += QString(
", ");
770 roboInfo += QString::number(rpy(2),
'f', 2);
771 ui->leRobotInfo->setText(roboInfo);
779 std::unique_lock lock(*
mutex3D);
781 for (
auto& model :
robot->getCollisionModels())
783 model->inflateModel(inflationValueMM);
785 ui->label_collisionModelInflationValue->setText(QString::number(inflationValueMM) +
" mm");
807 std::unique_lock lock(*
mutex3D);
812 Eigen::Matrix4f newPose = PosePtr::dynamicCast(pose)->toEigen();
814 if (!
robot->getGlobalPose().isApprox(newPose))
816 robot->setGlobalPose(newPose);
826 std::unique_lock lock(*
mutex3D);
832 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.
This file is part of ArmarX.
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