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 
28 
29 #include <ArmarXSimulation/interface/MMMSimulationInterface.h>
30 
31 #include <RobotAPI/interface/components/TrajectoryPlayerInterface.h>
32 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
34 #include <Eigen/Core>
35 
36 #include <mutex>
37 
38 namespace armarx
39 {
40  // forward declaration
41  class MotionFileWrapper;
42  class MotionData;
43 
44  /**
45  * \class MMMSimulationPropertyDefinitions
46  * \brief
47  */
50  {
51  public:
54  {
55  defineOptionalProperty<std::string>("AgentName", "MMM", "");
56  defineOptionalProperty<std::string>("MMMFile", "");
57  defineOptionalProperty<std::string>("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 :
91  virtual public armarx::Component,
92  public armarx::MMMSimulationInferface
93  {
94  public:
95  /**
96  * @see armarx::ManagedIceObject::getDefaultName()
97  */
98  std::string getDefaultName() const override
99  {
100  return "MMMSimulation";
101  }
102 
103  bool isMotionLoaded(const Ice::Current& = Ice::emptyCurrent) override;
104  bool loadMMMFile(const std::string& filePath, const std::string& projects = std::string(), bool createTrajectoryPlayer = true, const Ice::Current& = Ice::emptyCurrent) override;
105  void playMotion(const Ice::Current& = Ice::emptyCurrent) override;
106  void pauseMotion(const Ice::Current& = Ice::emptyCurrent) override;
107  void stopMotion(const Ice::Current& = Ice::emptyCurrent) override;
108  void setLoopBack(bool state, const Ice::Current& = Ice::emptyCurrent) override;
109  void setStartPose(const Eigen::Matrix4f& startPose, const Ice::Current& = Ice::emptyCurrent) override
110  {
111  this->startPose = startPose;
112  if (trajectoryPlayer)
113  {
114  trajectoryPlayer->setOffset(startPose);
115  }
116  }
117 
118  protected:
119  /**
120  * @see armarx::ManagedIceObject::onInitComponent()
121  */
122  void onInitComponent() override;
123 
124  /**
125  * @see armarx::ManagedIceObject::onConnectComponent()
126  */
127  void onConnectComponent() override;
128 
129  /**
130  * @see armarx::ManagedIceObject::onDisconnectComponent()
131  */
132  void onDisconnectComponent() override;
133 
134  /**
135  * @see armarx::ManagedIceObject::onExitComponent()
136  */
137  void onExitComponent() override;
138 
139  /**
140  * @see PropertyUser::createPropertyDefinitions()
141  */
143  void createTrajectoryPlayer();
144  void loadTrajectory();
145 
146  TrajectoryPlayerInterfacePrx trajectoryPlayer;
147  SimulatorInterfacePrx simulatorPrx;
148 
149  std::string kinematicUnitName;
150  std::string robotPoseUnitName;
151  std::string trajectoryPlayerName;
153 
154  std::shared_ptr<MotionFileWrapper> motionWrapper;
155  std::shared_ptr<MotionData> motionData;
156  std::string motionPath;
159  std::string agentName;
160  std::string modelFileName;
161 
162  std::recursive_mutex mmmMutex;
163 
164  private:
165  void initialize();
166 
168  };
169 
171 
172 }
173 
armarx::MMMSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MMMSimulation.cpp:347
armarx::MMMSimulation::trajectoryPlayerName
std::string trajectoryPlayerName
Definition: MMMSimulation.h:151
armarx::MMMSimulation::trajectoryPlayer
TrajectoryPlayerInterfacePrx trajectoryPlayer
Definition: MMMSimulation.h:146
armarx::MMMSimulation::agentName
std::string agentName
Definition: MMMSimulation.h:159
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::MMMSimulation::setLoopBack
void setLoopBack(bool state, const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:149
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:71
RunningTask.h
armarx::MMMSimulation::motionWrapper
std::shared_ptr< MotionFileWrapper > motionWrapper
Definition: MMMSimulation.h:154
armarx::MMMSimulation::getDefaultName
std::string getDefaultName() const override
Definition: MMMSimulation.h:98
armarx::MMMSimulation::createTrajectoryPlayer
void createTrajectoryPlayer()
Definition: MMMSimulation.cpp:306
armarx::MMMSimulation::onInitComponent
void onInitComponent() override
Definition: MMMSimulation.cpp:55
armarx::MMMSimulation::trajectoryLoaded
bool trajectoryLoaded
Definition: MMMSimulation.h:157
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MMMSimulation::isMotionLoaded
bool isMotionLoaded(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:66
armarx::MMMSimulation::simulatorPrx
SimulatorInterfacePrx simulatorPrx
Definition: MMMSimulation.h:147
armarx::MMMSimulation::kinematicUnitName
std::string kinematicUnitName
Definition: MMMSimulation.h:149
armarx::MMMSimulationPropertyDefinitions
Definition: MMMSimulation.h:48
armarx::MMMSimulationPropertyDefinitions::MMMSimulationPropertyDefinitions
MMMSimulationPropertyDefinitions(std::string prefix)
Definition: MMMSimulation.h:52
armarx::MMMSimulation::loadTrajectory
void loadTrajectory()
Definition: MMMSimulation.cpp:157
armarx::MMMSimulation::mmmMutex
std::recursive_mutex mmmMutex
Definition: MMMSimulation.h:162
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::MMMSimulation::robotPoseUnitName
std::string robotPoseUnitName
Definition: MMMSimulation.h:150
armarx::MMMSimulation::onDisconnectComponent
void onDisconnectComponent() override
Definition: MMMSimulation.cpp:334
armarx::MMMSimulation::startPose
Eigen::Matrix4f startPose
Definition: MMMSimulation.h:152
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::MMMSimulation::modelScaling
float modelScaling
Definition: MMMSimulation.h:158
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::MMMSimulation::pauseMotion
void pauseMotion(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:133
armarx::MMMSimulation::stopMotion
void stopMotion(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:141
armarx::MMMSimulation::motionData
std::shared_ptr< MotionData > motionData
Definition: MMMSimulation.h:155
armarx::MMMSimulation::onConnectComponent
void onConnectComponent() override
Definition: MMMSimulation.cpp:173
armarx::MMMSimulation::onExitComponent
void onExitComponent() override
Definition: MMMSimulation.cpp:342
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:109
armarx::MMMSimulation::modelFileName
std::string modelFileName
Definition: MMMSimulation.h:160
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MMMSimulation::playMotion
void playMotion(const Ice::Current &=Ice::emptyCurrent) override
Definition: MMMSimulation.cpp:124
armarx::MMMSimulation::motionPath
std::string motionPath
Definition: MMMSimulation.h:156