Changeset 716
- Timestamp:
- 07/20/09 05:01:43 (4 years ago)
- Location:
- branches/atorf/NXC/MotorControl2
- Files:
-
- 2 modified
-
ControllerCore.nxc (modified) (10 diffs)
-
MotorControl20.nxc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/NXC/MotorControl2/ControllerCore.nxc
r713 r716 56 56 57 57 58 safecall void_ADD_MOTORNAME(WaitUntilMotorStopped)(const byte &port) {58 safecall bool _ADD_MOTORNAME(WaitUntilMotorStopped)(const byte &port) { 59 59 /* 60 RETURNS true if stopped by direct command 61 60 62 This function waits until a braked motor has come to a full stop. The "trick" is 61 63 that it's not only beeing waited until the motor has stopped for a very short … … 90 92 }//end if 91 93 lastPos = curPos; 94 95 // check if direct command stopped us (indicated by TachoLimit...) 96 if ((MotorTachoLimit(port) == 0) && (MotorPower(port) == 0)) { 97 //direct command must have stopped us! 98 #ifdef ENABLEDEBUGGING_LCD_SLOW_ANTIBUG 99 TextOut(0, DebugLinePos[port], "ABORTED(wait4Stop) "); 100 Wait(300); 101 #endif 102 return true; 103 }//end if 104 105 92 106 93 107 if (CurrentTick() >= timeoutTick) { … … 96 110 }//end while 97 111 112 return false; 98 113 99 114 }//end void … … 111 126 112 127 // note how RunMotor2 doesn't need to be inline and takes 1 more argument... 128 // RETURN is wether a direct command stopped us!!!! 113 129 #ifdef RUNMOTOR2_SYNCMODE 114 voidRunMotor2(const byte &port, const int &power, const long &tacholimit, const bool &speedreg, const bool &holdbrake, const bool &smoothstart, const byte &port2) {130 bool RunMotor2(const byte &port, const int &power, const long &tacholimit, const bool &speedreg, const bool &holdbrake, const bool &smoothstart, const byte &port2) { 115 131 #else 116 inline void_ADD_MOTORNAME(RunMotor) (const byte &port, const int &power, const long &tacholimit, const bool &speedreg, const bool &holdbrake, const bool &smoothstart) {132 inline bool _ADD_MOTORNAME(RunMotor) (const byte &port, const int &power, const long &tacholimit, const bool &speedreg, const bool &holdbrake, const bool &smoothstart) { 117 133 #endif 118 134 … … 371 387 Wait(300); 372 388 #endif 373 return ;389 return true; 374 390 }//end if 375 391 … … 702 718 Wait(300); 703 719 #endif 704 return ;720 return true; 705 721 }//end if 706 722 … … 753 769 break; 754 770 }//end if 771 // even for syncmode, only check first motor... 772 if (MotorTachoLimit(port) == 0) { 773 //direct command must have stopped us! 774 #ifdef ENABLEDEBUGGING_LCD_SLOW_ANTIBUG 775 TextOut(0, DebugLinePos[port], "ABORTED(endgame) "); 776 Wait(300); 777 #endif 778 return true; 779 }//end if 755 780 #ifdef ENABLEDEBUGGING_LCD 756 781 endgameLoopCount++; … … 768 793 break; 769 794 }//end if 795 // even for syncmode, only check first motor... 796 if (MotorTachoLimit(port) == 0) { 797 //direct command must have stopped us! 798 #ifdef ENABLEDEBUGGING_LCD_SLOW_ANTIBUG 799 TextOut(0, DebugLinePos[port], "ABORTED(endgame) "); 800 Wait(300); 801 #endif 802 return true; 803 }//end if 804 770 805 #ifdef ENABLEDEBUGGING_LCD 771 806 endgameLoopCount++; … … 833 868 #endif 834 869 835 _ADD_MOTORNAME(WaitUntilMotorStopped)(port); 870 bool stoppedByDirectCmd = false; 871 stoppedByDirectCmd = _ADD_MOTORNAME(WaitUntilMotorStopped)(port); 836 872 837 873 … … 900 936 TextOut(0, DebugLinePos[port], "FINISHED "); 901 937 #endif 938 939 // return wether a direct command stopped us... 940 return stoppedByDirectCmd; 941 902 942 903 943 }//end void -
branches/atorf/NXC/MotorControl2/MotorControl20.nxc
r711 r716 148 148 taskArunning = true; 149 149 150 RunMotorA(OUT_A, motorParamsA.power, motorParamsA.tacholimit, motorParamsA.speedreg, motorParamsA.holdbrake, motorParamsA.smoothstart); 150 bool stoppedByDirectCmd; 151 stoppedByDirectCmd = RunMotorA(OUT_A, motorParamsA.power, motorParamsA.tacholimit, motorParamsA.speedreg, motorParamsA.holdbrake, motorParamsA.smoothstart); 152 153 // if we exited from external NXTMotor.Stop command, we might've overwritten 154 // the power value before exiting the main controller loop, so restore defined 155 // end state here again: 156 if (stoppedByDirectCmd) { 157 if (MotorRegulation(OUT_A) == OUT_REGMODE_SPEED) { 158 MotorBrake(OUT_A); 159 } else { 160 MotorOff(OUT_A); 161 }//end if 162 }//end if 151 163 152 164 taskArunning = false; … … 167 179 #endif 168 180 169 RunMotorB(OUT_B, motorParamsB.power, motorParamsB.tacholimit, motorParamsB.speedreg, motorParamsB.holdbrake, motorParamsB.smoothstart); 170 181 bool stoppedByDirectCmd; 182 stoppedByDirectCmd = RunMotorB(OUT_B, motorParamsB.power, motorParamsB.tacholimit, motorParamsB.speedreg, motorParamsB.holdbrake, motorParamsB.smoothstart); 183 184 // if we exited from external NXTMotor.Stop command, we might've overwritten 185 // the power value before exiting the main controller loop, so restore defined 186 // end state here again: 187 if (stoppedByDirectCmd) { 188 if (MotorRegulation(OUT_B) == OUT_REGMODE_SPEED) { 189 MotorBrake(OUT_B); 190 } else { 191 MotorOff(OUT_B); 192 }//end if 193 }//end if 171 194 172 195 #ifdef ENABLEDEBUGGING_OLDLCDTIMING … … 199 222 taskCrunning = true; 200 223 201 RunMotorC(OUT_C, motorParamsC.power, motorParamsC.tacholimit, motorParamsC.speedreg, motorParamsC.holdbrake, motorParamsC.smoothstart); 202 224 bool stoppedByDirectCmd; 225 stoppedByDirectCmd = RunMotorC(OUT_C, motorParamsC.power, motorParamsC.tacholimit, motorParamsC.speedreg, motorParamsC.holdbrake, motorParamsC.smoothstart); 226 227 // if we exited from external NXTMotor.Stop command, we might've overwritten 228 // the power value before exiting the main controller loop, so restore defined 229 // end state here again: 230 if (stoppedByDirectCmd) { 231 if (MotorRegulation(OUT_C) == OUT_REGMODE_SPEED) { 232 MotorBrake(OUT_C); 233 } else { 234 MotorOff(OUT_C); 235 }//end if 236 }//end if 237 203 238 taskCrunning = false; 204 239 … … 213 248 taskSyncRunning = true; 214 249 #endif 250 251 bool stoppedByDirectCmd; 215 252 216 253 if (SyncPorts == 3) { // OUT_AB … … 219 256 taskArunning = true; 220 257 taskBrunning = true; 221 RunMotor2(OUT_A, motorParamsSync.power, motorParamsSync.tacholimit, false, motorParamsSync.holdbrake, motorParamsSync.smoothstart, OUT_B); 258 stoppedByDirectCmd = RunMotor2(OUT_A, motorParamsSync.power, motorParamsSync.tacholimit, false, motorParamsSync.holdbrake, motorParamsSync.smoothstart, OUT_B); 259 if (stoppedByDirectCmd) { 260 if (MotorRegulation(OUT_A) == OUT_REGMODE_SPEED) { 261 MotorBrake2(OUT_A, OUT_B); 262 } else { 263 MotorOff2(OUT_A, OUT_B); 264 }//end if 265 }//end if 222 266 taskArunning = false; 223 267 taskBrunning = false; … … 229 273 taskArunning = true; 230 274 taskCrunning = true; 231 RunMotor2(OUT_A, motorParamsSync.power, motorParamsSync.tacholimit, false, motorParamsSync.holdbrake, motorParamsSync.smoothstart, OUT_C); 275 stoppedByDirectCmd = RunMotor2(OUT_A, motorParamsSync.power, motorParamsSync.tacholimit, false, motorParamsSync.holdbrake, motorParamsSync.smoothstart, OUT_C); 276 if (stoppedByDirectCmd) { 277 if (MotorRegulation(OUT_A) == OUT_REGMODE_SPEED) { 278 MotorBrake2(OUT_A, OUT_C); 279 } else { 280 MotorOff2(OUT_A, OUT_C); 281 }//end if 282 }//end if 232 283 taskArunning = false; 233 284 taskCrunning = false; … … 239 290 taskBrunning = true; 240 291 taskCrunning = true; 241 RunMotor2(OUT_B, motorParamsSync.power, motorParamsSync.tacholimit, false, motorParamsSync.holdbrake, motorParamsSync.smoothstart, OUT_C); 292 stoppedByDirectCmd = RunMotor2(OUT_B, motorParamsSync.power, motorParamsSync.tacholimit, false, motorParamsSync.holdbrake, motorParamsSync.smoothstart, OUT_C); 293 if (stoppedByDirectCmd) { 294 if (MotorRegulation(OUT_B) == OUT_REGMODE_SPEED) { 295 MotorBrake2(OUT_B, OUT_C); 296 } else { 297 MotorOff2(OUT_B, OUT_C); 298 }//end if 299 }//end if 242 300 taskBrunning = false; 243 301 taskCrunning = false; … … 767 825 MotorOff(OUT_B); 768 826 MotorOff(OUT_C); 769 PlayTone(440, 100);827 PlayTone(440, 500); 770 828 Wait(500); 829 830 831 TextOut(5,LCD_LINE7, "EMERGENCY STOP ", false); 832 TextOut(2,LCD_LINE8, "Restart program! ", false); 833 Wait(2000); 834 StopAllTasks(); 835 836 /* 771 837 // keep 772 838 while(ButtonPressed(BTNCENTER, false)) { … … 777 843 Wait(500); 778 844 }//end while 845 846 // purge incoming queue... 847 in = "..."; 848 while(StrLen(in) > 0) { 849 ReceiveRemoteString(INBOX, true, in); 850 }//end while 851 in = ""; 852 853 // manually reset task-semaphores 854 // not very clean, but this button is for emergencies anyway... 855 taskArunning = false; 856 taskBrunning = false; 857 taskCrunning = false; 858 859 // reset counters for a nice clean start 860 ResetErrorCorrectionAndBlockCount(OUT_A); 861 ResetErrorCorrectionAndBlockCount(OUT_B); 862 ResetErrorCorrectionAndBlockCount(OUT_C); 863 */ 779 864 }//end if 780 865
