operators.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005 + *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  ***************************************************************************/
00024 #ifndef __OPERATORS_H
00025 #define __OPERATORS_H
00026 
00027 #include "operator.h"
00028 #include "axis.h"
00029 
00030 namespace lpzrobots {
00031   /**
00032      An Operator for limiting the orientation of the main primitive of a robot.
00033    */
00034   class LimitOrientationOperator : public Operator {
00035   public:
00036     LimitOrientationOperator(const Axis& robotAxis, const Axis& globalAxis, 
00037                              double maxAngle, double force)
00038       : Operator("LimitOrientationOperator","1.0"), 
00039         robotAxis(robotAxis), globalAxis(globalAxis), 
00040         maxAngle(maxAngle), force(force), currentforce(force) {
00041     }
00042 
00043     virtual ManipType observe(OdeAgent* agent, GlobalData& global, ManipDescr& descr);
00044   protected:
00045     Axis robotAxis;
00046     Axis globalAxis;
00047     double maxAngle;
00048 
00049     double force;
00050     double currentforce;
00051   };
00052 
00053 
00054   struct LiftUpOperatorConf {
00055     bool   resetForceIfLifted;  ///< force is reseted as soon as robot has reached height
00056     bool   increaseForce;       ///< increase force (until robot has reached height)
00057     bool   propControl;         ///< if true then applied force is scaled with distance
00058 
00059     bool   intervalMode;        ///< if true then the operator works only in intervals 
00060     double duration;            ///< duration of operation in interval-mode
00061     double interval;            ///< interval between restart of operation ( > duration)
00062                                
00063     double height;              ///< height to which it is lifted
00064     double force;               ///< initial force
00065     double visualHeight;        ///< height above the robot main object for the visual sphere
00066   };
00067 
00068   /**
00069      An Operator for lifting up a robot from time to time.
00070    */
00071   class LiftUpOperator : public Operator {
00072   public:
00073     LiftUpOperator(const LiftUpOperatorConf conf = getDefaultConf())
00074       : Operator("LiftUpOperator","0.8"), conf(conf)
00075     {
00076       currentforce = conf.force;
00077       addParameter("force",    &this->conf.force,   0, 100, "lift up force");
00078       addParameter("height",   &this->conf.height,  0, 100, "lift up height");
00079       if(conf.intervalMode){
00080         addParameter("interval", &this->conf.interval,  0, 1000, "interval of operation");
00081         addParameter("duration", &this->conf.duration,  0, 1000, "duration of lifting within interval");
00082       }
00083     }
00084 
00085     static LiftUpOperatorConf getDefaultConf(){
00086       LiftUpOperatorConf c;
00087       c.resetForceIfLifted = true;
00088       c.increaseForce      = true; 
00089       c.intervalMode       = false; 
00090       c.propControl        = true; 
00091       c.duration           = 1; 
00092       c.interval           = 10;      
00093       c.height             = 1; 
00094       c.force              = 1; 
00095       c.visualHeight       = 0.5; 
00096       return c;
00097     }
00098 
00099     virtual ManipType observe(OdeAgent* agent, GlobalData& global, ManipDescr& descr);
00100   protected:
00101     LiftUpOperatorConf conf;
00102 
00103     double currentforce;
00104   };
00105 
00106 
00107   /**
00108      An Operator for pulling the main primitive of a robot towards a point
00109    */
00110   class PullToPointOperator : public Operator {
00111   public:
00112     /// defines which dimensions should be effected
00113     enum Dimensions { X = 1, Y = 2, Z = 4, XY = X | Y, XZ = X | Z, YZ = Y | Z, 
00114                       XYZ = X | Y | Z };
00115 
00116     /**
00117        @param dim dimensions along the force acts 
00118         (also only these coordinates of point are considered)
00119        @minDist threshold for distance below which no force acts
00120        @damp damping factor for movement of the robot
00121        @confPos whether to make the point configurable
00122      */
00123     PullToPointOperator(const Pos& point, double force,
00124                         bool showPoint, Dimensions dim = XYZ, 
00125                         double minDist = 0, double damp = 0, bool confPos = false)
00126       : Operator("PullToPointOperator","1.0"), 
00127         point(point), force(force), showPoint(showPoint), dim(dim),
00128         minDist(minDist), damp(damp)
00129     {
00130       addParameter("force",    &this->force,   0, 100, "pull to point force");
00131       addParameter("damp",     &this->damp,   0, 1,   "pull to point damping");
00132       if(confPos){
00133         if(dim & X) 
00134           addParameterDef("point_x", &px, point.x(), -100, 100,"pull to point x position");
00135         if(dim & Y) 
00136           addParameterDef("point_y", &py, point.y(), -100, 100,"pull to point y position");
00137         if(dim & Z) 
00138           addParameterDef("point_z", &pz, point.z(), -100, 100,"pull to point z position");
00139       }
00140     }
00141 
00142     virtual ManipType observe(OdeAgent* agent, GlobalData& global, ManipDescr& descr);
00143     
00144     virtual void notifyOnChange(const paramkey& key);
00145 
00146   protected:
00147     Pos point;    
00148     double force;
00149     bool showPoint;
00150     Dimensions dim;
00151     double minDist;
00152     double damp;
00153     double px,py,pz; // used to configure position (are floats and not doubles)
00154   };
00155 
00156   /**
00157      An Operator for keeping robots within a sphere / box
00158    */
00159   class BoxRingOperator : public Operator {
00160   public:
00161 
00162     /** a box ring (cube with edges 2*size or sphere with radius size)
00163         @param offset distance to wall before acting (to compensate for body width)
00164         @sphere spherical or box shape area
00165      */
00166 
00167     BoxRingOperator(const Pos& center, double size, double offset, 
00168                     double force, bool sphere = false)
00169       : Operator("BoxRingOperator","1.0"), 
00170         center(center), size(size), offset(offset), force(force), sphere(sphere)
00171     {
00172       addParameter("force",    &this->force,   0, 1000, 
00173                    "force of the boxring to keep robots inside");
00174       addParameter("boxringsize", &this->size,   .5, 100, 
00175                    "size of boxring/spherical arena (in radius or half-length)");
00176     }
00177 
00178     virtual ManipType observe(OdeAgent* agent, GlobalData& global, ManipDescr& descr);
00179 
00180   protected:
00181 
00182     Pos center;    
00183     double size;
00184     double offset;
00185     double force;
00186     bool sphere;
00187   };
00188 
00189 
00190 
00191 }
00192 
00193 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3