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
142 void stop(
const Ice::Current&
c = Ice::emptyCurrent)
override;
150 void setSpeed(Ice::Float newSpeed,
const Ice::Current&
c = Ice::emptyCurrent)
override;
151 Ice::Float
getSpeed(
const Ice::Current&
c = Ice::emptyCurrent)
override;
152 Ice::Long
getTime(
const Ice::Current&
c = Ice::emptyCurrent)
override;
153 Ice::Int
getStepTimeMS(const ::Ice::Current& = Ice::emptyCurrent)
override;
157 const NameValueMap& angles,
158 const NameValueMap& velocities,
159 const Ice::Current&
c = Ice::emptyCurrent)
override;
161 const NameValueMap& angles,
162 const Ice::Current&
c = Ice::emptyCurrent)
override;
164 const NameValueMap& velocities,
165 const Ice::Current&
c = Ice::emptyCurrent)
override;
167 const NameValueMap& torques,
168 const Ice::Current&
c = Ice::emptyCurrent)
override;
170 const PoseBasePtr& globalPose,
171 const Ice::Current&
c = Ice::emptyCurrent)
override;
174 const std::string& robotNodeName,
175 const Vector3BasePtr& force,
176 const Ice::Current&
c = Ice::emptyCurrent)
override;
178 const std::string& robotNodeName,
179 const Vector3BasePtr& torque,
180 const Ice::Current&
c = Ice::emptyCurrent)
override;
183 const Vector3BasePtr& force,
184 const Ice::Current&
c = Ice::emptyCurrent)
override;
186 const Vector3BasePtr& torque,
187 const Ice::Current&
c = Ice::emptyCurrent)
override;
190 std::string
addRobot(
const std::string& filename,
191 const Ice::Current&
c = Ice::emptyCurrent)
override;
194 const Ice::Current&
c = Ice::emptyCurrent)
override;
196 const std::string& filename,
198 const Ice::Current&
c = Ice::emptyCurrent)
override;
199 bool removeRobot(
const std::string& robotName,
const Ice::Current&
c = Ice::emptyCurrent);
200 void addObject(
const memoryx::ObjectClassBasePtr& objectClassBase,
201 const std::string& instanceName,
202 const PoseBasePtr& globalPose,
203 bool isStatic =
false,
204 const Ice::Current&
c = Ice::emptyCurrent)
override;
208 const Ice::Current&
c = Ice::emptyCurrent)
override;
210 const std::string& instanceName,
211 const PoseBasePtr& globalPose,
212 bool isStatic =
false,
213 const Ice::Current&
c = Ice::emptyCurrent)
override;
220 const DrawColor& color,
221 const std::string& instanceName,
222 const PoseBasePtr& globalPose,
223 bool isStatic =
false,
224 const Ice::Current&
c = Ice::emptyCurrent)
override;
227 void removeObject(
const std::string& instanceName,
const Ice::Current&)
override;
229 bool hasObject(
const std::string& instanceName,
230 const Ice::Current&
c = Ice::emptyCurrent)
override;
232 const PoseBasePtr& globalPose,
233 const Ice::Current&
c = Ice::emptyCurrent)
override;
235 armarx::SimulationType type,
236 const Ice::Current&
c = Ice::emptyCurrent)
override;
238 const Ice::Current&
c = Ice::emptyCurrent)
override;
240 bool hasRobot(
const std::string& robotName,
241 const Ice::Current&
c = Ice::emptyCurrent)
override;
243 const std::string& robotNodeName,
244 const Ice::Current&
c = Ice::emptyCurrent)
override;
246 const Ice::Current&
c = Ice::emptyCurrent)
override;
249 const Ice::Current&
c = Ice::emptyCurrent)
override;
251 const std::string& nodeName,
252 const Ice::Current&
c = Ice::emptyCurrent)
override;
254 const Ice::Current&
c = Ice::emptyCurrent)
override;
256 const std::string& nodeName,
257 const Ice::Current&
c = Ice::emptyCurrent)
override;
259 const Ice::Current&
c = Ice::emptyCurrent)
override;
262 const Ice::Current&
c = Ice::emptyCurrent)
override;
265 const std::string& nodeName,
266 const Ice::Current&
c = Ice::emptyCurrent)
override;
268 const std::string& nodeName,
269 const Ice::Current&
c = Ice::emptyCurrent)
override;
271 const Ice::Current&
c = Ice::emptyCurrent)
override;
272 SimulatedRobotState
getRobotState(
const std::string& robotName,
273 const Ice::Current&)
override;
276 const std::string& nodeName,
277 const Ice::Current&
c = Ice::emptyCurrent)
override;
279 const std::string& nodeName,
281 const Ice::Current&
c = Ice::emptyCurrent)
override;
284 const std::string& robotNodeName,
285 const Ice::Current&
c = Ice::emptyCurrent)
override;
288 const std::string& nodeName,
289 const Ice::Current&
c = Ice::emptyCurrent)
override;
291 const std::string& nodeName,
292 const Ice::Current&
c = Ice::emptyCurrent)
override;
295 const std::string& robotNodeName,
296 const Vector3BasePtr& vel,
297 const Ice::Current&
c = Ice::emptyCurrent)
override;
299 const std::string& robotNodeName,
300 const Vector3BasePtr& vel,
301 const Ice::Current&
c = Ice::emptyCurrent)
override;
304 const std::string& robotNodeName,
305 const Vector3BasePtr& vel,
306 const Ice::Current&
c = Ice::emptyCurrent)
override;
309 const std::string& robotNodeName,
310 const Vector3BasePtr& vel,
311 const Ice::Current&
c = Ice::emptyCurrent)
override;
315 const std::string& robotNodeName,
316 const std::string& objectName,
317 const Ice::Current&
c = Ice::emptyCurrent)
override;
321 const std::string& robotNodeName,
322 const std::string& objectName,
323 const Ice::Current&
c = Ice::emptyCurrent)
override;
326 const Ice::Current&
c = Ice::emptyCurrent)
override;
328 DistanceInfo
getDistance(
const std::string& robotName,
329 const std::string& robotNodeName,
330 const std::string& worldObjectName,
331 const Ice::Current&
c = Ice::emptyCurrent)
override;
333 const std::string& robotNodeName1,
334 const std::string& robotNodeName2,
335 const Ice::Current&
c = Ice::emptyCurrent)
override;
337 const std::string& layerName,
338 const Ice::Current&
c = Ice::emptyCurrent)
override;
344 ContactInfoSequence
getContacts(
const Ice::Current&
c = Ice::emptyCurrent)
override;
350 void updateContacts(
bool enable,
const Ice::Current&
c = Ice::emptyCurrent)
override;
352 ObjectClassInformationSequence
354 const std::string& frameName,
355 const std::string& className,
356 const Ice::Current&
c = Ice::emptyCurrent)
override;
364 void reInitialize(
const Ice::Current&
c = Ice::emptyCurrent)
override;
367 float getSimTime(
const Ice::Current&
c = Ice::emptyCurrent)
override;
370 SceneVisuData
getScene(
const Ice::Current&
c = Ice::emptyCurrent)
override;
380 void start(
const Ice::Current&
c = Ice::emptyCurrent)
override;
381 void pause(
const Ice::Current&
c = Ice::emptyCurrent)
override;
382 void step(
const Ice::Current&
c = Ice::emptyCurrent)
override;
383 bool isRunning(
const Ice::Current&
c = Ice::emptyCurrent)
override;
385 bool addSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx);
412 void resetData(
bool clearWorkingMemory =
false);
420 addRobot(std::string robotInstanceName,
421 const std::string& robFileGlobal,
423 const std::string& robFile,
427 bool isStatic =
false,
429 bool colModel =
false,
430 std::map<std::string, float> initConfig = std::map<std::string, float>(),
431 bool selfCollisions =
false);
504 void addRobotsFromProperties();
505 void addSceneFromFile(
const std::string& sceneFile);
506 void addSceneFromMemorySnapshot(
const std::string& snapshotName);
511 void addSceneFromJsonFile(
const std::string& scenePath);
516 void addSceneFromSdfFile(
const std::string& scenePath);
522 std::map<ObjectID, int>& idCounters);
524 void fixateRobotNode(
const std::string& robotName,
const std::string& robotNodeName);
525 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
static std::string GetDefaultName()
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