BeobotControl.H

Go to the documentation of this file.
00001 /*!@file Beobot/BeobotControl.H controls the movement of the Beobot
00002   via passed in BeoChip                                                 */
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // 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: Christian Siagian <siagian@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/BeobotControl.H $
00035 // $Id: BeobotControl.H 6795 2006-06-29 20:45:32Z rjpeters $
00036 //
00037 #ifndef BEOBOT_BEOBOTCONTROL_H_DEFINED
00038 #define BEOBOT_BEOBOTCONTROL_H_DEFINED
00039 
00040 #include "Beobot/BeobotAction.H"
00041 #include "Beobot/BeobotConfig.H"
00042 #include "Devices/BeoChip.H"
00043 #include "Component/ModelComponent.H"
00044 #include "Component/ModelParam.H"
00045 #include "Util/Timer.H"
00046 #include "Util/Types.H" // for byte definition
00047 #include <pthread.h>
00048 
00049 /*Beobot/BeobotControl.H controls the movement of the Beobot
00050   via passed in BeoChip
00051 
00052   Input:  geographical speed and direction
00053   Output: motor control for the next time stamp that will go toward
00054           achieving that goal
00055 
00056           - robot safety (tilting, etc) is being considered
00057             -> speed ramping is implicitly applied
00058 
00059           - robot can't turn all that well when not moving
00060             -> robot will move forward while turning
00061 */
00062 
00063 //! Speed ramping options
00064 enum SpeedRampType {
00065   SPEED_RAMP_LINEAR = 0, //!< use linear ramping
00066   SPEED_RAMP_SIGMOID = 1 //!< use sigmoid ramping
00067 };
00068 
00069 class BeobotControl : public ModelComponent
00070 {
00071 public:
00072 
00073   //! General constructor
00074   BeobotControl(nub::soft_ref<BeoChip> beoChip,
00075                 OptionManager& mgr,
00076                 const std::string& descrName = "Beobot Controller",
00077                 const std::string& tagName = "BeobotControl");
00078 
00079   //! Constructor
00080   ~BeobotControl();
00081 
00082   //! Move Beobot
00083   //BeobotAction move(float vel, float angle);
00084 
00085   //! calibrate the speed SSC to new values
00086   /*! The speed SSC is calibrated to the values defined in
00087     a car.conf file during construction.  This function allows
00088     the SSC to be recalibrated to new min/neutral/max values.
00089   */
00090   void calibrateSpeed( const byte neutralval, const byte minval,
00091                        const byte maxval );
00092 
00093   //! calibrate the steering SSC to new values
00094   /*! The steering SSC is calibrated to the values defined in
00095     a car.conf file during construction.  This function allows
00096     the SSC to be recalibrated to new min/neutral/max values.
00097   */
00098   void calibrateSteer( const byte neutralval, const byte minval,
00099                        const byte maxval );
00100 
00101   //! get speed value [-1.0 .. 1.0]
00102   float getSpeed() const;
00103 
00104   //! get gear value [-1.0 .. 1.0]
00105   float getGear() const;
00106 
00107   //! get steer value [-1.0 .. 1.0]
00108   float getSteer() const;
00109 
00110   //! set speed value: [-1.0 (full reverse) to 1.0 (full forward)]
00111   bool setSpeed(const float newspeed);
00112 
00113   //! set gear: -1.0 (neutral) 0.0 (first gear, slow), 1.0 (second gear, fast)
00114   bool setGear(const float newgear);
00115 
00116   //! set steer angle: [-1.0 (full left) to 1.0 (full right)]
00117   bool setSteer(const float newsteer);
00118 
00119   //! linear ramp of speed from current speed to new speed
00120   /*! Speed will reach newspeed after t milliseconds */
00121   bool toSpeedLinear( const float newspeed, const int t );
00122 
00123   //! sigmoid ramp of speed from current speed to new speed
00124   /*! Speed will reach newspeed after t milliseconds */
00125   bool toSpeedSigmoid( const float newspeed, const int t );
00126 
00127   //! speed ramping function
00128   /*! This function is used for gradually increasing the speed with a certain
00129     behavior over a certain period of time. The ramping will be done in a
00130     separate thread so this function will return immediately. It is not
00131     necessary to wait until the new speed has been reached before calling this
00132     function to modify the ramping parameters again. The ramping function will
00133     be stopped if abortRamp() is called, or else if the thread continues other
00134     calls to setSpeed() may seem to have no effect.
00135     @param newspeed new speed to be reached after ramping
00136     @param t time in which new speed will be reached (milliseconds)
00137     @param behavior specifies behavior of ramping function
00138   */
00139   void rampSpeed( const float newspeed, const int t, SpeedRampType behavior );
00140 
00141   //! aborts speed ramping
00142   /*! Used to stop speed ramping thread so that main program has priority for
00143     setting speed. */
00144   void abortRamp( void );
00145 
00146 private:
00147   nub::soft_ref<BeoChip> itsBeoChip;  //!< our servo controller
00148   BeobotConfig itsBeobotConfig;       //!< config params for car
00149 
00150   pthread_mutex_t setSpeedMutex;      //!< mutex for setting speed
00151 
00152   float startSpeed;                   //!< speed at beginning of ramping
00153   float desiredSpeed;                 //!< desired speed setting
00154   int desiredTime;                    //!< time to reach desired speed
00155   Timer speedRampTimer;               //!< timer to track ramping time
00156   SpeedRampType speedRampType;        //!< type of speed ramping behavior
00157   pthread_t speedRampThread;          //!< thread for speed ramping functions
00158   pthread_mutex_t speedRampMutex;     //!< mutex for speed ramping variables
00159   bool speedRampThreadCreated;        //!< tells if thread is created
00160 
00161   //! routine for speed ramp thread
00162   friend void *speedRampFunc( void *ptr );
00163 
00164   //! stop the car as we terminate execution
00165   void stop1();
00166 };
00167 
00168 #endif
00169 
00170 // ######################################################################
00171 /* So things look consistent in everyone's emacs... */
00172 /* Local Variables: */
00173 /* indent-tabs-mode: nil */
00174 /* End: */
Generated on Sun May 8 08:04:29 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3