SimulatedObjectAsObject.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package armarx::simulation::scene_generation
17 * @author Patrick Hegemann ( patrick dot hegemann at kit dot edu )
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
23
24#include <VirtualRobot/ManipulationObject.h>
25#include <VirtualRobot/XML/ObjectIO.h>
26
29#include <ArmarXCore/interface/core/PackagePath.h>
30
32
34{
35 SimulatedObjectAsObject::SimulatedObjectAsObject(const std::string& instanceName,
36 const ObjectSource& objectSource) :
37 SimulatedObject(instanceName, objectSource)
38 {
39 // TODO(patrick.hegemann): refactor this dirty fix of stupid behavior
40 const armarx::data::PackagePath& pp = objectSource.path.serialize();
41 std::filesystem::path relPath(pp.path);
42 ARMARX_CHECK(!relPath.empty()) << "Relative path to object should not be empty";
43 if (!relPath.empty() && relPath.begin()->string() == pp.package)
44 {
45 relPath = relPath.lexically_relative(*relPath.begin());
46 }
47 armarx::PackagePath newPackagePath(pp.package, relPath);
48
49 localCopy_ = VirtualRobot::ObjectIO::loadManipulationObject(newPackagePath.toSystemPath());
50 localCopy_->setName(instanceName);
51 }
52
53 void
54 SimulatedObjectAsObject::addToSimulator(armarx::SimulatorInterfacePrx& simulator)
55 {
56 PosePtr pose(new Pose(localCopy_->getGlobalPose()));
57 simulator->addObjectFromFile(
58 getObjectSource().path.serialize(), getInstanceName(), pose, false);
59 }
60
61 void
62 SimulatedObjectAsObject::updatePoseFromSimulator(armarx::SimulatorInterfacePrx& simulator)
63 {
64 const PoseBasePtr& poseBase = simulator->getObjectPose(getInstanceName());
65 Pose p(poseBase->position, poseBase->orientation);
66 localCopy_->setGlobalPose(p.toEigen());
67 }
68
69 void
70 SimulatedObjectAsObject::updatePoseToSimulator(armarx::SimulatorInterfacePrx& simulator)
71 {
72 PosePtr pose(new Pose(localCopy_->getGlobalPose()));
73 simulator->setObjectPose(getInstanceName(), pose);
74 }
75
76 bool
77 SimulatedObjectAsObject::checkCollision(const VirtualRobot::CollisionCheckerPtr& col,
78 const VirtualRobot::SceneObjectSetPtr& objectSet)
79 {
80 return col->checkCollision(localCopy_->getCollisionModel(), objectSet);
81 }
82
83 std::unique_ptr<Pose>
85 {
86 return std::make_unique<Pose>(localCopy_->getGlobalPose());
87 }
88
89 void
91 {
92 localCopy_->setGlobalPose(pose->toEigen());
93 }
94} // namespace armarx::simulation::scene_generation
data::PackagePath serialize() const
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
The Pose class.
Definition Pose.h:243
virtual Eigen::Matrix4f toEigen() const
Definition Pose.cpp:334
SimulatedObjectAsObject(const std::string &instanceName, const ObjectSource &source)
void updatePoseFromSimulator(armarx::SimulatorInterfacePrx &simulator) override
void addToSimulator(armarx::SimulatorInterfacePrx &simulator) override
bool checkCollision(const VirtualRobot::CollisionCheckerPtr &col, const VirtualRobot::SceneObjectSetPtr &objectSet) override
void updatePoseToSimulator(armarx::SimulatorInterfacePrx &simulator) override
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306