00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "BeoSub/BeoSubSim.H"
00039 #include "Devices/HMR3300.H"
00040 #include "BeoSub/BeoSubBallast.H"
00041 #include "BeoSub/BeoSubIMU.H"
00042 #include "Util/MathFunctions.H"
00043 #include "Devices/IEEE1394grabber.H"
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 BeoSubListener(BeoSubSim *sub) : itsBeoSub(sub) { }
00056
00057
00058 virtual ~BeoSubListener() { }
00059
00060
00061 virtual void event(const BeoChipEventType t, const int valint,
00062 const float valfloat)
00063 {
00064 //LDEBUG("Event: %d val = %d, fval = %f", int(t), valint, valfloat);
00065 itsBeoSub->dispatchBeoChipEvent(t, valint, valfloat);
00066 }
00067
00068 private:
00069 BeoSubSim *itsBeoSub; //!< pointer to our master
00070 };*/
00071
00072
00073
00074
00075
00076
00077 HMRlistener(BeoSubOneBal *sub) : itsBeoSub(sub) { }
00078
00079
00080 virtual ~HMRlistener() {};
00081
00082
00083 virtual void newData(const Angle heading, const Angle pitch,
00084 const Angle roll)
00085 {
00086 //LDEBUG("<Heading=%f Pitch=%f Roll=%f>", heading.getVal(),
00087 // pitch.getVal(), roll.getVal());
00088 itsBeoSub->updateCompass(heading, pitch, roll);
00089 }
00090
00091 private:
00092 BeoSubSim *itsBeoSub;
00093 };*/
00094
00095
00096
00097 BeoSubSim::BeoSubSim(OptionManager& mgr) :
00098 BeoSub(mgr),
00099 itsLeftThrusterServoNum("BeoSubLeftThrusterServoNum", this, 3),
00100 itsRightThrusterServoNum("BeoSubRightThrusterServoNum", this, 2),
00101 itsThrustLeft(0),
00102 itsThrustRight(0),
00103 relDistance(0),
00104 isStrafe(false),
00105 imageCounter(0),
00106 itsCurrentZ(0),
00107 itsCurrentX(0),
00108 upImageFlag(false),
00109 frontImageFlag(false),
00110 downImageFlag(false),
00111 itsDepthSensor(10),
00112 itsHeadingSensor(10),
00113 itsPitchSensor(10),
00114 itsDepthPID(0.1F, 0.001F, 0.1F, 1.5F, 1.5F),
00115 itsHeadingPID(0.1F, 0.001F, 0.1F, Angle(170.0), Angle(170.0)),
00116 itsPitchPID(0.1F, 0.001F, 0.1F, Angle(170.0), Angle(170.0)),
00117 itsDepthPIDon(false),
00118 itsHeadingPIDon(false),
00119 itsPitchPIDon(false)
00120
00121 {
00122
00123 }
00124
00125
00126 BeoSubSim::~BeoSubSim()
00127 { }
00128
00129
00130 void BeoSubSim::start1()
00131 {
00132
00133
00134
00135
00136 BeoSub::start1();
00137 }
00138
00139
00140 void BeoSubSim::start2()
00141 {
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 CLINFO("filling ballasts...");
00158 setBallasts(1.0F, 1.0F, false); sleep(4);
00159 CLINFO("emptying ballasts...");
00160 setBallasts(0.0F, 0.0F, true);
00161
00162
00163 itsHeadingPIDon = true;
00164 itsPitchPIDon = true;
00165 }
00166
00167
00168 void BeoSubSim::updateCompass(const Angle heading, const Angle pitch,
00169 const Angle roll)
00170 {
00171
00172 double t = itsMasterClock.getSecs();
00173
00174
00175 pthread_mutex_lock(&itsLock);
00176 itsCurrentAttitude.heading = heading;
00177 itsCurrentAttitude.pitch = pitch;
00178
00179 itsCurrentAttitude.compassTime = t;
00180
00181
00182
00183
00184
00185 pthread_mutex_unlock(&itsLock);
00186 }
00187
00188
00189
00190 void BeoSubSim::updateDepth(const float depth)
00191 {
00192
00193 double t = itsMasterClock.getSecs();
00194
00195
00196 pthread_mutex_lock(&itsLock);
00197 itsCurrentAttitude.depth = depth;
00198 itsCurrentAttitude.pressureTime = t;
00199
00200
00201 itsDepthSensor.newMeasurement(depth);
00202
00203 pthread_mutex_unlock(&itsLock);
00204 }
00205
00206 void BeoSubSim::updatePosition(const float z, const float x) {
00207 itsCurrentZ = z;
00208 itsCurrentX = x;
00209 }
00210
00211 void BeoSubSim::thrust(const float leftval, const float rightval)
00212 {
00213 itsThrustLeft = leftval;
00214 itsThrustRight = rightval;
00215 }
00216
00217
00218 void BeoSubSim::getThrusters(float& leftval, float& rightval) const
00219 { leftval = itsThrustLeft; rightval = itsThrustRight; }
00220
00221
00222 void BeoSubSim::setFrontBallast(const float val, const bool blocking)
00223 { }
00224
00225
00226 void BeoSubSim::setRearBallast(const float val, const bool blocking)
00227 { }
00228
00229
00230 void BeoSubSim::setBallasts(const float f, const float r,
00231 const bool blocking)
00232 { }
00233
00234
00235 float BeoSubSim::getFrontBallast() const
00236 { return 0;}
00237
00238
00239 float BeoSubSim::getRearBallast() const
00240 { return 0; }
00241
00242
00243 void BeoSubSim::getBallasts(float& f, float& r) const
00244 { }
00245
00246
00247 void BeoSubSim::dropMarker(const bool blocking)
00248 {
00249 LFATAL("unimplemented!");
00250 }
00251
00252
00253 void BeoSubSim::dispatchBeoChipEvent(const BeoChipEventType t,
00254 const int valint,
00255 const float valfloat)
00256 {
00257
00258 }
00259
00260
00261 Image< PixRGB<byte> > BeoSubSim::grabImage(const enum BeoSubCamera cam) const
00262 {
00263 if(cam == BEOSUBCAMFRONT) {
00264 const_cast<BeoSubSim *>(this)-> upImageFlag = true;
00265 const_cast<BeoSubSim *>(this)-> imageCounter++;
00266 sleep(1);
00267 return Raster::ReadRGB(sformat("upimage%d.ppm", imageCounter));
00268 }
00269 if(cam == BEOSUBCAMDOWN) {
00270 const_cast<BeoSubSim *>(this)-> downImageFlag = true;
00271 const_cast<BeoSubSim *>(this)-> imageCounter++;
00272 sleep(1);
00273 return Raster::ReadRGB(sformat("downimage%d.ppm", imageCounter));
00274 }
00275 if(cam == BEOSUBCAMUP) {
00276 const_cast<BeoSubSim *>(this)-> frontImageFlag = true;
00277 const_cast<BeoSubSim *>(this)-> imageCounter++;
00278 sleep(5);
00279
00280 return Raster::ReadRGB(sformat("upimage%d.ppm", imageCounter));
00281 }
00282
00283
00284 LERROR("Wrong camera %d -- RETURNING EMPTY IMAGE", int(cam));
00285 return Image< PixRGB<byte> >();
00286
00287 }
00288
00289
00290 void BeoSubSim::advanceRel(const float relDist, const bool stop) {
00291 float value = relDistance = relDist;
00292 if(relDist > 1.0F) value = 1.0F;
00293 if(relDist < -1.0F) value = -1.0F;
00294 thrust(value, value);
00295 usleep((int) (100000));
00296 }
00297
00298 void BeoSubSim::strafeRel(const float relDist) {
00299 relDistance = relDist;
00300 isStrafe = true;
00301 usleep((int) (100000));
00302 }
00303
00304 void BeoSubSim::turnAbs(const Angle finalHeading, const bool blocking) {
00305 itsTargetAttitude.heading = finalHeading;
00306 }
00307
00308 void BeoSubSim::turnRel(const Angle relHeading, const bool blocking) {
00309
00310 itsTargetAttitude.heading = itsCurrentAttitude.heading + relHeading;
00311 sleep(1);
00312 }
00313
00314 void BeoSubSim::turnOpen(const Angle relHeading, const bool blocking) {
00315
00316 itsTargetAttitude.heading = itsCurrentAttitude.heading + relHeading;
00317 sleep(1);
00318 }
00319
00320 void BeoSubSim::diveAbs(const float finalDepth, const bool blocking) {
00321 itsTargetAttitude.depth = finalDepth;
00322 }
00323
00324 void BeoSubSim::diveRel(const float relDepth, const bool blocking) {
00325 itsTargetAttitude.depth = itsCurrentAttitude.depth + relDepth;
00326 }
00327
00328
00329 void BeoSubSim::useDepthPID(const bool useit)
00330 { itsDepthPIDon = useit; }
00331
00332
00333 void BeoSubSim::useHeadingPID(const bool useit)
00334 { itsHeadingPIDon = useit; }
00335
00336
00337 void BeoSubSim::usePitchPID(const bool useit)
00338 { itsPitchPIDon = useit; }
00339
00340
00341
00342
00343
00344
00345