icub-test
Loading...
Searching...
No Matches
Public Member Functions
TorqueControlGravityConsistency Class Reference

The test is supposed to be run with the iCub fixed to the pole, with the pole leveled with respect to the gravity (please check this with a level before running the test) and with the wholeBodyDynamics(Tree) running. More...

#include <TorqueControlGravityConsistency.h>

Inherits yarp::robottestingframework::TestCase.

Public Member Functions

virtual bool setup (yarp::os::Property &property)
 
virtual void tearDown ()
 
virtual void run ()
 

Detailed Description

The test is supposed to be run with the iCub fixed to the pole, with the pole leveled with respect to the gravity (please check this with a level before running the test) and with the wholeBodyDynamics(Tree) running.

The tests opens the wholeBodyInterface (to be migrated to use material available on YARP and iDynTree) and compares the gravity compensation torque coming from the model and assuming that the gravity is fixed in the based with the joint torques measured by iCub (that actually come from the wholeBodyDynamics(Tree) ).

Example: testRunner -v -t TorqueControlGravityConsistency.dll -p ""

Definition at line 45 of file TorqueControlGravityConsistency.h.

Constructor & Destructor Documentation

◆ TorqueControlGravityConsistency()

TorqueControlGravityConsistency::TorqueControlGravityConsistency ( )

Definition at line 39 of file TorqueControlGravityConsistency.cpp.

39 : yarp::robottestingframework::TestCase("TorqueControlGravityConsistency"),
40 yarpRobot(0)
41{
42
43}

◆ ~TorqueControlGravityConsistency()

TorqueControlGravityConsistency::~TorqueControlGravityConsistency ( )
virtual

Definition at line 45 of file TorqueControlGravityConsistency.cpp.

46{
47}

Member Function Documentation

◆ run()

void TorqueControlGravityConsistency::run ( )
virtual

Definition at line 109 of file TorqueControlGravityConsistency.cpp.

110{
111 //Get the number of controlled degrees of freedom of the robot
112 int dof = yarpRobot->getDoFs();
113 printf("Number of (internal) controlled DoFs: %d\n", dof);
114
115 //Allocate yarp vector of the right dimensions
116 Vector q(dof), trqMeasured(dof), trqGravity(dof), generalizedBiasForces(dof+6), dq(dof);
117
118 //Read position and torque estimates
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());
122
123 // Compute gravity compensation torques
124 wbi::Frame world2base;
125 world2base.identity();
126 Vector baseTwist(6);
127 baseTwist.zero();
128
129 double m_gravity[3];
130 m_gravity[0] = 0;
131 m_gravity[1] = 0;
132 m_gravity[2] = -9.81;
133
134 yarpRobot->computeGeneralizedBiasForces(q.data(),world2base,dq.data(),baseTwist.data(),m_gravity,generalizedBiasForces.data());
135
136 // We extract the joint torques from the generalized bias forces
137 trqGravity = generalizedBiasForces.subVector(6,6+dof-1);
138
139 for(size_t i=0; i < dof; i++)
140 {
141 wbi::ID wbiID;
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;
147 }
148}

◆ setup()

bool TorqueControlGravityConsistency::setup ( yarp::os::Property &  property)
virtual

Definition at line 49 of file TorqueControlGravityConsistency.cpp.

50{
51 yarp::os::ResourceFinder & rf = yarp::os::ResourceFinder::getResourceFinderSingleton();
52
53 yarp::os::Property yarpWbiConfiguration;
54 std::string yarpWbiConfigurationFile;
55 if(property.check("wbi_conf_file") && property.find("wbi_conf_file").isString())
56 {
57 yarpWbiConfigurationFile = rf.findFileByName(property.find("wbi_conf_file").asString());
58 }
59 else
60 {
61 yarpWbiConfigurationFile = rf.findFileByName("yarpWholeBodyInterface.ini");
62 }
63
64 //It may be convenient to overload some option of the configuration file,
65 // so we load in the yarpWbiConfiguration also the option passed in the command line
66 yarpWbiConfiguration.fromConfigFile(yarpWbiConfigurationFile);
67
68 yarpWbiConfiguration.fromString(property.toString().c_str(),false);
69
70 // Create yarpWholeBodyInterface
71 std::string localName = "wbiTest";
72 if( property.check("local") )
73 {
74 localName = property.find("local").asString();
75 }
76
77 wbi::wholeBodyInterface *yarpRobot = new yarpWbi::yarpWholeBodyInterface (localName.c_str(), yarpWbiConfiguration);
78
79 wbi::IDList RobotMainJoints;
80 std::string RobotMainJointsListName = "ROBOT_TORQUE_CONTROL_JOINTS";
81 if( !yarpWbi::loadIdListFromConfig(RobotMainJointsListName,yarpWbiConfiguration,RobotMainJoints) )
82 {
83 fprintf(stderr, "[ERR] yarpWholeBodyInterface: impossible to load wbiId joint list with name %s\n",RobotMainJointsListName.c_str());
84 return false;
85 }
86
87 yarpRobot->addJoints(RobotMainJoints);
88
89 std::cout << "Joints added, calling init method" << std::endl;
90
91 if(!yarpRobot->init())
92 {
93 std::cout << "Error: init() method failed" << std::endl;
94 return false;
95 }
96
97 Time::delay(0.5);
98
99 return true;
100}

◆ tearDown()

void TorqueControlGravityConsistency::tearDown ( )
virtual

Definition at line 102 of file TorqueControlGravityConsistency.cpp.

103{
104 yarpRobot->close();
105 delete yarpRobot;
106 yarpRobot = 0;
107}

The documentation for this class was generated from the following files: