23 #include <robottestingframework/TestAssert.h>
24 #include <robottestingframework/dll/Plugin.h>
25 #include <yarp/os/Time.h>
26 #include <yarp/os/Property.h>
27 #include <yarp/sig/Vector.h>
29 #include "TorqueControlGravityConsistency.h"
31 using namespace robottestingframework;
32 using namespace yarp::os;
33 using namespace yarp::dev;
34 using namespace yarp::sig;
39 TorqueControlGravityConsistency::TorqueControlGravityConsistency() : yarp::robottestingframework::TestCase(
"TorqueControlGravityConsistency"),
45 TorqueControlGravityConsistency::~TorqueControlGravityConsistency()
49 bool TorqueControlGravityConsistency::setup(yarp::os::Property& property)
51 yarp::os::ResourceFinder & rf = yarp::os::ResourceFinder::getResourceFinderSingleton();
53 yarp::os::Property yarpWbiConfiguration;
54 std::string yarpWbiConfigurationFile;
55 if(property.check(
"wbi_conf_file") && property.find(
"wbi_conf_file").isString())
57 yarpWbiConfigurationFile = rf.findFileByName(property.find(
"wbi_conf_file").asString());
61 yarpWbiConfigurationFile = rf.findFileByName(
"yarpWholeBodyInterface.ini");
66 yarpWbiConfiguration.fromConfigFile(yarpWbiConfigurationFile);
68 yarpWbiConfiguration.fromString(property.toString().c_str(),
false);
71 std::string localName =
"wbiTest";
72 if( property.check(
"local") )
74 localName =
property.find(
"local").asString();
77 wbi::wholeBodyInterface *yarpRobot =
new yarpWbi::yarpWholeBodyInterface (localName.c_str(), yarpWbiConfiguration);
79 wbi::IDList RobotMainJoints;
80 std::string RobotMainJointsListName =
"ROBOT_TORQUE_CONTROL_JOINTS";
81 if( !yarpWbi::loadIdListFromConfig(RobotMainJointsListName,yarpWbiConfiguration,RobotMainJoints) )
83 fprintf(stderr,
"[ERR] yarpWholeBodyInterface: impossible to load wbiId joint list with name %s\n",RobotMainJointsListName.c_str());
87 yarpRobot->addJoints(RobotMainJoints);
89 std::cout <<
"Joints added, calling init method" << std::endl;
91 if(!yarpRobot->init())
93 std::cout <<
"Error: init() method failed" << std::endl;
102 void TorqueControlGravityConsistency::tearDown()
109 void TorqueControlGravityConsistency::run()
112 int dof = yarpRobot->getDoFs();
113 printf(
"Number of (internal) controlled DoFs: %d\n", dof);
116 Vector q(dof), trqMeasured(dof), trqGravity(dof), generalizedBiasForces(dof+6), dq(dof);
119 yarpRobot->getEstimates(wbi::ESTIMATE_JOINT_POS, q.data());
120 yarpRobot->getEstimates(wbi::ESTIMATE_JOINT_VEL, dq.data());
121 yarpRobot->getEstimates(wbi::ESTIMATE_JOINT_TORQUE, trqMeasured.data());
124 wbi::Frame world2base;
125 world2base.identity();
132 m_gravity[2] = -9.81;
134 yarpRobot->computeGeneralizedBiasForces(q.data(),world2base,dq.data(),baseTwist.data(),m_gravity,generalizedBiasForces.data());
137 trqGravity = generalizedBiasForces.subVector(6,6+dof-1);
139 for(
size_t i=0; i < dof; i++)
142 yarpRobot->getJointList().indexToID(i,wbiID);
143 std::cerr <<
"Joint " << wbiID.toString() <<
" : " << std::endl;
144 std::cerr <<
"\t Measured torque: " << trqMeasured[i] <<
"Nm" << std::endl;
145 std::cerr <<
"\t Gravity torque: " << trqGravity[i] <<
"Nm" << std::endl;
146 std::cerr <<
"\t Difference : " << trqMeasured[i]-trqGravity[i] <<
"Nm" << std::endl;
The test is supposed to be run with the iCub fixed to the pole, with the pole leveled with respect to...