BeoPilot.H
00001 #include "Component/ModelComponent.H"
00002 #include "Component/ModelParam.H"
00003 #include "Media/FrameSeries.H"
00004 #include "Transport/FrameInfo.H"
00005 #include "Raster/GenericFrame.H"
00006 #include "Image/Image.H"
00007 #include "Image/DrawOps.H"
00008 #include "Image/Point3D.H"
00009 #include "GUI/XWinManaged.H"
00010 #include "GUI/ImageDisplayStream.H"
00011 #include "Robots/RobotBrain/RobotBrainComponent.H"
00012 #include "Util/Timer.H"
00013 #include "GUI/SimpleMeter.H"
00014
00015 #include "Ice/RobotBrainObjects.ice.H"
00016 #include "Ice/RobotSimEvents.ice.H"
00017 #include <IceUtil/Thread.h>
00018
00019 #include <vector>
00020 #include <deque>
00021 #include <list>
00022
00023 #include "Devices/Serial.H"
00024 #include "Controllers/PID.H"
00025
00026
00027 typedef struct {
00028 double dist,angle;
00029 } sonarData;
00030
00031 typedef struct{
00032 float time,transVel,rotVel,encoderX,encoderY,encoderOri,rcTransVel,rcRotVel;
00033 int rcMode;
00034 } motorData;
00035 typedef struct{
00036 float time;
00037 std::string imagePath ;
00038 } imageData;
00039
00040
00041
00042
00043
00044
00045 template<typename T>
00046 class Point3DwithColor
00047 {
00048 public:
00049
00050
00051 T x,y,z;
00052 PixRGB<byte> color;
00053 Point3DwithColor(const T xx,const T yy, const T zz)
00054 {
00055 x = xx;y=yy;z=zz;
00056 color = PixRGB<byte>(0,0,0);
00057 }
00058
00059 ~Point3DwithColor(){};
00060 };
00061 template<typename T>
00062 class velocityQue{
00063
00064 velocityQue(const velocityQue&);
00065 velocityQue& operator=(const velocityQue&);
00066
00067 int m_size;
00068
00069 int m_total;
00070 std::deque<T> m_data;
00071
00072 public:
00073 velocityQue():m_size(0)
00074 {
00075 }
00076 velocityQue(int n):m_size(0)
00077 {
00078 m_size = n;
00079 }
00080 void add(const T& data){
00081
00082 if(m_total >= m_size)
00083 {
00084 m_data.pop_back();
00085 }else{
00086 m_total++;
00087 }
00088 m_data.push_front(data);
00089 }
00090 std::vector<T> getVector()
00091 {
00092 return std::vector<T>(m_data.begin(),m_data.end());
00093 }
00094 ~velocityQue(){}
00095 };
00096
00097
00098
00099 class BeoPilot : public RobotBrainComponent
00100 {
00101 public:
00102
00103 BeoPilot(int id, OptionManager& mgr,
00104 const std::string& descrName = "BeoPilot",
00105 const std::string& tagName = "BeoPilot");
00106
00107 ~BeoPilot();
00108
00109
00110
00111
00112 virtual void evolve();
00113
00114 virtual void updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00115 const Ice::Current&);
00116
00117 virtual void registerTopics();
00118
00119 void checkLogFile();
00120
00121
00122
00123 void loadFromLogFile();
00124 void start3();
00125
00126
00127 void updateGUI();
00128
00129
00130 void SetMotors(float motor1speed, float motor2speed);
00131
00132
00133 unsigned char getRCStatus();
00134
00135
00136 unsigned int getRCChannel(int channel);
00137
00138
00139 unsigned char getRCEnabled();
00140
00141
00142 unsigned int getRCSpeed();
00143
00144
00145 void UpdateRCStatus();
00146
00147
00148 void resetEncoder();
00149
00150
00151 void UpdatePosition(void);
00152
00153
00154 void getCurrentLogData(void);
00155
00156
00157 void reDrawMap(double scale);
00158
00159
00160 void drawAllMap(void);
00161 int file_exists(const char * fileName)
00162 {
00163 struct stat buf;
00164 int i = stat(fileName,&buf);
00165 if(i == 0)
00166 return 1;
00167 return 0;
00168
00169
00170 }
00171 private:
00172 nub::soft_ref<Serial> itsSerial;
00173 Timer itsSerialTimer;
00174 IceUtil::Mutex itsSerialMutex;
00175
00176 int itsCurrMessageID;
00177
00178
00179
00180
00181 std::vector<motorData> itsLogData;
00182 std::vector<imageData> itsLogImageData;
00183 int itsCurrentTimeIndex;
00184 int itsCurrentTimeIndex2;
00185 Timer itsLogTimer;
00186 bool itsLoadFromLogFile;
00187 int itsLogRemoteMode;
00188 double itsLogLeftMotorVelocity;
00189 double itsLogRightMotorVelocity;
00190
00191 Point3DwithColor<double> itsLogPosition;
00192 Point3DwithColor<double> itsLogDiffPosition;
00193
00194
00195
00196
00197
00198 IceUtil::Mutex itsSpeedMutex;
00199 double itsForwardSpeedReq;
00200 double itsRotationalSpeedReq;
00201 double itsForwardSpeed;
00202 double itsRotationalSpeed;
00203
00204 double itsRcTransSpeed;
00205 double itsRcRotSpeed;
00206 double itsRcTransSpeedCapped;
00207 double itsRcRotSpeedCapped;
00208
00209 double itsTransCap;
00210 double itsRotCap;
00211
00212 std::vector<int> itsRCChannels;
00213 int itsEmergencyMode;
00214 int itsRemoteMode;
00215 float itsMotor1Speed;
00216 float itsMotor2Speed;
00217 int itsLeftEncoder;
00218 int itsRightEncoder;
00219 int itsLastLeftEncoder;
00220 int itsLastRightEncoder;
00221 Point3DwithColor<double> itsPosition;
00222 Point3DwithColor<double> itsDiffPosition;
00223 Image<PixRGB<byte> > itsMapImage;
00224 Timer itsEncoderTimer;
00225 double itsLeftMotorVelocity;
00226 double itsRightMotorVelocity;
00227
00228 PID<float> itsPidLeft;
00229 PID<float> itsPidRight;
00230
00231
00232
00233
00234 IceUtil::Mutex itsSonarMutex;
00235 std::vector<double> itsSonarReadings;
00236 std::vector<double> itsSonarAngles;
00237 Timer itsSonarTimer;
00238 bool itsSonarProxAlert;
00239 float itsSonarTimeout;
00240
00241
00242
00243
00244
00245 Image<PixRGB<byte> > itsControlImage;
00246 Image<PixRGB<byte> > itsDispImage;
00247 Image<PixRGB<byte> > itsDispCameraImage;
00248 XWinManaged itsMeterXwin;
00249
00250 Timer itsDisplayTimer;
00251 float itsDisplayUpdateRate;
00252 float itsMapScale;
00253 std::vector<SimpleMeter> itsChannelMeters;
00254 velocityQue<float> itsVelocityQue;
00255 velocityQue<float> itsVelocityTargetQue;
00256 std::vector<Point3DwithColor<double> >itsLogPositionMap;
00257 std::vector<Point3DwithColor<double> >itsPositionMap;
00258
00259
00260
00261 OModelParam<float> itsMinimumSafeDistance;
00262 OModelParam<float> itsMaxSpeed;
00263 OModelParam<bool> itsIgnoreSonar;
00264 OModelParam<std::string> itsLogFile;
00265 OModelParam<int> itsReplaySpeed;
00266
00267 };
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277