bhfinger.h

Go to the documentation of this file.
00001 // ***************************************************************************
00002 //                           bhfinger.h
00003 //
00004 //    copyright            : (C) 2004 by tbaier
00005 //    email                : tbaier@informatik.uni-hamburg.de
00006 // ***************************************************************************
00007 #ifndef BHFINGER_H
00008 #define BHFINGER_H
00009 
00010 #include <iostream>
00011 #include <string>
00012 #include "bhcontroller.h"
00013 #include "bhmotorext.h"
00014 #include "zlog.h"
00015 
00018 #define MAX_FINGER_POS 17000
00019 
00022 #define MIN_FINGER_POS 0
00023 
00026 #define DEFAULT_FINGER_SPEED 60
00027 
00030 #define MAX_FINGER_SPEED 124
00031 
00035 //#define MIN_FINGER_SPEED 10
00036 
00040 #define MIN_FINGER_SPEED 9
00041 //#define MIN_FINGER_SPEED 10
00042 
00045 #define MAX_FINGER_FORCE 255
00046 
00049 #define MIN_FINGER_FORCE 0
00050 
00053 #define INIT_FORCE_MIN 100
00054 
00057 #define INIT_FORCE_MAX 140
00058 
00061 #define DEFAULT_GAIN 0
00062 
00065 #define MAX_FORCE_LOG 8
00066 
00067 
00068 
00072 // order of this strings is important (used by checkError)
00075 static const char* BHFingerException_info[] = {
00076         "Value out of range",
00077         "Speed out of range",
00078         "Position out of range.",
00079         "Init forces out of range.",
00080         "Force out of Range.",
00081         "Force to high.",
00082         "Force to low.",
00083         "UNDEF"};
00084 
00085 
00090 class BHFingerException : public BHMotorException
00091 {
00092  public:
00093 
00096   enum FingerError
00097     {
00098       EXCP_VALUE_OUT_OF_RANGE,       
00099       EXCP_SPEED_OUT_OF_RANGE,       
00100       EXCP_POSITION_OUT_OF_RANGE,    
00101       EXCP_INTIT_FORCE_OUT_OF_RANGE, 
00102       EXCP_FORCE_OUT_OF_RANGE,       
00103       EXCP_FORCE_TO_HIGH,            
00104       EXCP_FORCE_TO_LOW,             
00105       EXCP_UNDEF
00106     };
00107 
00108 
00111   BHFingerException(const FingerError e);
00112 
00113  protected:
00114   FingerError Err;
00115 
00116 };
00117 
00118 //****************************//
00119 //**                        **//
00120 //****************************//
00121 inline BHFingerException::BHFingerException(const FingerError e)
00122 {
00123   Msg = BHFingerException_info[e];
00124   Err = e;
00125 }
00126 
00127 
00128 
00129 
00130 //***********************************************//
00131 //**                                           **//
00132 //**  BHFinger                                 **//
00133 //**                                           **//
00134 //***********************************************//
00135 
00140 class BHFinger : public BHMotorExt
00141 {
00142  public:
00143 
00144 
00147   BHFinger(MotorFeedback *mf);
00148 
00151   BHFinger(MotorFeedback *mf, int speed);
00152 
00162   BHFinger(MotorFeedback *mf, int speed, int minForce, int maxForce);
00163 
00164   ~BHFinger();
00165 
00166   void setPos(const unsigned int pos) throw (BHMotorException);
00167 
00181   void setMaxForce(short force) throw (BHFingerException);
00182 
00191   void setMinForce(short force) throw (BHFingerException);
00192 
00193 
00199   void setMaxForceAbs(short force) throw (BHFingerException);
00200 
00206   void setMinForceAbs(short force) throw (BHFingerException);
00207 
00208 
00209 
00215   int getMaxForce() const ;
00216 
00222   int getMinForce() const;
00223 
00228   int getMaxForceAbs() const ;
00229 
00234   int getMinForceAbs() const;
00235 
00236 
00241   void resetMinForce();
00242 
00247   void resetMaxForce();
00248 
00253   void resetForce();
00254 
00255 
00261   void initForce(const short initForce) throw (BHFingerException);
00262 
00267   void initForce() throw (BHFingerException);
00268 
00273   int getInitForce() const;
00274 
00286   int forceInRange(const short force);
00287 
00298   int forceInRange();
00299 
00308   int getForce() const;
00309 
00316   int getForceAbs() const;
00317 
00318 
00327   void setDForce(const short force) throw (BHFingerException);
00328 
00332   short getDForce() const;
00334 
00341 
00346    void log();
00347 
00349 
00350   bool positionInRange();
00351 
00354   BHPIDController *ForceCtr;
00355 
00356 
00357  protected:
00358 
00359 
00362   short MaxForce;
00363 
00366   short MinForce;
00367 
00370   short ZeroForce;
00371 
00374   short DForce;
00375 
00379   ZLog *ForceLog;
00380 
00381 
00382 };
00383 
00384 
00385 
00386 // ****************************
00387 // **                        **
00388 // ****************************
00389 inline void BHFinger::setMaxForce(short force) throw (BHFingerException)
00390 {
00391   if(force+ZeroForce > MAX_FINGER_FORCE){
00392         std::cerr << " ** void BHFinger::setMaxForce(" << force << "): force to high" << std::endl;
00393     throw BHFingerException(BHFingerException::EXCP_FORCE_TO_HIGH);
00394   }
00395   else if(force+ZeroForce < MIN_FINGER_FORCE){
00396     throw BHFingerException(BHFingerException::EXCP_FORCE_TO_LOW);
00397   }
00398   else{
00399     MaxForce = force+ZeroForce;
00400   }
00401 }
00402 
00403 
00404 // ****************************
00405 // **                        **
00406 // ****************************
00407 inline void BHFinger::setMinForce(short force)throw (BHFingerException)
00408 {
00409   if(force+ZeroForce > MAX_FINGER_FORCE){
00410     throw BHFingerException(BHFingerException:: EXCP_FORCE_TO_HIGH);
00411   }
00412   else if(force+ZeroForce < MIN_FINGER_FORCE){
00413     throw BHFingerException(BHFingerException:: EXCP_FORCE_TO_LOW);
00414   }
00415   else{
00416     MinForce = force+ZeroForce;
00417   }
00418 }
00419 
00420 
00421 // ****************************
00422 // **                        **
00423 // ****************************
00424 inline void BHFinger::setMaxForceAbs(short force) throw (BHFingerException)
00425 {
00426   if(ZeroForce > MAX_FINGER_FORCE){
00427     throw BHFingerException(BHFingerException:: EXCP_FORCE_TO_HIGH);
00428   }
00429   else if(ZeroForce < MIN_FINGER_FORCE){
00430     throw BHFingerException(BHFingerException:: EXCP_FORCE_TO_LOW);
00431   }
00432   else{
00433     MaxForce = force;
00434   }
00435 }
00436 
00437 
00438 // ****************************
00439 // **                        **
00440 // ****************************
00441 inline void BHFinger::setMinForceAbs(short force)throw (BHFingerException)
00442 {
00443   if(force > MAX_FINGER_FORCE){
00444     throw BHFingerException(BHFingerException:: EXCP_FORCE_TO_HIGH);
00445   }
00446   else if(force < MIN_FINGER_FORCE){
00447     throw BHFingerException(BHFingerException:: EXCP_FORCE_TO_LOW);
00448   }
00449   else{
00450     MinForce = force;
00451   }
00452 }
00453 
00454 
00455 // ****************************
00456 // **                        **
00457 // ****************************
00458 inline void BHFinger::resetMinForce()
00459 {
00460   MinForce = MIN_FINGER_FORCE;
00461 }
00462 
00463 // ****************************
00464 // **                        **
00465 // ****************************
00466 inline void BHFinger::resetMaxForce()
00467 {
00468   MaxForce = MAX_FINGER_FORCE;
00469 }
00470 
00471 
00472 // ****************************
00473 // **                        **
00474 // ****************************
00475 inline void BHFinger::resetForce()
00476 {
00477   MaxForce = MAX_FINGER_FORCE;
00478   MinForce = MIN_FINGER_FORCE;
00479 }
00480 
00481 
00482 // ****************************
00483 // **                        **
00484 // ****************************
00485 inline int BHFinger::getMaxForce() const
00486 {
00487   return MaxForce-ZeroForce;
00488 }
00489 
00490 // ****************************
00491 // **                        **
00492 // ****************************
00493 inline int BHFinger::getMinForce() const
00494 {
00495   return MinForce-ZeroForce;
00496 }
00497 
00498 
00499 // ****************************
00500 // **                        **
00501 // ****************************
00502 inline int BHFinger::getMaxForceAbs() const
00503 {
00504   return MaxForce;
00505 }
00506 
00507 // ****************************
00508 // **                        **
00509 // ****************************
00510 inline int BHFinger::getMinForceAbs() const
00511 {
00512   return MinForce;
00513 }
00514 
00515 
00516 // ****************************
00517 // **                        **
00518 // ****************************
00519 inline void BHFinger::initForce(const short initForce) throw (BHFingerException)
00520 {
00521   if(initForce < INIT_FORCE_MIN || initForce > INIT_FORCE_MAX) {
00522     std::cerr << "\n\t ** Initilisation forces out of range!! \n"
00523               << "\t ** Look at users manual for maintainance and \n"
00524               << "\t ** adjust force sensor!!\n " << std::endl;
00525 
00526     ZeroForce = initForce;
00527     ForceLog->setLog(initForce);
00528     throw BHFingerException(BHFingerException::EXCP_INTIT_FORCE_OUT_OF_RANGE);
00529   }
00530   else{
00531     ZeroForce = initForce;
00532     ForceLog->setLog(initForce);
00533   }
00534 }
00535 
00536 
00537 // ****************************
00538 // **                        **
00539 // ****************************
00540 inline void BHFinger::initForce() throw (BHFingerException)
00541 {
00542   int initForce = (int)FeedBack->loopFeedbackStrain;
00543   if(initForce < INIT_FORCE_MIN || initForce > INIT_FORCE_MAX) {
00544     std::cerr << "\n\t ** Initilisation forces out of range!! \n"
00545               << "\t ** Look at users manual for maintainance and \n"
00546               << "\t ** adjust force sensor!!\n " << std::endl;
00547 
00548     ZeroForce = initForce;
00549     ForceLog->setLog((short)FeedBack->loopFeedbackStrain);
00550     throw BHFingerException(BHFingerException::EXCP_INTIT_FORCE_OUT_OF_RANGE);
00551   }
00552   else{
00553     ForceLog->setLog((short)FeedBack->loopFeedbackStrain);
00554     ZeroForce = initForce;
00555   }
00556 }
00557 
00558 
00559 // ****************************
00560 // **                        **
00561 // ****************************
00562 inline int BHFinger::getInitForce() const
00563 {
00564   return ZeroForce;
00565 }
00566 
00567 // ****************************
00568 // **                        **
00569 // ****************************
00570 inline int BHFinger::forceInRange(const short force)
00571 {
00572   if(force > MinForce-1 && force < MaxForce+1)
00573     return 0;
00574 
00575   else if (force < MinForce-1)
00576     return -1;
00577 
00578   else
00579     return 1;
00580 }
00581 
00582 // ****************************
00583 // **                        **
00584 // ****************************
00585 inline int BHFinger::getForce() const
00586 {
00587   return (int)FeedBack->loopFeedbackStrain - ZeroForce;
00588 }
00589 
00590 
00591 // ****************************
00592 // **                        **
00593 // ****************************
00594 inline int BHFinger::getForceAbs() const
00595 {
00596   return (int)FeedBack->loopFeedbackStrain;
00597 }
00598 
00599 
00600 // ****************************
00601 // **                        **
00602 // ****************************
00603 inline int BHFinger::forceInRange()
00604 {
00605   int dummy = (int)FeedBack->loopFeedbackStrain;
00606 
00607   //std::cout << " Actual force : " << dummy  << " min : " << MinForce-1 << " max " << MaxForce << std::endl;
00608 
00609   if(dummy >= MinForce && dummy <= MaxForce){
00610     //    std::cout << " returning 0 " << std::endl;
00611     return 0;
00612   }
00613   else if (dummy < MinForce-1)
00614     return -1;
00615 
00616   else
00617     return 1;
00618 
00619 }
00620 
00621 // ****************************
00622 // **                        **
00623 // ****************************
00624 inline void BHFinger::setDForce(const short force) throw (BHFingerException)
00625 {
00626   if(force < MinForce || force > MaxForce){
00627     throw BHFingerException(BHFingerException:: EXCP_FORCE_OUT_OF_RANGE);
00628   }
00629   else
00630     DForce = force;
00631 }
00632 
00633 
00634 // ****************************
00635 // **                        **
00636 // ****************************
00637 inline short BHFinger::getDForce() const
00638 {
00639   return DForce;
00640 }
00641 
00642 
00643 // ****************************
00644 // **                        **
00645 // ****************************
00646 inline void BHFinger::log()
00647 {
00648   ForceLog->writeLog((short)FeedBack->loopFeedbackStrain);
00649 }
00650 
00651 
00652 
00653 // ****************************
00654 // **                        **
00655 // ****************************
00656 inline bool BHFinger::positionInRange()
00657 {
00658     if( ((int)FeedBack->loopFeedbackAbsPos > MIN_FINGER_POS) &&
00659         ((int)FeedBack->loopFeedbackAbsPos < MAX_FINGER_POS) )
00660       return true;
00661     else
00662       return false;
00663 }
00664 
00665 
00666 // ****************************
00667 // **                        **
00668 // ****************************
00669 inline void BHFinger::setPos(const unsigned int pos) throw (BHMotorException)
00670 {
00671   //std::cout << " ** ::setPos(const unsigned int pos) throw (BHMotorException)" << std::endl;
00672 
00673   if(pos > MaxPos){
00674     throw BHMotorException(BHMotorException::EXCP_POSITION_OUT_OF_RANGE);
00675   }
00676   else{
00677     DPos = (pos < MinPos) ? MinPos : pos;
00678     //std::cout << " ** set DPOS to : " << DPos << std::endl;
00679   }
00680 }
00681 
00682 
00683 #endif //BHFINGER_H


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