tutorials/tut00_test.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 
00034 #include "tutsim.hpp"
00035 #include <jspace/test/sai_util.hpp>
00036 #include <boost/shared_ptr.hpp>
00037 #include <err.h>
00038 
00039 
00040 static std::string model_filename(TUTROB_XML_PATH_STR);
00041 static boost::shared_ptr<jspace::Model> model;
00042 
00043 
00044 static bool servo_cb(size_t toggle_count,
00045          double wall_time_ms,
00046          double sim_time_ms,
00047          jspace::State & state,
00048          jspace::Vector & command)
00049 {
00050   model->update(state);
00051   jspace::Matrix mass_inertia;
00052   model->getMassInertia(mass_inertia);
00053   jspace::Vector gravity;
00054   model->getGravity(gravity);
00055   
00056   static size_t counter(0);
00057   if (0 == (counter % 50)) {
00058     std::cerr << "wall: " << wall_time_ms << "  sim: " << sim_time_ms << "\n";
00059     jspace::pretty_print(state.position_, std::cerr, "jpos", "  ");
00060     jspace::pretty_print(mass_inertia, std::cerr, "mass_inertia", "  ");
00061     jspace::pretty_print(gravity, std::cerr, "gravity", "  ");
00062   }
00063   ++counter;
00064   
00065   if (0 == (toggle_count % 2)) {
00066     static double const aa(M_PI / 2);
00067     for (int ii(0); ii < state.position_.rows(); ++ii) {
00068       state.position_[ii] = aa * sin((1.0 + 0.1 * ii) * 1e-3 * wall_time_ms);
00069       state.velocity_[ii] = 0.0;
00070     }
00071     return false;
00072   }
00073   
00074   command = jspace::Vector::Zero(state.position_.rows());
00075   return true;
00076 }
00077 
00078 
00079 int main(int argc, char ** argv)
00080 {
00081   try {
00082     model.reset(jspace::test::parse_sai_xml_file(model_filename, true));
00083   }
00084   catch (std::runtime_error const & ee) {
00085     errx(EXIT_FAILURE, "%s", ee.what());
00086   }
00087   return tutsim::run(servo_cb);
00088 }

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