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   //debugging
00136   std::string getDebugStream() { return debug_output; } //stream.str(); }
00137   //std::string getDebugStream() { return debug_stream.str(); }
00138   //std::ostringstream debug_stream;
00139 
00140   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00141 
00142 private:
00143   bool is_enabled, can_run;
00144 
00145   State state;
00146   std::string state_str, debug_str;
00147   ecl::Pose2D<double> pose;
00148   double vx, wz;
00149   std::vector<std::vector<unsigned char> > past_signals;
00150   int bump_remainder;
00151   int dock_stabilizer;
00152   int dock_detector;
00153   double rotated;
00154 
00155   std::string binary(unsigned char number) const;
00156 
00157   std::string debug_output;
00158 };
00159 
00160 } // namespace kobuki
00161 
00162 #endif /* KOBUKI_DOCK_DRIVE_HPP_ */


kobuki_auto_docking
Author(s): Younghun Ju
autogenerated on Mon Oct 6 2014 01:30:37