diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp index df3fb7eafae6f4e2366f1b66a7056fbbd4d10ddd..b72b3669da6e9be36db05727efc249e8772a5a2f 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.cpp @@ -1226,12 +1226,52 @@ Eigen::Vector3f BulletRobot::getJointTorques(RobotNodePtr rn) } LinkInfo link = getLink(rn); + if(rn->isRotationalJoint()) + { + enableForceTorqueFeedback(link, true); + result = getJointForceTorqueGlobal(link).tail(3); + } + + return result; +} + +double BulletRobot::getJointTorque(RobotNodePtr rn) +{ + VR_ASSERT(rn); + if (!hasLink(rn)) + { + VR_ERROR << "No link with node " << rn->getName() << endl; + return 0.0; + } + LinkInfo link = getLink(rn); + if(!rn->isRotationalJoint()) + return 0.0; + enableForceTorqueFeedback(link, true); + Eigen::Vector3f torqueVector = getJointForceTorqueGlobal(link).tail(3); + + // project onto joint axis + double troque = (torqueVector.adjoint() * link.nodeJoint->getGlobalPose().block(0, 2, 3, 1))(0, 0); + return troque; +} + +Eigen::Vector3f BulletRobot::getJointForces(RobotNodePtr rn) +{ + VR_ASSERT(rn); + Eigen::Vector3f result; + result.setZero(); + if (!hasLink(rn)) + { + VR_ERROR << "No link with node " << rn->getName() << endl; + return result; + } + LinkInfo link = getLink(rn); if(rn->isRotationalJoint()) { - result = getJointForceTorqueGlobal(link).tail(3); + enableForceTorqueFeedback(link, true); + result = getJointForceTorqueGlobal(link).head(3); } return result; diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h index 45c441bc4395cf27c4d0711fa56c7c9348d5535b..0d9dee199f861184b23b641b6ad3ffb8e83d98ed 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h @@ -118,12 +118,31 @@ public: * \brief getJointTorques retrieves the torques in the given joint. * \param rn * \return Returns the torques in the given joint. If rn is not a - * rotational joint. + * rotational joint zero is returned. * Values are in N*m. Position of the values is in the middle of the joint * in the global coordinate system. */ Eigen::Vector3f getJointTorques(VirtualRobot::RobotNodePtr rn); + /*! + * \brief getJointTorque retrieves the torque along the axis in the given joint. + * \param rn + * \return Returns the torque in the given joint. If rn is not a + * rotational joint zero is returned. + * Values are in N*m. + */ + double getJointTorque(VirtualRobot::RobotNodePtr rn); + + /*! + * \brief getJointForce retrieves the forces in the given joint. + * \param rn + * \return Returns the forces in the given joint. If rn is not a + * rotational joint zero is returned. + * Values are in N. Position of the values is in the middle of the joint + * in the global coordinate system. + */ + Eigen::Vector3f getJointForces(VirtualRobot::RobotNodePtr rn); + /*! Returns the CoM pose, which is reported by bullet */ diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.cpp b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.cpp index 28e195e030c1f09a3c6b23206eb4d267db11b86d..281767799e85c9e73e6e92603b228b31727f264c 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.cpp +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.cpp @@ -32,6 +32,10 @@ void BulletRobotLogger::writeToFile(const std::string& path) output << "ActualAngle" << name << ","; output << "TargetVelocity" << name << ","; output << "ActualVelocity" << name << ","; + output << "ActualTorque" << name << ","; + output << "ActualForceX" << name << ","; + output << "ActualForceY" << name << ","; + output << "ActualForceZ" << name << ","; } output << "CoM X" << ","; output << "CoM Y" << ","; @@ -51,6 +55,10 @@ void BulletRobotLogger::writeToFile(const std::string& path) output << actualAngleLog[frame](dof) << ","; output << targetVelocityLog[frame](dof) << ","; output << actualVelocityLog[frame](dof) << ","; + output << actualJointTorquesLog[frame](dof) << ","; + output << actualJointForcesLog[frame](0, dof) << ","; + output << actualJointForcesLog[frame](1, dof) << ","; + output << actualJointForcesLog[frame](2, dof) << ","; } output << actualCoMLog[frame].x() << ","; output << actualCoMLog[frame].y() << ","; @@ -85,6 +93,8 @@ void BulletRobotLogger::log(btScalar dt) Eigen::VectorXf targetAngle(dof); Eigen::VectorXf actualVelocity(dof); Eigen::VectorXf targetVelocity(dof); + Eigen::VectorXf actualTorque(dof); + Eigen::Matrix3Xf actualForces(3, dof); for (unsigned int i = 0; i < jointNodes->getSize(); i++) { @@ -94,8 +104,12 @@ void BulletRobotLogger::log(btScalar dt) actualVelocity(i) = -robot->getJointSpeed(node); targetAngle(i) = robot->getNodeTarget(node); targetVelocity(i) = robot->getJointTargetSpeed(node); + actualTorque(i) = robot->getJointTorque(node); + actualForces.col(i) = robot->getJointForces(node); } + actualJointTorquesLog.push_back(actualTorque); + actualJointForcesLog.push_back(actualForces); actualCoMLog.push_back(bodyNodes->getCoM()); actualCoMVelocityLog.push_back(robot->getComGlobalVelocity(bodyNodes)); actualVelocityLog.push_back(actualVelocity); diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h index 1e9adeeac6e4bff52fa91099d2d932ea15534168..ecabd5af2c29031bd0cc7bc68a0ccfc80ae3a2c9 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h @@ -41,6 +41,8 @@ private: std::vector<Eigen::VectorXf> targetVelocityLog; std::vector<Eigen::VectorXf> actualAngleLog; std::vector<Eigen::VectorXf> actualVelocityLog; + std::vector<Eigen::VectorXf> actualJointTorquesLog; + std::vector<Eigen::Matrix3Xf> actualJointForcesLog; std::vector<Eigen::Vector3f> actualCoMLog; std::vector<Eigen::Vector3f> actualCoMVelocityLog; std::vector<double> timestamps;