SimulatedObjectAsRobot.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 <memory>
25
26#include <Eigen/src/Core/Matrix.h>
27
28#include <VirtualRobot/XML/RobotIO.h>
29
31
33
35{
36 SimulatedObjectAsRobot::SimulatedObjectAsRobot(const std::string& instanceName,
37 const ObjectSource& objectSource) :
38 SimulatedObject(instanceName, objectSource),
39 localCopy_(VirtualRobot::RobotIO::loadRobot(objectSource.path.toSystemPath()))
40 {
41 localCopy_->setName(instanceName);
42 }
43
44 void
45 SimulatedObjectAsRobot::addToSimulator(armarx::SimulatorInterfacePrx& simulator)
46 {
47 const std::string& newName = simulator->addRobot(getObjectSource().path.toSystemPath());
48 setInstanceName(newName);
49 }
50
51 void
52 SimulatedObjectAsRobot::updatePoseFromSimulator(armarx::SimulatorInterfacePrx& simulator)
53 {
54 const PoseBasePtr& poseBase = simulator->getRobotPose(getInstanceName());
55 Pose p(poseBase->position, poseBase->orientation);
56 localCopy_->setGlobalPose(p.toEigen());
57 }
58
59 void
60 SimulatedObjectAsRobot::updatePoseToSimulator(armarx::SimulatorInterfacePrx& simulator)
61 {
62 PosePtr pose(new Pose(localCopy_->getGlobalPose()));
63 simulator->setRobotPose(getInstanceName(), pose);
64 }
65
66 bool
67 SimulatedObjectAsRobot::checkCollision(const VirtualRobot::CollisionCheckerPtr& col,
68 const VirtualRobot::SceneObjectSetPtr& objectSet)
69 {
70 bool collision = false;
71 for (const auto& colModel : localCopy_->getCollisionModels())
72 {
73 collision |= col->checkCollision(colModel, objectSet);
74 }
75 return collision;
76 }
77
78 std::unique_ptr<Pose>
80 {
81 return std::make_unique<Pose>(localCopy_->getGlobalPose());
82 }
83
84 void
86 {
87 localCopy_->setGlobalPose(pose->toEigen());
88 }
89} // namespace armarx::simulation::scene_generation
The Pose class.
Definition Pose.h:243
virtual Eigen::Matrix4f toEigen() const
Definition Pose.cpp:334
void updatePoseFromSimulator(armarx::SimulatorInterfacePrx &simulator) override
void addToSimulator(armarx::SimulatorInterfacePrx &simulator) override
bool checkCollision(const VirtualRobot::CollisionCheckerPtr &col, const VirtualRobot::SceneObjectSetPtr &objectSet) override
SimulatedObjectAsRobot(const std::string &instanceName, const ObjectSource &source)
void updatePoseToSimulator(armarx::SimulatorInterfacePrx &simulator) override
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306