dock_drive.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Yujin Robot.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Yujin Robot nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00035 /*****************************************************************************
00036 ** Ifdefs
00037 *****************************************************************************/
00038 
00039 #ifndef KOBUKI_DOCK_DRIVE_HPP_
00040 #define KOBUKI_DOCK_DRIVE_HPP_
00041 
00042 /*****************************************************************************
00043 ** Includes
00044 *****************************************************************************/
00045 
00046 #include <iostream>
00047 #include <sstream>
00048 #include <iomanip>
00049 #include <cmath>
00050 #include <vector>
00051 #include <ecl/geometry/pose2d.hpp>
00052 #include <ecl/linear_algebra.hpp>
00053 
00054 /*****************************************************************************
00055 ** Namespaces
00056 *****************************************************************************/
00057 
00058 namespace kobuki {
00059 
00060 /*****************************************************************************
00061 ** Interfaces
00062 *****************************************************************************/
00063 
00064 class DockDrive {
00065 public:
00066   enum Station {
00067     NEAR_LEFT=1,
00068     NEAR_CENTER=2,
00069     NEAR_RIGHT=4,
00070     FAR_CENTER=8,
00071     FAR_LEFT=16,
00072     FAR_RIGHT=32,
00073     NEAR = 7,
00074     FAR = 56,
00075   };
00076   enum State {
00077     IDLE,
00078     LOST,
00079     UNKNOWN,
00080     INSIDE_FIELD,
00081     AWAY,
00082     SCAN,
00083     SPIN,
00084     SPIRAL,
00085     FIND_STREAM,
00086     GET_STREAM,
00087     ALIGNED,
00088     ALIGNED_FAR,
00089     ALIGNED_NEAR,
00090     BUMPED,
00091     BUMPED_DOCK,
00092     RUN,
00093     STOP,
00094     DOCKED_IN,
00095     DONE,
00096   };
00097 
00098   DockDrive();
00099   ~DockDrive();
00100 
00101   bool init(){ return true; }
00102   bool isEnabled() const { return is_enabled; }
00103   bool canRun() const { return can_run; }
00104 
00105   void enable() { modeShift("enable"); }
00106   void disable() { modeShift("disable"); }
00107   void modeShift(const std::string& mode);
00108 
00109   void update(const std::vector<unsigned char> &signal /* dock_ir signal*/
00110                 , const unsigned char &bumper
00111                 , const unsigned char &charger
00112                 , const ecl::Pose2D<double> &pose);
00113 
00114   void update(const std::vector<unsigned char> &signal /* dock_ir signal*/
00115                 , const unsigned char &bumper
00116                 , const unsigned char &charger
00117                 , const ecl::Pose2D<double> &pose_update
00118                 , const ecl::linear_algebra::Vector3d &pose_update_rates);
00119 
00120   void velocityCommands(const double &vx, const double &wz);
00121 
00122   /*********************
00123   ** Command Accessors
00124   **********************/
00125   double getVX() const { return vx; }
00126   double getWZ() const { return wz; }
00127 
00128   /*********************
00129   ** Mode Accessors
00130   **********************/
00131   State getState() const { return state; }
00132   std::string getStateStr() const { return state_str; }
00133   std::string getDebugStr() const { return debug_str; }
00134 
00135   /*********************
00136   ** Parameters Mutators
00137   **********************/
00138   void setMinAbsV(double mav) { min_abs_v = mav; }
00139   void setMinAbsW(double maw) { min_abs_w = maw; }
00140 
00141   //debugging
00142   std::string getDebugStream() { return debug_output; } //stream.str(); }
00143   //std::string getDebugStream() { return debug_stream.str(); }
00144   //std::ostringstream debug_stream;
00145 
00146   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00147 
00148 private:
00149   bool is_enabled, can_run;
00150 
00151   State state;
00152   std::string state_str, debug_str;
00153   double vx, wz;
00154   std::vector<std::vector<unsigned char> > past_signals;
00155   int bump_remainder;
00156   int dock_stabilizer;
00157   int dock_detector;
00158   double rotated;
00159   double min_abs_v;
00160   double min_abs_w;
00161 
00162   void setVel(double v, double w);
00163 
00164   std::string binary(unsigned char number) const;
00165 
00166   std::string debug_output;
00167 };
00168 
00169 } // namespace kobuki
00170 
00171 #endif /* KOBUKI_DOCK_DRIVE_HPP_ */


kobuki_dock_drive
Author(s): Younghun Ju
autogenerated on Thu Aug 27 2015 13:43:56