test_transforms.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00037 #include <moveit/robot_model/robot_model.h>
00038 #include <moveit/robot_state/robot_state.h>
00039 #include <moveit/robot_state/transforms.h>
00040 #include <urdf_parser/urdf_parser.h>
00041 #include <fstream>
00042 #include <gtest/gtest.h>
00043 
00044 class LoadPlanningModelsPr2 : public testing::Test
00045 {
00046 protected:
00047 
00048   virtual void SetUp()
00049   {
00050     srdf_model_.reset(new srdf::Model());
00051 
00052     std::string xml_string;
00053     std::fstream xml_file("test/urdf/robot.xml", std::fstream::in);
00054     if (xml_file.is_open())
00055     {
00056       while ( xml_file.good() )
00057       {
00058         std::string line;
00059         std::getline( xml_file, line);
00060         xml_string += (line + "\n");
00061       }
00062       xml_file.close();
00063       urdf_model_ = urdf::parseURDF(xml_string);
00064       urdf_ok_ = urdf_model_;
00065     }
00066     else
00067       urdf_ok_ = false;
00068     srdf_ok_ = srdf_model_->initFile(*urdf_model_, "test/srdf/robot.xml");
00069   };
00070 
00071   virtual void TearDown()
00072   {
00073   }
00074 
00075 protected:
00076 
00077   boost::shared_ptr<urdf::ModelInterface> urdf_model_;
00078   boost::shared_ptr<srdf::Model> srdf_model_;
00079   bool                           urdf_ok_;
00080   bool                           srdf_ok_;
00081 
00082 };
00083 
00084 TEST_F(LoadPlanningModelsPr2, InitOK)
00085 {
00086   ASSERT_TRUE(urdf_ok_);
00087   ASSERT_EQ(urdf_model_->getName(), "pr2_test");
00088 
00089   robot_model::RobotModelPtr kmodel(new robot_model::RobotModel(urdf_model_, srdf_model_));
00090   robot_state::RobotState ks(kmodel);
00091   ks.setToRandomValues();
00092   ks.setToDefaultValues();
00093 
00094 
00095   robot_state::Transforms tf(kmodel->getModelFrame());
00096 
00097   Eigen::Affine3d t1;
00098   t1.setIdentity();
00099   t1.translation() = Eigen::Vector3d(10.0, 1.0, 0.0);
00100   tf.setTransform(t1, "some_frame_1");
00101 
00102   Eigen::Affine3d t2(Eigen::Translation3d(10.0, 1.0, 0.0)*Eigen::AngleAxisd(0.5, Eigen::Vector3d::UnitY()));
00103   tf.setTransform(t2, "some_frame_2");
00104 
00105   Eigen::Affine3d t3;
00106   t3.setIdentity();
00107   t3.translation() = Eigen::Vector3d(0.0, 1.0, -1.0);
00108   tf.setTransform(t3, "some_frame_3");
00109 
00110 
00111   EXPECT_TRUE(tf.isFixedFrame("some_frame_1"));
00112   EXPECT_FALSE(tf.isFixedFrame("base_footprint"));
00113   EXPECT_TRUE(tf.isFixedFrame(kmodel->getModelFrame()));
00114 
00115   Eigen::Affine3d x;
00116   x.setIdentity();
00117   tf.transformPose(ks, "some_frame_2", x, x);
00118 
00119   EXPECT_TRUE(t2.translation() == x.translation());
00120   EXPECT_TRUE(t2.rotation() == x.rotation());
00121 
00122   tf.transformPose(ks, kmodel->getModelFrame(), x, x);
00123   EXPECT_TRUE(t2.translation() == x.translation());
00124   EXPECT_TRUE(t2.rotation() == x.rotation());
00125 
00126   x.setIdentity();
00127   tf.transformPose(ks, "r_wrist_roll_link", x, x);
00128 
00129   EXPECT_NEAR(x.translation().x(), 0.585315, 1e-4);
00130   EXPECT_NEAR(x.translation().y(), -0.188, 1e-4);
00131   EXPECT_NEAR(x.translation().z(), 1.24001, 1e-4);
00132 }
00133 
00134 
00135 int main(int argc, char **argv)
00136 {
00137   testing::InitGoogleTest(&argc, argv);
00138   return RUN_ALL_TESTS();
00139 }


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Mon Oct 6 2014 02:24:47