opspace/src/skill_library.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/skill_library.hpp>
00023 #include <opspace/task_library.hpp>
00024 
00025 using boost::shared_ptr;
00026 
00027 
00028 namespace opspace {
00029   
00030   
00031   GenericSkill::
00032   GenericSkill(std::string const & name)
00033     : Skill(name)
00034   {
00035     slot_ = declareSlot<Task>("task");
00036   }
00037   
00038   
00039   Status GenericSkill::
00040   init(Model const & model)
00041   {
00042     Status const st(Skill::init(model));
00043     if ( ! st) {
00044       return st;
00045     }
00046     if (task_table_.empty()) {
00047       for (size_t ii(0); ii < slot_->getNInstances(); ++ii) {
00048   task_table_.push_back(slot_->getInstance(ii).get());
00049       }
00050     }
00051     return st;
00052   }
00053   
00054   
00055   Status GenericSkill::
00056   update(Model const & model)
00057   {
00058     Status st;
00059     if ( task_table_.empty()) {
00060       st.ok = false;
00061       st.errstr = "empty task table, did you assign any? did you forget to init()?";
00062     }
00063     else {
00064       for (size_t ii(0); ii < task_table_.size(); ++ii) {
00065   st = task_table_[ii]->update(model);
00066   if ( ! st) {
00067     return st;
00068   }
00069       }
00070     }
00071     return st;
00072   }
00073   
00074   
00075   Skill::task_table_t const * GenericSkill::
00076   getTaskTable()
00077   {
00078     return &task_table_;
00079   }
00080   
00081   
00082   void GenericSkill::
00083   appendTask(boost::shared_ptr<Task> task)
00084   {
00085     slot_->assign(task);
00086   }
00087   
00088   
00089   TaskPostureSkill::
00090   TaskPostureSkill(std::string const & name)
00091     : Skill(name)
00092   {
00093     declareSlot("eepos", &eepos_);
00094     declareSlot("posture", &posture_);
00095   }
00096   
00097   
00098   Status TaskPostureSkill::
00099   init(Model const & model)
00100   {
00101     Status st(Skill::init(model));
00102     if ( ! st) {
00103       return st;
00104     }
00105     task_table_.push_back(eepos_);
00106     task_table_.push_back(posture_);
00107     return st;
00108   }
00109   
00110   
00111   Status TaskPostureSkill::
00112   update(Model const & model)
00113   {
00114     for (size_t ii(0); ii < task_table_.size(); ++ii) {
00115       Status const st(task_table_[ii]->update(model));
00116       if ( ! st) {
00117   return st;
00118       }
00119     }
00120     Status ok;
00121     return ok;
00122   }
00123   
00124   
00125   Skill::task_table_t const * TaskPostureSkill::
00126   getTaskTable()
00127   {
00128     return &task_table_;
00129   }
00130   
00131   
00132   Status TaskPostureSkill::
00133   checkJStarSV(Task const * task, Vector const & sv)
00134   {
00135     if (task == eepos_) {
00136       if (sv.rows() != 3) {
00137   return Status(false, "eepos dimension mismatch");
00138       }
00139       if (sv[2] < eepos_->getSigmaThreshold()) {
00140   return Status(false, "singular eepos");
00141       }
00142     }
00143     Status ok;
00144     return ok;
00145   }
00146 
00147 
00148   TaskPostureTrjSkill::
00149   TaskPostureTrjSkill(std::string const & name)
00150     : Skill(name)
00151   {
00152     declareSlot("eepos", &eepos_);
00153     declareSlot("posture", &posture_);
00154   }
00155   
00156   
00157   Status TaskPostureTrjSkill::
00158   init(Model const & model)
00159   {
00160     Status st(Skill::init(model));
00161     if ( ! st) {
00162       return st;
00163     }
00164     task_table_.push_back(eepos_);
00165     task_table_.push_back(posture_);
00166     return st;
00167   }
00168   
00169   
00170   Status TaskPostureTrjSkill::
00171   update(Model const & model)
00172   {
00173     for (size_t ii(0); ii < task_table_.size(); ++ii) {
00174       Status const st(task_table_[ii]->update(model));
00175       if ( ! st) {
00176   return st;
00177       }
00178     }
00179     Status ok;
00180     return ok;
00181   }
00182   
00183   
00184   Skill::task_table_t const * TaskPostureTrjSkill::
00185   getTaskTable()
00186   {
00187     return &task_table_;
00188   }
00189   
00190   
00191   Status TaskPostureTrjSkill::
00192   checkJStarSV(Task const * task, Vector const & sv)
00193   {
00194     if (task == eepos_) {
00195       if (sv.rows() != 3) {
00196   return Status(false, "eepos dimension mismatch");
00197       }
00198       if (sv[2] < eepos_->getSigmaThreshold()) {
00199   return Status(false, "singular eepos");
00200       }
00201     }
00202     Status ok;
00203     return ok;
00204   }
00205   
00206 }

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