dock_drive.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Yujin Robot.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Yujin Robot nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
35 /*****************************************************************************
36 ** Ifdefs
37 *****************************************************************************/
38 
39 #ifndef KOBUKI_DOCK_DRIVE_HPP_
40 #define KOBUKI_DOCK_DRIVE_HPP_
41 
42 /*****************************************************************************
43 ** Includes
44 *****************************************************************************/
45 
46 #include <iostream>
47 #include <sstream>
48 #include <iomanip>
49 #include <cmath>
50 #include <vector>
52 #include <ecl/linear_algebra.hpp>
53 
55 
56 /*****************************************************************************
57 ** Namespaces
58 *****************************************************************************/
59 
60 namespace kobuki {
61 
62 /*****************************************************************************
63 ** Interfaces
64 *****************************************************************************/
65 
66 class DockDrive {
67 public:
68  DockDrive();
69  ~DockDrive();
70 
71  bool init(){ return true; }
72  bool isEnabled() const { return is_enabled; }
73  bool canRun() const { return can_run; }
74 
75  void enable() { modeShift("enable"); }
76  void disable() { modeShift("disable"); }
77  void modeShift(const std::string& mode);
78 
79  void update(const std::vector<unsigned char> &signal /* dock_ir signal*/
80  , const unsigned char &bumper
81  , const unsigned char &charger
82  , const ecl::LegacyPose2D<double> &pose);
83 
84  void velocityCommands(const double &vx, const double &wz);
85 
86  /*********************
87  ** Command Accessors
88  **********************/
89  double getVX() const { return vx; }
90  double getWZ() const { return wz; }
91 
92  /*********************
93  ** Mode Accessors
94  **********************/
96  std::string getStateStr() const { return state_str; }
97  std::string getDebugStr() const { return debug_str; }
98 
99  /*********************
100  ** Parameters Mutators
101  **********************/
102  void setMinAbsV(double mav) { min_abs_v = mav; }
103  void setMinAbsW(double maw) { min_abs_w = maw; }
104 
105  //debugging
106  std::string getDebugStream() { return debug_output; } //stream.str(); }
107  //std::string getDebugStream() { return debug_stream.str(); }
108  //std::ostringstream debug_stream;
109 
110  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
111 
112 protected:
113  void processBumpChargeEvent(const unsigned char& bumper, const unsigned char& charger);
115  void filterIRSensor(std::vector<unsigned char>& signal_filt,const std::vector<unsigned char> &signal );
116  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);
117  void updateVelocity(const std::vector<unsigned char>& signal_filt, const ecl::LegacyPose2D<double>& pose_update, std::string& debug_str);
118  RobotDockingState::State determineRobotLocation(const std::vector<unsigned char>& signal_filt,const unsigned char& charger);
119  bool validateSignal(const std::vector<unsigned char>& signal_filt, const unsigned int state);
120 
121 
122  // States
123  void idle(RobotDockingState::State& state,double& vx, double& wz);
124  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);
125  void find_stream(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt);
126  void get_stream(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt);
127  void aligned(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt, std::string& debug_str);
128  void bumped(RobotDockingState::State& nstate,double& nvx, double& nwz, int& bump_count);
129 
130 
131 private:
133 
135  std::string state_str, debug_str;
136  double vx, wz;
137  std::vector<std::vector<unsigned char> > past_signals;
138  unsigned int signal_window;
142  double rotated;
143  double min_abs_v;
144  double min_abs_w;
146 
147  void setVel(double v, double w);
148 
149  std::string binary(unsigned char number) const;
150 
151  std::string debug_output;
152  std::vector<std::string> ROBOT_STATE_STR;
153 };
154 
155 } // namespace kobuki
156 
157 #endif /* KOBUKI_DOCK_DRIVE_HPP_ */
void processBumpChargeEvent(const unsigned char &bumper, const unsigned char &charger)
Definition: dock_drive.cpp:199
void setMinAbsV(double mav)
Definition: dock_drive.hpp:102
void computePoseUpdate(ecl::LegacyPose2D< double > &pose_update, const ecl::LegacyPose2D< double > &pose)
compute pose update from previouse pose and current pose
Definition: dock_drive.cpp:149
unsigned int signal_window
Definition: dock_drive.hpp:138
std::string getDebugStream()
Definition: dock_drive.hpp:106
RobotDockingState::State determineRobotLocation(const std::vector< unsigned char > &signal_filt, const unsigned char &charger)
bool isEnabled() const
Definition: dock_drive.hpp:72
void modeShift(const std::string &mode)
Definition: dock_drive.cpp:96
RobotDockingState::State state
Definition: dock_drive.hpp:134
void bumped(RobotDockingState::State &nstate, double &nvx, double &nwz, int &bump_count)
States.
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)
void find_stream(RobotDockingState::State &state, double &vx, double &wz, const std::vector< unsigned char > &signal_filt)
void setVel(double v, double w)
Definition: dock_drive.cpp:90
std::string getStateStr() const
Definition: dock_drive.hpp:96
RobotDockingState::State getState() const
Definition: dock_drive.hpp:95
std::string getDebugStr() const
Definition: dock_drive.hpp:97
void idle(RobotDockingState::State &state, double &vx, double &wz)
bool canRun() const
Definition: dock_drive.hpp:73
std::vector< std::string > ROBOT_STATE_STR
Definition: dock_drive.hpp:152
void filterIRSensor(std::vector< unsigned char > &signal_filt, const std::vector< unsigned char > &signal)
Definition: dock_drive.cpp:168
void updateVelocity(const std::vector< unsigned char > &signal_filt, const ecl::LegacyPose2D< double > &pose_update, std::string &debug_str)
Definition: dock_drive.cpp:239
std::vector< std::vector< unsigned char > > past_signals
Definition: dock_drive.hpp:137
double getWZ() const
Definition: dock_drive.hpp:90
bool validateSignal(const std::vector< unsigned char > &signal_filt, const unsigned int state)
Definition: dock_drive.cpp:289
void setMinAbsW(double maw)
Definition: dock_drive.hpp:103
std::string debug_output
Definition: dock_drive.hpp:151
std::string state_str
Definition: dock_drive.hpp:135
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)
void get_stream(RobotDockingState::State &state, double &vx, double &wz, const std::vector< unsigned char > &signal_filt)
double getVX() const
Definition: dock_drive.hpp:89
std::string debug_str
Definition: dock_drive.hpp:135
void aligned(RobotDockingState::State &state, double &vx, double &wz, const std::vector< unsigned char > &signal_filt, std::string &debug_str)
void velocityCommands(const double &vx, const double &wz)
Definition: dock_drive.cpp:185
ecl::LegacyPose2D< double > pose_priv
Definition: dock_drive.hpp:145
void update(const std::vector< unsigned char > &signal, const unsigned char &bumper, const unsigned char &charger, const ecl::LegacyPose2D< double > &pose)
Updates the odometry from firmware stamps and encoders.
Definition: dock_drive.cpp:115
std::string binary(unsigned char number) const


kobuki_dock_drive
Author(s): Younghun Ju
autogenerated on Fri Sep 18 2020 03:22:00