Kobuki 1.0.0
C++ API for the Kobuki research robot
Loading...
Searching...
No Matches
dock_drive.hpp
1
9/*****************************************************************************
10** Ifdefs
11*****************************************************************************/
12
13#ifndef KOBUKI_CORE_DOCK_DRIVE_HPP_
14#define KOBUKI_CORE_DOCK_DRIVE_HPP_
15
16/*****************************************************************************
17** Includes
18*****************************************************************************/
19
20#include <iostream>
21#include <sstream>
22#include <iomanip>
23#include <cmath>
24#include <vector>
25// Version 3.4.0 of Eigen in Ubuntu 22.04 has a bug that causes -Wclass-memaccess warnings on
26// aarch64. Upstream Eigen has already fixed this in
27// https://gitlab.com/libeigen/eigen/-/merge_requests/645 . The Debian fix for this is in
28// https://salsa.debian.org/science-team/eigen3/-/merge_requests/1 .
29// However, it is not clear that that fix is going to make it into Ubuntu 22.04 before it
30// freezes, so disable the warning here.
31#if defined(__GNUC__) && !defined(__clang__)
32#pragma GCC diagnostic push
33#pragma GCC diagnostic ignored "-Wclass-memaccess"
34#endif
35#include <ecl/geometry.hpp>
36#if defined(__GNUC__) && !defined(__clang__)
37#pragma GCC diagnostic pop
38#endif
39
40#include <ecl/linear_algebra.hpp>
41
42/*****************************************************************************
43** Namespaces
44*****************************************************************************/
45
46namespace kobuki {
47
48/*****************************************************************************
49** Definitions
50*****************************************************************************/
51
52// indicates the ir sensor from docking station
54 enum State {
55 INVISIBLE=0,
56 NEAR_LEFT=1,
57 NEAR_CENTER=2,
58 NEAR_RIGHT=4,
59 FAR_CENTER=8,
60 FAR_LEFT=16,
61 FAR_RIGHT=32,
62 NEAR = 7, // NEAR_LEFT + NEAR_CENTER + NEAR_RIGHT
63 FAR = 56, // FAR_CENTER + FAR_LEFT + FAR_RIGHT
64 };
65};
66
67// the current robot states
69 enum State {
70 IDLE,
71 DONE,
72 DOCKED_IN,
73 BUMPED_DOCK,
74 BUMPED,
75 SCAN,
76 FIND_STREAM,
77 GET_STREAM,
78 ALIGNED,
79 ALIGNED_FAR,
80 ALIGNED_NEAR,
81 UNKNOWN,
82 LOST
83 };
84
85};
86
87/*****************************************************************************
88** Interfaces
89*****************************************************************************/
90
91class DockDrive {
92public:
93 DockDrive();
94 ~DockDrive();
95
96 bool init(){ return true; }
97 bool isEnabled() const { return is_enabled; }
98 bool canRun() const { return can_run; }
99
100 void enable() { modeShift("enable"); }
101 void disable() { modeShift("disable"); }
102 void modeShift(const std::string& mode);
103
104 void update(const std::vector<unsigned char> &signal /* dock_ir signal*/
105 , const unsigned char &bumper
106 , const unsigned char &charger
107 , const ecl::linear_algebra::Vector3d &pose);
108
109 void velocityCommands(const double &vx, const double &wz);
110
111 /*********************
112 ** Command Accessors
113 **********************/
114 double getVX() const { return vx; }
115 double getWZ() const { return wz; }
116
117 /*********************
118 ** Mode Accessors
119 **********************/
120 RobotDockingState::State getState() const { return state; }
121 std::string getStateStr() const { return state_str; }
122 std::string getDebugStr() const { return debug_str; }
123
124 /*********************
125 ** Parameters Mutators
126 **********************/
127 void setMinAbsV(double mav) { min_abs_v = mav; }
128 void setMinAbsW(double maw) { min_abs_w = maw; }
129
130 //debugging
131 std::string getDebugStream() { return debug_output; } //stream.str(); }
132 //std::string getDebugStream() { return debug_stream.str(); }
133 //std::ostringstream debug_stream;
134
135 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
136
137protected:
138 void processBumpChargeEvent(const unsigned char& bumper, const unsigned char& charger);
139 void computePoseUpdate(ecl::linear_algebra::Vector3d& pose_update, const ecl::linear_algebra::Vector3d& pose);
140 void filterIRSensor(std::vector<unsigned char>& signal_filt,const std::vector<unsigned char> &signal );
141 void generateDebugMessage(const std::vector<unsigned char>& signal_filt, const unsigned char &bumper, const unsigned char &charger, const std::string& debug_str);
142 void updateVelocity(const std::vector<unsigned char>& signal_filt, const ecl::linear_algebra::Vector3d& pose_update, std::string& debug_str);
143 RobotDockingState::State determineRobotLocation(const std::vector<unsigned char>& signal_filt,const unsigned char& charger);
144 bool validateSignal(const std::vector<unsigned char>& signal_filt, const unsigned int state);
145
146
147 // States
148 void idle(RobotDockingState::State& state,double& vx, double& wz);
149 void scan(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt, const ecl::linear_algebra::Vector3d& pose_update, std::string& debug_str);
150 void find_stream(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt);
151 void get_stream(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt);
152 void aligned(RobotDockingState::State& state,double& vx, double& wz, const std::vector<unsigned char>& signal_filt, std::string& debug_str);
153 void bumped(RobotDockingState::State& nstate,double& nvx, double& nwz, int& bump_count);
154
155
156private:
157 bool is_enabled, can_run;
158
159 RobotDockingState::State state;
160 std::string state_str, debug_str;
161 double vx, wz;
162 std::vector<std::vector<unsigned char> > past_signals;
163 unsigned int signal_window;
164 int bump_remainder;
165 int dock_stabilizer;
166 int dock_detector;
167 double rotated;
168 double min_abs_v;
169 double min_abs_w;
170 ecl::linear_algebra::Vector3d pose_priv;
171
172 void setVel(double v, double w);
173
174 std::string binary(unsigned char number) const;
175
176 std::string debug_output;
177 std::vector<std::string> ROBOT_STATE_STR;
178};
179
180} // namespace kobuki
181
182#endif /* KOBUKI_CORE_DOCK_DRIVE_HPP_ */
Definition dock_drive.hpp:91
void update(const std::vector< unsigned char > &signal, const unsigned char &bumper, const unsigned char &charger, const ecl::linear_algebra::Vector3d &pose)
Updates the odometry from firmware stamps and encoders.
Definition dock_drive.cpp:89
void computePoseUpdate(ecl::linear_algebra::Vector3d &pose_update, const ecl::linear_algebra::Vector3d &pose)
compute pose update from previouse pose and current pose
Definition dock_drive.cpp:124
void filterIRSensor(std::vector< unsigned char > &signal_filt, const std::vector< unsigned char > &signal)
pushing into signal into signal window. and go through the signal window to find what has detected
Definition dock_drive.cpp:145
Definition dock_drive.hpp:53
Definition dock_drive.hpp:68