MMMSimulation.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2020, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXSimulation::components::MMMSimulation
19 * @author Andre Meixner ( andre dot meixner at kit dot edu )
20 * @date 2020
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27#include <mutex>
28
29#include <Eigen/Core>
30
33
34#include <RobotAPI/interface/components/TrajectoryPlayerInterface.h>
35
36#include <ArmarXSimulation/interface/MMMSimulationInterface.h>
37#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
38
39namespace armarx
40{
41 // forward declaration
43 class MotionData;
44
45 /**
46 * \class MMMSimulationPropertyDefinitions
47 * \brief
48 */
50 {
51 public:
53 {
54 defineOptionalProperty<std::string>("AgentName", "MMM", "");
57 "RobotFileName", "RobotAPI/robots/MMM/mmm.xml", "Path to MMM XML File");
58 defineOptionalProperty<std::string>("RobotFileNameProject", "RobotAPI", "");
59 //defineOptionalProperty<std::string>("RobotName", "MMM");
60 defineOptionalProperty<std::string>("RobotNodeSetName", "Joints_Revolute");
61 defineOptionalProperty<std::string>("WorkingMemoryName", "WorkingMemory");
62 defineOptionalProperty<std::string>("SimulatorName", "Simulator");
63 defineOptionalProperty<bool>("LoopPlayback", false);
64 defineOptionalProperty<float>("Scaling", 1.8);
65 defineOptionalProperty<float>("StartPose.x", 0);
66 defineOptionalProperty<float>("StartPose.y", 0);
67 defineOptionalProperty<float>("StartPose.z", 0);
68 defineOptionalProperty<float>("StartPose.roll", 0);
69 defineOptionalProperty<float>("StartPose.pitch", 0);
70 defineOptionalProperty<float>("StartPose.yaw", 0);
71 defineOptionalProperty<bool>("AutoPlay", false);
72 defineOptionalProperty<bool>("LoadToMemory", false);
73 }
74 };
75
76 /**
77 * \defgroup Component-MMMSimulation MMMSimulation
78 * \ingroup RobotComponents-Components
79 * \brief Replays an MMM trajectory from a file.
80 *
81 * MMMSimulation reads an MMM trajectory from an MMM XML file (component property) and replays the motion using the KinematicUnit and its currently loaded robot.
82 * The trajectory can be replayed using position control or velocity control.
83 * In the latter case, the control parameters (P, I, D) can be configured via component properties.
84 */
85
86 /**
87 * @ingroup Component-MMMSimulation
88 * @brief The MMMSimulation class
89 */
90 class MMMSimulation : virtual public armarx::Component, public armarx::MMMSimulationInferface
91 {
92 public:
93 /**
94 * @see armarx::ManagedIceObject::getDefaultName()
95 */
96 std::string
97 getDefaultName() const override
98 {
99 return "MMMSimulation";
100 }
101
102 bool isMotionLoaded(const Ice::Current& = Ice::emptyCurrent) override;
103 bool loadMMMFile(const std::string& filePath,
104 const std::string& projects = std::string(),
105 bool createTrajectoryPlayer = true,
106 const Ice::Current& = Ice::emptyCurrent) override;
107 void playMotion(const Ice::Current& = Ice::emptyCurrent) override;
108 void pauseMotion(const Ice::Current& = Ice::emptyCurrent) override;
109 void stopMotion(const Ice::Current& = Ice::emptyCurrent) override;
110 void setLoopBack(bool state, const Ice::Current& = Ice::emptyCurrent) override;
111
112 void
113 setStartPose(const Eigen::Matrix4f& startPose,
114 const Ice::Current& = Ice::emptyCurrent) override
115 {
116 this->startPose = startPose;
118 {
119 trajectoryPlayer->setOffset(startPose);
120 }
121 }
122
123 protected:
124 /**
125 * @see armarx::ManagedIceObject::onInitComponent()
126 */
127 void onInitComponent() override;
128
129 /**
130 * @see armarx::ManagedIceObject::onConnectComponent()
131 */
132 void onConnectComponent() override;
133
134 /**
135 * @see armarx::ManagedIceObject::onDisconnectComponent()
136 */
137 void onDisconnectComponent() override;
138
139 /**
140 * @see armarx::ManagedIceObject::onExitComponent()
141 */
142 void onExitComponent() override;
143
144 /**
145 * @see PropertyUser::createPropertyDefinitions()
146 */
149 void loadTrajectory();
150
151 TrajectoryPlayerInterfacePrx trajectoryPlayer;
152 SimulatorInterfacePrx simulatorPrx;
153
154 std::string kinematicUnitName;
155 std::string robotPoseUnitName;
157 Eigen::Matrix4f startPose;
158
159 std::shared_ptr<MotionFileWrapper> motionWrapper;
160 std::shared_ptr<MotionData> motionData;
161 std::string motionPath;
164 std::string agentName;
165 std::string modelFileName;
166
167 std::recursive_mutex mmmMutex;
168
169 private:
170 void initialize();
171
173 };
174
176
177} // namespace armarx
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
MMMSimulationPropertyDefinitions(std::string prefix)
The MMMSimulation class.
Eigen::Matrix4f startPose
void onInitComponent() override
void stopMotion(const Ice::Current &=Ice::emptyCurrent) override
void pauseMotion(const Ice::Current &=Ice::emptyCurrent) override
std::string trajectoryPlayerName
bool isMotionLoaded(const Ice::Current &=Ice::emptyCurrent) override
std::string kinematicUnitName
void onDisconnectComponent() override
TrajectoryPlayerInterfacePrx trajectoryPlayer
std::string robotPoseUnitName
std::shared_ptr< MotionData > motionData
std::shared_ptr< MotionFileWrapper > motionWrapper
void playMotion(const Ice::Current &=Ice::emptyCurrent) override
SimulatorInterfacePrx simulatorPrx
void onConnectComponent() override
PropertyDefinitionsPtr createPropertyDefinitions() override
bool loadMMMFile(const std::string &filePath, const std::string &projects=std::string(), bool createTrajectoryPlayer=true, const Ice::Current &=Ice::emptyCurrent) override
void setStartPose(const Eigen::Matrix4f &startPose, const Ice::Current &=Ice::emptyCurrent) override
void setLoopBack(bool state, const Ice::Current &=Ice::emptyCurrent) override
void onExitComponent() override
std::recursive_mutex mmmMutex
std::string getDefaultName() const override
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::Handle<::armarx::MMMSimulation > MMMSimulationPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.