Go to the documentation of this file.00001 #include <iostream>
00002
00003 #include <hayai/hayai.hpp>
00004
00005 #include "robodyn_controllers/TrajectoryMonitor.h"
00006 #include "robodyn_controllers/RosMsgTreeFk.h"
00007 #include <ros/package.h>
00008
00009 class TrajectoryMonitorBasicFixture : public hayai::Fixture
00010 {
00011 protected:
00012 virtual void SetUp()
00013 {
00014 ros::Time::init();
00015
00016 std::string packagePath = ros::package::getPath("robodyn_controllers");
00017 treeFk.loadFromFile(packagePath + "/test/urdf/r2c_full_body_dynamics.urdf.xml");
00018
00019 baseMsg.data.resize(1);
00020 baseMsg.data[0] = "r2/robot_world";
00021 trajMon.setBases(baseMsg);
00022
00023 jointStatesMsg.name.push_back("/r2/left_leg/joint0");
00024 jointStatesMsg.name.push_back("/r2/left_leg/joint1");
00025 jointStatesMsg.name.push_back("/r2/left_leg/joint2");
00026 jointStatesMsg.name.push_back("/r2/left_leg/joint3");
00027 jointStatesMsg.name.push_back("/r2/left_leg/joint4");
00028 jointStatesMsg.name.push_back("/r2/left_leg/joint5");
00029 jointStatesMsg.name.push_back("/r2/left_leg/joint6");
00030 jointStatesMsg.name.push_back("/r2/right_leg/joint0");
00031 jointStatesMsg.name.push_back("/r2/right_leg/joint1");
00032 jointStatesMsg.name.push_back("/r2/right_leg/joint2");
00033 jointStatesMsg.name.push_back("/r2/right_leg/joint3");
00034 jointStatesMsg.name.push_back("/r2/right_leg/joint4");
00035 jointStatesMsg.name.push_back("/r2/right_leg/joint5");
00036 jointStatesMsg.name.push_back("/r2/right_leg/joint6");
00037 jointStatesMsg.name.push_back("/r2/waist/joint0");
00038 jointStatesMsg.name.push_back("/r2/left_arm/joint0");
00039 jointStatesMsg.name.push_back("/r2/left_arm/joint1");
00040 jointStatesMsg.name.push_back("/r2/left_arm/joint2");
00041 jointStatesMsg.name.push_back("/r2/left_arm/joint3");
00042 jointStatesMsg.name.push_back("/r2/left_arm/joint4");
00043 jointStatesMsg.name.push_back("/r2/left_arm/joint5");
00044 jointStatesMsg.name.push_back("/r2/left_arm/joint6");
00045 jointStatesMsg.name.push_back("/r2/right_arm/joint0");
00046 jointStatesMsg.name.push_back("/r2/right_arm/joint1");
00047 jointStatesMsg.name.push_back("/r2/right_arm/joint2");
00048 jointStatesMsg.name.push_back("/r2/right_arm/joint3");
00049 jointStatesMsg.name.push_back("/r2/right_arm/joint4");
00050 jointStatesMsg.name.push_back("/r2/right_arm/joint5");
00051 jointStatesMsg.name.push_back("/r2/right_arm/joint6");
00052 jointStatesMsg.name.push_back("/r2/neck/joint0");
00053 jointStatesMsg.name.push_back("/r2/neck/joint1");
00054 jointStatesMsg.name.push_back("/r2/neck/joint2");
00055
00056 jointStatesMsg.position.resize(jointStatesMsg.name.size(), 0.);
00057 jointStatesMsg.velocity.resize(jointStatesMsg.name.size(), 0.);
00058 jointStatesMsg.effort.resize(jointStatesMsg.name.size(), 0.);
00059
00060 jointStatusMsg.joint = jointStatesMsg.name;
00061 jointStatusMsg.data.resize(jointStatusMsg.joint.size());
00062
00063 jointCommandMsg.name = jointStatesMsg.name;
00064 jointCommandMsg.desiredPosition.resize(jointCommandMsg.name.size(), 0.);
00065 jointCommandMsg.desiredPositionVelocityLimit.resize(jointCommandMsg.name.size(), 0.);
00066 jointCommandMsg.proportionalGain.resize(jointCommandMsg.name.size(), 0.);
00067 jointCommandMsg.derivativeGain.resize(jointCommandMsg.name.size(), 0.);
00068 jointCommandMsg.positionLoopTorqueLimit.resize(jointCommandMsg.name.size(), 0.);
00069
00070
00071 for (unsigned int i = 0; i < jointStatesMsg.name.size(); ++i)
00072 {
00073
00074 jointStatesMsg.position[i] = 3.1416 * (static_cast<double>(rand() % 10001) / 10000.) - 1.5708;
00075
00076 jointStatesMsg.velocity[i] = 2.*(static_cast<double>(rand() % 10001) / 10000.) - 1.;
00077
00078 jointStatesMsg.effort[i] = 200.*(static_cast<double>(rand() % 10001) / 10000.) - 100.;
00079
00080 jointStatusMsg.data[i].coeffState.state = rand() % 2;
00081
00082 jointCommandMsg.desiredPosition[i] = jointStatesMsg.position[i];
00083
00084 if (rand() % 5 == 0)
00085 {
00086 jointCommandMsg.desiredPosition[i] += 0.2 * (static_cast<double>(rand() % 10001) / 10000.) - 0.1;
00087 }
00088
00089 jointCommandMsg.desiredPositionVelocityLimit[i] = 0.2 * (static_cast<double>(rand() % 10001) / 10000.) - 0.1;
00090 jointCommandMsg.proportionalGain[i] = 1000.;
00091 jointCommandMsg.derivativeGain[i] = 50.;
00092 jointCommandMsg.positionLoopTorqueLimit[i] = 20.;
00093 }
00094
00095 jointCommandStateMsg.name = jointCommandMsg.name;
00096 jointCommandStateMsg.position = jointCommandMsg.desiredPosition;
00097 jointCommandStateMsg.velocity = jointCommandMsg.desiredPositionVelocityLimit;
00098 jointCommandStateMsg.effort = jointCommandMsg.feedForwardTorque;
00099 treeFk.getPoseState(jointCommandStateMsg, poseCommandMsg);
00100
00101 jointTraj.joint_names = jointCommandStateMsg.name;
00102 jointTraj.points.resize(1);
00103 jointTraj.points[0].positions = jointCommandStateMsg.position;
00104
00105 unsigned int nodeIndex = rand() % poseCommandMsg.name.size();
00106 cartTraj.nodes.resize(1);
00107 cartTraj.nodes[0] = poseCommandMsg.name[nodeIndex];
00108 cartTraj.refFrames = cartTraj.nodes;
00109 cartTraj.points.resize(1);
00110 cartTraj.points[0].positions.resize(1);
00111 cartTraj.points[0].positions[0] = poseCommandMsg.positions[nodeIndex];
00112 }
00113
00114 virtual void TearDown()
00115 {
00116 }
00117
00118 class MyTrajMon : public TrajectoryMonitor
00119 {
00120 public:
00121 MyTrajMon() : TrajectoryMonitor("TrajMonBenchmark") {}
00122 protected:
00123 virtual void writeCartesianWaypoints(const r2_msgs::PoseTrajectoryReplan& trajectory) {}
00124 virtual void writeJointWaypoints(const r2_msgs::JointTrajectoryReplan& trajectory) {}
00125 virtual void writeBases(const r2_msgs::StringArray& basesMsg) {}
00126 virtual void writeStatus(const actionlib_msgs::GoalStatusArray& goalStatusMsg_out) {}
00127 };
00128
00129 MyTrajMon trajMon;
00130 sensor_msgs::JointState jointStatesMsg, jointCommandStateMsg;
00131 r2_msgs::JointControlDataArray jointStatusMsg;
00132 r2_msgs::JointCommand jointCommandMsg;
00133 RosMsgTreeFk treeFk;
00134 r2_msgs::PoseState poseCommandMsg;
00135 r2_msgs::JointCapability jointCapabilitiesMsg;
00136 trajectory_msgs::JointTrajectory jointTraj;
00137 r2_msgs::PoseTrajectory cartTraj;
00138 r2_msgs::StringArray baseMsg;
00139 };
00140
00141 class TrajectoryMonitorUpdateFixture : public TrajectoryMonitorBasicFixture
00142 {
00143 protected:
00144 virtual void SetUp()
00145 {
00146 TrajectoryMonitorBasicFixture::SetUp();
00147 trajMon.addJointWaypoints(jointTraj);
00148 trajMon.addCartesianWaypoints(cartTraj, poseCommandMsg);
00149 }
00150
00151 virtual void TearDown()
00152 {
00153 }
00154 };
00155
00156 BENCHMARK_F(TrajectoryMonitorBasicFixture, AddTrajTest, 10, 1000)
00157 {
00158 trajMon.addJointWaypoints(jointTraj);
00159 trajMon.addCartesianWaypoints(cartTraj, poseCommandMsg);
00160 }
00161
00162 BENCHMARK_F(TrajectoryMonitorUpdateFixture, UpdateTest, 10, 1000)
00163 {
00164 trajMon.updateMonitor(jointCommandMsg, poseCommandMsg);
00165 trajMon.evaluateReplanTrigger(jointStatesMsg, jointCommandMsg, jointStatusMsg, jointCapabilitiesMsg);
00166 trajMon.replan();
00167 }
00168
00169 int main(int argc, char** argv)
00170 {
00171 hayai::Benchmarker::RunAllTests();
00172 return 0;
00173 }
00174