Homepage Demos Overview Downloads Tutorials Reference
Credits

WalkCalibration.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_WalkCalibration_h_
00003 #define INCLUDED_WalkCalibration_h_
00004 
00005 #include "ControlBase.h"
00006 #include "StringInputControl.h"
00007 #include "FileInputControl.h"
00008 #include "ToggleControl.h"
00009 #include "Events/EventRouter.h"
00010 
00011 //! allows interactive calibration of a walk engine
00012 /*! 
00013  *  In retrospect, this might have been a little easier to do as a
00014  *  ControlBase/StateNode multiple inheritance instead of
00015  *  ControlBase/EventListener... oh well.
00016  */
00017 class WalkCalibration : public ControlBase, public EventListener {
00018 public:
00019   //! constructor
00020   WalkCalibration();
00021   
00022   //! destructor
00023   ~WalkCalibration();
00024 
00025   virtual ControlBase * activate(MotionManager::MC_ID disp_id, Socket * gui);
00026 
00027   virtual void refresh();
00028 
00029   virtual void deactivate() {
00030     erouter->removeListener(this);
00031     ControlBase::deactivate();
00032   }
00033 
00034   virtual ControlBase* doSelect();
00035 
00036   //! listens for locomotion events so we know when to stop recording
00037   virtual void processEvent(const EventBase& e);
00038 
00039   virtual ControlBase * takeInput(const std::string& msg);
00040   
00041   virtual void setHilights(const std::vector<unsigned int>& hi);
00042 
00043   virtual void hilightFirst();
00044 
00045 protected:
00046   enum {
00047     ROOT,
00048     CHOOSE,
00049     READY,
00050     MOVING,
00051     READING_1,
00052     READING_2,
00053     CLEAR,
00054   } st; //!< the currently active state
00055 
00056   //! allows representation of the current sample type
00057   enum dataSource {
00058     fs,
00059     fr,
00060     sr,
00061     br,
00062     bs,
00063     r,
00064     NUM_SRC
00065   } curType;
00066 
00067   static void loadData(const std::string& name, std::vector<float*>& data); //!< does the work of loading data sets
00068   static void saveData(const std::string& name, const std::vector<float*>& data); //!< does the work of saving data sets
00069   static void clearData(std::vector<float*>& data); //!< clears current data
00070 
00071   void setupRoot(); //!< sets state to root menu
00072   void setupChoose(); //!< sets state to choose type menu
00073   void setupReady(); //!< sets state to ready menu
00074   void setupMoving(); //!< sets state to moving menu
00075   void setupReading1(); //!< sets state to enter first measurement menu
00076   void setupReading2(); //!< sets state to enter second measurement menu
00077   void setupClear(); //!< sets state to clear confirmation menu
00078 
00079   unsigned int getType(); //!< returns current sample type
00080   unsigned int getFirstIndex(dataSource t); //!< returns a name index for the first measurement type
00081   unsigned int getSecondIndex(dataSource t); //!< returns a name index for the second measurement type
00082   char * getIndexName(unsigned int t); //!< returns name for measurement type
00083   char * getFirstMeasure(dataSource t); //!< returns name for first measurement type
00084   char * getSecondMeasure(dataSource t); //!< returns name for second measurement type
00085 
00086   float arclen(float d, float a, float sign); //!< calculates arc distance corresponding to a displacement and angle, negated if necessary to match @a sign
00087   void addSample(); //!< adds data point corresponding to measurements stored in #firstIn and #secondIn
00088   void addSample(std::vector<float*>& dat, unsigned int row, float sol); //!< adds data point to @a dat at row with solution (deprecated)
00089   void addSample(std::vector<float*>& dat, float x, float y, float a); //!< adds data point to @a dat for a given x,y,a (and #old_x, #old_y, #old_a)
00090   static void report(unsigned int row, float cmd, float actual); //!< reports data as they are being taken
00091   static void err(const std::string& str); //!< pops up an error message on the controller and also displays it on the console
00092 
00093   float old_x; //!< the x velocity recorded when we started moving
00094   float old_y; //!< the y velocity recorded when we started moving
00095   float old_a; //!< the a velocity recorded when we started moving
00096   unsigned int startTime; //!< the time recording started
00097   unsigned int stopTime; //!< the time recording stopped
00098 
00099   ControlBase * help; //!< control holding help info
00100   FileInputControl * load; //!< control for loading data
00101   StringInputControl * save; //!< control for saving data
00102   ControlBase * measure; //!< control for taking measurements
00103   ControlBase * clear; //!< control for clearing data
00104   ToggleControl * polar; //!< control for selecting polar measurements for fs/bs
00105   ToggleControl * rect; //!< control for selecting cartesian measurements for fs/bs
00106   bool isPolar; //!< true if polar measurements is selected
00107   std::string lastLoad; //!< name last data file selected (so we know if a new has been selected
00108 
00109   float firstIn; //!< the input given for the first measurement
00110   float secondIn;  //!< the input given for the second measurement
00111   std::vector<float*> data[NUM_SRC]; //!< an array of vectors of sample points (one veotor for each of the sample types)
00112   unsigned int cnts[NUM_SRC]; //!< count of samples for each sample type (cnts[i] should equal data[i].size())
00113   static char * datanames[NUM_SRC]; //!< name for each sample type
00114 
00115   std::string status; //!< string to send for ControllerGUI status message (current count of each sample type)
00116   
00117 private:
00118   WalkCalibration(const WalkCalibration& ); //!< don't call
00119   WalkCalibration& operator=(const WalkCalibration& ); //!< don't call
00120 };
00121 
00122 /*! @file
00123  * @brief Describes WalkCalibration, which allows interactive calibration of a walk engine
00124  * @author ejt (Creator)
00125  *
00126  * $Author: ejt $
00127  * $Name: tekkotsu-2_2_2 $
00128  * $Revision: 1.6 $
00129  * $State: Exp $
00130  * $Date: 2004/10/07 19:07:04 $
00131  */
00132 
00133 #endif

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:16 2005 by Doxygen 1.4.0