Show
Ignore:
Timestamp:
07/15/09 06:26:14 (4 years ago)
Author:
atorf
Message:

Bugfixing in MotorControl 2.0:

  • Fixed the strange "motor runs too slow with speed regulation although power seems high" bug
  • Added support for all "direct command like" instructions via NXC_MotorControl call from MATLAB
  • Overwriting a currently running motor WITHOUT tacholimit with a new speed is now possible…
  • For synced driving, motors have to be stopped before every time, otherwise it doesn't work!
  • Tweaked some timeout constants
  • Still one bug missing: With many motors running at the same time, a task can lock up, but where? Can't be stopped with direct command, why?
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/atorf/NXC/MotorControl2/ControllerCore.nxc

    r658 r663  
    135135//     * tacholimit already... 
    136136 
    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? 
    138141    #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 
    139151        MotorCmdDoubleReset(port, powerSgn, tacholimit, port2); 
    140152    #else 
    141         MotorCmdSingleReset(port, powerSgn, tacholimit, false); 
     153        MotorCmdSingleReset(port, powerSgn, tacholimit, speedreg); 
    142154    #endif 
    143155     
     
    241253//      - direct command stopped us? 
    242254        // 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        /* 
    244257        if ( abs(tachoTarget - MotorTachoCount(port)) >= 2 ) { 
    245258            // we are almost already there :-) 
    246259            // or even too far :-/ 
    247260        }//end if 
    248  
     261        */ 
    249262         
    250263        if ( MotorPower(port) == 0 ) { 
     
    291304                // when rampup is done 
    292305                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 
    298315                    curStage = STAGE_DRIVING; 
    299316                } else { 
     
    302319                    // if power < 100 we might be done sooner: 
    303320                    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 
    309330                        curStage = STAGE_DRIVING; 
    310331                    } else { 
     
    320341             
    321342                // 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 
    328353                curStage = STAGE_DRIVING; 
    329354