diff --git a/VirtualRobot/XML/mujoco/RobotMjcf.cpp b/VirtualRobot/XML/mujoco/RobotMjcf.cpp index 42131e5e79f94645df8879995f41d5c386f5cd02..fcd8f3f0a860bfaecaa872166c4d3d03d2eec3e2 100644 --- a/VirtualRobot/XML/mujoco/RobotMjcf.cpp +++ b/VirtualRobot/XML/mujoco/RobotMjcf.cpp @@ -86,11 +86,17 @@ const mjcf::Document& RobotMjcf::getDocument() const return *document; } + RobotPtr RobotMjcf::getRobot() const { return robot; } +mjcf::Body RobotMjcf::getRobotBody() const +{ + return robotBody; +} + mjcf::Body RobotMjcf::getRobotNodeBody(const std::string& nodeName) const { try @@ -108,6 +114,11 @@ bool RobotMjcf::hasRobotNodeBody(const std::string& nodeName) const return nodeBodies.find(nodeName) != nodeBodies.end(); } +mjcf::DefaultClass RobotMjcf::getRobotDefaults() const +{ + return document->default_().getClass(robot->getName()); +} + void RobotMjcf::setOutputFile(const std::filesystem::path& filePath) { this->outputFile = filePath; @@ -129,9 +140,14 @@ void RobotMjcf::addCompiler(bool angleRadian, bool boundMass, bool balanceInerat compiler.balanceinertia = balanceIneratia; } -void RobotMjcf::addDefaultsClass(float meshScale) +void RobotMjcf::addRobotDefaults() { - mjcf::DefaultClass defaultsClass = document->default_().addClass(robot->getName()); + addRobotDefaults(meshScale); +} + +void RobotMjcf::addRobotDefaults(float meshScale) +{ + mjcf::DefaultClass defaultsClass = getRobotDefaults(); defaultsClass.insertComment("Add default values for " + robot->getName() + " here.", true); @@ -443,6 +459,10 @@ mjcf::Body RobotMjcf::addMocapBodyWeld( mjcf::Body RobotMjcf::addMocapBodyWeldRobot( const std::string& bodyName, const std::string& className) { + if (!robotBody.hasFreeJoint()) + { + robotBody.addFreeJoint(); + } return addMocapBodyWeld(bodyName.empty() ? robot->getName() + "_mocap" : bodyName, className); } @@ -653,4 +673,34 @@ void RobotMjcf::addActuators(const std::map<std::string, ActuatorType>& nodeType } } +float RobotMjcf::getLengthScale() const +{ + return lengthScale; +} + +void RobotMjcf::setLengthScale(float value) +{ + lengthScale = value; +} + +float RobotMjcf::getMeshScale() const +{ + return meshScale; +} + +void RobotMjcf::setMeshScale(float value) +{ + meshScale = value; +} + +float RobotMjcf::getMassScale() const +{ + return massScale; +} + +void RobotMjcf::setMassScale(float value) +{ + massScale = value; +} + } diff --git a/VirtualRobot/XML/mujoco/RobotMjcf.h b/VirtualRobot/XML/mujoco/RobotMjcf.h index 02d9b2c60c03229abba924b12b3b2910590ee1d8..75de23b09f8c94f9f369e047c51df336b76ebfe2 100644 --- a/VirtualRobot/XML/mujoco/RobotMjcf.h +++ b/VirtualRobot/XML/mujoco/RobotMjcf.h @@ -39,6 +39,31 @@ namespace VirtualRobot::mujoco const mjcf::Document& getDocument() const; + // PREPARATION + + /// Get the length scaling (to m). + float getLengthScale() const; + /// Set the length scaling (to m). + void setLengthScale(float value); + + /// Get the mesh scaling (to m). + float getMeshScale() const; + /// Set the mesh scaling (to m). + void setMeshScale(float value); + + /// Get the mass scaling (to kg). + float getMassScale() const; + /// Set the mass scaling (to kg). + void setMassScale(float value); + + + /// Set the path to the output XML file. + void setOutputFile(const std::filesystem::path& filePath); + + /// Set the path to the directory where meshes shall be stored. + void setOutputMeshDirectory(const std::filesystem::path& path); + + // ELEMENT ACCESS /// Get the robot. @@ -58,13 +83,9 @@ namespace VirtualRobot::mujoco bool hasRobotNodeBody(const std::string& nodeName) const; - // PREPARATION - - /// Set the path to the output XML file. - void setOutputFile(const std::filesystem::path& filePath); + /// Get the robot default class. + mjcf::DefaultClass getRobotDefaults() const; - /// Set the path to the directory where meshes shall be stored. - void setOutputMeshDirectory(const std::filesystem::path& path); // MODIFIERS @@ -81,8 +102,10 @@ namespace VirtualRobot::mujoco bool boundMass = true, bool balanceIneratia = true); - /// Make defaults class with robot's name. - void addDefaultsClass(float meshScale = 1.0f); + /// Add defaults to robot class, using the set mesh scale. + void addRobotDefaults(); + /// Add defaults to robot class with robot's name. + void addRobotDefaults(float meshScale); // ASSETS @@ -183,6 +206,7 @@ namespace VirtualRobot::mujoco /** * @brief Add a mocap body and a weld constraint to the robot body. + * If the robot body does not have a free joint, a free joint is added. * @param bodyName Name of the mocap body. If left empty, is derived from the robot name. * @see addMocapBodyWeld() */ @@ -242,8 +266,12 @@ namespace VirtualRobot::mujoco // SENSORS + + + + private: - + /// The robot. RobotPtr robot;