opspace/src/testFactory.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 The Board of Trustees of The Leland Stanford Junior University. All rights reserved.
00003  *
00004  * Author: Roland Philippsen
00005  *         http://cs.stanford.edu/group/manips/
00006  *
00007  * This program is free software: you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation, either version 3 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this program.  If not, see
00019  * <http://www.gnu.org/licenses/>
00020  */
00021 
00022 #include <gtest/gtest.h>
00023 #include <opspace/Skill.hpp>
00024 #include <opspace/Factory.hpp>
00025 #include <opspace/parse_yaml.hpp>
00026 #include <stdexcept>
00027 
00028 using namespace opspace;
00029 using boost::shared_ptr;
00030 using jspace::State;
00031 using namespace std;
00032 
00033 
00034 TEST (parse, tasks_only)
00035 {
00036   static char * const yaml_string =
00037     "- tasks:\n"
00038     "  - type: opspace::SelectedJointPostureTask\n"
00039     "    name: odd\n"
00040     "    selection: [  1.0,  0.0,  1.0,  0.0,  1.0,  0.0 ]\n"
00041     "    kp: 100.0\n"
00042     "    kd:  20.0\n"
00043     "  - type: opspace::SelectedJointPostureTask\n"
00044     "    name: even\n"
00045     "    selection: [  0.0,  1.0,  0.0,  1.0,  0.0,  1.0 ]\n"
00046     "    kp: 100.0\n"
00047     "    kd:  20.0\n"
00048     "  - type: opspace::CartPosTrjTask\n"
00049     "    name: eepos\n"
00050     "    dt_seconds: 0.002\n"
00051     "    kp: [ 100.0 ]\n"
00052     "    kd: [  20.0 ]\n"
00053     "    maxvel: [ 0.5 ]\n"
00054     "    maxacc: [ 1.5 ]\n"
00055     "  - type: opspace::JPosTrjTask\n"
00056     "    name: posture\n"
00057     "    dt_seconds: 0.002\n"
00058     "    kp: [ 400.0, 400.0, 400.0, 100.0, 100.0, 100.0, 100.0 ]\n"
00059     "    kd: [  40.0,  40.0,  40.0,  20.0,  20.0,  20.0,  20.0 ]\n"
00060     "    maxvel: [ 3.1416 ]\n"
00061     "    maxacc: [ 6.2832 ]\n";
00062   
00063   try {
00064     Factory::setDebugStream(&cout);
00065     Factory factory;
00066     Status st;
00067     st = factory.parseString(yaml_string);
00068     EXPECT_TRUE (st.ok) << st.errstr;
00069     EXPECT_FALSE (factory.getTaskTable().empty()) << "task table should not be empty";
00070     EXPECT_TRUE (factory.getSkillTable().empty()) << "skill table should be empty";
00071     factory.dump(cout, "*** dump of factory", "* ");
00072   }
00073   catch (YAML::Exception const & ee) {
00074     ADD_FAILURE () << "unexpected YAML::Exception: " << ee.what();
00075   }
00076   catch (std::runtime_error const & ee) {
00077     ADD_FAILURE () << "unexpected std::runtime_error: " << ee.what();
00078   }
00079 }
00080 
00081 
00082 TEST (parse, tasks_and_skills)
00083 {
00084   static char * const yaml_string =
00085     "- tasks:\n"
00086     "  - type: opspace::SelectedJointPostureTask\n"
00087     "    name: odd_instance\n"
00088     "    selection: [  1.0,  0.0,  1.0,  0.0,  1.0,  0.0 ]\n"
00089     "    kp: 100.0\n"
00090     "    kd:  20.0\n"
00091     "  - type: opspace::SelectedJointPostureTask\n"
00092     "    name: even_instance\n"
00093     "    selection: [  0.0,  1.0,  0.0,  1.0,  0.0,  1.0 ]\n"
00094     "    kp: 100.0\n"
00095     "    kd:  20.0\n"
00096     "  - type: opspace::CartPosTrjTask\n"
00097     "    name: eepos_trj\n"
00098     "    dt_seconds: 0.002\n"
00099     "    kp: [ 100.0 ]\n"
00100     "    kd: [  20.0 ]\n"
00101     "    maxvel: [ 0.5 ]\n"
00102     "    maxacc: [ 1.5 ]\n"
00103     "  - type: opspace::JPosTrjTask\n"
00104     "    name: posture_trj\n"
00105     "    dt_seconds: 0.002\n"
00106     "    kp: [ 400.0, 400.0, 400.0, 100.0, 100.0, 100.0, 100.0 ]\n"
00107     "    kd: [  40.0,  40.0,  40.0,  20.0,  20.0,  20.0,  20.0 ]\n"
00108     "    maxvel: [ 3.1416 ]\n"
00109     "    maxacc: [ 6.2832 ]\n"
00110     "  - type: opspace::CartPosTask\n"
00111     "    name: eepos_notrj\n"
00112     "    kp: [ 100.0 ]\n"
00113     "    kd: [  20.0 ]\n"
00114     "    maxvel: [ 0.5 ]\n"
00115     "  - type: opspace::JPosTask\n"
00116     "    name: posture_notrj\n"
00117     "    kp: [ 400.0, 400.0, 400.0, 100.0, 100.0, 100.0, 100.0 ]\n"
00118     "    kd: [  40.0,  40.0,  40.0,  20.0,  20.0,  20.0,  20.0 ]\n"
00119     "    maxvel: [ 3.1416 ]\n"
00120     "- skills:\n"
00121     "  - type: opspace::TaskPostureTrjSkill\n"
00122     "    name: tpb\n"
00123     "    slots:\n"
00124     "      eepos: eepos_trj\n"
00125     "      posture: posture_trj\n"
00126     "  - type: opspace::TaskPostureSkill\n"
00127     "    name: tpb\n"
00128     "    slots:\n"
00129     "      eepos: eepos_notrj\n"
00130     "      posture: posture_notrj\n";
00131   
00132   try {
00133     Factory::setDebugStream(&cout);
00134     Factory factory;
00135     Status st;
00136     st = factory.parseString(yaml_string);
00137     EXPECT_TRUE (st.ok) << st.errstr;
00138     EXPECT_FALSE (factory.getTaskTable().empty()) << "task table should not be empty";
00139     EXPECT_FALSE (factory.getSkillTable().empty()) << "skills table should not be empty";
00140     factory.dump(cout, "*** dump of factory", "* ");
00141   }
00142   catch (YAML::Exception const & ee) {
00143     ADD_FAILURE () << "unexpected YAML::Exception: " << ee.what();
00144   }
00145   catch (std::runtime_error const & ee) {
00146     ADD_FAILURE () << "unexpected std::runtime_error: " << ee.what();
00147   }
00148 }
00149 
00150 
00151 int main(int argc, char ** argv)
00152 {
00153   testing::InitGoogleTest(&argc, argv);
00154   return RUN_ALL_TESTS ();
00155 }

Generated on Fri Aug 26 01:31:17 2011 for Stanford Whole-Body Control Framework by  doxygen 1.5.4