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
26#include <mutex>
27#include <set>
28
30
32#include <RobotAPI/interface/units/KinematicUnitInterface.h>
34
35#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
36
37#include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
38
39namespace armarx
40{
41
44 {
45 public:
48 {
50 "MapVelocityToPositionVelocity",
51 false,
52 "If set, velocity control mode is internally handled as position velocity mode.");
53 defineOptionalProperty<std::string>("RobotName", "", "Name of the robot");
55 "SimulatorName",
56 "Simulator",
57 "Name of the simulator component that should be used");
58 defineOptionalProperty<float>("ControlFrequency", 100, "Frequency of the control loop");
59 }
60 };
61
62 /**
63 * @class KinematicUnitDynamicSimulation
64 * @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".
65 *
66 * @ingroup ArmarXSimulatorComponents
67 * @ingroup SensorActorUnits
68 *
69 */
71 virtual public KinematicUnit,
72 virtual public KinematicUnitDynamicSimulationInterface
73 {
74 public:
75 /**
76 * @see armarx::ManagedIceObject::getDefaultName()
77 */
78 std::string
79 getDefaultName() const override
80 {
81 return "KinematicUnitDynamicSimulation";
82 }
83
84 void onInitKinematicUnit() override;
85 void onStartKinematicUnit() override;
86 void onExitKinematicUnit() override;
87
88 // proxy implementation (KinematicUnit)
89 void requestJoints(const Ice::StringSeq& joints,
90 const Ice::Current& c = Ice::emptyCurrent) override;
91 void releaseJoints(const Ice::StringSeq& joints,
92 const Ice::Current& c = Ice::emptyCurrent) override;
93 void switchControlMode(const NameControlModeMap& targetJointModes,
94 const Ice::Current& c = Ice::emptyCurrent) override;
95 void setJointAngles(const NameValueMap& targetJointAngles,
96 const Ice::Current& c = Ice::emptyCurrent) override;
97 void setJointVelocities(const NameValueMap& targetJointVelocities,
98 const Ice::Current& c = Ice::emptyCurrent) override;
99 void setJointTorques(const NameValueMap& targetJointTorques,
100 const Ice::Current& c = Ice::emptyCurrent) override;
101 void setJointAccelerations(const NameValueMap& targetJointAccelerations,
102 const Ice::Current& c = Ice::emptyCurrent) override;
103 void setJointDecelerations(const NameValueMap& targetJointDecelerations,
104 const Ice::Current& c = Ice::emptyCurrent) override;
105
106 NameValueMap
107 getJointAngles(const Ice::Current&) const override
108 {
109 ARMARX_WARNING << "NYI";
110 return {};
111 }
112
113 NameValueMap
114 getJointVelocities(const Ice::Current&) const override
115 {
116 ARMARX_WARNING << "NYI";
117 return {};
118 }
119
120 Ice::StringSeq
121 getJoints(const Ice::Current&) const override
122 {
123 ARMARX_WARNING << "NYI";
124 return {};
125 }
126
127 DebugInfo getDebugInfo(const Ice::Current& c = Ice::emptyCurrent) const override;
128
129 protected:
130 // implement SimulatorRobotListener to receive robot updates from simulator
131 void reportState(SimulatedRobotState const& state, const Ice::Current&) override;
132
133 NameControlModeMap getControlModes(const Ice::Current& c = Ice::emptyCurrent) override;
134
136
137 void periodicExec();
138
139 /**
140 * @see PropertyUser::createPropertyDefinitions()
141 */
148
149 std::set<std::string> nodeNames;
150 std::string robotName;
151 std::string robotTopicName;
152 std::string simulatorPrxName;
153
157 NameControlModeMap currentControlModes;
158
160
161 NameValueMap currentJointValues;
162
164
165 std::recursive_mutex accessMutex;
166
167 SimulatorInterfacePrx simulatorPrx;
168 };
169} // namespace armarx
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
This component implements the KinemticUnit with access to a physics simulator.
void releaseJoints(const Ice::StringSeq &joints, const Ice::Current &c=Ice::emptyCurrent) override
void requestJoints(const Ice::StringSeq &joints, const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getJointVelocities(const Ice::Current &) const override
Ice::StringSeq getJoints(const Ice::Current &) const override
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &c=Ice::emptyCurrent) override
void switchControlMode(const NameControlModeMap &targetJointModes, const Ice::Current &c=Ice::emptyCurrent) override
void setJointTorques(const NameValueMap &targetJointTorques, const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
PeriodicTask< KinematicUnitDynamicSimulation >::pointer_type execTask
NameValueMap getJointAngles(const Ice::Current &) const override
void setJointAccelerations(const NameValueMap &targetJointAccelerations, const Ice::Current &c=Ice::emptyCurrent) override
void setJointDecelerations(const NameValueMap &targetJointDecelerations, const Ice::Current &c=Ice::emptyCurrent) override
DebugInfo getDebugInfo(const Ice::Current &c=Ice::emptyCurrent) const override
void reportState(SimulatedRobotState const &state, const Ice::Current &) override
NameControlModeMap getControlModes(const Ice::Current &c=Ice::emptyCurrent) override
void setJointVelocities(const NameValueMap &targetJointVelocities, const Ice::Current &c=Ice::emptyCurrent) override
KinematicUnitPropertyDefinitions(std::string prefix)
The KinematicUnit class.
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
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)
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.