Go to the documentation of this file.
27 #include <condition_variable>
31 #include <Eigen/Geometry>
37 #include <ArmarXCore/interface/core/PackagePath.h>
38 #include <ArmarXCore/interface/core/TimeServerInterface.h>
39 #include <ArmarXCore/interface/events/SimulatorResetEvent.h>
42 #include <RobotAPI/interface/core/RobotState.h>
46 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
53 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
54 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
55 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
56 #include <MemoryX/interface/gui/EntityDrawerInterface.h>
61 #define MAX_INITIAL_ROBOT_COUNT 4
66 class SimulatorTimeServerProxy;
119 virtual public SimulatorInterface,
121 virtual protected IceUtil::Thread,
122 virtual public TimeServerInterface
141 void stop(
const Ice::Current&
c = Ice::emptyCurrent)
override;
158 const Ice::Current&
c = Ice::emptyCurrent)
override;
161 const Ice::Current&
c = Ice::emptyCurrent)
override;
164 const Ice::Current&
c = Ice::emptyCurrent)
override;
167 const Ice::Current&
c = Ice::emptyCurrent)
override;
169 const PoseBasePtr& globalPose,
170 const Ice::Current&
c = Ice::emptyCurrent)
override;
173 const std::string& robotNodeName,
174 const Vector3BasePtr& force,
175 const Ice::Current&
c = Ice::emptyCurrent)
override;
177 const std::string& robotNodeName,
178 const Vector3BasePtr& torque,
179 const Ice::Current&
c = Ice::emptyCurrent)
override;
182 const Vector3BasePtr& force,
183 const Ice::Current&
c = Ice::emptyCurrent)
override;
185 const Vector3BasePtr& torque,
186 const Ice::Current&
c = Ice::emptyCurrent)
override;
190 const Ice::Current&
c = Ice::emptyCurrent)
override;
193 const Ice::Current&
c = Ice::emptyCurrent)
override;
197 const Ice::Current&
c = Ice::emptyCurrent)
override;
198 bool removeRobot(
const std::string& robotName,
const Ice::Current&
c = Ice::emptyCurrent);
199 void addObject(
const memoryx::ObjectClassBasePtr& objectClassBase,
200 const std::string& instanceName,
201 const PoseBasePtr& globalPose,
202 bool isStatic =
false,
203 const Ice::Current&
c = Ice::emptyCurrent)
override;
207 const Ice::Current&
c = Ice::emptyCurrent)
override;
209 const std::string& instanceName,
210 const PoseBasePtr& globalPose,
211 bool isStatic =
false,
212 const Ice::Current&
c = Ice::emptyCurrent)
override;
219 const DrawColor& color,
220 const std::string& instanceName,
221 const PoseBasePtr& globalPose,
222 bool isStatic =
false,
223 const Ice::Current&
c = Ice::emptyCurrent)
override;
226 void removeObject(
const std::string& instanceName,
const Ice::Current&)
override;
228 bool hasObject(
const std::string& instanceName,
229 const Ice::Current&
c = Ice::emptyCurrent)
override;
231 const PoseBasePtr& globalPose,
232 const Ice::Current&
c = Ice::emptyCurrent)
override;
234 armarx::SimulationType type,
235 const Ice::Current&
c = Ice::emptyCurrent)
override;
237 const Ice::Current&
c = Ice::emptyCurrent)
override;
239 bool hasRobot(
const std::string& robotName,
240 const Ice::Current&
c = Ice::emptyCurrent)
override;
242 const std::string& robotNodeName,
243 const Ice::Current&
c = Ice::emptyCurrent)
override;
245 const Ice::Current&
c = Ice::emptyCurrent)
override;
248 const Ice::Current&
c = Ice::emptyCurrent)
override;
250 const std::string& nodeName,
251 const Ice::Current&
c = Ice::emptyCurrent)
override;
253 const Ice::Current&
c = Ice::emptyCurrent)
override;
255 const std::string& nodeName,
256 const Ice::Current&
c = Ice::emptyCurrent)
override;
258 const Ice::Current&
c = Ice::emptyCurrent)
override;
261 const Ice::Current&
c = Ice::emptyCurrent)
override;
264 const std::string& nodeName,
265 const Ice::Current&
c = Ice::emptyCurrent)
override;
267 const std::string& nodeName,
268 const Ice::Current&
c = Ice::emptyCurrent)
override;
270 const Ice::Current&
c = Ice::emptyCurrent)
override;
271 SimulatedRobotState
getRobotState(
const std::string& robotName,
272 const Ice::Current&)
override;
275 const std::string& nodeName,
276 const Ice::Current&
c = Ice::emptyCurrent)
override;
278 const std::string& nodeName,
280 const Ice::Current&
c = Ice::emptyCurrent)
override;
283 const std::string& robotNodeName,
284 const Ice::Current&
c = Ice::emptyCurrent)
override;
287 const std::string& nodeName,
288 const Ice::Current&
c = Ice::emptyCurrent)
override;
290 const std::string& nodeName,
291 const Ice::Current&
c = Ice::emptyCurrent)
override;
294 const std::string& robotNodeName,
295 const Vector3BasePtr& vel,
296 const Ice::Current&
c = Ice::emptyCurrent)
override;
298 const std::string& robotNodeName,
299 const Vector3BasePtr& vel,
300 const Ice::Current&
c = Ice::emptyCurrent)
override;
303 const std::string& robotNodeName,
304 const Vector3BasePtr& vel,
305 const Ice::Current&
c = Ice::emptyCurrent)
override;
308 const std::string& robotNodeName,
309 const Vector3BasePtr& vel,
310 const Ice::Current&
c = Ice::emptyCurrent)
override;
314 const std::string& robotNodeName,
315 const std::string& objectName,
316 const Ice::Current&
c = Ice::emptyCurrent)
override;
320 const std::string& robotNodeName,
321 const std::string& objectName,
322 const Ice::Current&
c = Ice::emptyCurrent)
override;
325 const Ice::Current&
c = Ice::emptyCurrent)
override;
327 DistanceInfo
getDistance(
const std::string& robotName,
328 const std::string& robotNodeName,
329 const std::string& worldObjectName,
330 const Ice::Current&
c = Ice::emptyCurrent)
override;
332 const std::string& robotNodeName1,
333 const std::string& robotNodeName2,
334 const Ice::Current&
c = Ice::emptyCurrent)
override;
336 const std::string& layerName,
337 const Ice::Current&
c = Ice::emptyCurrent)
override;
343 ContactInfoSequence
getContacts(
const Ice::Current&
c = Ice::emptyCurrent)
override;
349 void updateContacts(
bool enable,
const Ice::Current&
c = Ice::emptyCurrent)
override;
351 ObjectClassInformationSequence
353 const std::string& frameName,
354 const std::string& className,
355 const Ice::Current&
c = Ice::emptyCurrent)
override;
363 void reInitialize(
const Ice::Current&
c = Ice::emptyCurrent)
override;
366 float getSimTime(
const Ice::Current&
c = Ice::emptyCurrent)
override;
369 SceneVisuData
getScene(
const Ice::Current&
c = Ice::emptyCurrent)
override;
379 void start(
const Ice::Current&
c = Ice::emptyCurrent)
override;
380 void pause(
const Ice::Current&
c = Ice::emptyCurrent)
override;
381 void step(
const Ice::Current&
c = Ice::emptyCurrent)
override;
382 bool isRunning(
const Ice::Current&
c = Ice::emptyCurrent)
override;
384 bool addSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx);
411 void resetData(
bool clearWorkingMemory =
false);
419 addRobot(std::string robotInstanceName,
420 const std::string& robFileGlobal,
422 const std::string& robFile,
426 bool isStatic =
false,
428 bool colModel =
false,
429 std::map<std::string, float> initConfig = std::map<std::string, float>(),
430 bool selfCollisions =
false);
503 void addRobotsFromProperties();
504 void addSceneFromFile(
const std::string& sceneFile);
505 void addSceneFromMemorySnapshot(
const std::string& snapshotName);
510 void addSceneFromJsonFile(
const std::string& scenePath);
515 void addSceneFromSdfFile(
const std::string& scenePath);
521 std::map<ObjectID, int>& idCounters);
523 void fixateRobotNode(
const std::string& robotName,
const std::string& robotNodeName);
524 void fixateObject(
const std::string& objectName);
void addBox(float width, float height, float depth, float massKG, const DrawColor &color, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
Hook for subclass.
void setRobotLinearVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< Simulator >::pointer_type reportVisuTask
The report visu task.
PoseBasePtr getObjectPose(const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
const VariantTypeId Float
SimulatorTimeServerProxyPtr timeserverProxy
Proxy object to offer the Timeserver proxy.
void stop(const Ice::Current &c=Ice::emptyCurrent) override
int lastPublishedContacts
void actuateRobotJointsTorque(const std::string &robotName, const NameValueMap &torques, const Ice::Current &c=Ice::emptyCurrent) override
std::string addRobot(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void onInitComponent() override
Pure virtual hook for the subclass.
void setRobotAngularVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
PoseBasePtr getRobotPose(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
Vector3BasePtr getRobotAngularVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
MatrixXX< 4, 4, float > Matrix4f
void applyForceObject(const std::string &objectName, const Vector3BasePtr &force, const Ice::Current &c=Ice::emptyCurrent) override
std::condition_variable condSimulatorThreadRunning
bool hasRobotNode(const std::string &robotName, const std::string &robotNodeName, const Ice::Current &c=Ice::emptyCurrent) override
float getRobotMaxTorque(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorInformation getSimulatorInformation(const ::Ice::Current &=Ice::emptyCurrent) override
~SimulatorPropertyDefinitions() override
PeriodicTask< Simulator >::pointer_type simulationTask
The sim task.
Ice::Float getSpeed(const Ice::Current &c=Ice::emptyCurrent) override
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
NameValueMap getRobotJointTorques(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
float timeServerSpeed
Scaling factor for the passing of time.
float currentComTimeMS
Stores the time that was needed for communictaion.
std::atomic< float > reportVisuTimeMS
void addObjectFromFile(const armarx::data::PackagePath &packagePath, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
float getRobotMass(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
std::string addScaledRobotName(const std::string &instanceName, const std::string &filename, float scale, const Ice::Current &c=Ice::emptyCurrent) override
void resetData(bool clearWorkingMemory=false)
resetData Clears all data
bool isRunning(const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsPos(const std::string &robotName, const NameValueMap &angles, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsVel(const std::string &robotName, const NameValueMap &velocities, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJoints(const std::string &robotName, const NameValueMap &angles, const NameValueMap &velocities, const Ice::Current &c=Ice::emptyCurrent) override
bool hasRobot(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
DistanceInfo getDistance(const std::string &robotName, const std::string &robotNodeName, const std::string &worldObjectName, const Ice::Current &c=Ice::emptyCurrent) override
float getRobotJointLimitHi(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
PropertyDefinitionsPtr createPropertyDefinitions() override
ObjectClassInformationSequence getObjectClassPoses(const std::string &robotName, const std::string &frameName, const std::string &className, const Ice::Current &c=Ice::emptyCurrent) override
void pause(const Ice::Current &c=Ice::emptyCurrent) override
void activateObject(const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
memoryx::GridFileManagerPtr fileManager
void start(const Ice::Current &c=Ice::emptyCurrent) override
std::string contactLayerName
memoryx::GridFileManagerPtr requestFileManager()
SimulatorResetEventPrx simulatorResetEventTopic
bool addSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx)
DistanceInfo getRobotNodeDistance(const std::string &robotName, const std::string &robotNodeName1, const std::string &robotNodeName2, const Ice::Current &c=Ice::emptyCurrent) override
bool removeRobot(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent)
void setRobotPose(const std::string &robotName, const PoseBasePtr &globalPose, const Ice::Current &c=Ice::emptyCurrent) override
int getFixedTimeStepMS(const Ice::Current &c=Ice::emptyCurrent) override
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
float getRobotJointAngle(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
memoryx::EntityDrawerInterfacePrx entityDrawerPrx
Drawing contacts.
Ice::Long getTime(const Ice::Current &c=Ice::emptyCurrent) override
PoseBasePtr getRobotNodePose(const std::string &robotName, const std::string &robotNodeName, const Ice::Current &c=Ice::emptyCurrent) override
bool simulatorThreadRunning
float currentSimTimeMS
Stores the time that was needed to perform the last simulation loop.
void setRobotAngularVelocity(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
SimulatedRobotState stateFromRobotInfo(RobotInfo const &robot, IceUtil::Time timestamp)
std::string getDefaultName() const override
Retrieve default name of component.
void showContacts(bool enable, const std::string &layerName, const Ice::Current &c=Ice::emptyCurrent) override
ContactInfoSequence getContacts(const Ice::Current &c=Ice::emptyCurrent) override
Returns a list of all contacts. Note that you must call updateContacts() first to enable contacts han...
Ice::Int getStepTimeMS(const ::Ice::Current &=Ice::emptyCurrent) override
memoryx::PriorKnowledgeInterfacePrx priorKnowledgePrx
std::string addScaledRobot(const std::string &filename, float scale, const Ice::Current &c=Ice::emptyCurrent) override
bool simulatorThreadShutdown
memoryx::WorkingMemoryInterfacePrx memoryPrx
void onDisconnectComponent() override
Hook for subclass.
PeriodicTask< Simulator >::pointer_type reportDataTask
The report data task.
void removeObject(const std::string &instanceName, const Ice::Current &) override
float getRobotJointVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
Ice::StringSeq getRobotNames(const Ice::Current &) override
void setRobotLinearVelocity(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
armarx::core::time::DateTime Time
std::string commonStorageName
Baseclass for all ArmarX ManagedIceObjects requiring properties.
void applyTorqueObject(const std::string &objectName, const Vector3BasePtr &torque, const Ice::Current &c=Ice::emptyCurrent) override
std::mutex simulatorRunningMutex
std::string addRobotFromFile(const armarx::data::PackagePath &packagePath, const Ice::Current &c=Ice::emptyCurrent) override
The Simulator class holds an instance of the AmrarXPhysicsWorld and communicates to ArmarX.
void objectReleased(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
remove a joint
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
void addObject(const memoryx::ObjectClassBasePtr &objectClassBase, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
std::map< std::string, std::vector< std::string > > classInstanceMap
Stores all instances that belong to a class.
std::shared_ptr< SimulatedWorld > SimulatedWorldPtr
bool hasObject(const std::string &instanceName, const Ice::Current &c=Ice::emptyCurrent) override
TimeServerListenerPrx timeTopicPrx
void onConnectComponent() override
Pure virtual hook for the subclass.
NameValueMap getRobotJointAngles(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
Default component property definition container.
std::string priorKnowledgeName
std::shared_ptr< GridFileManager > GridFileManagerPtr
void applyTorqueRobotNode(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &torque, const Ice::Current &c=Ice::emptyCurrent) override
void shutdownSimulationLoop()
stop the simulation and join the simulation thread
void setRobotMaxTorque(const std::string &robotName, const std::string &nodeName, float maxTorque, const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointVelocities(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorPropertyDefinitions(std::string prefix)
float getSimTime(const Ice::Current &c=Ice::emptyCurrent) override
void setSpeed(Ice::Float newSpeed, const Ice::Current &c=Ice::emptyCurrent) override
setSpeed sets the scaling factor for the speed of passing of time e.g.
void reInitialize(const Ice::Current &c=Ice::emptyCurrent) override
reInitialize Re-initializes the scene. Removes all robots and objects (and, in case the scene was loa...
void setObjectPose(const std::string &objectName, const PoseBasePtr &globalPose, const Ice::Current &c=Ice::emptyCurrent) override
Vector3BasePtr getRobotLinearVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
SimulatedRobotState getRobotState(const std::string &robotName, const Ice::Current &) override
ForceTorqueDataSeq getRobotForceTorqueSensors(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
void step(const Ice::Current &c=Ice::emptyCurrent) override
SimulatedWorldPtr physicsWorld
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ObjectFinder objectFinder
Constructed once based on the ObjectPackage property.
SimulatorListenerInterfacePrx simulatorVisuUpdateListenerPrx
void objectGrasped(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
create a joint
float getRobotJointLimitLo(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
GlobalRobotPoseLocalizationListenerPrx globalRobotLocalization
SceneVisuData getScene(const Ice::Current &c=Ice::emptyCurrent) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
float currentSyncTimeMS
stores the time that was needed to sync the data
bool loadAgentsFromSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx)
void setObjectSimulationType(const std::string &objectName, armarx::SimulationType type, const Ice::Current &c=Ice::emptyCurrent) override
void applyForceRobotNode(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &force, const Ice::Current &c=Ice::emptyCurrent) override
void updateContacts(bool enable, const Ice::Current &c=Ice::emptyCurrent) override
Enables the handling of contacts. If you intend to use getContacts(), call this method with enabled =...
memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx