00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #include <planning_environment/models/robot_models.h>
00038 #include <planning_models/kinematic_state.h>
00039 #include <ros/time.h>
00040 #include <gtest/gtest.h>
00041 #include <iostream>
00042 #include <sstream>
00043
00044 TEST(Loading, Simple)
00045 {
00046 planning_environment::RobotModels m("robot_description");
00047
00048 EXPECT_TRUE(m.getKinematicModel().get() != NULL);
00049
00050
00051 boost::shared_ptr<planning_models::KinematicModel> kmodel = m.getKinematicModel();
00052
00053 const planning_models::KinematicModel::JointModel* j = kmodel->getRoot();
00054
00055
00056 const planning_models::KinematicModel::FloatingJointModel* pj = dynamic_cast<const planning_models::KinematicModel::FloatingJointModel*>(j);
00057 EXPECT_TRUE(pj != NULL);
00058 }
00059
00060 TEST(SetGetOperations, Simple)
00061 {
00062 planning_environment::RobotModels m("robot_description");
00063 boost::shared_ptr<planning_models::KinematicModel> kmodel = m.getKinematicModel();
00064
00065 planning_models::KinematicState state(kmodel);
00066
00067 state.setKinematicStateToDefault();
00068
00069
00070 std::map<std::string, double> vals;
00071 state.getKinematicStateValues(vals);
00072 for(std::map<std::string, double>::iterator it = vals.begin();
00073 it != vals.end();
00074 it++) {
00075 it->second = .1;
00076 }
00077 state.setKinematicState(vals);
00078
00079 std::map<std::string, double> test_vals;
00080 state.getKinematicStateValues(test_vals);
00081 for(std::map<std::string, double>::iterator it = vals.begin();
00082 it != vals.end();
00083 it++) {
00084 EXPECT_TRUE(test_vals.find(it->first) != test_vals.end()) << "no value set for joint " << it->first;
00085 EXPECT_LE(fabs(it->second-test_vals[it->first]),.00001) << "Value for " << it->first << " is " << test_vals[it->first] << " instead of " << it->second;
00086 }
00087
00088
00089 for(std::map<std::string, double>::iterator it = vals.begin();
00090 it != vals.end();
00091 it++) {
00092 it->second = -.1;
00093 }
00094 state.setKinematicState(vals);
00095
00096 state.getKinematicStateValues(test_vals);
00097 for(std::map<std::string, double>::iterator it = vals.begin();
00098 it != vals.end();
00099 it++) {
00100 EXPECT_TRUE(test_vals.find(it->first) != test_vals.end()) << "no value set for joint " << it->first;
00101 EXPECT_LE(fabs(it->second-test_vals[it->first]),.00001) << "Value for " << it->first << " is " << test_vals[it->first] << " instead of " << it->second;
00102 }
00103
00104
00105 const planning_models::KinematicModel::JointModel* j = kmodel->getRoot();
00106 btTransform bt;
00107 bt.setOrigin(btVector3(5.0, 5.0, 5.0));
00108 bt.setRotation(btQuaternion(0,0,.7071,.7071));
00109 state.getJointState(j->getName())->setJointStateValues(bt);
00110
00111 test_vals.clear();
00112
00113 state.getKinematicStateValues(test_vals);
00114
00115
00116
00117
00118
00119
00120 EXPECT_EQ(test_vals["floating_trans_x"],5.0);
00121 EXPECT_EQ(test_vals["floating_trans_y"], 5.0);
00122 EXPECT_LE(fabs(test_vals["floating_rot_z"]-.7071), .001);
00123 }
00124
00125 TEST(SetGetBounds,Simple)
00126 {
00127
00128 }
00129
00130 TEST(ForwardKinematics, RuntimeArm)
00131 {
00132 planning_environment::RobotModels m("robot_description");
00133 boost::shared_ptr<planning_models::KinematicModel> kmodel = m.getKinematicModel();
00134
00135 planning_models::KinematicState state(kmodel);
00136
00137 state.setKinematicStateToDefault();
00138
00139 planning_models::KinematicState::JointStateGroup *group = state.getJointStateGroup("right_arm");
00140
00141 std::map<std::string, double> vals;
00142 group->getKinematicStateValues(vals);
00143 for(std::map<std::string, double>::iterator it = vals.begin();
00144 it != vals.end();
00145 it++) {
00146 it->second = .1;
00147 }
00148 std::map<std::string, double> vals2;
00149 group->getKinematicStateValues(vals2);
00150 for(std::map<std::string, double>::iterator it = vals2.begin();
00151 it != vals2.end();
00152 it++) {
00153 it->second = .1;
00154 }
00155 ros::WallTime tm = ros::WallTime::now();
00156 const unsigned int NT = 1000000;
00157 for (unsigned int i = 0 ; i < NT ; ++i) {
00158 if(i%2 == 0) {
00159 group->setKinematicState(vals);
00160 } else {
00161 group->setKinematicState(vals2);
00162 }
00163 }
00164 double fps = (double)NT / (ros::WallTime::now() - tm).toSec();
00165 ROS_INFO("Map %f forward kinematics steps per second", fps);
00166
00167 EXPECT_GT(fps,5000.0);
00168
00169 std::vector<double> jv(group->getDimension(), 0.1);
00170 std::vector<double> jv2(group->getDimension(), 0.2);
00171 tm = ros::WallTime::now();
00172 for (unsigned int i = 0 ; i < NT ; ++i) {
00173 if(i%2 == 0) {
00174 group->setKinematicState(jv);
00175 } else {
00176 group->setKinematicState(jv2);
00177 }
00178 }
00179 fps = (double)NT / (ros::WallTime::now() - tm).toSec();
00180 ROS_INFO("Vector %f forward kinematics steps per second", fps);
00181 EXPECT_GT(fps,5000.0);
00182 }
00183
00184 int main(int argc, char **argv)
00185 {
00186 testing::InitGoogleTest(&argc, argv);
00187 ros::init(argc, argv, "test_robot_models");
00188
00189 return RUN_ALL_TESTS();
00190 }