TrajectoryManagerBenchmark.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <hayai/hayai.hpp>
00004 
00005 #include "robodyn_controllers/TrajectoryManager.h"
00006 #include "robodyn_controllers/RosMsgTreeFk.h"
00007 #include "r2_msgs/JointCapability.h"
00008 #include <ros/package.h>
00009 
00010 class TrajectoryManagerBasicFixture : public hayai::Fixture
00011 {
00012 protected:
00013     virtual void SetUp()
00014     {
00015         ros::Time::init();
00016 
00017         std::string packagePath = ros::package::getPath("robodyn_controllers");
00018         treeFk.loadFromFile(packagePath + "/test/urdf/r2c_full_body_dynamics.urdf.xml");
00019 
00020         trajMan.initialize(packagePath + "/test/urdf/r2c_full_body_dynamics.urdf.xml", 0.03);
00021 
00022         baseMsg.data.resize(1);
00023         baseMsg.data[0] = "r2/robot_world";
00024         trajMan.setBases(baseMsg);
00025 
00026         poseSettings.maxLinearAcceleration = 0.05;
00027         poseSettings.maxLinearVelocity = 0.1;
00028         poseSettings.maxRotationalAcceleration = 0.05;
00029         poseSettings.maxRotationalVelocity = 0.1;
00030         trajMan.setPoseSettings(poseSettings);
00031 
00032         jointStatesMsg.name.push_back("/r2/left_leg/joint0");
00033         jointStatesMsg.name.push_back("/r2/left_leg/joint1");
00034         jointStatesMsg.name.push_back("/r2/left_leg/joint2");
00035         jointStatesMsg.name.push_back("/r2/left_leg/joint3");
00036         jointStatesMsg.name.push_back("/r2/left_leg/joint4");
00037         jointStatesMsg.name.push_back("/r2/left_leg/joint5");
00038         jointStatesMsg.name.push_back("/r2/left_leg/joint6");
00039         jointStatesMsg.name.push_back("/r2/right_leg/joint0");
00040         jointStatesMsg.name.push_back("/r2/right_leg/joint1");
00041         jointStatesMsg.name.push_back("/r2/right_leg/joint2");
00042         jointStatesMsg.name.push_back("/r2/right_leg/joint3");
00043         jointStatesMsg.name.push_back("/r2/right_leg/joint4");
00044         jointStatesMsg.name.push_back("/r2/right_leg/joint5");
00045         jointStatesMsg.name.push_back("/r2/right_leg/joint6");
00046         jointStatesMsg.name.push_back("/r2/waist/joint0");
00047         jointStatesMsg.name.push_back("/r2/left_arm/joint0");
00048         jointStatesMsg.name.push_back("/r2/left_arm/joint1");
00049         jointStatesMsg.name.push_back("/r2/left_arm/joint2");
00050         jointStatesMsg.name.push_back("/r2/left_arm/joint3");
00051         jointStatesMsg.name.push_back("/r2/left_arm/joint4");
00052         jointStatesMsg.name.push_back("/r2/left_arm/joint5");
00053         jointStatesMsg.name.push_back("/r2/left_arm/joint6");
00054         jointStatesMsg.name.push_back("/r2/right_arm/joint0");
00055         jointStatesMsg.name.push_back("/r2/right_arm/joint1");
00056         jointStatesMsg.name.push_back("/r2/right_arm/joint2");
00057         jointStatesMsg.name.push_back("/r2/right_arm/joint3");
00058         jointStatesMsg.name.push_back("/r2/right_arm/joint4");
00059         jointStatesMsg.name.push_back("/r2/right_arm/joint5");
00060         jointStatesMsg.name.push_back("/r2/right_arm/joint6");
00061         jointStatesMsg.name.push_back("/r2/neck/joint0");
00062         jointStatesMsg.name.push_back("/r2/neck/joint1");
00063         jointStatesMsg.name.push_back("/r2/neck/joint2");
00064 
00065         jointStatesMsg.position.resize(jointStatesMsg.name.size(), 0.);
00066         jointStatesMsg.velocity.resize(jointStatesMsg.name.size(), 0.);
00067         jointStatesMsg.effort.resize(jointStatesMsg.name.size(), 0.);
00068 
00069         jointSettings.joint_names             = jointStatesMsg.name;
00070         jointSettings.jointVelocityLimits     = std::vector<double>(jointStatesMsg.name.size(), 0.1);
00071         jointSettings.jointAccelerationLimits = std::vector<double>(jointStatesMsg.name.size(), 0.05);
00072         trajMan.setJointSettings(jointSettings);
00073 
00074         jointStatusMsg.joint = jointStatesMsg.name;
00075         jointStatusMsg.data.resize(jointStatusMsg.joint.size());
00076 
00077         jointCommandMsg.name = jointStatesMsg.name;
00078         jointCommandMsg.desiredPosition.resize(jointCommandMsg.name.size(), 0.);
00079         jointCommandMsg.desiredPositionVelocityLimit.resize(jointCommandMsg.name.size(), 0.);
00080         jointCommandMsg.proportionalGain.resize(jointCommandMsg.name.size(), 0.);
00081         jointCommandMsg.derivativeGain.resize(jointCommandMsg.name.size(), 0.);
00082         jointCommandMsg.positionLoopTorqueLimit.resize(jointCommandMsg.name.size(), 0.);
00083 
00084         inertiaInMsg.name = jointStatesMsg.name;
00085         inertiaInMsg.position.resize(inertiaInMsg.name.size());
00086 
00087         // add some random data
00088         for (unsigned int i = 0; i < jointStatesMsg.name.size(); ++i)
00089         {
00090             // position between -90 and 90 deg
00091             jointStatesMsg.position[i] = 3.1416 * (static_cast<double>(rand() % 10001) / 10000.) - 1.5708;
00092             // velocity between -1 and 1 rad/s
00093             jointStatesMsg.velocity[i] = 0.;
00094             // effort between -100 and 100 N/m
00095             jointStatesMsg.effort[i]   = 200.*(static_cast<double>(rand() % 10001) / 10000.) - 100.;
00096 
00097             jointStatusMsg.data[i].coeffState.state = rand() % 2;
00098 
00099             jointCommandMsg.desiredPosition[i] = jointStatesMsg.position[i];
00100 
00101             if (rand() % 5 == 0)
00102             {
00103                 jointCommandMsg.desiredPosition[i] += 0.2 * (static_cast<double>(rand() % 10001) / 10000.) - 0.1;
00104             }
00105 
00106             jointCommandMsg.desiredPositionVelocityLimit[i] = 0.;
00107             jointCommandMsg.proportionalGain[i]             = 1000.;
00108             jointCommandMsg.derivativeGain[i]               = 50.;
00109             jointCommandMsg.positionLoopTorqueLimit[i]      = 20.;
00110 
00111             inertiaInMsg.position[i] = 50.*(static_cast<double>(rand() % 10001) / 10000.) + 1.;
00112         }
00113 
00114         jointCommandStateMsg.name     = jointCommandMsg.name;
00115         jointCommandStateMsg.position = jointCommandMsg.desiredPosition;
00116         jointCommandStateMsg.velocity = jointCommandMsg.desiredPositionVelocityLimit;
00117         jointCommandStateMsg.effort   = jointCommandMsg.feedForwardTorque;
00118         treeFk.getPoseState(jointCommandStateMsg, poseCommandMsg);
00119         treeFk.getPoseState(jointStatesMsg, poseStateMsg);
00120 
00121         jointTraj.joint_names = jointCommandStateMsg.name;
00122         jointTraj.points.resize(1);
00123         jointTraj.points[0].positions = jointCommandStateMsg.position;
00124         jointTraj.points[0].time_from_start = ros::Duration(100.);
00125 
00126         unsigned int nodeIndex = rand() % poseCommandMsg.name.size();
00127         cartTraj.nodes.resize(1);
00128         cartTraj.nodes[0]  = poseCommandMsg.name[nodeIndex];
00129         cartTraj.refFrames = cartTraj.nodes;
00130         cartTraj.points.resize(1);
00131         cartTraj.points[0].positions.resize(1);
00132         cartTraj.points[0].positions[0]    = poseCommandMsg.positions[nodeIndex];
00133         cartTraj.points[0].time_from_start = ros::Duration(100.);
00134 
00135         jointCapabilitiesMsg.name = jointStatesMsg.name;
00136         jointCapabilitiesMsg.positionLimitMax.resize(jointCapabilitiesMsg.name.size(), 1.57);
00137         jointCapabilitiesMsg.positionLimitMin.resize(jointCapabilitiesMsg.name.size(), -1.57);
00138         jointCapabilitiesMsg.torqueLimit.resize(jointCapabilitiesMsg.name.size(), 100.);
00139     }
00140 
00141     virtual void TearDown()
00142     {
00143     }
00144 
00145     class MyTrajMan : public TrajectoryManager
00146     {
00147     public:
00148         MyTrajMan() : TrajectoryManager("TrajManBenchmark") {}
00149     protected:
00150         virtual void writeJointState(const sensor_msgs::JointState& jointState_out) {}
00151         virtual void writeJointControl(const r2_msgs::JointControlDataArray& jointControl_out) {}
00152         virtual void writeStatus(const actionlib_msgs::GoalStatusArray& goalStatusMsg_out) {}
00153     };
00154 
00155     MyTrajMan trajMan;
00156 
00157     sensor_msgs::JointState                      jointStatesMsg, jointCommandStateMsg;
00158     r2_msgs::JointControlDataArray   jointStatusMsg;
00159     RosMsgTreeFk                                 treeFk;
00160     r2_msgs::JointCommand            jointCommandMsg;
00161     r2_msgs::PoseState               poseCommandMsg, poseStateMsg;
00162     r2_msgs::JointCapability         jointCapabilitiesMsg;
00163     trajectory_msgs::JointTrajectory             jointTraj;
00164     r2_msgs::PoseTrajectory          cartTraj;
00165     r2_msgs::StringArray             baseMsg;
00166     sensor_msgs::JointState                      inertiaInMsg;
00167     r2_msgs::ControllerJointSettings jointSettings;
00168     r2_msgs::ControllerPoseSettings  poseSettings;
00169 };
00170 
00171 class TrajectoryManagerJointUpdateFixture : public TrajectoryManagerBasicFixture
00172 {
00173 protected:
00174     virtual void SetUp()
00175     {
00176         TrajectoryManagerBasicFixture::SetUp();
00177         trajMan.addJointWaypoints(jointTraj, jointStatesMsg, jointStatesMsg, jointStatesMsg);
00178     }
00179 
00180     virtual void TearDown()
00181     {
00182     }
00183 };
00184 
00185 class TrajectoryManagerCartUpdateFixture : public TrajectoryManagerBasicFixture
00186 {
00187 protected:
00188     virtual void SetUp()
00189     {
00190         TrajectoryManagerBasicFixture::SetUp();
00191         trajMan.addCartesianWaypoints(cartTraj, jointStatesMsg, jointStatesMsg, jointStatesMsg, poseStateMsg, poseStateMsg);
00192         trajMan.setJointCapabilities(jointCapabilitiesMsg);
00193         trajMan.updateInertia(inertiaInMsg);
00194         trajMan.setIkParameters(5E-12, .000032, 50, .1);
00195     }
00196 
00197     virtual void TearDown()
00198     {
00199     }
00200 };
00201 
00202 BENCHMARK_F(TrajectoryManagerBasicFixture, BasicUpdateTest, 10, 1000)
00203 {
00204     jointCommandStateMsg = jointCommandStateMsg;
00205     jointStatesMsg       = jointStatesMsg;
00206     trajMan.setJointCapabilities(jointCapabilitiesMsg);
00207     trajMan.updateInertia(inertiaInMsg);
00208     trajMan.updateTrajectories(jointCommandMsg, jointStatusMsg, jointStatesMsg, jointStatesMsg);
00209 }
00210 
00211 BENCHMARK_F(TrajectoryManagerJointUpdateFixture, JointUpdateTest, 10, 1000)
00212 {
00213     jointCommandStateMsg = jointCommandStateMsg;
00214     jointStatesMsg       = jointStatesMsg;
00215     trajMan.setJointCapabilities(jointCapabilitiesMsg);
00216     trajMan.updateInertia(inertiaInMsg);
00217     trajMan.updateTrajectories(jointCommandMsg, jointStatusMsg, jointStatesMsg, jointStatesMsg);
00218 }
00219 
00220 BENCHMARK_F(TrajectoryManagerCartUpdateFixture, CartUpdateTest, 10, 1000)
00221 {
00222     jointCommandStateMsg = jointCommandStateMsg;
00223     jointStatesMsg       = jointStatesMsg;
00224     trajMan.setJointCapabilities(jointCapabilitiesMsg);
00225     trajMan.updateInertia(inertiaInMsg);
00226     trajMan.updateTrajectories(jointCommandMsg, jointStatusMsg, jointStatesMsg, jointStatesMsg);
00227 }
00228 
00229 BENCHMARK_F(TrajectoryManagerBasicFixture, AddJointTrajTest, 10, 100)
00230 {
00231     jointCommandStateMsg   = jointCommandStateMsg;
00232     jointStatesMsg         = jointStatesMsg;
00233     jointTraj.header.stamp = ros::Time::now();
00234     trajMan.addJointWaypoints(jointTraj, jointStatesMsg, jointStatesMsg, jointStatesMsg);
00235     trajMan.setJointCapabilities(jointCapabilitiesMsg);
00236     trajMan.updateInertia(inertiaInMsg);
00237     trajMan.updateTrajectories(jointCommandMsg, jointStatusMsg, jointStatesMsg, jointStatesMsg);
00238 }
00239 
00240 BENCHMARK_F(TrajectoryManagerBasicFixture, AddCartTrajTest, 10, 100)
00241 {
00242     jointCommandStateMsg = jointCommandStateMsg;
00243     jointStatesMsg       = jointStatesMsg;
00244     trajMan.setIkParameters(5E-12, .000032, 50, .1);
00245     cartTraj.header.stamp = ros::Time::now();
00246     trajMan.addCartesianWaypoints(cartTraj, jointStatesMsg, jointStatesMsg, jointStatesMsg, poseStateMsg, poseStateMsg);
00247     trajMan.setJointCapabilities(jointCapabilitiesMsg);
00248     trajMan.updateInertia(inertiaInMsg);
00249     trajMan.updateTrajectories(jointCommandMsg, jointStatusMsg, jointStatesMsg, jointStatesMsg);
00250 }
00251 
00252 int main(int argc, char** argv)
00253 {
00254     hayai::Benchmarker::RunAllTests();
00255     return 0;
00256 }
00257 


robodyn_controllers
Author(s):
autogenerated on Sat Jun 8 2019 20:20:53