00001 /*!@file BeoSub/BeoSubBallast.H Ballast for a BeoSub */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeoSubBallast.H $ 00035 // $Id: BeoSubBallast.H 5130 2005-07-30 06:07:25Z itti $ 00036 // 00037 00038 #ifndef BEOSUBBALLAST_H_DEFINED 00039 #define BEOSUBBALLAST_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Component/ModelParam.H" 00043 #include <pthread.h> 00044 00045 class BeoChip; 00046 00047 //! BeoSub Ballast Class - responsible for the lower level movement of the Sub 00048 /*! This is the class that does the actual workhorse of moving ballast 00049 This class gets instantiated in BeoSub constructor. */ 00050 00051 class BeoSubBallast : public ModelComponent 00052 { 00053 public: 00054 //! Constructor 00055 /*! Ballast Class Constructor 00056 */ 00057 BeoSubBallast(OptionManager& mgr, 00058 const std::string& descrName = "BeoSubBallast", 00059 const std::string& tagName = "BeoSubBallast"); 00060 00061 //! Set our BeoChip 00062 void setBeoChip(nub::soft_ref<BeoChip>& bc); 00063 00064 //! Destructor 00065 ~BeoSubBallast(); 00066 00067 //! Initialize the ballast by probing its endpoints 00068 void mechanicalInitialize(); 00069 00070 //! Set to a given fill level, between 0.0 (empty) and 1.0 (full) 00071 void set(const float val, const bool blocking = false); 00072 00073 //! Get the current level, between 0.0 (empty) and 1.0 (full) 00074 float get() const; 00075 00076 //! Get the current level, in number of pulses 00077 int getPulses() const; 00078 00079 //! Something changed on the BeoChip's inputs 00080 void input(const int val); 00081 00082 //! Are we moving? 00083 bool moving() const; 00084 00085 protected: 00086 NModelParam<int> itsPulsesPerFill; //!< how many pulses per full travel? 00087 NModelParam<int> itsOutRed; //!< BeoChip digital out number for red wire 00088 NModelParam<int> itsOutWhite; //!< BeoChip digital out number for wht wire 00089 NModelParam<int> itsInYellow; //!< BeoChip keyboard in number for yellow wire 00090 NModelParam<int> itsInWhite; //!< BeoChip keyboard in number for yellow wire 00091 00092 private: 00093 nub::soft_ref<BeoChip> itsBeoChip; 00094 volatile int itsDesiredPulses; // our desired value 00095 volatile int itsCurrentPulses; // our current value 00096 enum MotorDirection { Idle = 0, Filling = 1, Emptying = 2 }; 00097 MotorDirection itsDirection; 00098 MotorDirection itsPreviousDirection; 00099 bool itsIsFull, itsIsEmpty; 00100 bool itsInitialized; 00101 00102 int itsPreviousInputs; // copy of previous inputs 00103 00104 void move(const MotorDirection dir); 00105 void inputDuringInit(const int val); 00106 bool itsGotEndstop; 00107 00108 pthread_mutex_t itsLock; 00109 }; 00110 00111 00112 #endif 00113 00114 // ###################################################################### 00115 /* So things look consistent in everyone's emacs... */ 00116 /* Local Variables: */ 00117 /* indent-tabs-mode: nil */ 00118 /* End: */