opspace/include/opspace/task_library.hpp

Go to the documentation of this file.
00001 /*
00002  * Shared copyright notice and LGPLv3 license statement.
00003  *
00004  * Copyright (C) 2011 The Board of Trustees of The Leland Stanford Junior University. All rights reserved.
00005  * Copyright (C) 2011 University of Texas at Austin. All rights reserved.
00006  *
00007  * Authors: Roland Philippsen (Stanford) and Luis Sentis (UT Austin)
00008  *          http://cs.stanford.edu/group/manips/
00009  *          http://www.me.utexas.edu/~hcrl/
00010  *
00011  * This program is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public License
00013  * as published by the Free Software Foundation, either version 3 of
00014  * the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this program.  If not, see
00023  * <http://www.gnu.org/licenses/>
00024  */
00025 
00026 #ifndef OPSPACE_TASK_LIBRARY_HPP
00027 #define OPSPACE_TASK_LIBRARY_HPP
00028 
00029 #include <opspace/Task.hpp>
00030 
00031 namespace opspace {
00032   
00033   class TypeIOTGCursor;
00034   
00035 
00051   class PDTask
00052     : public Task
00053   {
00054   public:
00063     virtual Status check(Vector const * param, Vector const & value) const;
00064     
00065     inline void quickSetup(Vector const & kp, Vector const & kd, Vector const & maxvel)
00066     {
00067       kp_ = kd;
00068       kd_ = kd;
00069       maxvel_ = maxvel;
00070     }
00071     
00072   protected:
00088     typedef enum {
00089       SATURATION_OFF,
00090       SATURATION_COMPONENT_WISE,
00091       SATURATION_MAX_COMPONENT,
00092       SATURATION_NORM
00093     } saturation_policy_t;
00094     
00095     PDTask(std::string const & name, saturation_policy_t saturation_policy);
00096     
00109     Status initPDTask(Vector const & initpos);
00110     
00118     Status computePDCommand(Vector const & curpos,
00119           Vector const & curvel,
00120           Vector & command);
00121     
00122     saturation_policy_t const saturation_policy_;
00123     bool initialized_;
00124     Vector goalpos_;
00125     Vector goalvel_;
00126     Vector errpos_;
00127     Vector errvel_;
00128     Vector kp_;
00129     Vector kd_;
00130     Vector maxvel_;
00131   };
00132   
00133   
00134   class DraftPIDTask
00135     : public PDTask
00136   {
00137   public:
00138     explicit DraftPIDTask(std::string const & name);
00139     
00140     virtual Status check(double const * param, double value) const;
00141     virtual Status check(Vector const * param, Vector const & value) const;
00142     
00143     virtual Status init(Model const & model);
00144     virtual Status update(Model const & model);
00145     
00146     virtual void dbg(std::ostream & os,
00147          std::string const & title,
00148          std::string const & prefix) const;
00149     
00150   protected:
00151     Status initDraftPIDTask(Vector const & initpos);
00152     
00153     Status computeDraftPIDCommand(Vector const & curpos,
00154           Vector const & curvel,
00155           Vector & command);
00156     
00157     double dt_seconds_;
00158     Vector ki_;
00159     Vector errsum_;
00160     Vector limitpos_;
00161     Vector limitvel_;
00162     Vector triggerpos_;
00163   };
00164   
00165   
00178   class CartPosTask
00179     : public PDTask
00180   {
00181   public:
00182     explicit CartPosTask(std::string const & name);
00183     
00184     virtual Status init(Model const & model);
00185     virtual Status update(Model const & model);
00186     virtual Status check(std::string const * param, std::string const & value) const;
00187     
00188     inline void quickSetup(Vector const & kp, Vector const & kd, Vector const & maxvel,
00189          std::string const & name, Vector const & control_point)
00190     {
00191       PDTask::quickSetup(kp, kd, maxvel);
00192       end_effector_name_ = name;
00193       control_point_ = control_point;
00194     }
00195     
00196   protected:
00197     std::string end_effector_name_;
00198     Vector control_point_;
00199     
00200     mutable taoDNode const * end_effector_node_;
00201     
00202     taoDNode const * updateActual(Model const & model);
00203   };
00204   
00205   
00214   class JPosTask
00215     : public PDTask
00216   {
00217   public:
00218     explicit JPosTask(std::string const & name);
00219     
00220     virtual Status init(Model const & model);
00221     virtual Status update(Model const & model);
00222   };
00223   
00224   
00234   class SelectedJointPostureTask
00235     : public Task
00236   {
00237   public:
00238     explicit SelectedJointPostureTask(std::string const & name);
00239     
00240     virtual Status init(Model const & model);
00241     virtual Status update(Model const & model);
00242     virtual Status check(double const * param, double value) const;
00243     virtual Status check(Vector const * param, Vector const & value) const;
00244     
00245   protected:
00246     Vector selection_;
00247     double kp_;
00248     double kd_;
00249     bool initialized_;
00250     std::vector<size_t> active_joints_;
00251   };
00252   
00253   
00274   class TrajectoryTask
00275     : public PDTask
00276   {
00277   public:
00278     virtual ~TrajectoryTask();
00279     
00283     virtual Status check(double const * param, double value) const;
00284     
00289     virtual Status check(Vector const * param, Vector const & value) const;
00290     
00291     virtual void dbg(std::ostream & os,
00292          std::string const & title,
00293          std::string const & prefix) const;
00294     
00295   protected:
00296     typedef PDTask::saturation_policy_t saturation_policy_t;
00297     
00298     TrajectoryTask(std::string const & name, saturation_policy_t saturation_policy);
00299     
00307     Status initTrajectoryTask(Vector const & initpos);
00308     
00314     Status computeTrajectoryCommand(Vector const & curpos,
00315             Vector const & curvel,
00316             Vector & command);
00317     
00318     TypeIOTGCursor * cursor_;
00319     double dt_seconds_;
00320     Vector trjgoal_;
00321     Vector maxacc_;
00322     mutable Vector qh_maxvel_;  // grr, cursor always needs multi-dim maxvel, even if saturation_norm
00323   };
00324   
00325   
00337   class CartPosTrjTask
00338     : public TrajectoryTask
00339   {
00340   public:
00341     explicit CartPosTrjTask(std::string const & name);
00342     
00343     virtual Status init(Model const & model);
00344     virtual Status update(Model const & model);
00345     
00346   protected:
00347     int end_effector_id_;
00348     Vector control_point_;
00349     
00350     taoDNode const * updateActual(Model const & model);
00351   };
00352   
00353   
00361   class JPosTrjTask
00362     : public TrajectoryTask
00363   {
00364   public:
00365     explicit JPosTrjTask(std::string const & name);
00366     
00367     virtual Status init(Model const & model);
00368     virtual Status update(Model const & model);
00369     
00373     void quickSetup(double dt_seconds, double kp, double kd, double maxvel, double maxacc);
00374   };
00375 
00376 
00377   class JointLimitTask
00378     : public Task
00379   {
00380   public:
00381     explicit JointLimitTask(std::string const & name);
00382     virtual ~JointLimitTask();
00383     
00384     virtual Status check(Vector const * param, Vector const & value) const;
00385     virtual Status check(double const * param, double const & value) const;
00386     virtual Status init(Model const & model);
00387     virtual Status update(Model const & model);
00388     
00389     virtual void dbg(std::ostream & os,
00390          std::string const & title,
00391          std::string const & prefix) const;
00392     
00393   protected:
00394     // parameters
00395     Vector upper_stop_deg_;
00396     Vector upper_trigger_deg_;
00397     Vector lower_stop_deg_;
00398     Vector lower_trigger_deg_;
00399     double dt_seconds_;
00400     Vector maxvel_;
00401     Vector maxacc_;
00402     Vector kp_;
00403     Vector kd_;
00404     
00405     // non-parameters
00406     Vector upper_stop_;
00407     Vector upper_trigger_;
00408     Vector lower_stop_;
00409     Vector lower_trigger_;
00410     
00411     std::vector<TypeIOTGCursor *> cursor_;
00412     Vector goal_;
00413 
00414     void updateState(Model const & model);
00415   };
00416   
00417   
00418   class OrientationTask
00419     : public Task
00420   {
00421   public:
00422     explicit OrientationTask(std::string const & name);
00423     
00424     virtual Status init(Model const & model);
00425     virtual Status update(Model const & model);
00426     
00427     virtual void dbg(std::ostream & os,
00428          std::string const & title,
00429          std::string const & prefix) const;
00430     
00431   protected:
00432     taoDNode const * updateActual(Model const & model);
00433     
00434     //    Vector goal_;   // direction cosines
00435     Eigen::Vector3d goal_x_;
00436     Eigen::Vector3d goal_y_;
00437     Eigen::Vector3d goal_z_;
00438     Eigen::Vector3d actual_x_;
00439     Eigen::Vector3d actual_y_;
00440     Eigen::Vector3d actual_z_;
00441     Vector velocity_;   // instantaneous omega
00442     Vector delta_;    // instantaneous angular difference
00443     int end_effector_id_;
00444     double kp_;
00445     double kd_;
00446     double maxvel_;
00447     Vector eepos_;    // just for logging...
00448   };
00449 
00450   
00451 }
00452 
00453 #endif // OPSPACE_TASK_LIBRARY_HPP

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