Go to the documentation of this file.
29 #include <VirtualRobot/XML/mujoco/RobotMjcf.h>
31 #include <MujocoX/libraries/MJCF/Document.h>
32 #include <MujocoX/libraries/Simulation/MujocoSim.h>
33 #include <MujocoX/libraries/Simulation/SimCallbackListener.h>
34 #include <MujocoX/libraries/Simulation/SimEntity.h>
69 void initialize(
int stepTimeMs,
bool floorEnabled,
const std::string& floorTexture);
84 const std::map<std::string, float>& angles,
85 const std::map<std::string, float>& velocities)
override;
87 const std::map<std::string, float>& angles)
override;
89 const std::map<std::string, float>& velocities)
override;
91 const std::map<std::string, float>& torques)
override;
93 virtual void applyForceRobotNode(
const std::string& robotName,
const std::string& robotNodeName,
94 const Eigen::Vector3f& force)
override;
95 virtual void applyTorqueRobotNode(
const std::string& robotName,
const std::string& robotNodeName,
96 const Eigen::Vector3f& torque)
override;
98 virtual void applyForceObject(
const std::string& objectName,
const Eigen::Vector3f& force)
override;
99 virtual void applyTorqueObject(
const std::string& objectName,
const Eigen::Vector3f& torque)
override;
101 virtual std::map<std::string, float>
getRobotJointAngles(
const std::string& robotName)
override;
102 virtual float getRobotJointAngle(
const std::string& robotName,
const std::string& nodeName)
override;
105 virtual float getRobotJointVelocity(
const std::string& robotName,
const std::string& nodeName)
override;
107 virtual std::map<std::string, float>
getRobotJointTorques(
const std::string& robotName)
override;
118 virtual Eigen::Vector3f
getRobotLinearVelocity(
const std::string& robotName,
const std::string& nodeName)
override;
119 virtual Eigen::Vector3f
getRobotAngularVelocity(
const std::string& robotName,
const std::string& nodeName)
override;
122 const Eigen::Vector3f& vel)
override;
124 const Eigen::Vector3f& vel)
override;
127 const Eigen::Vector3f& vel)
override;
129 const Eigen::Vector3f& vel)
override;
131 virtual bool hasObject(
const std::string& instanceName)
override;
133 virtual bool hasRobot(
const std::string& robotName)
override;
134 virtual bool hasRobotNode(
const std::string& robotName,
const std::string& robotNodeName)
override;
136 virtual std::vector<VirtualRobot::SceneObjectPtr>
getObjects()
override;
139 virtual std::map<std::string, VirtualRobot::RobotPtr>
getRobots()
override;
141 virtual float getRobotJointLimitLo(
const std::string& robotName,
const std::string& nodeName)
override;
142 virtual float getRobotJointLimitHi(
const std::string& robotName,
const std::string& nodeName)
override;
144 virtual float getRobotMaxTorque(
const std::string& robotName,
const std::string& nodeName)
override;
145 virtual void setRobotMaxTorque(
const std::string& robotName,
const std::string& nodeName,
float maxTorque)
override;
147 virtual float getRobotMass(
const std::string& robotName)
override;
149 virtual DistanceInfo
getRobotNodeDistance(
const std::string& robotName,
const std::string& robotNodeName1,
150 const std::string& robotNodeName2)
override;
151 virtual DistanceInfo
getDistance(
const std::string& robotName,
const std::string& robotNodeName,
152 const std::string& worldObjectName)
override;
154 virtual std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo>
copyContacts()
override;
157 const std::string& frameName)
override;
160 VirtualRobot::SceneObject::Physics::SimulationType simType)
override;
162 virtual void setRobotNodeSimType(
const std::string& robotName,
const std::string& robotNodeName,
163 VirtualRobot::SceneObject::Physics::SimulationType simType)
override;
175 VirtualRobot::SceneObject::Physics::SimulationType simType)
override;
179 double pid_p,
double pid_i,
double pid_d,
180 const std::string&
filename,
bool staticRobot,
bool selfCollisions)
override;
183 virtual bool objectGraspedEngine(
const std::string& robotName,
const std::string& robotNodeName,
184 const std::string& objectName,
Eigen::Matrix4f& storeLocalTransform)
override;
185 virtual bool objectReleasedEngine(
const std::string& robotName,
const std::string& robotNodeName,
186 const std::string& objectName)
override;
190 virtual void setupFloorEngine(
bool enable,
const std::string& floorTexture)
override;
198 std::map<std::string, PoseBasePtr>& objMap)
override;
201 std::map<std::string, PoseBasePtr>& objMap)
override;
205 Eigen::Vector3f& linearVelocity, Eigen::Vector3f& angularVelocity)
override;
215 virtual void onLoadModel(mujoco::Model& model)
override;
216 virtual void onMakeData(mujoco::Model& model, mujoco::Data&
data)
override;
222 static const std::filesystem::path BASE_MJCF_FILENAME;
224 static const std::filesystem::path TEMP_DIR;
226 static const std::filesystem::path TEMP_MODEL_FILE;
228 static const std::filesystem::path TEMP_MESH_DIR_REL;
230 static const std::filesystem::path TEMP_MESH_DIR;
233 static const std::string FLOOR_NAME;
235 static const std::string OBJECT_CLASS_NAME;
240 VirtualRobot::ObstaclePtr makeFloorObject(
241 mujoco::Model& model,
const mujoco::SimGeom& floorGeom)
const;
248 void reloadModel(
bool request =
true);
257 mjcf::Document mjcfDocument;
260 SimMJCF simMjcf { mjcfDocument, lengthScaling,
"MujocoPhysicsWorld" };
264 mujoco::MujocoSim sim;
267 std::chrono::milliseconds fixedTimeStep;
275 std::filesystem::path floorTextureFile;
279 std::map<std::string, mujoco::SimObject> obstacles;
282 std::map<std::string, mujoco::SimObject> objects;
285 std::map<std::string, mujoco::SimRobot> robots;
291 std::vector<mjContact> contacts;
virtual bool addRobotEngine(VirtualRobot::RobotPtr robot, double pid_p, double pid_i, double pid_d, const std::string &filename, bool staticRobot, bool selfCollisions) override
virtual FramedPosePtr toFramedPose(const Eigen::Matrix4f &globalPose, const std::string &robotName, const std::string &frameName) override
toFramedPose Constructs a framed pose
virtual void stepPhysicsFixedTimeStep() override
Perform one simulation step.
virtual bool synchronizeRobotNodePoses(const std::string &robotName, std::map< std::string, PoseBasePtr > &objMap) override
virtual bool hasRobot(const std::string &robotName) override
virtual bool synchronizeSimulationDataEngine() override
According to other SimulatedWorlds, this method's only job is to update contacts.
virtual void setRobotAngularVelocity(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
virtual VirtualRobot::SceneObjectPtr getFloor() override
virtual void applyTorqueObject(const std::string &objectName, const Eigen::Vector3f &torque) override
virtual void setRobotNodeSimType(const std::string &robotName, const std::string &robotNodeName, VirtualRobot::SceneObject::Physics::SimulationType simType) override
The MujocoPhysicsWorld class encapsulates the whole physics simulation and the corresponding data.
virtual float getRobotJointLimitHi(const std::string &robotName, const std::string &nodeName) override
virtual float getRobotMaxTorque(const std::string &robotName, const std::string &nodeName) override
virtual bool synchronizeSceneObjectPoses(VirtualRobot::SceneObjectPtr currentObjEngine, std::map< std::string, PoseBasePtr > &objMap) override
virtual float getRobotJointLimitLo(const std::string &robotName, const std::string &nodeName) override
virtual std::map< std::string, float > getRobotJointAngles(const std::string &robotName) override
The SimulatedWorld class encapsulates the whole physics simulation and the corresponding data.
virtual void onLoadModel(mujoco::Model &model) override
Sets time step and fetches entity IDs.
virtual Eigen::Matrix4f getRobotNodePose(const std::string &robotName, const std::string &robotNodeName) override
virtual Eigen::Vector3f getRobotLinearVelocity(const std::string &robotName, const std::string &nodeName) override
virtual void actuateRobotJointsPos(const std::string &robotName, const std::map< std::string, float > &angles) override
virtual bool objectGraspedEngine(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, Eigen::Matrix4f &storeLocalTransform) override
create a joint
virtual DistanceInfo getRobotNodeDistance(const std::string &robotName, const std::string &robotNodeName1, const std::string &robotNodeName2) override
virtual void applyForceRobotNode(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &force) override
virtual void applyForceObject(const std::string &objectName, const Eigen::Vector3f &force) override
virtual VirtualRobot::RobotPtr getRobot(const std::string &robotName) override
virtual bool objectReleasedEngine(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName) override
remove a joint
virtual ForceTorqueDataSeq getRobotForceTorqueSensors(const std::string &robotName) override
virtual bool hasObject(const std::string &instanceName) override
virtual void onMakeData(mujoco::Model &model, mujoco::Data &data) override
virtual void setRobotPose(const std::string &robotName, const Eigen::Matrix4f &globalPose) override
virtual void actuateRobotJoints(const std::string &robotName, const std::map< std::string, float > &angles, const std::map< std::string, float > &velocities) override
virtual bool removeRobotEngine(const std::string &robotName) override
virtual bool removeObstacleEngine(const std::string &name) override
virtual Eigen::Vector3f getRobotAngularVelocity(const std::string &robotName, const std::string &nodeName) override
std::shared_ptr< MujocoPhysicsWorld > MujocoPhysicsWorldPtr
virtual bool addObstacleEngine(VirtualRobot::SceneObjectPtr o, VirtualRobot::SceneObject::Physics::SimulationType simType) override
virtual void setupFloorEngine(bool enable, const std::string &floorTexture) override
const KinematicUnitDatafieldCreator jointVelocities("jointVelocities")
virtual void setRobotLinearVelocity(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
virtual void applyTorqueRobotNode(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &torque) override
virtual ~MujocoPhysicsWorld() override=default
virtual std::map< std::string, float > getRobotJointTorques(const std::string &robotName) override
virtual std::map< std::string, VirtualRobot::RobotPtr > getRobots() override
virtual std::vector< std::string > getObstacleNames() override
void initialize(int stepTimeMs, bool floorEnabled, const std::string &floorTexture)
Initialize *this.
virtual void actuateRobotJointsTorque(const std::string &robotName, const std::map< std::string, float > &torques) override
virtual std::vector< VirtualRobot::SceneObjectPtr > getObjects() override
virtual std::vector< std::string > getRobotNames() override
virtual std::map< std::string, float > getRobotJointVelocities(const std::string &robotName) override
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
virtual int getContactCount() override
MatrixXX< 4, 4, float > Matrix4f
virtual bool getRobotStatus(const std::string &robotName, NameValueMap &jointAngles, NameValueMap &jointVelocities, NameValueMap &jointTorques, Eigen::Vector3f &linearVelocity, Eigen::Vector3f &angularVelocity) override
virtual float getRobotJointAngle(const std::string &robotName, const std::string &nodeName) override
virtual void setObjectPose(const std::string &objectName, const Eigen::Matrix4f &globalPose) override
virtual void actuateRobotJointsVel(const std::string &robotName, const std::map< std::string, float > &velocities) override
boost::intrusive_ptr< SceneObject > SceneObjectPtr
virtual void setObjectSimType(const std::string &objectName, VirtualRobot::SceneObject::Physics::SimulationType simType) override
virtual void setRobotAngularVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override
virtual Eigen::Matrix4f getRobotPose(const std::string &robotName) override
virtual void setRobotMaxTorque(const std::string &robotName, const std::string &nodeName, float maxTorque) override
virtual float getRobotJointVelocity(const std::string &robotName, const std::string &nodeName) override
const KinematicUnitDatafieldCreator jointTorques("jointTorques")
virtual int getFixedTimeStepMS() override
virtual bool updateForceTorqueSensor(ForceTorqueInfo &ftInfo) override
virtual bool synchronizeObjects() override
virtual DistanceInfo getDistance(const std::string &robotName, const std::string &robotNodeName, const std::string &worldObjectName) override
virtual bool hasRobotNode(const std::string &robotName, const std::string &robotNodeName) override
virtual float getRobotMass(const std::string &robotName) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
virtual std::vector< SimDynamics::DynamicsEngine::DynamicsContactInfo > copyContacts() override
virtual void stepPhysicsRealTime() override
Perform one simulation step.
std::shared_ptr< class Robot > RobotPtr
virtual Eigen::Matrix4f getObjectPose(const std::string &objectName) override
virtual void setRobotLinearVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Eigen::Vector3f &vel) override