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;
149 void setSpeed(Ice::Float newSpeed,
const Ice::Current&
c = Ice::emptyCurrent)
override;
150 Ice::Float
getSpeed(
const Ice::Current&
c = Ice::emptyCurrent)
override;
151 Ice::Long
getTime(
const Ice::Current&
c = Ice::emptyCurrent)
override;
152 Ice::Int
getStepTimeMS(const ::Ice::Current& = Ice::emptyCurrent)
override;
156 const NameValueMap& angles,
157 const NameValueMap& velocities,
158 const Ice::Current&
c = Ice::emptyCurrent)
override;
160 const NameValueMap& angles,
161 const Ice::Current&
c = Ice::emptyCurrent)
override;
163 const NameValueMap& velocities,
164 const Ice::Current&
c = Ice::emptyCurrent)
override;
166 const NameValueMap& torques,
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;
189 std::string
addRobot(
const std::string& filename,
190 const Ice::Current&
c = Ice::emptyCurrent)
override;
193 const Ice::Current&
c = Ice::emptyCurrent)
override;
195 const std::string& filename,
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);
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
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.
SimulatorPropertyDefinitions(std::string prefix)
~SimulatorPropertyDefinitions() override
std::mutex simulatorRunningMutex
memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx
void applyForceObject(const std::string &objectName, const Vector3BasePtr &force, const Ice::Current &c=Ice::emptyCurrent) override
void setRobotLinearVelocity(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
std::string addScaledRobot(const std::string &filename, float scale, const Ice::Current &c=Ice::emptyCurrent) override
void onInitComponent() override
Pure virtual hook for the subclass.
memoryx::WorkingMemoryInterfacePrx memoryPrx
void setObjectSimulationType(const std::string &objectName, armarx::SimulationType type, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorTimeServerProxyPtr timeserverProxy
Proxy object to offer the Timeserver proxy.
Ice::Long getTime(const Ice::Current &c=Ice::emptyCurrent) override
void showContacts(bool enable, const std::string &layerName, 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 start(const Ice::Current &c=Ice::emptyCurrent) override
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
float getRobotJointAngle(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsTorque(const std::string &robotName, const NameValueMap &torques, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorInformation getSimulatorInformation(const ::Ice::Current &=Ice::emptyCurrent) override
void resetData(bool clearWorkingMemory=false)
resetData Clears all data
bool hasRobotNode(const std::string &robotName, const std::string &robotNodeName, const Ice::Current &c=Ice::emptyCurrent) override
PoseBasePtr getRobotPose(const std::string &robotName, 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
void shutdownSimulationLoop()
stop the simulation and join the simulation thread
GlobalRobotPoseLocalizationListenerPrx globalRobotLocalization
void onDisconnectComponent() override
Hook for subclass.
SimulatorResetEventPrx simulatorResetEventTopic
void applyTorqueRobotNode(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &torque, const Ice::Current &c=Ice::emptyCurrent) override
float timeServerSpeed
Scaling factor for the passing of time.
PoseBasePtr getObjectPose(const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
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...
float currentComTimeMS
Stores the time that was needed for communictaion.
void applyForceRobotNode(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &force, const Ice::Current &c=Ice::emptyCurrent) override
float getRobotJointVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void addObjectFromFile(const armarx::data::PackagePath &packagePath, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointAngles(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
void step(const Ice::Current &c=Ice::emptyCurrent) override
void setRobotAngularVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
std::string addRobotFromFile(const armarx::data::PackagePath &packagePath, const Ice::Current &c=Ice::emptyCurrent) override
memoryx::GridFileManagerPtr fileManager
memoryx::PriorKnowledgeInterfacePrx priorKnowledgePrx
SimulatorListenerInterfacePrx simulatorVisuUpdateListenerPrx
std::condition_variable condSimulatorThreadRunning
bool hasObject(const std::string &instanceName, const Ice::Current &c=Ice::emptyCurrent) override
Ice::Float getSpeed(const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointTorques(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
bool loadAgentsFromSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx)
void removeObject(const std::string &instanceName, const Ice::Current &) override
DistanceInfo getDistance(const std::string &robotName, const std::string &robotNodeName, const std::string &worldObjectName, const Ice::Current &c=Ice::emptyCurrent) override
float getSimTime(const Ice::Current &c=Ice::emptyCurrent) override
void stop(const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointVelocities(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< Simulator >::pointer_type reportVisuTask
The report visu task.
bool addSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx)
float getRobotJointLimitHi(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
bool hasRobot(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
std::string contactLayerName
void pause(const Ice::Current &c=Ice::emptyCurrent) override
void setRobotAngularVelocity(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< Simulator >::pointer_type reportDataTask
The report data task.
void setRobotLinearVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
float currentSimTimeMS
Stores the time that was needed to perform the last simulation loop.
Vector3BasePtr getRobotLinearVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
SimulatedWorldPtr physicsWorld
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.
std::string addScaledRobotName(const std::string &instanceName, const std::string &filename, float scale, const Ice::Current &c=Ice::emptyCurrent) override
ObjectFinder objectFinder
Constructed once based on the ObjectPackage property.
void onConnectComponent() override
Pure virtual hook for the subclass.
void objectReleased(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
remove a joint
bool isRunning(const Ice::Current &c=Ice::emptyCurrent) override
int lastPublishedContacts
std::atomic< float > reportVisuTimeMS
float getRobotMaxTorque(const std::string &robotName, const std::string &nodeName, 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 =...
PropertyDefinitionsPtr createPropertyDefinitions() override
memoryx::GridFileManagerPtr requestFileManager()
float currentSyncTimeMS
stores the time that was needed to sync the data
SimulatedRobotState getRobotState(const std::string &robotName, const Ice::Current &) override
bool removeRobot(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent)
float getRobotMass(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
bool simulatorThreadShutdown
SceneVisuData getScene(const Ice::Current &c=Ice::emptyCurrent) override
float getRobotJointLimitLo(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void setObjectPose(const std::string &objectName, const PoseBasePtr &globalPose, const Ice::Current &c=Ice::emptyCurrent) override
DistanceInfo getRobotNodeDistance(const std::string &robotName, const std::string &robotNodeName1, const std::string &robotNodeName2, const Ice::Current &c=Ice::emptyCurrent) override
void objectGrasped(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
create a joint
TimeServerListenerPrx timeTopicPrx
void setRobotPose(const std::string &robotName, const PoseBasePtr &globalPose, const Ice::Current &c=Ice::emptyCurrent) override
std::string addRobot(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
Hook for subclass.
void addObject(const memoryx::ObjectClassBasePtr &objectClassBase, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
SimulatedRobotState stateFromRobotInfo(RobotInfo const &robot, IceUtil::Time timestamp)
void actuateRobotJoints(const std::string &robotName, const NameValueMap &angles, const NameValueMap &velocities, const Ice::Current &c=Ice::emptyCurrent) override
ForceTorqueDataSeq getRobotForceTorqueSensors(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
void setRobotMaxTorque(const std::string &robotName, const std::string &nodeName, float maxTorque, const Ice::Current &c=Ice::emptyCurrent) override
ObjectClassInformationSequence getObjectClassPoses(const std::string &robotName, const std::string &frameName, const std::string &className, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsPos(const std::string &robotName, const NameValueMap &angles, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< Simulator >::pointer_type simulationTask
The sim task.
PoseBasePtr getRobotNodePose(const std::string &robotName, const std::string &robotNodeName, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsVel(const std::string &robotName, const NameValueMap &velocities, const Ice::Current &c=Ice::emptyCurrent) override
std::string commonStorageName
void activateObject(const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
bool simulatorThreadRunning
std::string priorKnowledgeName
Ice::StringSeq getRobotNames(const Ice::Current &) override
memoryx::EntityDrawerInterfacePrx entityDrawerPrx
Drawing contacts.
std::map< std::string, std::vector< std::string > > classInstanceMap
Stores all instances that belong to a class.
std::string getDefaultName() const override
Retrieve default name of component.
int getFixedTimeStepMS(const Ice::Current &c=Ice::emptyCurrent) override
void applyTorqueObject(const std::string &objectName, const Vector3BasePtr &torque, const Ice::Current &c=Ice::emptyCurrent) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< SimulatorTimeServerProxy > SimulatorTimeServerProxyPtr
std::shared_ptr< SimulatedWorld > SimulatedWorldPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< Simulator > SimulatorPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr