bhmotor.h

Go to the documentation of this file.
00001 // ***************************************************************************
00002 //                           bhmotor.h
00003 //
00004 //    copyright            : (C) 2004 by tbaier
00005 //    email                : tbaier@informatik.uni-hamburg.de
00006 // ***************************************************************************
00007 #ifndef BHMOTOR_H
00008 #define BHMOTOR_H
00009 
00010 #include "bhcontroller.h"
00011 
00014 // order of this strings is important (used by checkError)
00017 static const char* BHMotorException_info[] = {
00018         "Value out of range",
00019         "Speed out of range",
00020         "Position out of range.",
00021         "Init forces out of range.",
00022         "Force out of Range.",
00023         "Force to high.",
00024         "Force to low.",
00025         "UNDEF"};
00026 
00027 
00033 class BHMotorException
00034 {
00035  public:
00036 
00039   enum error
00040     {
00041       EXCP_VALUE_OUT_OF_RANGE,       
00042       EXCP_SPEED_OUT_OF_RANGE,       
00043       EXCP_POSITION_OUT_OF_RANGE,    
00044       EXCP_UNDEF
00045     };
00046 
00047 
00050   BHMotorException(const error e);
00051   BHMotorException(){};
00052 
00053 
00054 
00057   const void show();
00058 
00061   friend std::ostream& operator<<(std::ostream& os,const BHMotorException& e);
00062 
00065   bool operator==(error e);
00066 
00068   error Err;
00069 
00070  protected:
00071   std::string Msg;
00072 
00073 
00074 
00075 };
00076 
00077 
00078 // ****************************
00079 // **                        **
00080 // ****************************
00081 inline BHMotorException::BHMotorException(const error e)
00082 {
00083   Msg = BHMotorException_info[e];
00084   Err = e;
00085 }
00086 
00087 
00088 // ****************************
00089 // **                        **
00090 // ****************************
00091 inline const void BHMotorException::show ()
00092 {
00093   std::cout << Msg << std::endl;
00094 }
00095 
00096 
00097 // ****************************
00098 // **                        **
00099 // ****************************
00100 inline std::ostream& operator<<(std::ostream& os,const BHMotorException& e)
00101 {
00102   os << e.Msg << std::endl;
00103   return os;
00104 }
00105 
00106 
00107 // ****************************
00108 // **                        **
00109 // ****************************
00110 inline bool BHMotorException:: operator==(error e)
00111 {
00112   return (Err == e);
00113 }
00114 
00115 
00116 
00117 
00118 
00119 // ***********************************************
00120 // **                                           **
00121 // **  BHMotor                                  **
00122 // **                                           **
00123 // ***********************************************
00124 
00131 class BHMotor
00132 {
00133  public:
00134 
00137   BHMotor();
00138 
00144   BHMotor(int speed);
00145 
00148   virtual ~BHMotor();
00149 
00154   // @{
00155 
00160   void setSpeed(const int speed) throw (BHMotorException);
00161 
00166   int getSpeed() const;
00167 
00175   void setGain(const short gain);
00176 
00181   int getGain() const;
00182 
00184 
00185 
00190   // @{
00191 
00196   void setPos(const unsigned int pos) throw (BHMotorException);
00197 
00202   int getPos() const;
00203 
00204 
00206 
00207 
00208 
00211   BHPIDController *Ctr;
00212 
00213 
00214  protected:
00215 
00220   int Speed;
00221 
00226   short Gain;
00227 
00232   unsigned int DPos;
00233 
00236   int MinSpeed;
00237 
00240   int MaxSpeed;
00241 
00244   unsigned short MinPos;
00245 
00248   unsigned short MaxPos;
00249 
00250   int DeltaPos;
00251 
00252 };
00253 
00254 
00255 // ****************************
00256 // **                        **
00257 // ****************************
00258 inline BHMotor::BHMotor() :
00259   Speed(0),
00260      Gain(0),
00261      MinSpeed(0),
00262      MaxSpeed(0)
00263 {
00264   Ctr = new BHPIDController(0.0, 0.0, 0.0);
00265 }
00266 
00267 
00268 // ****************************
00269 // **                        **
00270 // ****************************
00271 inline BHMotor::~BHMotor()
00272 {
00273   delete Ctr;
00274 }
00275 
00276 // ****************************
00277 // **                        **
00278 // ****************************
00279 inline void BHMotor::setSpeed(const int speed) throw (BHMotorException)
00280 {
00281   if(speed < MinSpeed || speed > MaxSpeed){
00282     std::cout << " **BHMotor::setSpeed( " << speed << " ) : < " << MinSpeed << " ||  > " << MaxSpeed << std::endl;   
00283     throw BHMotorException(BHMotorException::EXCP_SPEED_OUT_OF_RANGE);
00284   }
00285   else{
00286     Speed = speed;
00287   }
00288 }
00289 
00290 // ****************************
00291 // **                        **
00292 // ****************************
00293 inline void BHMotor::setPos(const unsigned int pos) throw (BHMotorException)
00294 {
00295   if(pos < MinPos || pos > MaxPos){
00296     throw BHMotorException(BHMotorException::EXCP_POSITION_OUT_OF_RANGE);
00297   }
00298   else{
00299     DPos = pos;
00300   }
00301 }
00302 
00303 
00304 // ****************************
00305 // **                        **
00306 // ****************************
00307 inline void BHMotor::setGain(const short gain)
00308 {
00309   Gain = gain;
00310 }
00311 
00312 // ****************************
00313 // **                        **
00314 // ****************************
00315 inline int BHMotor::getSpeed() const
00316 {
00317   return Speed;
00318 }
00319 
00320 // ****************************
00321 // **                        **
00322 // ****************************
00323 inline int BHMotor::getPos() const
00324 {
00325   return DPos;
00326 }
00327 
00328 
00329 // ****************************
00330 // **                        **
00331 // ****************************
00332 inline int BHMotor::getGain() const
00333 {
00334   return Gain;
00335 }
00336 
00337 #endif //BHANDMOTOR_H


tams Tim Baier bhandlib v0.25
Generated Wed Aug 16 14:57:09 2006 by doxygen 1.4.7