Changeset 663
- Timestamp:
- 07/15/09 06:26:14 (4 years ago)
- Location:
- branches/atorf/NXC/MotorControl2
- Files:
-
- 4 modified
-
Controller.nxc (modified) (2 diffs)
-
ControllerCore.nxc (modified) (5 diffs)
-
MotorControl20.nxc (modified) (4 diffs)
-
MotorFunctions.nxc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/NXC/MotorControl2/Controller.nxc
r660 r663 64 64 // lower this time cautiously, if the motor stalls during this loop, probably 65 65 // for a good reason 66 #define ENDGAME_INNERLOOP_TIMEOUT 600 //PARAM66 #define ENDGAME_INNERLOOP_TIMEOUT 500 //PARAM 67 67 68 68 // enable this to free/sleep 1ms of CPU time every waiting-loop iteration … … 98 98 // before, rampup is finished. Multiply this with LOOP_DURATION to get the maximum 99 99 // starting/rampup time for the power=100 case... 100 #define SMOOTHSTARTSTEPS 20100 #define SMOOTHSTARTSTEPS 18 101 101 102 102 -
branches/atorf/NXC/MotorControl2/ControllerCore.nxc
r658 r663 135 135 // * tacholimit already... 136 136 137 // do not yet enable speedreg 137 138 //TODO why exactly do we only power up to +/-1 here? couldn't it be full speed already? 139 // maybe it's because for speed monitor initialization, we use TachoCount and need it to remain 140 // constant etc? 138 141 #ifdef RUNMOTOR2_SYNCMODE 142 //avoid already synced motors (that doesn't work as we know...) 143 until((MotorRegulation(port) == OUT_REGMODE_IDLE) && (MotorRegulation(port2) == OUT_REGMODE_IDLE)) { 144 // repeatedly setting this is not nice, but so 145 // we don't need a timeout...! 146 MotorOff(port); 147 MotorOff(port2); 148 // make sure VM applies our settings 149 Wait(1); 150 }//end until 139 151 MotorCmdDoubleReset(port, powerSgn, tacholimit, port2); 140 152 #else 141 MotorCmdSingleReset(port, powerSgn, tacholimit, false);153 MotorCmdSingleReset(port, powerSgn, tacholimit, speedreg); 142 154 #endif 143 155 … … 241 253 // - direct command stopped us? 242 254 // this is like an emergency-check to see if endgame should be enabled? 243 //TODO seems obsolete! 255 //TODO do we need this below? 256 /* 244 257 if ( abs(tachoTarget - MotorTachoCount(port)) >= 2 ) { 245 258 // we are almost already there :-) 246 259 // or even too far :-/ 247 260 }//end if 248 261 */ 249 262 250 263 if ( MotorPower(port) == 0 ) { … … 291 304 // when rampup is done 292 305 if (rampupLoopCount >= SMOOTHSTARTSTEPS) { 293 UpdatePower(port, power); 294 #ifdef RUNMOTOR2_SYNCMODE 295 UpdatePower(port2, power); 296 #endif 297 if (speedreg) { EnableSpeedRegWhithMotorOn(port); } 306 if (speedreg) { 307 //there's no speedreg for synced driving... 308 UpdatePowerAndEnableSpeedReg(port, power); 309 } else { 310 UpdatePower(port, power); 311 #ifdef RUNMOTOR2_SYNCMODE 312 UpdatePower(port2, power); 313 #endif 314 }//end if 298 315 curStage = STAGE_DRIVING; 299 316 } else { … … 302 319 // if power < 100 we might be done sooner: 303 320 if (newPower > absPower) { 304 UpdatePower(port, power); 305 #ifdef RUNMOTOR2_SYNCMODE 306 UpdatePower(port2, power); 307 #endif 308 if (speedreg) { EnableSpeedRegWhithMotorOn(port); } 321 if (speedreg) { 322 //there's no speedreg for synced driving... 323 UpdatePowerAndEnableSpeedReg(port, power); 324 } else { 325 UpdatePower(port, power); 326 #ifdef RUNMOTOR2_SYNCMODE 327 UpdatePower(port2, power); 328 #endif 329 }//end if 309 330 curStage = STAGE_DRIVING; 310 331 } else { … … 320 341 321 342 // full power right away 322 UpdatePower(port, power); 323 #ifdef RUNMOTOR2_SYNCMODE 324 UpdatePower(port2, power); 325 #endif 326 //there's no speedreg for synced driving... 327 if (speedreg) { EnableSpeedRegWhithMotorOn(port); } 343 if (speedreg) { 344 //there's no speedreg for synced driving... 345 UpdatePowerAndEnableSpeedReg(port, power); 346 } else { 347 UpdatePower(port, power); 348 #ifdef RUNMOTOR2_SYNCMODE 349 UpdatePower(port2, power); 350 #endif 351 }//end if 352 328 353 curStage = STAGE_DRIVING; 329 354 -
branches/atorf/NXC/MotorControl2/MotorControl20.nxc
r660 r663 324 324 325 325 326 task main() {326 task TESTmain() { 327 327 328 328 byte port = OUT_B; … … 371 371 372 372 373 task NEWmain(){373 task main(){ 374 374 375 375 // parameter initialization … … 629 629 if (port <= 2) { 630 630 631 //ResetErrorCorrection(port); 632 //TODO check if motor is ready 633 MotorCmdSingleReset(port, power, angle, speedreg); 631 // if no current tacholimit and no new one, allow speed change 632 if ((MotorTachoLimit(port) == 0) && (angle == 0)) { 633 MotorCmdSingleReset(port, power, angle, speedreg); 634 } else { 635 if (IsMotorReady(port)) { 636 MotorCmdSingleReset(port, power, angle, speedreg); 637 } else { 638 TaskBusySignal(); 639 }//end if 640 }//end if 634 641 635 642 } else { // Otherwise (OUT_AB, OUT_AC, OUT_BC, OUT_ABC?) … … 650 657 }//end switch 651 658 652 if (IsMotorReady(port1) && IsMotorReady(port2)) { 653 //needed? shouldn't make any difference actually 654 //MotorOff(port1); 655 //MotorOff(port2); 659 660 // if no current tacholimit and no new one, allow speed change 661 if ((MotorTachoLimit(port1) == 0) && (MotorTachoLimit(port2) == 0) && (angle == 0)) { 662 //~~~~BEGIN COPY PASTE CODE~~~~~~~~~~~~~~~~~~ 663 //avoid already synced motors (that doesn't work as we know...) 664 until((MotorRegulation(port1) == OUT_REGMODE_IDLE) && (MotorRegulation(port2) == OUT_REGMODE_IDLE)) { 665 // repeatedly setting this is not nice, but so 666 // we don't need a timeout...! 667 MotorOff(port1); 668 MotorOff(port2); 669 // make sure VM applies our settings 670 Wait(1); 671 }//end until 672 MotorCmdDoubleReset(port1, power, angle, port2); 673 //~~~~END COPY PASTE CODE~~~~~~~~~~~~~~~~~~ 674 } else { 675 if (IsMotorReady(port1) && IsMotorReady(port2)) { 676 //~~~~BEGIN COPY PASTE CODE~~~~~~~~~~~~~~~~~~ 677 //avoid already synced motors (that doesn't work as we know...) 678 until((MotorRegulation(port1) == OUT_REGMODE_IDLE) && (MotorRegulation(port2) == OUT_REGMODE_IDLE)) { 679 // repeatedly setting this is not nice, but so 680 // we don't need a timeout...! 681 MotorOff(port1); 682 MotorOff(port2); 683 // make sure VM applies our settings 684 Wait(1); 685 }//end until 686 MotorCmdDoubleReset(port1, power, angle, port2); 687 //~~~~END COPY PASTE CODE~~~~~~~~~~~~~~~~~~ 688 } else { 689 TaskBusySignal(); 690 }//end if 656 691 657 //ResetErrorCorrectionAndBlockCount(port1);658 //ResetErrorCorrectionAndBlockCount(port2);659 MotorCmdDoubleReset(port1, power, angle, port2);660 661 } else {662 TaskBusySignal();663 692 }//end if 664 693 -
branches/atorf/NXC/MotorControl2/MotorFunctions.nxc
r660 r663 40 40 */ 41 41 42 #define MOTORSTOPPED_TIMEOUT 700 //in ms42 #define MOTORSTOPPED_TIMEOUT 800 //in ms 43 43 //TODO this can / should be lowered! very important to reduce 44 44 // total execution time of motor controlling task! 45 45 // this period is basically "wasted" at the end of EACH AND EVERY SINGLE 46 46 // movement, so it really is a sort of "full blackout" for a motor... 47 #define MOTORSTOPPED_RESTINGPERIOD 2 50 //in ms47 #define MOTORSTOPPED_RESTINGPERIOD 200 //in ms 48 48 49 49 … … 342 342 }//end UpdatePower 343 343 344 inline void UpdatePowerAndEnableSpeedReg(const byte &port, const int &pwr) { 345 SetOutput(port, Power, pwr, OutputMode, OUT_MODE_BRAKE + OUT_MODE_MOTORON + OUT_MODE_REGULATED, RegMode, OUT_REGMODE_SPEED, UpdateFlags, UF_UPDATE_SPEED + UF_UPDATE_MODE); 346 }//end UpdatePowerAndEnableSpeedReg 347 348 344 349 inline void UpdatePowerSync(const byte &port, const int &pwr) { 345 350 SetOutput(port, Power, pwr, RunState, OUT_RUNSTATE_RUNNING, UpdateFlags, UF_UPDATE_SPEED); // + UF_UPDATE_MODE); 346 }//end UpdatePower 351 }//end UpdatePowerSync 347 352 348 353
