diff --git a/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.cpp b/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.cpp index 37e0ff33815e1588a902bea07c32036916b47536..3e09e0643473c053b68fb8f254e1cf8c988c5d50 100644 --- a/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.cpp +++ b/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.cpp @@ -28,6 +28,7 @@ #include <VirtualRobot/Robot.h> #include <VirtualRobot/Nodes/ForceTorqueSensor.h> #include <VirtualRobot/CollisionDetection/CollisionChecker.h> +#include <VirtualRobot/RobotFactory.h> #include <ArmarXCore/core/logging/Logging.h> #include <ArmarXCore/core/system/ArmarXDataPath.h> @@ -1090,6 +1091,12 @@ void BulletPhysicsWorld::setRobotLinearVelocityRobotRootFrame(const std::string& return; } + if (!dynamicsRobot->hasDynamicsRobotNode(kinRob->getRobotNode(robotNodeName))) + { + ARMARX_WARNING_S << "No dynamic robotNode available with name " << robotNodeName; + return; + } + Eigen::Matrix4f newPose; newPose.setIdentity(); newPose.block<3, 1>(0, 3) = vel; @@ -1128,6 +1135,12 @@ void BulletPhysicsWorld::setRobotAngularVelocityRobotRootFrame(const std::string return; } + if (!dynamicsRobot->hasDynamicsRobotNode(kinRob->getRobotNode(robotNodeName))) + { + ARMARX_WARNING_S << "No dynamic robotNode available with name " << robotNodeName; + return; + } + Eigen::Matrix4f newPose; newPose.setIdentity(); newPose.block<3, 1>(0, 3) = vel; @@ -1136,7 +1149,10 @@ void BulletPhysicsWorld::setRobotAngularVelocityRobotRootFrame(const std::string globalPose(1, 3) = 0; globalPose(2, 3) = 0; auto globalNewPose = globalPose * newPose; - dynamicsRobot->getDynamicsRobotNode(kinRob->getRobotNode(robotNodeName))->setAngularVelocity(globalNewPose.block<3, 1>(0, 3)); + + auto robotNode = kinRob->getRobotNode(robotNodeName); + auto dynamicsRobotNode = dynamicsRobot->getDynamicsRobotNode(robotNode); + dynamicsRobotNode->setAngularVelocity(globalNewPose.block<3, 1>(0, 3)); } bool BulletPhysicsWorld::hasRobot(const std::string& robotName) @@ -2109,3 +2125,7 @@ DistanceInfo BulletPhysicsWorld::getDistance(const std::string& robotName, const return di; } +RobotPtr BulletPhysicsWorld::adaptRobotToWorld(VirtualRobot::RobotPtr robot) +{ + return RobotFactory::createFlattenedModel(*robot); +} diff --git a/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.h b/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.h index 94601b65c793d0146fd7f0e1942e8268aa5be0eb..59d11572f8ccac4d5b51bb1fab4865ec54b48844 100644 --- a/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.h +++ b/source/ArmarXSimulation/components/Simulator/BulletPhysicsWorld.h @@ -61,6 +61,8 @@ namespace armarx virtual void initialize(int stepSizeMS, int bulletFixedTimeStepMS, int bulletFixedTimeStepMaxNrLoops, float maxRealTimeSimSpeed = 1, bool floorPlane = false, std::string floorTexture = std::string()); + VirtualRobot::RobotPtr adaptRobotToWorld(VirtualRobot::RobotPtr robot) override; + void actuateRobotJoints(const std::string& robotName, const std::map< std::string, float>& angles, const std::map< std::string, float>& velocities) override; void actuateRobotJointsPos(const std::string& robotName, const std::map< std::string, float>& angles) override; void actuateRobotJointsVel(const std::string& robotName, const std::map< std::string, float>& velocities) override; diff --git a/source/ArmarXSimulation/components/Simulator/SimulatedWorld.cpp b/source/ArmarXSimulation/components/Simulator/SimulatedWorld.cpp index d96b8cb9edef0a5228c3e483d4df9c3797d9893c..6d3d3de85e3b7482ca6402ed2d306cff71193e52 100644 --- a/source/ArmarXSimulation/components/Simulator/SimulatedWorld.cpp +++ b/source/ArmarXSimulation/components/Simulator/SimulatedWorld.cpp @@ -188,8 +188,6 @@ bool SimulatedWorld::addRobot(RobotPtr robot, double pid_p, double pid_i, double return true; } - - void SimulatedWorld::objectReleased(const std::string& robotName, const std::string& robotNodeName, const std::string& objectName) { ScopedRecursiveLockPtr lockEngine = getScopedEngineLock(__FUNCTION__); @@ -327,7 +325,9 @@ bool SimulatedWorld::addRobot(std::string& robotInstanceName, const std::string& { loadMode = VirtualRobot::RobotIO::eCollisionModel; } + robot = RobotIO::loadRobot(filename, loadMode); + robot = adaptRobotToWorld(robot); ARMARX_TRACE; // ensure that the robot has the standard name @@ -419,6 +419,10 @@ bool SimulatedWorld::addRobot(std::string& robotInstanceName, const std::string& return success; } +VirtualRobot::RobotPtr SimulatedWorld::adaptRobotToWorld(VirtualRobot::RobotPtr robot) +{ + return robot; +} bool SimulatedWorld::removeRobot(const std::string& robotName) { diff --git a/source/ArmarXSimulation/components/Simulator/SimulatedWorld.h b/source/ArmarXSimulation/components/Simulator/SimulatedWorld.h index bae5d2b12f0fcfede12896027f4a7159317d88a8..7cb53629ba4809b9854902aa8a44f20968f7e804 100644 --- a/source/ArmarXSimulation/components/Simulator/SimulatedWorld.h +++ b/source/ArmarXSimulation/components/Simulator/SimulatedWorld.h @@ -241,6 +241,7 @@ namespace armarx const std::string& filename, bool staticRobot = false, float scaling = 1.0f, bool colModel = false, bool selfCollisions = false); + virtual VirtualRobot::RobotPtr adaptRobotToWorld(VirtualRobot::RobotPtr); /*! * \brief toFramedPose Constructs a framed pose