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/legacy_pose2d.hpp>
00052 #include <ecl/linear_algebra.hpp>
00053 
00054 #include "kobuki_dock_drive/state.hpp"
00055 
00056 /*****************************************************************************
00057 ** Namespaces
00058 *****************************************************************************/
00059 
00060 namespace kobuki {
00061 
00062 /*****************************************************************************
00063 ** Interfaces
00064 *****************************************************************************/
00065 
00066 class DockDrive {
00067 public:
00068   DockDrive();
00069   ~DockDrive();
00070 
00071   bool init(){ return true; }
00072   bool isEnabled() const { return is_enabled; }
00073   bool canRun() const { return can_run; }
00074 
00075   void enable() { modeShift("enable"); }
00076   void disable() { modeShift("disable"); }
00077   void modeShift(const std::string& mode);
00078 
00079   void update(const std::vector<unsigned char> &signal /* dock_ir signal*/
00080                 , const unsigned char &bumper
00081                 , const unsigned char &charger
00082                 , const ecl::LegacyPose2D<double> &pose);
00083 
00084   void velocityCommands(const double &vx, const double &wz);
00085 
00086   /*********************
00087   ** Command Accessors
00088   **********************/
00089   double getVX() const { return vx; }
00090   double getWZ() const { return wz; }
00091 
00092   /*********************
00093   ** Mode Accessors
00094   **********************/
00095   RobotDockingState::State getState() const { return state; }
00096   std::string getStateStr() const { return state_str; }
00097   std::string getDebugStr() const { return debug_str; }
00098 
00099   /*********************
00100   ** Parameters Mutators
00101   **********************/
00102   void setMinAbsV(double mav) { min_abs_v = mav; }
00103   void setMinAbsW(double maw) { min_abs_w = maw; }
00104 
00105   //debugging
00106   std::string getDebugStream() { return debug_output; } //stream.str(); }
00107   //std::string getDebugStream() { return debug_stream.str(); }
00108   //std::ostringstream debug_stream;
00109 
00110   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00111 
00112 protected:
00113   void processBumpChargeEvent(const unsigned char& bumper, const unsigned char& charger);
00114   void computePoseUpdate(ecl::LegacyPose2D<double>& pose_update, const ecl::LegacyPose2D<double>& pose);
00115   void filterIRSensor(std::vector<unsigned char>& signal_filt,const std::vector<unsigned char> &signal );
00116   void generateDebugMessage(const std::vector<unsigned char>& signal_filt, const unsigned char &bumper, const unsigned char &charger, const ecl::LegacyPose2D<double>& pose_update, const std::string& debug_str);
00117   void updateVelocity(const std::vector<unsigned char>& signal_filt, const ecl::LegacyPose2D<double>& pose_update, std::string& debug_str);
00118   RobotDockingState::State determineRobotLocation(const std::vector<unsigned char>& signal_filt,const unsigned char& charger);
00119   bool validateSignal(const std::vector<unsigned char>& signal_filt, const unsigned int state);
00120 
00121 
00122   // States
00123   void idle(RobotDockingState::State& state,double& vx, double& wz);
00124   void scan(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt, const ecl::LegacyPose2D<double>& pose_update, std::string& debug_str);
00125   void find_stream(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt);
00126   void get_stream(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt);
00127   void aligned(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt, std::string& debug_str);
00128   void bumped(RobotDockingState::State& nstate,double& nvx, double& nwz, int& bump_count);
00129 
00130 
00131 private:
00132   bool is_enabled, can_run;
00133 
00134   RobotDockingState::State state;
00135   std::string state_str, debug_str;
00136   double vx, wz;
00137   std::vector<std::vector<unsigned char> > past_signals;
00138   unsigned int signal_window;
00139   int bump_remainder;
00140   int dock_stabilizer;
00141   int dock_detector;
00142   double rotated;
00143   double min_abs_v;
00144   double min_abs_w;
00145   ecl::LegacyPose2D<double> pose_priv;
00146 
00147   void setVel(double v, double w);
00148 
00149   std::string binary(unsigned char number) const;
00150 
00151   std::string debug_output;
00152   std::vector<std::string> ROBOT_STATE_STR;
00153 };
00154 
00155 } // namespace kobuki
00156 
00157 #endif /* KOBUKI_DOCK_DRIVE_HPP_ */


kobuki_dock_drive
Author(s): Younghun Ju
autogenerated on Thu Jun 6 2019 20:24:33