KinematicUnitSimulation.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-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 ArmarXCore::units
19 * @author Christian Boege (boege dot at kit dot edu)
20 * @date 2011
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#include <random>
29
30#include <IceUtil/Time.h>
31
34
36
37#include "KinematicUnit.h"
38
39namespace armarx
40{
41 /**
42 * \class KinematicUnitSimulationJointState.
43 * \brief State of a joint.
44 * \ingroup RobotAPI-SensorActorUnits-util
45 *
46 * Includes the control mode, the joint angle, velocity, torque, and motor temperature.
47 * Controlmode defaults to ePositionControl, all other values default to zero.
48 */
50 {
51 public:
56
57 void
59 {
60 controlMode = eDisabled;
61 angle = 0.0f;
62 velocity = 0.0f;
63 velocityActual = 0.0f;
64 torque = 0.0f;
65 temperature = 0.0f;
66 }
67
68 ControlMode controlMode;
69 float angle;
70 float velocity;
72 float torque;
74 };
75
77 std::map<std::string, KinematicUnitSimulationJointState>;
78
79 /**
80 * \class JointInfo.
81 * \brief Additional information about a joint.
82 * \ingroup RobotAPI-SensorActorUnits-util
83 *
84 * Joint info including lower and upper joint limits (rad).
85 * No limits are set by default (lo = hi).
86 */
88 {
89 public:
94
95 void
97 {
98 limitLo = 0.0f;
99 limitHi = 0.0f;
100 }
101
102 bool
103 hasLimits() const
104 {
105 return (limitLo != limitHi);
106 }
107
108 bool
110 {
111 return !hasLimits() || limitLo - limitHi >= 360.0f;
112 }
113
114 float limitLo;
115 float limitHi;
116 };
117
119 std::map<std::string, KinematicUnitSimulationJointInfo>;
120
121 /**
122 * \class KinematicUnitSimulationPropertyDefinitions
123 * \brief
124 */
130
131 /**
132 * \class KinematicUnitSimulation
133 * \brief Simulates robot kinematics
134 * \ingroup RobotAPI-SensorActorUnits-simulation
135 */
137 {
138 public:
139 // inherited from Component
140 std::string
141 getDefaultName() const override
142 {
143 return "KinematicUnitSimulation";
144 }
145
146 void onInitKinematicUnit() override;
147 void onStartKinematicUnit() override;
148 void onExitKinematicUnit() override;
149
150 void simulationFunction();
151
152 // proxy implementation
153 void requestJoints(const Ice::StringSeq& joints,
154 const Ice::Current& c = Ice::emptyCurrent) override;
155 void releaseJoints(const Ice::StringSeq& joints,
156 const Ice::Current& c = Ice::emptyCurrent) override;
157 void switchControlMode(const NameControlModeMap& targetJointModes,
158 const Ice::Current& c = Ice::emptyCurrent) override;
159 void setJointAngles(const NameValueMap& targetJointAngles,
160 const Ice::Current& c = Ice::emptyCurrent) override;
161 void setJointVelocities(const NameValueMap& targetJointVelocities,
162 const Ice::Current& c = Ice::emptyCurrent) override;
163 void setJointTorques(const NameValueMap& targetJointTorques,
164 const Ice::Current& c = Ice::emptyCurrent) override;
165
166 NameControlModeMap getControlModes(const Ice::Current& c = Ice::emptyCurrent) override;
167
168 /// @warning Not implemented yet!
169 void setJointAccelerations(const NameValueMap& targetJointAccelerations,
170 const Ice::Current& c = Ice::emptyCurrent) override;
171
172 /// @warning Not implemented yet!
173 void setJointDecelerations(const NameValueMap& targetJointDecelerations,
174 const Ice::Current& c = Ice::emptyCurrent) override;
175
176 void stop(const Ice::Current& c = Ice::emptyCurrent) override;
177
178 armarx::NameValueMap getJointAngles(const Ice::Current& c) const override;
179 armarx::NameValueMap getJointVelocities(const Ice::Current& c) const override;
180 Ice::StringSeq getJoints(const Ice::Current& c) const override;
181
182 DebugInfo getDebugInfo(const Ice::Current& c = Ice::emptyCurrent) const override;
183
184 /// @see PropertyUser::createPropertyDefinitions()
186
187 protected:
191 mutable std::mutex jointStatesMutex;
192 IceUtil::Time lastExecutionTime;
193 float noise;
195 std::normal_distribution<double> distribution;
196 std::default_random_engine generator;
198 std::map<std::string, PIDControllerPtr> positionControlPIDController;
200
201 mutable std::mutex sensorDataMutex;
202 NameValueMap sensorAngles;
203 NameValueMap sensorVelocities;
204 };
205} // namespace armarx
constexpr T c
KinematicUnitPropertyDefinitions(std::string prefix)
void releaseJoints(const Ice::StringSeq &joints, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< KinematicUnitSimulation >::pointer_type simulationTask
void requestJoints(const Ice::StringSeq &joints, const Ice::Current &c=Ice::emptyCurrent) override
std::normal_distribution< double > distribution
armarx::NameValueMap getJointVelocities(const Ice::Current &c) const override
armarx::NameValueMap getJointAngles(const Ice::Current &c) 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
DebugInfo getDebugInfo(const Ice::Current &c=Ice::emptyCurrent) const override
std::map< std::string, PIDControllerPtr > positionControlPIDController
void stop(const Ice::Current &c=Ice::emptyCurrent) 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
PropertyDefinitionsPtr createPropertyDefinitions() override
NameControlModeMap getControlModes(const Ice::Current &c=Ice::emptyCurrent) override
KinematicUnitSimulationJointStates jointStates
KinematicUnitSimulationJointInfos jointInfos
Ice::StringSeq getJoints(const Ice::Current &c) const override
KinematicUnitSimulationJointStates previousJointStates
void setJointVelocities(const NameValueMap &targetJointVelocities, const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
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.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, KinematicUnitSimulationJointState > KinematicUnitSimulationJointStates
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::map< std::string, KinematicUnitSimulationJointInfo > KinematicUnitSimulationJointInfos