00001 #include <iostream>
00002
00003 #include <gtest/gtest.h>
00004
00005 #include "robodyn_controllers/RosMsgTreeId.h"
00006 #include "robodyn_controllers/KdlTreeId.h"
00007 #include "robodyn_controllers/JointDynamicsData.h"
00008 #include <ros/package.h>
00009
00010 #include <ros/package.h>
00011
00012 #include <ros/package.h>
00013 #include <kdl/treefksolverpos_recursive.hpp>
00014
00015
00016 class InvDynIntegratedTest : public ::testing::Test
00017 {
00018 protected:
00019 virtual void SetUp()
00020 {
00021 ros::Time::init();
00022 }
00023
00024 virtual void TearDown()
00025 {
00026 }
00027
00028 KdlTreeId id;
00029 RosMsgTreeId rmt;
00030 JointDynamicsData jd;
00031 sensor_msgs::JointState actualState;
00032 sensor_msgs::JointState traj1;
00033 r2_msgs::WrenchState wrenchState;
00034
00035 };
00036
00037 TEST_F(InvDynIntegratedTest, SimpleDynTest)
00038 {
00039 std::string packagePath = ros::package::getPath("robodyn_controllers");
00040 id.loadFromFile(packagePath + "/test/urdf/SimpleDynRobot.xml");
00041 jd.InitializeMaps(id.getTree());
00042
00043 actualState.name.push_back("joint1");
00044 actualState.position.push_back(0.0);
00045
00046 traj1.name.push_back("joint1");
00047 traj1.position.push_back(1.0);
00048 traj1.velocity.push_back(0.0);
00049 traj1.effort.push_back(0.0);
00050
00051 KDL::Twist velIn, accelIn;
00052 KDL::Wrench forceOut;
00053 KDL::RigidBodyInertia inertiaOut;
00054
00055 sensor_msgs::JointState tauFF, Hv;
00056
00057
00058
00059 std::cout << "Actual state only" << std::endl;
00060
00061 rmt.setJointData(actualState, traj1, wrenchState, jd);
00062
00063 id.treeRecursiveNewtonEuler(jd, "link1", "null", velIn, accelIn, forceOut, inertiaOut);
00064 std::cout << "forceOut: " << forceOut.force.data[0] << " " << forceOut.force.data[1] << " " << forceOut.force.data[2] << " " << forceOut.torque.data[0] << " " << forceOut.torque.data[1] << " " << forceOut.torque.data[2] << std::endl;
00065 std::cout << "inertiaOut: " << inertiaOut.getMass() << std::endl;
00066
00067 rmt.getJointCommand(jd, tauFF);
00068
00069 rmt.getJointInertias(jd, Hv);
00070
00071 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00072 {
00073 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00074 }
00075
00076 for (unsigned int i = 0; i < Hv.name.size(); i++)
00077 {
00078 std::cout << "Hv name: " << Hv.name[i] << " tau: " << Hv.position[i] << std::endl;
00079 }
00080
00081
00082 std::cout << "No trajectory with gravity" << std::endl;
00083
00084 accelIn = KDL::Twist(KDL::Vector(0, 9.8, 0), KDL::Vector::Zero());
00085
00086 rmt.setJointData(actualState, traj1, wrenchState, jd);
00087
00088 id.treeRecursiveNewtonEuler(jd, "link1", "null", velIn, accelIn, forceOut, inertiaOut);
00089 std::cout << "forceOut: " << forceOut.force.data[0] << " " << forceOut.force.data[1] << " " << forceOut.force.data[2] << " " << forceOut.torque.data[0] << " " << forceOut.torque.data[1] << " " << forceOut.torque.data[2] << std::endl;
00090 std::cout << "inertiaOut: " << inertiaOut.getMass() << std::endl;
00091
00092 rmt.getJointCommand(jd, tauFF);
00093
00094 rmt.getJointInertias(jd, Hv);
00095
00096 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00097 {
00098 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00099 }
00100
00101 for (unsigned int i = 0; i < Hv.name.size(); i++)
00102 {
00103 std::cout << "Hv name: " << Hv.name[i] << " tau: " << Hv.position[i] << std::endl;
00104 }
00105
00106
00107 std::cout << "One trajectory with gravity" << std::endl;
00108
00109 traj1.velocity.clear();
00110 traj1.effort.clear();
00111 traj1.velocity.push_back(1.0);
00112 traj1.effort.push_back(1.0);
00113
00114 rmt.setJointData(actualState, traj1, wrenchState, jd);
00115
00116 id.treeRecursiveNewtonEuler(jd, "link1", "null", velIn, accelIn, forceOut, inertiaOut);
00117 std::cout << "forceOut: " << forceOut.force.data[0] << " " << forceOut.force.data[1] << " " << forceOut.force.data[2] << std::endl;
00118 std::cout << "inertiaOut: " << inertiaOut.getMass() << std::endl;
00119 rmt.getJointCommand(jd, tauFF);
00120
00121 rmt.getJointInertias(jd, Hv);
00122
00123 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00124 {
00125 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00126 }
00127
00128 for (unsigned int i = 0; i < Hv.name.size(); i++)
00129 {
00130 std::cout << "Hv name: " << Hv.name[i] << " tau: " << Hv.position[i] << std::endl;
00131 }
00132
00133 }
00134
00135 TEST_F(InvDynIntegratedTest, BranchingTest)
00136 {
00137 std::string packagePath = ros::package::getPath("robodyn_controllers");
00138 id.loadFromFile(packagePath + "/test/urdf/BranchingTestRobot.xml");
00139 jd.InitializeMaps(id.getTree());
00140
00141 actualState.name.push_back("joint0");
00142 actualState.name.push_back("joint1");
00143 actualState.name.push_back("joint2");
00144 actualState.name.push_back("joint3");
00145
00146 actualState.position.push_back(0.0);
00147 actualState.position.push_back(0.0);
00148 actualState.position.push_back(5.0);
00149 actualState.position.push_back(5.0);
00150
00151 traj1.name.push_back("joint0");
00152 traj1.position.push_back(0.0);
00153 traj1.velocity.push_back(0.0);
00154 traj1.effort.push_back(0.0);
00155
00156 traj1.name.push_back("joint1");
00157 traj1.position.push_back(1.0);
00158 traj1.velocity.push_back(1.0);
00159 traj1.effort.push_back(1.0);
00160
00161 traj1.name.push_back("joint2");
00162 traj1.name.push_back("joint3");
00163
00164 traj1.position.push_back(2.0);
00165 traj1.position.push_back(2.0);
00166
00167 traj1.velocity.push_back(2.0);
00168 traj1.velocity.push_back(2.0);
00169
00170 traj1.effort.push_back(2.0);
00171 traj1.effort.push_back(2.0);
00172
00173 KDL::Twist velIn, accelIn;
00174 KDL::Wrench forceOut;
00175 KDL::RigidBodyInertia inertiaOut;
00176
00177 sensor_msgs::JointState tauFF, Hv;
00178
00179
00180
00181 std::cout << "Trajectory no gravity" << std::endl;
00182
00183 rmt.setJointData(actualState, traj1, wrenchState, jd);
00184
00185 id.treeRecursiveNewtonEuler(jd, "linkb", "null", velIn, accelIn, forceOut, inertiaOut);
00186 std::cout << "forceOut: " << forceOut.force.data[0] << " " << forceOut.force.data[1] << " " << forceOut.force.data[2] << std::endl;
00187 std::cout << "inertiaOut: " << inertiaOut.getMass() << std::endl;
00188
00189 rmt.getJointCommand(jd, tauFF);
00190
00191 rmt.getJointInertias(jd, Hv);
00192
00193 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00194 {
00195 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00196 }
00197
00198 for (unsigned int i = 0; i < Hv.name.size(); i++)
00199 {
00200 std::cout << "Hv name: " << Hv.name[i] << " tau: " << Hv.position[i] << std::endl;
00201 }
00202
00203
00204 std::cout << "Trajectory with gravity" << std::endl;
00205
00206 accelIn = KDL::Twist(KDL::Vector(0, 9.8, 0), KDL::Vector::Zero());
00207
00208 rmt.setJointData(actualState, traj1, wrenchState, jd);
00209
00210 id.treeRecursiveNewtonEuler(jd, "linkb", "null", velIn, accelIn, forceOut, inertiaOut);
00211 std::cout << "forceOut: " << forceOut.force.data[0] << " " << forceOut.force.data[1] << " " << forceOut.force.data[2] << std::endl;
00212 std::cout << "inertiaOut: " << inertiaOut.getMass() << std::endl;
00213
00214 rmt.getJointCommand(jd, tauFF);
00215
00216 rmt.getJointInertias(jd, Hv);
00217
00218 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00219 {
00220 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00221 }
00222
00223 for (unsigned int i = 0; i < Hv.name.size(); i++)
00224 {
00225 std::cout << "Hv name: " << Hv.name[i] << " tau: " << Hv.position[i] << std::endl;
00226 }
00227
00228 }
00229
00230 TEST_F(InvDynIntegratedTest, R2LegsTest)
00231 {
00232 std::string packagePath = ros::package::getPath("robodyn_controllers");
00233 id.loadFromFile(packagePath + "/test/urdf/r2c_legs_control.urdf.xml");
00234 jd.InitializeMaps(id.getTree());
00235
00236 actualState.name.push_back("/r2/left_leg/joint0");
00237 actualState.name.push_back("/r2/left_leg/joint1");
00238 actualState.name.push_back("/r2/left_leg/joint2");
00239 actualState.name.push_back("/r2/left_leg/joint3");
00240 actualState.name.push_back("/r2/left_leg/joint4");
00241 actualState.name.push_back("/r2/left_leg/joint5");
00242 actualState.name.push_back("/r2/left_leg/joint6");
00243 actualState.name.push_back("/r2/right_leg/joint0");
00244 actualState.name.push_back("/r2/right_leg/joint1");
00245 actualState.name.push_back("/r2/right_leg/joint2");
00246 actualState.name.push_back("/r2/right_leg/joint3");
00247 actualState.name.push_back("/r2/right_leg/joint4");
00248 actualState.name.push_back("/r2/right_leg/joint5");
00249 actualState.name.push_back("/r2/right_leg/joint6");
00250
00251 actualState.position.resize(actualState.name.size(), 0.);
00252 actualState.position[3] = 90 * 3.14159 / 180;
00253 actualState.position[8] = -90 * 3.14159 / 180;
00254
00255 actualState.velocity.resize(actualState.name.size(), 0.);
00256 actualState.effort.resize(actualState.name.size(), 0.);
00257
00258 KDL::Twist velIn, accelIn;
00259 KDL::Wrench forceOut;
00260 KDL::RigidBodyInertia inertiaOut;
00261
00262 sensor_msgs::JointState tauFF;
00263
00264 accelIn = KDL::Twist(KDL::Vector(0, 0, 9.81), KDL::Vector::Zero());
00265
00266 rmt.setJointData(actualState, actualState, wrenchState, jd);
00267
00268 id.treeRecursiveNewtonEuler(jd, "r2/robot_world", "null", velIn, accelIn, forceOut, inertiaOut);
00269 std::cout << "forceOut: " << forceOut.force.data[0] << " " << forceOut.force.data[1] << " " << forceOut.force.data[2] << std::endl;
00270 std::cout << "inertiaOut: " << inertiaOut.getMass() << std::endl;
00271
00272 rmt.getJointCommand(jd, tauFF);
00273
00274 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00275 {
00276 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00277 }
00278
00279
00280
00281
00282 }
00283
00284 TEST_F(InvDynIntegratedTest, R2LegsArgos)
00285 {
00286 std::string packagePath = ros::package::getPath("robodyn_controllers");
00287 id.loadFromFile(packagePath + "/test/urdf/r2c_legs_control_wUpperMass.urdf.xml");
00288 jd.InitializeMaps(id.getTree());
00289
00290 actualState.name.push_back("/r2/left_leg/joint0");
00291 actualState.name.push_back("/r2/left_leg/joint1");
00292 actualState.name.push_back("/r2/left_leg/joint2");
00293 actualState.name.push_back("/r2/left_leg/joint3");
00294 actualState.name.push_back("/r2/left_leg/joint4");
00295 actualState.name.push_back("/r2/left_leg/joint5");
00296 actualState.name.push_back("/r2/left_leg/joint6");
00297 actualState.name.push_back("/r2/right_leg/joint0");
00298 actualState.name.push_back("/r2/right_leg/joint1");
00299 actualState.name.push_back("/r2/right_leg/joint2");
00300 actualState.name.push_back("/r2/right_leg/joint3");
00301 actualState.name.push_back("/r2/right_leg/joint4");
00302 actualState.name.push_back("/r2/right_leg/joint5");
00303 actualState.name.push_back("/r2/right_leg/joint6");
00304
00305 actualState.position.resize(actualState.name.size(), 0.);
00306 actualState.position[1] = -90 * 3.14159 / 180;
00307 actualState.position[8] = -90 * 3.14159 / 180;
00308
00309 actualState.velocity.resize(actualState.name.size(), 0.);
00310 actualState.effort.resize(actualState.name.size(), 0.);
00311
00312 KDL::Twist velIn, accelIn, zeroTwist;
00313 KDL::Wrench forceOut;
00314 KDL::RigidBodyInertia inertiaOut;
00315
00316 sensor_msgs::JointState tauFF;
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 r2_msgs::WrenchState emptyForceMsg;
00327 sensor_msgs::JointState emptyTrajMsg;
00328 rmt.setJointData(actualState, actualState, wrenchState, jd);
00329
00330 std::string baseFrame("r2/right_leg/gripper/tip");
00331
00332 id.getAccelInBaseFrame(KDL::Vector(0, 0, 9.81), "r2/robot_world", jd, baseFrame, accelIn);
00333 std::cout << "gravity in base frame: " << accelIn.vel.x() << ", " << accelIn.vel.y() << ", " << accelIn.vel.z() << std::endl;
00334 id.treeRecursiveNewtonEuler(jd, baseFrame, "null", zeroTwist, zeroTwist, forceOut, inertiaOut);
00335
00336 rmt.getJointCommand(jd, tauFF);
00337
00338 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00339 {
00340 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00341 }
00342
00343
00344
00345
00346 }
00347
00348 TEST_F(InvDynIntegratedTest, R2FullBody)
00349 {
00350 std::string packagePath = ros::package::getPath("robodyn_controllers");
00351 id.loadFromFile(packagePath + "/test/urdf/r2c_full_body_dynamics.urdf.xml");
00352 jd.InitializeMaps(id.getTree());
00353
00354 actualState.name.push_back("/r2/left_leg/joint0");
00355 actualState.name.push_back("/r2/left_leg/joint1");
00356 actualState.name.push_back("/r2/left_leg/joint2");
00357 actualState.name.push_back("/r2/left_leg/joint3");
00358 actualState.name.push_back("/r2/left_leg/joint4");
00359 actualState.name.push_back("/r2/left_leg/joint5");
00360 actualState.name.push_back("/r2/left_leg/joint6");
00361 actualState.name.push_back("/r2/right_leg/joint0");
00362 actualState.name.push_back("/r2/right_leg/joint1");
00363 actualState.name.push_back("/r2/right_leg/joint2");
00364 actualState.name.push_back("/r2/right_leg/joint3");
00365 actualState.name.push_back("/r2/right_leg/joint4");
00366 actualState.name.push_back("/r2/right_leg/joint5");
00367 actualState.name.push_back("/r2/right_leg/joint6");
00368 actualState.name.push_back("/r2/waist/joint0");
00369 actualState.name.push_back("/r2/left_arm/joint0");
00370 actualState.name.push_back("/r2/left_arm/joint1");
00371 actualState.name.push_back("/r2/left_arm/joint2");
00372 actualState.name.push_back("/r2/left_arm/joint3");
00373 actualState.name.push_back("/r2/left_arm/joint4");
00374 actualState.name.push_back("/r2/left_arm/joint5");
00375 actualState.name.push_back("/r2/left_arm/joint6");
00376 actualState.name.push_back("/r2/right_arm/joint0");
00377 actualState.name.push_back("/r2/right_arm/joint1");
00378 actualState.name.push_back("/r2/right_arm/joint2");
00379 actualState.name.push_back("/r2/right_arm/joint3");
00380 actualState.name.push_back("/r2/right_arm/joint4");
00381 actualState.name.push_back("/r2/right_arm/joint5");
00382 actualState.name.push_back("/r2/right_arm/joint6");
00383
00384 actualState.position.resize(actualState.name.size(), 0.);
00385 actualState.position[1] = -90 * 3.14159 / 180;
00386 actualState.position[8] = -90 * 3.14159 / 180;
00387
00388 actualState.velocity.resize(actualState.name.size(), 0.);
00389 actualState.effort.resize(actualState.name.size(), 0.);
00390
00391 KDL::Twist velIn, accelIn, zeroTwist;
00392 KDL::Wrench forceOut;
00393 KDL::RigidBodyInertia inertiaOut;
00394
00395 sensor_msgs::JointState tauFF;
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 r2_msgs::WrenchState emptyForceMsg;
00406 sensor_msgs::JointState emptyTrajMsg;
00407 rmt.setJointData(actualState, actualState, wrenchState, jd);
00408
00409 std::string baseFrame("r2/right_leg/gripper/tip");
00410
00411 id.getAccelInBaseFrame(KDL::Vector(0, 0, 9.81), "r2/robot_world", jd, baseFrame, accelIn);
00412 std::cout << "gravity in base frame: " << accelIn.vel.x() << ", " << accelIn.vel.y() << ", " << accelIn.vel.z() << std::endl;
00413
00414 id.treeRecursiveNewtonEuler(jd, baseFrame, "null", velIn, accelIn, forceOut, inertiaOut);
00415
00416 rmt.getJointCommand(jd, tauFF);
00417
00418 for (unsigned int i = 0; i < tauFF.name.size(); i++)
00419 {
00420 std::cout << "Tau name: " << tauFF.name[i] << " tau: " << tauFF.effort[i] << std::endl;
00421 }
00422
00423
00424
00425
00426 }
00427
00428 int main(int argc, char** argv)
00429 {
00430 ::testing::InitGoogleTest(&argc, argv);
00431 return RUN_ALL_TESTS();
00432 }