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 "SeaBee/MovementController.H"
00039 #include "Component/ModelOptionDef.H"
00040
00041
00042
00043 MovementController::MovementController(OptionManager& mgr,
00044 nub::soft_ref<SubController> subController,
00045 const std::string& descrName,
00046 const std::string& tagName):
00047
00048 ModelComponent(mgr, descrName, tagName),
00049 itsDepthErrThresh(&OPT_DepthErrThresh, this, ALLOW_ONLINE_CHANGES),
00050 itsHeadingErrThresh(&OPT_HeadingErrThresh, this, ALLOW_ONLINE_CHANGES),
00051 pipeP("pipeP", this, 0, ALLOW_ONLINE_CHANGES),
00052 pipeI("pipeI", this, 0, ALLOW_ONLINE_CHANGES),
00053 pipeD("pipeD", this, 0, ALLOW_ONLINE_CHANGES),
00054 itsPipePID(pipeP.getVal(), pipeI.getVal(), pipeD.getVal(), -20, 20,
00055 5, 0, 0, 100, -100, 150, true, 1, 25, -25),
00056 setDiveValue(&OPT_DiveValue, this, ALLOW_ONLINE_CHANGES),
00057 setGoStraightTimeValue(&OPT_GoStraightTime, this, ALLOW_ONLINE_CHANGES),
00058 setSpeedValue(&OPT_SpeedValue, this, ALLOW_ONLINE_CHANGES),
00059 setHeadingValue(&OPT_HeadingValue, this, ALLOW_ONLINE_CHANGES),
00060 setRelative("setRelative", this, false, ALLOW_ONLINE_CHANGES),
00061 setTimeout(&OPT_TimeoutValue, this, ALLOW_ONLINE_CHANGES),
00062 itsSubController(subController)
00063 {
00064
00065 }
00066
00067
00068 MovementController::~MovementController()
00069 {
00070
00071 }
00072
00073
00074 bool MovementController::dive(int depth, bool relative, int timeout)
00075 {
00076 LINFO("Dive to depth: %d", depth);
00077 if(relative)
00078 {
00079 int currentDepth = itsSubController->getDepth();
00080
00081
00082 if(currentDepth == -1)
00083 sleep(1);
00084
00085 currentDepth = itsSubController->getDepth();
00086 if(currentDepth == -1)
00087 return false;
00088
00089
00090 itsSubController->setDepth(depth + currentDepth);
00091 LINFO("Diving to depth: %d", currentDepth + depth);
00092 }
00093 else
00094 {
00095 itsSubController->setDepth(depth);
00096 }
00097
00098 int time = 0;
00099
00100 while(itsSubController->getDepthErr() > itsDepthErrThresh.getVal())
00101 {
00102
00103 usleep(3000);
00104 time++;
00105
00106
00107
00108 }
00109
00110 return true;
00111 }
00112
00113
00114 bool MovementController::goStraight(int speed, int time)
00115 {
00116 LINFO("Go Straight");
00117 itsSubController->setHeading(itsSubController->getHeading());
00118 itsSubController->setSpeed(speed);
00119 sleep(time);
00120 itsSubController->setSpeed(0);
00121 return true;
00122 }
00123
00124
00125 bool MovementController::setHeading(int heading, bool relative, int timeout)
00126 {
00127 if(relative)
00128 {
00129 itsSubController->setHeading(heading + itsSubController->getHeading());
00130 }
00131 else
00132 {
00133 itsSubController->setHeading(heading);
00134 }
00135
00136 int time = 0;
00137
00138 while(itsSubController->getHeadingErr() > itsHeadingErrThresh.getVal())
00139 {
00140
00141 if(time++ > timeout) return false;
00142
00143 }
00144
00145 return true;
00146 }
00147
00148
00149 int MovementController::trackPipe(const Point2D<int>& pointToTrack,
00150 const Point2D<int>& desiredPoint)
00151 {
00152 float pipeCorrection = (float)itsPipePID.update(pointToTrack.i, desiredPoint.i);
00153
00154
00155
00156
00157 itsSubController->setTurningSpeed(pipeCorrection);
00158
00159 return abs(pointToTrack.i - desiredPoint.i);
00160 }
00161
00162
00163 void MovementController::paramChanged(ModelParamBase* const param,
00164 const bool valueChanged,
00165 ParamClient::ChangeStatus* status)
00166 {
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 if (param == &pipeP && valueChanged)
00190 itsPipePID.setPIDPgain(pipeP.getVal());
00191 else if(param == &pipeI && valueChanged)
00192 itsPipePID.setPIDIgain(pipeI.getVal());
00193 else if(param == &pipeD && valueChanged)
00194 itsPipePID.setPIDDgain(pipeD.getVal());
00195
00196 }
00197
00198
00199
00200
00201
00202