Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __FLAC_H__
00012 #define __FLAC_H__
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #pragma systemFile
00037
00038 #define STALL_TIME_SLOW 1200
00039 #define STALL_TIME_FAST 800
00040
00041 long _encoderTarget[3] = {0, 0, 0};
00042 long _motorHighPower[3] = {0, 0, 0};
00043 bool _stalled[3] = {false, false, false};
00044
00045
00046
00047 task _FLACcontrolTaskA();
00048 task _FLACcontrolTaskB();
00049 task _FLACcontrolTaskC();
00050
00051
00052 void _FLACcontrolTasks(tMotor _motor, int _highPower, long _encTarget);
00053
00054 bool isDone(tMotor _motor);
00055 void FLACextendLA(tMotor _motor, int _highPower);
00056 void FLACextendLA(tMotor _motor, int _highPower, int distance);
00057 void FLACtretractLA(tMotor _motor, int _highPower);
00058 void FLACtretractLA(tMotor _motor, int _highPower, int distance);
00059 void FLACmoveLA(tMotor _motor, int highpower, int pos);
00060
00061
00062
00063 task _FLACcontrolTaskA() {
00064 long _currentEncVal;
00065 bool _reverse = false;
00066 bool _done = false;
00067 long _lastEncoderCount = 0;
00068 long _stallCounter = 0;
00069
00070
00071
00072 nMotorPIDSpeedCtrl[motorA] = mtrNoReg;
00073
00074
00075 _stalled[motorA] = false;
00076
00077 _currentEncVal = nMotorEncoder[motorA];
00078 _stallCounter = 0;
00079
00080
00081 if (_encoderTarget[motorA] < _currentEncVal)
00082 _reverse = true;
00083
00084 while (!_done) {
00085 _currentEncVal = nMotorEncoder[motorA];
00086
00087
00088 if (_reverse && (_currentEncVal <= _encoderTarget[motorA]))
00089 _done = true;
00090 else if (!_reverse && (_currentEncVal >= _encoderTarget[motorA]))
00091 _done = true;
00092
00093
00094 if (!_done && (abs(_lastEncoderCount - _currentEncVal) > 0)) {
00095 _stallCounter = 0;
00096 } else if (!_done && (_stallCounter > STALL_TIME_SLOW) && _motorHighPower[motorA] < 50) {
00097 _stalled[motorA] = true;
00098 _done = true;
00099 } else if (!_done && (_stallCounter > STALL_TIME_SLOW) && _motorHighPower[motorA] >= 50) {
00100 _stalled[motorA] = true;
00101 _done = true;
00102 } else {
00103 _stallCounter++;
00104 }
00105
00106
00107 if (!_done)
00108 motor[motorA] = (_reverse) ? -_motorHighPower[motorA] : _motorHighPower[motorA];
00109
00110
00111 _lastEncoderCount = _currentEncVal;
00112 EndTimeSlice();
00113 }
00114 motor[motorA] = 0;
00115 }
00116
00117
00118
00119 task _FLACcontrolTaskB() {
00120 long _currentEncVal;
00121 bool _reverse = false;
00122 bool _done = false;
00123 long _lastEncoderCount = 0;
00124 long _stallCounter = 0;
00125
00126
00127
00128 nMotorPIDSpeedCtrl[motorB] = mtrNoReg;
00129
00130
00131 _stalled[motorA] = false;
00132
00133 _currentEncVal = nMotorEncoder[motorB];
00134 _stallCounter = 0;
00135
00136
00137 if (_encoderTarget[motorB] < _currentEncVal)
00138 _reverse = true;
00139
00140 while (!_done) {
00141 _currentEncVal = nMotorEncoder[motorB];
00142
00143
00144 if (_reverse && (_currentEncVal <= _encoderTarget[motorB]))
00145 _done = true;
00146 else if (!_reverse && (_currentEncVal >= _encoderTarget[motorB]))
00147 _done = true;
00148
00149
00150 if (!_done && (abs(_lastEncoderCount - _currentEncVal) > 0)) {
00151 _stallCounter = 0;
00152 } else if (!_done && (_stallCounter > STALL_TIME_SLOW) && _motorHighPower[motorB] < 50) {
00153 _stalled[motorA] = true;
00154 _done = true;
00155 } else if (!_done && (_stallCounter > STALL_TIME_SLOW) && _motorHighPower[motorB] >= 50) {
00156 _stalled[motorA] = true;
00157 _done = true;
00158 } else {
00159 _stallCounter++;
00160 }
00161
00162
00163 if (!_done)
00164 motor[motorB] = (_reverse) ? -_motorHighPower[motorB] : _motorHighPower[motorB];
00165
00166
00167 _lastEncoderCount = _currentEncVal;
00168 EndTimeSlice();
00169 }
00170 motor[motorB] = 0;
00171 }
00172
00173
00174
00175 task _FLACcontrolTaskC() {
00176 long _currentEncVal;
00177 bool _reverse = false;
00178 bool _done = false;
00179 long _lastEncoderCount = 0;
00180 long _stallCounter = 0;
00181
00182
00183
00184 nMotorPIDSpeedCtrl[motorC] = mtrNoReg;
00185
00186
00187 _stalled[motorC] = false;
00188
00189 _currentEncVal = nMotorEncoder[motorC];
00190 _stallCounter = 0;
00191
00192
00193 if (_encoderTarget[motorC] < _currentEncVal)
00194 _reverse = true;
00195
00196 while (!_done) {
00197 _currentEncVal = nMotorEncoder[motorC];
00198
00199
00200 if (_reverse && (_currentEncVal <= _encoderTarget[motorC]))
00201 _done = true;
00202 else if (!_reverse && (_currentEncVal >= _encoderTarget[motorC]))
00203 _done = true;
00204
00205
00206 if (!_done && (abs(_lastEncoderCount - _currentEncVal) > 0)) {
00207 _stallCounter = 0;
00208 } else if (!_done && (_stallCounter > STALL_TIME_SLOW) && _motorHighPower[motorC] < 50) {
00209 _stalled[motorC] = true;
00210 _done = true;
00211 } else if (!_done && (_stallCounter > STALL_TIME_SLOW) && _motorHighPower[motorC] >= 50) {
00212 _stalled[motorC] = true;
00213 _done = true;
00214 } else {
00215 _stallCounter++;
00216 }
00217
00218
00219 if (!_done)
00220 motor[motorC] = (_reverse) ? -_motorHighPower[motorC] : _motorHighPower[motorC];
00221
00222
00223 _lastEncoderCount = _currentEncVal;
00224 EndTimeSlice();
00225 }
00226 motor[motorC] = 0;
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 void _FLACcontrolTasks(tMotor _motor, int _highPower, long _encTarget) {
00239 switch(_motor) {
00240 case motorA:
00241 if (getTaskState(_FLACcontrolTaskA) == taskStateRunning) {
00242 StopTask(_FLACcontrolTaskA);
00243 while(getTaskState(_FLACcontrolTaskA) != taskStateStopped) EndTimeSlice();
00244 wait1Msec(50);
00245 motor[motorA] = 0;
00246 }
00247 _motorHighPower[_motor] = _highPower;
00248 _encoderTarget[_motor] = _encTarget;
00249
00250 StartTask(_FLACcontrolTaskA);
00251 while(getTaskState(_FLACcontrolTaskA) != taskStateRunning) EndTimeSlice();
00252 break;
00253
00254 case motorB:
00255 if (getTaskState(_FLACcontrolTaskB) == taskStateRunning) {
00256 StopTask(_FLACcontrolTaskB);
00257 while(getTaskState(_FLACcontrolTaskB) != taskStateStopped) EndTimeSlice();
00258 wait1Msec(50);
00259 motor[motorB] = 0;
00260 }
00261 _motorHighPower[_motor] = _highPower;
00262 _encoderTarget[_motor] = _encTarget;
00263
00264 StartTask(_FLACcontrolTaskB);
00265 while(getTaskState(_FLACcontrolTaskB) != taskStateRunning) EndTimeSlice();
00266 break;
00267
00268 case motorC:
00269 if (getTaskState(_FLACcontrolTaskC) == taskStateRunning) {
00270 StopTask(_FLACcontrolTaskC);
00271 while(getTaskState(_FLACcontrolTaskC) != taskStateStopped) EndTimeSlice();
00272 wait1Msec(50);
00273 motor[motorA] = 0;
00274 }
00275 _motorHighPower[_motor] = _highPower;
00276 _encoderTarget[_motor] = _encTarget;
00277
00278 StartTask(_FLACcontrolTaskC);
00279 while(getTaskState(_FLACcontrolTaskC) != taskStateRunning) EndTimeSlice();
00280 break;
00281 }
00282 }
00283
00284
00285
00286
00287
00288
00289
00290 bool isDone(tMotor _motor) {
00291 switch(_motor) {
00292 case motorA: return (getTaskState(_FLACcontrolTaskA) == taskStateStopped);
00293 case motorB: return (getTaskState(_FLACcontrolTaskB) == taskStateStopped);
00294 case motorC: return (getTaskState(_FLACcontrolTaskC) == taskStateStopped);
00295 }
00296 return false;
00297 }
00298
00299
00300
00301
00302
00303
00304
00305 bool isStalled(tMotor _motor) {
00306 return _stalled[_motor];
00307 }
00308
00309
00310
00311
00312
00313
00314
00315 void FLACextendLA(tMotor _motor, int _highPower) {
00316 _FLACcontrolTasks(_motor, _highPower, -210);
00317 _stalled[_motor] = false;
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327 void FLACextendLA(tMotor _motor, int _highPower, int distance) {
00328 _FLACcontrolTasks(_motor, _highPower, nMotorEncoder[_motor] - distance);
00329 _stalled[_motor] = false;
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339 void FLACtretractLA(tMotor _motor, int _highPower) {
00340 _FLACcontrolTasks(_motor, _highPower, 210);
00341 _stalled[_motor] = false;
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351 void FLACtretractLA(tMotor _motor, int _highPower, int distance) {
00352 _FLACcontrolTasks(_motor, _highPower, nMotorEncoder[_motor] + distance);
00353 _stalled[_motor] = false;
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363 void FLACmoveLA(tMotor _motor, int highpower, int pos) {
00364 _FLACcontrolTasks(_motor, highpower, pos);
00365 }
00366
00367 #endif // __FLAC_H__
00368
00369
00370
00371
00372
00373