diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletEngine.cpp b/SimDynamics/DynamicsEngine/BulletEngine/BulletEngine.cpp index 530522e77ef53374d8b175ad3dbdf01d9baa76d8..056403bff497c413a0c03761faf15498eec0e6e9 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletEngine.cpp +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletEngine.cpp @@ -191,7 +191,9 @@ namespace SimDynamics VR_ERROR << "Skipping non-BULLET object " << (*i)->getName() << "!" << std::endl; continue; } + auto friction = btObject->getSceneObject()->getPhysics().friction; + // TODO const auto damping = btObject->getSceneObject()->getPhysics().damping; btObject->getRigidBody()->setRestitution(bulletConfig->bulletObjectRestitution); btObject->getRigidBody()->setFriction(friction > 0.0 ? friction : bulletConfig->bulletObjectFriction); diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp index 466460a2aa5a1a5d003a7baf2c1e690395762097..babd671d30db0ecc794679a05d4f7701be5660f0 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp @@ -30,13 +30,20 @@ using namespace std; namespace SimDynamics { - BulletRobot::BulletRobot(VirtualRobot::RobotPtr rob, bool enableJointMotors) + BulletRobot::BulletRobot(VirtualRobot::RobotPtr rob) : DynamicsRobot(rob) // should be enough for up to 10ms/step , bulletMaxMotorImulse(30 * BulletObject::ScaleFactor) { ignoreTranslationalJoints = false; + const bool enableJointMotors = not rob->isPassive(); + + if(not enableJointMotors) + { + VR_INFO << "Robot " << rob->getName() << " is passive (no joint motors)"; + } + buildBulletModels(enableJointMotors); // activate force torque sensors @@ -65,12 +72,10 @@ namespace SimDynamics } } - BulletRobot::~BulletRobot() - = default; - + BulletRobot::~BulletRobot() = default; - void BulletRobot::buildBulletModels(bool /*enableJointMotors*/) + void BulletRobot::buildBulletModels(const bool enableJointMotors) { MutexLockPtr lock = getScopedLock(); @@ -157,7 +162,7 @@ namespace SimDynamics if (bodyA != bodyB) { - createLink(bodyA, joint, /*joint2,*/ bodyB); + createLink(bodyA, joint, /*joint2,*/ bodyB, enableJointMotors); } } @@ -325,7 +330,7 @@ namespace SimDynamics } - void BulletRobot::createLink(VirtualRobot::RobotNodePtr bodyA, VirtualRobot::RobotNodePtr joint, /*VirtualRobot::RobotNodePtr joint2,*/ VirtualRobot::RobotNodePtr bodyB, bool enableJointMotors) + void BulletRobot::createLink(VirtualRobot::RobotNodePtr bodyA, VirtualRobot::RobotNodePtr joint, /*VirtualRobot::RobotNodePtr joint2,*/ VirtualRobot::RobotNodePtr bodyB, const bool enableJointMotors) { MutexLockPtr lock = getScopedLock(); diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h index cc877825e6cb5190cf6e6e187098657912d436df..59301963d252389758cee9f4183077ecc48010de 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h @@ -39,7 +39,7 @@ namespace SimDynamics Constructor. Create a dynamic representation by building all related bullet objects. */ - BulletRobot(VirtualRobot::RobotPtr rob, bool enableJointMotors = true); + BulletRobot(VirtualRobot::RobotPtr rob); /*! */ @@ -213,7 +213,7 @@ namespace SimDynamics // fixed (joint=fixed !joint2) // hinge (joint=revolute !joint2) // universal (hinge2) (joint=revolute joint2=revolute) // experimental - void createLink(VirtualRobot::RobotNodePtr bodyA, VirtualRobot::RobotNodePtr joint, /*VirtualRobot::RobotNodePtr joint2,*/ VirtualRobot::RobotNodePtr bodyB, bool enableJointMotors = true); + void createLink(VirtualRobot::RobotNodePtr bodyA, VirtualRobot::RobotNodePtr joint, /*VirtualRobot::RobotNodePtr joint2,*/ VirtualRobot::RobotNodePtr bodyB, bool enableJointMotors); void createLink(VirtualRobot::RobotNodePtr node1, VirtualRobot::RobotNodePtr node2, bool enableJointMotors); diff --git a/VirtualRobot/Robot.h b/VirtualRobot/Robot.h index e832ffb80f83684dec213bfa419ad136257bf117..6eb0feffc80bc1a4f342fef1697358c2e73d3dae 100644 --- a/VirtualRobot/Robot.h +++ b/VirtualRobot/Robot.h @@ -419,6 +419,17 @@ namespace VirtualRobot bool getPropagatingJointValuesEnabled() const; void setPropagatingJointValuesEnabled(bool enabled); + + + void setPassive(){ + passive = true; + } + + bool isPassive() const + { + return passive; + } + protected: Robot(); /*! @@ -441,6 +452,8 @@ namespace VirtualRobot bool use_mutex; bool propagatingJointValuesEnabled = true; + bool passive{false}; + //float radianToMMfactor = 10; }; diff --git a/VirtualRobot/XML/RobotIO.cpp b/VirtualRobot/XML/RobotIO.cpp index 077e5d9c469f666feb18a5606f70976371b00297..b9d1f226cd5ec56fb0571e149d4d00d95900d305 100644 --- a/VirtualRobot/XML/RobotIO.cpp +++ b/VirtualRobot/XML/RobotIO.cpp @@ -909,11 +909,25 @@ namespace VirtualRobot return robo; } + inline bool toBool(const std::string& strRepr) noexcept + { + try { + const int passiveIntRepr = std::stoi(strRepr); + return static_cast<bool>(passiveIntRepr); + + } catch (std::invalid_argument&) { + // nothing to do here + } + + return strRepr == "true"; + } + RobotPtr RobotIO::processRobotAttributes(rapidxml::xml_node<char>* robotXMLNode, std::string& robotRoot) { std::string robotName; std::string robotType; + bool passive{false}; // if true, robot joints will not be actuated // process attributes of robot rapidxml::xml_attribute<>* attr; @@ -974,6 +988,20 @@ namespace VirtualRobot robotRoot = attr->value(); + attr = robotXMLNode->first_attribute("passive", 0, false); + + if (!attr) + { + VR_INFO << "Robot definition expects attribute 'passive' but is not set" << std::endl; + } + else + { + const std::string passiveStrRep = attr->value(); + passive = toBool(passiveStrRep); + + VR_INFO << "Robot is 'passive' according to config" << std::endl; + } + // build robot RobotPtr robo(new LocalRobot(robotName, robotType)); /*attr = robotXMLNode->first_attribute("RadianToMMfactor", 0, false); @@ -981,6 +1009,12 @@ namespace VirtualRobot { robo->setRadianToMMfactor(atof(attr->value())); }*/ + + if(passive){ + robo->setPassive(); + } + + return robo; }