Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
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(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,      //!< indicates the root menu is currently displayed (save/load data sets...)
00048     CHOOSE,    //!< indicates the sample type selection is displayed
00049     READY,     //!< waiting for user to indicate 0 point
00050     MOVING,    //!< recording, waiting for the motion stop event
00051     READING_1, //!< waiting for user to supply the first measurement coordinate
00052     READING_2, //!< waiting for user to supply the second measurement coordinate
00053     CLEAR,     //!< clear data confirmation menu
00054   } st; //!< the currently active state
00055 
00056   //! allows representation of the current sample type
00057   enum dataSource {
00058     fs, //!< forward-sideways
00059     fr, //!< forward-rotate
00060     sr, //!< sideways-rotate
00061     br, //!< backward-rotate
00062     bs, //!< backward-sideways
00063     r,  //!< pure rotation
00064     NUM_SRC //!< number of data types
00065   } curType; //!< the currently selected type of data being recorded  
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   const char * getIndexName(unsigned int t); //!< returns name for measurement type
00083   const char * getFirstMeasure(dataSource t); //!< returns name for first measurement type
00084   const 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, 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)
00089   static void report(unsigned int row, float cmd, float actual); //!< reports data as they are being taken
00090   static void err(const std::string& str); //!< pops up an error message on the controller and also displays it on the console
00091 
00092   float old_x; //!< the x velocity recorded when we started moving
00093   float old_y; //!< the y velocity recorded when we started moving
00094   float old_a; //!< the a velocity recorded when we started moving
00095   unsigned int startTime; //!< the time recording started
00096   unsigned int stopTime; //!< the time recording stopped
00097 
00098   ControlBase * help; //!< control holding help info
00099   FileInputControl * load; //!< control for loading data
00100   StringInputControl * save; //!< control for saving data
00101   ControlBase * measure; //!< control for taking measurements
00102   ControlBase * clear; //!< control for clearing data
00103   ToggleControl * polar; //!< control for selecting polar measurements for fs/bs
00104   ToggleControl * rect; //!< control for selecting cartesian measurements for fs/bs
00105   bool isPolar; //!< true if polar measurements is selected
00106   std::string lastLoad; //!< name last data file selected (so we know if a new has been selected
00107 
00108   float firstIn; //!< the input given for the first measurement
00109   float secondIn;  //!< the input given for the second measurement
00110   std::vector<float*> data[NUM_SRC]; //!< an array of vectors of sample points (one veotor for each of the sample types)
00111   unsigned int cnts[NUM_SRC]; //!< count of samples for each sample type (cnts[i] should equal data[i].size())
00112   static const char * datanames[NUM_SRC]; //!< name for each sample type
00113 
00114   std::string status; //!< string to send for ControllerGUI status message (current count of each sample type)
00115   
00116 private:
00117   WalkCalibration(const WalkCalibration& ); //!< don't call
00118   WalkCalibration& operator=(const WalkCalibration& ); //!< don't call
00119 };
00120 
00121 /*! @file
00122  * @brief Describes WalkCalibration, which allows interactive calibration of a walk engine
00123  * @author ejt (Creator)
00124  */
00125 
00126 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3