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 
39 namespace armarx
40 {
41  // forward declaration
42  class MotionFileWrapper;
43  class MotionData;
44 
45  /**
46  * \class MMMSimulationPropertyDefinitions
47  * \brief
48  */
50  {
51  public:
53  {
54  defineOptionalProperty<std::string>("AgentName", "MMM", "");
55  defineOptionalProperty<std::string>("MMMFile", "");
56  defineOptionalProperty<std::string>(
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
114  const Ice::Current& = Ice::emptyCurrent) override
115  {
116  this->startPose = startPose;
117  if (trajectoryPlayer)
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  */
148  void createTrajectoryPlayer();
149  void loadTrajectory();
150 
151  TrajectoryPlayerInterfacePrx trajectoryPlayer;
152  SimulatorInterfacePrx simulatorPrx;
153 
154  std::string kinematicUnitName;
155  std::string robotPoseUnitName;
156  std::string trajectoryPlayerName;
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
armarx::MMMSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MMMSimulation.cpp:403
armarx::MMMSimulation::trajectoryPlayerName
std::string trajectoryPlayerName
Definition: MMMSimulation.h:156
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::MMMSimulation::trajectoryPlayer
TrajectoryPlayerInterfacePrx trajectoryPlayer
Definition: MMMSimulation.h:151
armarx::MMMSimulation::agentName
std::string agentName
Definition: MMMSimulation.h:164
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::MMMSimulation::setLoopBack
void setLoopBack(bool state, const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:163
armarx::MMMSimulation::loadMMMFile
bool loadMMMFile(const std::string &filePath, const std::string &projects=std::string(), bool createTrajectoryPlayer=true, const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:76
RunningTask.h
armarx::MMMSimulation::motionWrapper
std::shared_ptr< MotionFileWrapper > motionWrapper
Definition: MMMSimulation.h:159
armarx::MMMSimulation::getDefaultName
std::string getDefaultName() const override
Definition: MMMSimulation.h:97
armarx::MMMSimulation::createTrajectoryPlayer
void createTrajectoryPlayer()
Definition: MMMSimulation.cpp:353
armarx::MMMSimulation::onInitComponent
void onInitComponent() override
Definition: MMMSimulation.cpp:58
armarx::MMMSimulation::trajectoryLoaded
bool trajectoryLoaded
Definition: MMMSimulation.h:162
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MMMSimulation::isMotionLoaded
bool isMotionLoaded(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:70
armarx::MMMSimulation::simulatorPrx
SimulatorInterfacePrx simulatorPrx
Definition: MMMSimulation.h:152
armarx::MMMSimulation::kinematicUnitName
std::string kinematicUnitName
Definition: MMMSimulation.h:154
armarx::MMMSimulationPropertyDefinitions
Definition: MMMSimulation.h:49
armarx::MMMSimulationPropertyDefinitions::MMMSimulationPropertyDefinitions
MMMSimulationPropertyDefinitions(std::string prefix)
Definition: MMMSimulation.h:52
armarx::MMMSimulation::loadTrajectory
void loadTrajectory()
Definition: MMMSimulation.cpp:172
armarx::MMMSimulation::mmmMutex
std::recursive_mutex mmmMutex
Definition: MMMSimulation.h:167
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::MMMSimulation::robotPoseUnitName
std::string robotPoseUnitName
Definition: MMMSimulation.h:155
armarx::MMMSimulation::onDisconnectComponent
void onDisconnectComponent() override
Definition: MMMSimulation.cpp:389
armarx::MMMSimulation::startPose
Eigen::Matrix4f startPose
Definition: MMMSimulation.h:157
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::MMMSimulation::modelScaling
float modelScaling
Definition: MMMSimulation.h:163
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::MMMSimulation::pauseMotion
void pauseMotion(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:145
armarx::MMMSimulation::stopMotion
void stopMotion(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:154
armarx::MMMSimulation::motionData
std::shared_ptr< MotionData > motionData
Definition: MMMSimulation.h:160
armarx::MMMSimulation::onConnectComponent
void onConnectComponent() override
Definition: MMMSimulation.cpp:189
armarx::MMMSimulation::onExitComponent
void onExitComponent() override
Definition: MMMSimulation.cpp:398
armarx::MMMSimulation
The MMMSimulation class.
Definition: MMMSimulation.h:90
armarx::MMMSimulation::setStartPose
void setStartPose(const Eigen::Matrix4f &startPose, const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.h:113
armarx::MMMSimulation::modelFileName
std::string modelFileName
Definition: MMMSimulation.h:165
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::MMMSimulation::playMotion
void playMotion(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:135
armarx::MMMSimulation::motionPath
std::string motionPath
Definition: MMMSimulation.h:161