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>
43 #include <RobotAPI/interface/core/RobotState.h>
44 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
45 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
46 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
48 #include <MemoryX/interface/gui/EntityDrawerInterface.h>
53 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
62 #define MAX_INITIAL_ROBOT_COUNT 4
68 class SimulatorTimeServerProxy;
125 virtual public SimulatorInterface,
127 virtual protected IceUtil::Thread,
128 virtual public TimeServerInterface
148 void stop(
const Ice::Current&
c = Ice::emptyCurrent)
override;
166 void setRobotPose(
const std::string& robotName,
const PoseBasePtr& globalPose,
const Ice::Current&
c = Ice::emptyCurrent)
override;
168 void applyForceRobotNode(
const std::string& robotName,
const std::string& robotNodeName,
const Vector3BasePtr& force,
const Ice::Current&
c = Ice::emptyCurrent)
override;
169 void applyTorqueRobotNode(
const std::string& robotName,
const std::string& robotNodeName,
const Vector3BasePtr& torque,
const Ice::Current&
c = Ice::emptyCurrent)
override;
171 void applyForceObject(
const std::string& objectName,
const Vector3BasePtr& force,
const Ice::Current&
c = Ice::emptyCurrent)
override;
172 void applyTorqueObject(
const std::string& objectName,
const Vector3BasePtr& torque,
const Ice::Current&
c = Ice::emptyCurrent)
override;
175 std::string
addRobot(
const std::string&
filename,
const Ice::Current&
c = Ice::emptyCurrent)
override;
176 std::string
addScaledRobot(
const std::string&
filename,
float scale,
const Ice::Current&
c = Ice::emptyCurrent)
override;
177 std::string
addScaledRobotName(
const std::string& instanceName,
const std::string&
filename,
float scale,
const Ice::Current&
c = Ice::emptyCurrent)
override;
178 bool removeRobot(
const std::string& robotName,
const Ice::Current&
c = Ice::emptyCurrent);
179 void addObject(
const memoryx::ObjectClassBasePtr& objectClassBase,
const std::string& instanceName,
const PoseBasePtr& globalPose,
bool isStatic =
false,
const Ice::Current&
c = Ice::emptyCurrent)
override;
182 std::string
addRobotFromFile(
const armarx::data::PackagePath& packagePath,
const Ice::Current&
c = Ice::emptyCurrent)
override;
183 void addObjectFromFile(
const armarx::data::PackagePath& packagePath,
const std::string& instanceName,
const PoseBasePtr& globalPose,
bool isStatic =
false,
const Ice::Current&
c = Ice::emptyCurrent)
override;
186 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;
189 void removeObject(
const std::string& instanceName,
const Ice::Current&)
override;
191 bool hasObject(
const std::string& instanceName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
192 void setObjectPose(
const std::string& objectName,
const PoseBasePtr& globalPose,
const Ice::Current&
c = Ice::emptyCurrent)
override;
193 void setObjectSimulationType(
const std::string& objectName, armarx::SimulationType type,
const Ice::Current&
c = Ice::emptyCurrent)
override;
194 void activateObject(
const std::string& objectName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
196 bool hasRobot(
const std::string& robotName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
197 bool hasRobotNode(
const std::string& robotName,
const std::string& robotNodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
198 float getRobotMass(
const std::string& robotName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
201 float getRobotJointAngle(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
203 float getRobotJointVelocity(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
207 float getRobotJointLimitLo(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
208 float getRobotJointLimitHi(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
209 PoseBasePtr
getRobotPose(
const std::string& robotName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
210 SimulatedRobotState
getRobotState(
const std::string& robotName,
const Ice::Current&)
override;
212 float getRobotMaxTorque(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
213 void setRobotMaxTorque(
const std::string& robotName,
const std::string& nodeName,
float maxTorque,
const Ice::Current&
c = Ice::emptyCurrent)
override;
215 PoseBasePtr
getRobotNodePose(
const std::string& robotName,
const std::string& robotNodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
217 Vector3BasePtr
getRobotLinearVelocity(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
218 Vector3BasePtr
getRobotAngularVelocity(
const std::string& robotName,
const std::string& nodeName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
220 void setRobotLinearVelocity(
const std::string& robotName,
const std::string& robotNodeName,
const Vector3BasePtr& vel,
const Ice::Current&
c = Ice::emptyCurrent)
override;
221 void setRobotAngularVelocity(
const std::string& robotName,
const std::string& robotNodeName,
const Vector3BasePtr& vel,
const Ice::Current&
c = Ice::emptyCurrent)
override;
222 void setRobotLinearVelocityRobotRootFrame(
const std::string& robotName,
const std::string& robotNodeName,
const Vector3BasePtr& vel,
const Ice::Current&
c = Ice::emptyCurrent)
override;
223 void setRobotAngularVelocityRobotRootFrame(
const std::string& robotName,
const std::string& robotNodeName,
const Vector3BasePtr& vel,
const Ice::Current&
c = Ice::emptyCurrent)
override;
226 void objectGrasped(
const std::string& robotName,
const std::string& robotNodeName,
const std::string& objectName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
229 void objectReleased(
const std::string& robotName,
const std::string& robotNodeName,
const std::string& objectName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
231 PoseBasePtr
getObjectPose(
const std::string& objectName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
233 DistanceInfo
getDistance(
const std::string& robotName,
const std::string& robotNodeName,
const std::string& worldObjectName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
234 DistanceInfo
getRobotNodeDistance(
const std::string& robotName,
const std::string& robotNodeName1,
const std::string& robotNodeName2,
const Ice::Current&
c = Ice::emptyCurrent)
override;
235 void showContacts(
bool enable,
const std::string& layerName,
const Ice::Current&
c = Ice::emptyCurrent)
override;
241 ContactInfoSequence
getContacts(
const Ice::Current&
c = Ice::emptyCurrent)
override;
247 void updateContacts(
bool enable,
const Ice::Current&
c = Ice::emptyCurrent)
override;
250 const std::string& robotName,
const std::string& frameName,
const std::string& className,
251 const Ice::Current&
c = Ice::emptyCurrent)
override;
259 void reInitialize(
const Ice::Current&
c = Ice::emptyCurrent)
override;
262 float getSimTime(
const Ice::Current&
c = Ice::emptyCurrent)
override;
265 SceneVisuData
getScene(
const Ice::Current&
c = Ice::emptyCurrent)
override;
274 void start(
const Ice::Current&
c = Ice::emptyCurrent)
override;
275 void pause(
const Ice::Current&
c = Ice::emptyCurrent)
override;
276 void step(
const Ice::Current&
c = Ice::emptyCurrent)
override;
277 bool isRunning(
const Ice::Current&
c = Ice::emptyCurrent)
override;
279 bool addSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx);
306 void resetData(
bool clearWorkingMemory =
false);
313 std::string
addRobot(std::string robotInstanceName,
const std::string& robFileGlobal,
Eigen::Matrix4f gp,
const std::string& robFile,
double pid_p = 10.0,
double pid_i = 0.0,
double pid_d = 0.0,
bool isStatic =
false,
float scaling = 1,
bool colModel =
false, std::map<std::string, float> initConfig = std::map<std::string, float>(),
bool selfCollisions =
false);
388 void addRobotsFromProperties();
389 void addSceneFromFile(
const std::string& sceneFile);
390 void addSceneFromMemorySnapshot(
const std::string& snapshotName);
395 void addSceneFromJsonFile(
const std::string& scenePath);
400 void addSceneFromSdfFile(
const std::string& scenePath);
406 std::map<ObjectID, int>& idCounters);
408 void fixateRobotNode(
const std::string& robotName,
const std::string& robotNodeName);
409 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
std::map< std::string, std::vector< std::string > > classInstanceMap
Stores all instances that belong to a class.
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
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::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.
MatrixXX< 4, 4, float > Matrix4f
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