KinematicsWorld.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::Simulator
19 * @author Nikolaus Vahrenkamp ( vahrenkamp at kit dot edu )
20 * @date 2017
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27#include <Eigen/Core>
28#include <Eigen/Geometry>
29
30// just needed for SceneData
31#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
32// #include <ArmarXCore/core/system/Synchronization.h>
33#include <mutex>
34
36
39
40#include "SimulatedWorld.h"
41
42namespace armarx
43{
44 /*!
45 * \brief The KinematicsWorld class encapsulates the kinemtics simulation and the corresponding data.
46 * All real physics simulation is either approximated through simple kinemtics or disabled.
47 *
48 */
50 {
51 public:
53 ~KinematicsWorld() override;
54
55 virtual void initialize(int stepSizeMS,
56 float maxRealTimeSimSpeed = 1,
57 bool floorPlane = false,
58 std::string floorTexture = std::string());
59
60 //! ignoring velocity target
61 void actuateRobotJoints(const std::string& robotName,
62 const std::map<std::string, float>& angles,
63 const std::map<std::string, float>& velocities) override;
64 void actuateRobotJointsPos(const std::string& robotName,
65 const std::map<std::string, float>& angles) override;
66 void actuateRobotJointsVel(const std::string& robotName,
67 const std::map<std::string, float>& velocities) override;
68 void actuateRobotJointsTorque(const std::string& robotName,
69 const std::map<std::string, float>& torques) override;
70 void setRobotPose(const std::string& robotName, const Eigen::Matrix4f& globalPose) override;
71
72 void applyForceRobotNode(const std::string& robotName,
73 const std::string& robotNodeName,
74 const Eigen::Vector3f& force) override;
75 void applyTorqueRobotNode(const std::string& robotName,
76 const std::string& robotNodeName,
77 const Eigen::Vector3f& torque) override;
78
79 void applyForceObject(const std::string& objectName, const Eigen::Vector3f& force) override;
80 void applyTorqueObject(const std::string& objectName,
81 const Eigen::Vector3f& torque) override;
82
83 bool hasObject(const std::string& instanceName) override;
84 void setObjectPose(const std::string& objectName,
85 const Eigen::Matrix4f& globalPose) override;
86
87 bool hasRobot(const std::string& robotName) override;
88 bool hasRobotNode(const std::string& robotName, const std::string& robotNodeName) override;
89 float getRobotMass(const std::string& robotName) override;
90
91 std::map<std::string, float> getRobotJointAngles(const std::string& robotName) override;
92 float getRobotJointAngle(const std::string& robotName,
93 const std::string& nodeName) override;
94 std::map<std::string, float> getRobotJointVelocities(const std::string& robotName) override;
95 float getRobotJointVelocity(const std::string& robotName,
96 const std::string& nodeName) override;
97 std::map<std::string, float> getRobotJointTorques(const std::string&) override;
98 ForceTorqueDataSeq getRobotForceTorqueSensors(const std::string&) override;
99
100 float getRobotJointLimitLo(const std::string& robotName,
101 const std::string& nodeName) override;
102 float getRobotJointLimitHi(const std::string& robotName,
103 const std::string& nodeName) override;
104 Eigen::Matrix4f getRobotPose(const std::string& robotName) override;
105
106 float getRobotMaxTorque(const std::string& robotName, const std::string& nodeName) override;
107 void setRobotMaxTorque(const std::string& robotName,
108 const std::string& nodeName,
109 float maxTorque) override;
110
111 Eigen::Matrix4f getRobotNodePose(const std::string& robotName,
112 const std::string& robotNodeName) override;
113
114 Eigen::Vector3f getRobotLinearVelocity(const std::string& robotName,
115 const std::string& nodeName) override;
116 Eigen::Vector3f getRobotAngularVelocity(const std::string& robotName,
117 const std::string& nodeName) override;
118
119 // the robotNodeName is ignored, the whole robot is moved...
120 void setRobotLinearVelocity(const std::string& robotName,
121 const std::string& robotNodeName,
122 const Eigen::Vector3f& vel) override;
123 void setRobotAngularVelocity(const std::string& robotName,
124 const std::string& robotNodeName,
125 const Eigen::Vector3f& vel) override;
126 void setRobotLinearVelocityRobotRootFrame(const std::string& robotName,
127 const std::string& robotNodeName,
128 const Eigen::Vector3f& vel) override;
129 void setRobotAngularVelocityRobotRootFrame(const std::string& robotName,
130 const std::string& robotNodeName,
131 const Eigen::Vector3f& vel) override;
132
133 Eigen::Matrix4f getObjectPose(const std::string& objectName) override;
134
135 VirtualRobot::RobotPtr getRobot(const std::string& robotName) override;
136 std::map<std::string, VirtualRobot::RobotPtr> getRobots() override;
137 virtual VirtualRobot::SceneObjectPtr getObject(const std::string& objectName);
138 std::vector<VirtualRobot::SceneObjectPtr> getObjects() override;
139
140 std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo> copyContacts() override;
141
142
143 FramedPosePtr toFramedPose(const Eigen::Matrix4f& globalPose,
144 const std::string& robotName,
145 const std::string& frameName) override;
146
147 /**
148 * Perform one simulation step. Calculates the delta update time from the time that has passed since the last call.
149 * This updates all models.
150 */
151 void stepPhysicsRealTime() override;
152
153 /**
154 * Perform one simulation step.
155 * This updates all models.
156 */
157 void stepPhysicsFixedTimeStep() override;
158
159 /*!
160 * \brief
161 * \return The number of steps * the timestep in MS
162 */
163 int getFixedTimeStepMS() override;
164
165
166 void enableLogging(const std::string& robotName, const std::string& logFile) override;
167
168 armarx::DistanceInfo getRobotNodeDistance(const std::string& robotName,
169 const std::string& robotNodeName1,
170 const std::string& robotNodeName2) override;
171 armarx::DistanceInfo getDistance(const std::string& robotName,
172 const std::string& robotNodeName,
173 const std::string& worldObjectName) override;
174
175 std::vector<std::string> getRobotNames() override;
176 std::vector<std::string> getObstacleNames() override;
177
178 void
179 setRobotNodeSimType(const std::string& robotName,
180 const std::string& robotNodeName,
181 VirtualRobot::SceneObject::Physics::SimulationType simType) override;
182 void setObjectSimType(const std::string& objectName,
183 VirtualRobot::SceneObject::Physics::SimulationType simType) override;
184
185 protected:
186 bool addObstacleEngine(VirtualRobot::SceneObjectPtr o,
187 VirtualRobot::SceneObject::Physics::SimulationType simType) override;
188 bool removeObstacleEngine(const std::string& name) override;
190 double pid_p,
191 double pid_i,
192 double pid_d,
193 const std::string& filename,
194 bool staticRobot,
195 bool selfCollisions) override;
196
197 //! create a joint
198 bool objectGraspedEngine(const std::string& robotName,
199 const std::string& robotNodeName,
200 const std::string& objectName,
201 Eigen::Matrix4f& storeLocalTransform) override;
202
203 //! remove a joint
204 bool objectReleasedEngine(const std::string& robotName,
205 const std::string& robotNodeName,
206 const std::string& objectName) override;
207
208 bool removeRobotEngine(const std::string& robotName) override;
209 bool synchronizeSimulationDataEngine() override;
210
211 void setupFloorEngine(bool enable, const std::string& floorTexture) override;
212
213 bool synchronizeObjects() override;
214
215 bool getRobotStatus(const std::string& robotName,
216 NameValueMap& jointAngles,
217 NameValueMap& jointVelocities,
218 NameValueMap& jointTorques,
219 Eigen::Vector3f& linearVelocity,
220 Eigen::Vector3f& angularVelocity) override;
221
222 bool updateForceTorqueSensor(ForceTorqueInfo& ftInfo) override;
223
224 bool
225 synchronizeSceneObjectPoses(VirtualRobot::SceneObjectPtr currentObjEngine,
226 std::map<std::string, armarx::PoseBasePtr>& objMap) override;
227
228 VirtualRobot::SceneObjectPtr getFloor() override;
229
230 // manually apply velocities to static robots
231 void stepStaticRobots(double deltaInSeconds);
232 void stepStaticObjects(double deltaInSeconds);
233
235
237 {
239 {
240 velTransTarget.setZero();
241 velRotTarget.setZero();
242 velTransActual.setZero();
243 velRotActual.setZero();
244 }
245
247 std::map<std::string, float> targetVelocities;
248 std::map<std::string, float> actualVelocities;
250 Eigen::Vector3f velRotTarget, velRotActual;
251 };
252
253 std::map<std::string, KinematicRobotInfo> kinematicRobots;
254 std::vector<VirtualRobot::SceneObjectPtr> kinematicObjects;
255 std::map<VirtualRobot::RobotNodePtr, std::pair<IceUtil::Time, float>>
257 std::map<VirtualRobot::RobotPtr, std::pair<IceUtil::Time, Eigen::Vector3f>>
259 std::map<VirtualRobot::RobotPtr, std::pair<IceUtil::Time, Eigen::Matrix4f>>
261 VirtualRobot::SceneObjectPtr floor;
262 Eigen::Vector3f floorPos;
263 Eigen::Vector3f floorUp;
266 VirtualRobot::ObstaclePtr groundObject;
267 virtual void createFloorPlane(const Eigen::Vector3f& pos, const Eigen::Vector3f& up);
268
269 IceUtil::Time lastTime;
270
271 float getDeltaTimeMilli();
272
273 bool synchronizeRobotNodePoses(const std::string& robotName,
274 std::map<std::string, armarx::PoseBasePtr>& objMap) override;
276 };
277
278 using KinematicsWorldPtr = std::shared_ptr<KinematicsWorld>;
279} // namespace armarx
void setRobotAngularVelocity(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
void actuateRobotJoints(const std::string &robotName, const std::map< std::string, float > &angles, const std::map< std::string, float > &velocities) override
ignoring velocity target
std::vector< VirtualRobot::SceneObjectPtr > kinematicObjects
bool removeRobotEngine(const std::string &robotName) override
void setRobotLinearVelocity(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
float getRobotJointLimitLo(const std::string &robotName, const std::string &nodeName) override
float getRobotMass(const std::string &robotName) override
bool hasRobot(const std::string &robotName) override
std::map< std::string, float > getRobotJointAngles(const std::string &robotName) override
float getRobotJointAngle(const std::string &robotName, const std::string &nodeName) override
VirtualRobot::SceneObjectPtr getFloor() override
void applyForceObject(const std::string &objectName, const Eigen::Vector3f &force) override
std::vector< std::string > getRobotNames() override
std::map< VirtualRobot::RobotNodePtr, std::pair< IceUtil::Time, float > > jointAngleDerivationFilters
Eigen::Vector3f getRobotLinearVelocity(const std::string &robotName, const std::string &nodeName) override
armarx::DistanceInfo getRobotNodeDistance(const std::string &robotName, const std::string &robotNodeName1, const std::string &robotNodeName2) override
std::map< VirtualRobot::RobotPtr, std::pair< IceUtil::Time, Eigen::Matrix4f > > angularVelocityFilters
armarx::DistanceInfo getDistance(const std::string &robotName, const std::string &robotNodeName, const std::string &worldObjectName) override
std::vector< SimDynamics::DynamicsEngine::DynamicsContactInfo > copyContacts() override
void applyForceRobotNode(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &force) override
std::vector< std::string > getObstacleNames() override
void stepStaticRobots(double deltaInSeconds)
Eigen::Vector3f getRobotAngularVelocity(const std::string &robotName, const std::string &nodeName) override
float getRobotMaxTorque(const std::string &robotName, const std::string &nodeName) override
void actuateRobotJointsPos(const std::string &robotName, const std::map< std::string, float > &angles) override
VirtualRobot::RobotPtr getRobot(const std::string &robotName) override
Eigen::Matrix4f getRobotNodePose(const std::string &robotName, const std::string &robotNodeName) override
void stepPhysicsRealTime() override
Perform one simulation step.
float getRobotJointVelocity(const std::string &robotName, const std::string &nodeName) override
std::map< std::string, float > getRobotJointVelocities(const std::string &robotName) override
bool getRobotStatus(const std::string &robotName, NameValueMap &jointAngles, NameValueMap &jointVelocities, NameValueMap &jointTorques, Eigen::Vector3f &linearVelocity, Eigen::Vector3f &angularVelocity) override
bool synchronizeRobotNodePoses(const std::string &robotName, std::map< std::string, armarx::PoseBasePtr > &objMap) override
bool objectGraspedEngine(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, Eigen::Matrix4f &storeLocalTransform) override
create a joint
void setRobotLinearVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
void stepStaticObjects(double deltaInSeconds)
std::map< std::string, KinematicRobotInfo > kinematicRobots
bool objectReleasedEngine(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName) override
remove a joint
bool removeObstacleEngine(const std::string &name) override
bool hasRobotNode(const std::string &robotName, const std::string &robotNodeName) override
bool synchronizeObjects() override
Eigen::Matrix4f getObjectPose(const std::string &objectName) override
Eigen::Matrix4f getRobotPose(const std::string &robotName) override
void enableLogging(const std::string &robotName, const std::string &logFile) override
std::map< std::string, float > getRobotJointTorques(const std::string &) override
bool synchronizeSimulationDataEngine() override
void applyTorqueObject(const std::string &objectName, const Eigen::Vector3f &torque) override
std::map< std::string, VirtualRobot::RobotPtr > getRobots() override
VirtualRobot::SceneObjectPtr floor
void applyTorqueRobotNode(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &torque) override
bool addObstacleEngine(VirtualRobot::SceneObjectPtr o, VirtualRobot::SceneObject::Physics::SimulationType simType) override
void setRobotMaxTorque(const std::string &robotName, const std::string &nodeName, float maxTorque) override
void setObjectSimType(const std::string &objectName, VirtualRobot::SceneObject::Physics::SimulationType simType) override
virtual void initialize(int stepSizeMS, float maxRealTimeSimSpeed=1, bool floorPlane=false, std::string floorTexture=std::string())
void setRobotNodeSimType(const std::string &robotName, const std::string &robotNodeName, VirtualRobot::SceneObject::Physics::SimulationType simType) override
bool addRobotEngine(VirtualRobot::RobotPtr robot, double pid_p, double pid_i, double pid_d, const std::string &filename, bool staticRobot, bool selfCollisions) override
float getRobotJointLimitHi(const std::string &robotName, const std::string &nodeName) override
void setRobotAngularVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
void setRobotPose(const std::string &robotName, const Eigen::Matrix4f &globalPose) override
VirtualRobot::ObstaclePtr groundObject
virtual VirtualRobot::SceneObjectPtr getObject(const std::string &objectName)
void setObjectPose(const std::string &objectName, const Eigen::Matrix4f &globalPose) override
std::vector< VirtualRobot::SceneObjectPtr > getObjects() override
void stepPhysicsFixedTimeStep() override
Perform one simulation step.
FramedPosePtr toFramedPose(const Eigen::Matrix4f &globalPose, const std::string &robotName, const std::string &frameName) override
toFramedPose Constructs a framed pose
virtual void createFloorPlane(const Eigen::Vector3f &pos, const Eigen::Vector3f &up)
ForceTorqueDataSeq getRobotForceTorqueSensors(const std::string &) override
void setupFloorEngine(bool enable, const std::string &floorTexture) override
bool hasObject(const std::string &instanceName) override
void actuateRobotJointsVel(const std::string &robotName, const std::map< std::string, float > &velocities) override
bool updateForceTorqueSensor(ForceTorqueInfo &ftInfo) override
std::map< VirtualRobot::RobotPtr, std::pair< IceUtil::Time, Eigen::Vector3f > > linearVelocityFilters
bool synchronizeSceneObjectPoses(VirtualRobot::SceneObjectPtr currentObjEngine, std::map< std::string, armarx::PoseBasePtr > &objMap) override
void actuateRobotJointsTorque(const std::string &robotName, const std::map< std::string, float > &torques) override
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< KinematicsWorld > KinematicsWorldPtr
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
std::map< std::string, float > actualVelocities
std::map< std::string, float > targetVelocities