opspace/src/TypeIOTGCursor.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 <opspace/TypeIOTGCursor.hpp>
00023 
00024 namespace opspace {
00025   
00026   
00027   TypeIOTGCursor::
00028   TypeIOTGCursor(size_t ndof, double dt_seconds)
00029     : ndof_(ndof),
00030       dt_seconds_(dt_seconds),
00031       otg_(ndof, dt_seconds)
00032   {
00033     pos_clean_ = Vector::Zero(ndof);
00034     vel_clean_ = Vector::Zero(ndof);
00035     pos_dirty_ = Vector::Zero(ndof);
00036     vel_dirty_ = Vector::Zero(ndof);
00037     selection_.resize(ndof);
00038     for (size_t ii(0); ii < ndof; ++ii) {
00039       selection_[ii] = true;
00040     }
00041   }
00042   
00043   
00044   int TypeIOTGCursor::
00045   next(Vector const & maxvel,
00046        Vector const & maxacc,
00047        Vector const & goal)
00048   {
00049     int const result(otg_.GetNextMotionState_Position(pos_clean_.data(),
00050                   vel_clean_.data(),
00051                   maxvel.data(),
00052                   maxacc.data(),
00053                   goal.data(),
00054                   selection_.data(),
00055                   pos_dirty_.data(),
00056                   vel_dirty_.data()));
00057     if (0 <= result) {
00058       pos_clean_ = pos_dirty_;
00059       vel_clean_ = vel_dirty_;
00060     }
00061     return result;
00062   }
00063   
00064   
00065   int TypeIOTGCursor::
00066   next(double maxvel,
00067        double maxacc,
00068        double goal)
00069   {
00070     if (ndof_ != 1) {
00071       return -1000;
00072     }
00073     int const result(otg_.GetNextMotionState_Position(pos_clean_.data(),
00074                   vel_clean_.data(),
00075                   &maxvel,
00076                   &maxacc,
00077                   &goal,
00078                   selection_.data(),
00079                   pos_dirty_.data(),
00080                   vel_dirty_.data()));
00081     if (0 <= result) {
00082       pos_clean_ = pos_dirty_;
00083       vel_clean_ = vel_dirty_;
00084     }
00085     return result;
00086   }
00087   
00088   
00089   char const * otg_errstr(int otg_error_code)
00090   {
00091     switch (otg_error_code) {
00092     case TypeIOTG::OTG_ERROR:
00093       return "OTG_ERROR (general error)";
00094     case TypeIOTG::OTG_MAX_VELOCITY_ERROR:
00095       return "OTG_MAX_VELOCITY_ERROR (maxvel too small)";
00096     case TypeIOTG::OTG_MAX_ACCELERATION_ERROR:
00097       return "OTG_MAX_ACCELERATION_ERROR (maxacc too small)";
00098     case TypeIOTG::OTG_WORKING:
00099       return "OTG_WORKING (everything is fine)";
00100     case TypeIOTG::OTG_FINAL_STATE_REACHED:
00101       return "OTG_FINAL_STATE_REACHED (all is fine and we're at the goal)";
00102     }
00103     return "invalid or unrecognized otg_error_code";
00104   }
00105   
00106 }

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