tutorials/tut01_joint_coupling.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 
00036 #include "tutsim.hpp"
00037 
00038 
00039 static bool servo_cb(size_t toggle_count,
00040          double wall_time_ms,
00041          double sim_time_ms,
00042          jspace::State & state,
00043          jspace::Vector & command)
00044 {
00045   if (0 == (toggle_count % 2)) {
00046     command = -400.0 * state.position_ - 20.0 * state.velocity_;
00047   }
00048   else {
00049     command = jspace::Vector::Zero(state.position_.rows());
00050     int const idx(command.rows() - 1);
00051     double dq_des(15.0);
00052     if (fmod(sim_time_ms, 4e3) > 2e3) {
00053       dq_des = -dq_des;
00054     }
00055     command[idx] = dq_des - 2.0 * state.velocity_[idx];
00056   }
00057   
00058   static size_t iteration(0);
00059   if (0 == (iteration++ % 100)) {
00060     std::cerr << "sim_time_ms: " << sim_time_ms << "\n";
00061     jspace::pretty_print(state.position_, std::cerr, "jpos", "  ");
00062     jspace::pretty_print(state.velocity_, std::cerr, "jvel", "  ");
00063     jspace::pretty_print(command, std::cerr, "command", "  ");
00064   }
00065   
00066   return true;
00067 }
00068 
00069 
00070 int main(int argc, char ** argv)
00071 {
00072   return tutsim::run(servo_cb);
00073 }

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