KinematicUnitDynamicSimulation.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2013-2016, 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::ArmarXObjects::KinematicUnitDynamicSimulation
19  * @author Nikolaus ( vahrenkamp at kit dot edu )
20  * @date 2013
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
28 
29 #include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
30 
31 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
32 #include <RobotAPI/interface/units/KinematicUnitInterface.h>
34 #include <set>
35 
36 #include <mutex>
37 
38 namespace armarx
39 {
40 
43  {
44  public:
47  {
48  defineOptionalProperty<bool>("MapVelocityToPositionVelocity", false, "If set, velocity control mode is internally handled as position velocity mode.");
49  defineOptionalProperty<std::string>("RobotName", "", "Name of the robot");
50  defineOptionalProperty<std::string>("SimulatorName", "Simulator", "Name of the simulator component that should be used");
51  defineOptionalProperty<float>("ControlFrequency", 100, "Frequency of the control loop");
52 
53  }
54  };
55 
56  /**
57  * @class KinematicUnitDynamicSimulation
58  * @brief This component implements the KinemticUnit with access to a physics simulator. The Simulator is quried through the simulator interface and connects to the simulator topic with name "ArmarXPhysicsWorld".
59  *
60  * @ingroup ArmarXSimulatorComponents
61  * @ingroup SensorActorUnits
62  *
63  */
65  virtual public KinematicUnit,
66  virtual public KinematicUnitDynamicSimulationInterface
67  {
68  public:
69  /**
70  * @see armarx::ManagedIceObject::getDefaultName()
71  */
72  std::string getDefaultName() const override
73  {
74  return "KinematicUnitDynamicSimulation";
75  }
76 
77  void onInitKinematicUnit() override;
78  void onStartKinematicUnit() override;
79  void onExitKinematicUnit() override;
80 
81  // proxy implementation (KinematicUnit)
82  void requestJoints(const Ice::StringSeq& joints, const Ice::Current& c = Ice::emptyCurrent) override;
83  void releaseJoints(const Ice::StringSeq& joints, const Ice::Current& c = Ice::emptyCurrent) override;
84  void switchControlMode(const NameControlModeMap& targetJointModes, const Ice::Current& c = Ice::emptyCurrent) override;
85  void setJointAngles(const NameValueMap& targetJointAngles, const Ice::Current& c = Ice::emptyCurrent) override;
86  void setJointVelocities(const NameValueMap& targetJointVelocities, const Ice::Current& c = Ice::emptyCurrent) override;
87  void setJointTorques(const NameValueMap& targetJointTorques, const Ice::Current& c = Ice::emptyCurrent) override;
88  void setJointAccelerations(const NameValueMap& targetJointAccelerations, const Ice::Current& c = Ice::emptyCurrent) override;
89  void setJointDecelerations(const NameValueMap& targetJointDecelerations, const Ice::Current& c = Ice::emptyCurrent) override;
90 
91  NameValueMap getJointAngles(const Ice::Current&) const override
92  {
93  ARMARX_WARNING << "NYI";
94  return {};
95  }
96  NameValueMap getJointVelocities(const Ice::Current&) const override
97  {
98  ARMARX_WARNING << "NYI";
99  return {};
100  }
101  Ice::StringSeq getJoints(const Ice::Current&) const override
102  {
103  ARMARX_WARNING << "NYI";
104  return {};
105  }
106 
107  DebugInfo getDebugInfo(const Ice::Current& c = Ice::emptyCurrent) const override;
108 
109  protected:
110 
111  // implement SimulatorRobotListener to receive robot updates from simulator
112  void reportState(SimulatedRobotState const& state, const Ice::Current&) override;
113 
114  NameControlModeMap getControlModes(const Ice::Current& c = Ice::emptyCurrent) override;
115 
117 
118  void periodicExec();
119 
120  /**
121  * @see PropertyUser::createPropertyDefinitions()
122  */
124  {
128  }
129 
130  std::set<std::string> nodeNames;
131  std::string robotName;
132  std::string robotTopicName;
133  std::string simulatorPrxName;
134 
138  NameControlModeMap currentControlModes;
139 
141 
143 
145 
146  std::recursive_mutex accessMutex;
147 
148  SimulatorInterfacePrx simulatorPrx;
149  };
150 }
armarx::KinematicUnitDynamicSimulation::execTask
PeriodicTask< KinematicUnitDynamicSimulation >::pointer_type execTask
Definition: KinematicUnitDynamicSimulation.h:116
armarx::KinematicUnitDynamicSimulation::currentControlModes
NameControlModeMap currentControlModes
Definition: KinematicUnitDynamicSimulation.h:138
armarx::KinematicUnitDynamicSimulation::periodicExec
void periodicExec()
Definition: KinematicUnitDynamicSimulation.cpp:284
armarx::KinematicUnitDynamicSimulation::getJointVelocities
NameValueMap getJointVelocities(const Ice::Current &) const override
Definition: KinematicUnitDynamicSimulation.h:96
armarx::KinematicUnit
The KinematicUnit class.
Definition: KinematicUnit.h:76
armarx::KinematicUnitDynamicSimulation::currentJointTargets
NameValueMap currentJointTargets
Definition: KinematicUnitDynamicSimulation.h:135
armarx::KinematicUnitDynamicSimulation::mapVelToPosVel
bool mapVelToPosVel
Definition: KinematicUnitDynamicSimulation.h:144
armarx::KinematicUnitDynamicSimulation::robotTopicName
std::string robotTopicName
Definition: KinematicUnitDynamicSimulation.h:132
armarx::KinematicUnitDynamicSimulation::onExitKinematicUnit
void onExitKinematicUnit() override
Definition: KinematicUnitDynamicSimulation.cpp:89
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::KinematicUnitDynamicSimulation::onStartKinematicUnit
void onStartKinematicUnit() override
Definition: KinematicUnitDynamicSimulation.cpp:69
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::KinematicUnitDynamicSimulation::currentJointValues
NameValueMap currentJointValues
Definition: KinematicUnitDynamicSimulation.h:142
armarx::KinematicUnitDynamicSimulation::accessMutex
std::recursive_mutex accessMutex
Definition: KinematicUnitDynamicSimulation.h:146
armarx::KinematicUnitDynamicSimulation::simulatorPrx
SimulatorInterfacePrx simulatorPrx
Definition: KinematicUnitDynamicSimulation.h:148
RobotAPIObjectFactories.h
armarx::KinematicUnitDynamicSimulation::requestJoints
void requestJoints(const Ice::StringSeq &joints, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:252
armarx::KinematicUnitDynamicSimulation::setJointAngles
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:200
armarx::KinematicUnitDynamicSimulation::getDebugInfo
DebugInfo getDebugInfo(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: KinematicUnitDynamicSimulation.cpp:402
armarx::KinematicUnitDynamicSimulation::getDefaultName
std::string getDefaultName() const override
Definition: KinematicUnitDynamicSimulation.h:72
armarx::KinematicUnitDynamicSimulation::currentJointTorqueTargets
NameValueMap currentJointTorqueTargets
Definition: KinematicUnitDynamicSimulation.h:137
KinematicUnitSimulation.h
armarx::KinematicUnitDynamicSimulation::setJointAccelerations
void setJointAccelerations(const NameValueMap &targetJointAccelerations, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:242
armarx::KinematicUnitDynamicSimulation::switchControlMode
void switchControlMode(const NameControlModeMap &targetJointModes, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:183
armarx::KinematicUnitDynamicSimulation::currentJointVelTargets
NameValueMap currentJointVelTargets
Definition: KinematicUnitDynamicSimulation.h:136
armarx::KinematicUnitDynamicSimulation::releaseJoints
void releaseJoints(const Ice::StringSeq &joints, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:267
armarx::KinematicUnitDynamicSimulation::setJointDecelerations
void setJointDecelerations(const NameValueMap &targetJointDecelerations, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:246
armarx::KinematicUnitDynamicSimulation::simulatorPrxName
std::string simulatorPrxName
Definition: KinematicUnitDynamicSimulation.h:133
armarx::KinematicUnitDynamicSimulation::robotName
std::string robotName
Definition: KinematicUnitDynamicSimulation.h:131
armarx::KinematicUnitDynamicSimulation
This component implements the KinemticUnit with access to a physics simulator. The Simulator is qurie...
Definition: KinematicUnitDynamicSimulation.h:64
armarx::KinematicUnitPropertyDefinitions
Definition: KinematicUnit.h:44
armarx::KinematicUnitDynamicSimulation::cycleTime
int cycleTime
Definition: KinematicUnitDynamicSimulation.h:140
armarx::KinematicUnitDynamicSimulation::getJointAngles
NameValueMap getJointAngles(const Ice::Current &) const override
Definition: KinematicUnitDynamicSimulation.h:91
Component.h
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::KinematicUnitDynamicSimulation::setJointVelocities
void setJointVelocities(const NameValueMap &targetJointVelocities, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:216
armarx::KinematicUnitDynamicSimulation::getControlModes
NameControlModeMap getControlModes(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:160
armarx::KinematicUnitDynamicSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: KinematicUnitDynamicSimulation.h:123
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::KinematicUnitDynamicSimulation::onInitKinematicUnit
void onInitKinematicUnit() override
Definition: KinematicUnitDynamicSimulation.cpp:39
armarx::KinematicUnitDynamicSimulation::getJoints
Ice::StringSeq getJoints(const Ice::Current &) const override
Definition: KinematicUnitDynamicSimulation.h:101
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::KinematicUnitDynamicSimulationPropertyDefinitions::KinematicUnitDynamicSimulationPropertyDefinitions
KinematicUnitDynamicSimulationPropertyDefinitions(std::string prefix)
Definition: KinematicUnitDynamicSimulation.h:45
armarx::KinematicUnitDynamicSimulationPropertyDefinitions
Definition: KinematicUnitDynamicSimulation.h:41
armarx::KinematicUnitDynamicSimulation::nodeNames
std::set< std::string > nodeNames
Definition: KinematicUnitDynamicSimulation.h:130
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::KinematicUnitDynamicSimulation::reportState
void reportState(SimulatedRobotState const &state, const Ice::Current &) override
Definition: KinematicUnitDynamicSimulation.cpp:97
armarx::KinematicUnitDynamicSimulation::setJointTorques
void setJointTorques(const NameValueMap &targetJointTorques, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnitDynamicSimulation.cpp:228