Changeset 368

Show
Ignore:
Timestamp:
09/30/08 19:52:23 (5 years ago)
Author:
behrens
Message:

add comments in MotorControl.nxc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/atorf/NXC/MotorControl.nxc

    r356 r368  
    2020byte SyncPorts; 
    2121 
     22// tasks 
    2223task MoveA() { 
    23  
    2424    Acquire(movingA); 
    2525        RotateMotorEx(OUT_A, motorA.power, motorA.angle, motorA.turnratio, motorA.syncmode, motorA.endbrake); 
    2626    Release(movingA); 
    27  
    2827}//MoveA 
    2928 
    3029task MoveB() { 
    31  
    3230    Acquire(movingB); 
    3331        RotateMotorEx(OUT_B, motorB.power, motorB.angle, motorB.turnratio, motorB.syncmode, motorB.endbrake); 
    3432    Release(movingB); 
    35  
    3633}//MoveB 
    3734 
    3835task MoveC() { 
    39  
    4036    Acquire(movingC); 
    4137        RotateMotorEx(OUT_C, motorC.power, motorC.angle, motorC.turnratio, motorC.syncmode, motorC.endbrake); 
    4238    Release(movingC); 
    43  
    4439}//MoveC 
    4540 
    46  
    4741task MoveSync() { 
    48  
    49     if (SyncPorts == 3) { 
     42    if (SyncPorts == 3) { // OUT_AB 
    5043        Acquire(movingA); 
    5144        Acquire(movingB); 
     
    5346        Release(movingA); 
    5447        Release(movingB); 
    55     } else if (SyncPorts == 4) { 
     48    } else if (SyncPorts == 4) { // OUT_AC 
    5649        Acquire(movingA); 
    5750        Acquire(movingC); 
     
    5952        Release(movingA); 
    6053        Release(movingC); 
    61     } else if (SyncPorts == 5) { 
     54    } else if (SyncPorts == 5) { // OUT_BC 
    6255        Acquire(movingB); 
    6356        Acquire(movingC); 
     
    6659        Release(movingC); 
    6760    }//end if 
    68  
    69  
    70  
    71 }//MoveC 
    72  
    73  
     61}//MoveSync 
     62 
     63 
     64// ------------------------------------------------- 
     65// functions 
     66// TODO: function parameters 
    7467void ResetAllCounters(byte port, int pwr, long tacholimit, int turnratio, bool speedreg, bool sync) { 
    7568 
     
    9083    }//end if 
    9184 
    92  
    9385    SetOutput(port, Power, pwr, TachoLimit, tacholimit, TurnRatio, turnratio, OutputMode, mode, RegMode, reg,  RunState, state, UpdateFlags, flags); 
    94  
    95  
    9686} // end MotorCmd 
    97  
    9887 
    9988 
     
    117106    }//end if 
    118107 
    119  
    120108    SetOutput(port, Power, pwr, TachoLimit, tacholimit, TurnRatio, turnratio, OutputMode, mode, RegMode, reg,  RunState, state, UpdateFlags, flags); 
    121  
    122  
    123109} // end MotorCmd 
    124110 
    125111 
     112 
     113// ------------------------------------------------- 
     114// main function 
    126115task main(){ 
    127116 
     117    // parameter initialization 
    128118    string in = ""; 
    129119    int i = 0; 
     
    141131    string tmp2 = ""; 
    142132     
     133     
    143134    while(true){ 
    144135 
     
    148139         
    149140            // read values 
    150              
    151141            tmp      = SubStr(in,  0, 1);  // pos 0 
    152142            port     = StrToNum(tmp); 
     
    165155 
    166156 
    167              
    168  
    169  
    170  
     157            // interpretate values 
     158             
     159            // power 
    171160            if (power == 201) { 
    172161                if (port <= 2) { 
    173162                    ResetAllTachoCounts(port); 
    174                 } else if (port == 6) { 
     163                } else if (port == 6) { // OUT_ABC 
    175164                    ResetAllTachoCounts(OUT_A); 
    176165                    ResetAllTachoCounts(OUT_B); 
     
    182171               // process... 
    183172 
     173               // power 
    184174                if(power > 100) { 
    185175                    power = -(power - 100); 
    186176                }//end if 
    187177 
     178                // turnratio 
    188179                if(turnratio > 100) { 
    189180                    turnratio = -(turnratio - 100); 
    190181                }//end if 
    191182 
     183                // sync / brake mode 
    192184                synctext = "syncOFF"; 
    193185                braketext = "endCOAST"; 
     
    212204 
    213205 
    214                 // debug out 
    215  
    216  
     206                // debug out on NXT display 
    217207                tmp = NumToStr(i); 
    218208                msg = StrCat("MotorCmdNr=", tmp); 
     
    232222 
    233223                // finally, the command 
    234  
    235                 if (port == 0) { 
     224                // start motors 
     225                if (port == 0) { // OUT_A 
    236226 
    237227                    motorA.power = power; 
     
    243233                    start MoveA; 
    244234 
    245                 } else if (port == 1) { 
     235                } else if (port == 1) { // OUT_B 
    246236 
    247237                    motorB.power = power; 
     
    253243                    start MoveB; 
    254244 
    255  
    256                 } else if (port == 2) { 
     245                } else if (port == 2) { // OUT_C 
    257246 
    258247                    motorC.power = power; 
     
    263252 
    264253                    start MoveC; 
    265                 } else { 
     254                     
     255                } else { // Otherwise (OUT_AB, OUT_AC, OUT_BC, OUT_ABC?) 
    266256 
    267257                    SyncPorts = port; 
     
    278268 
    279269                //RotateMotorEx(port, power, angle, turnratio, syncmode, endbrake); 
     270                // problem command is waiting until finished. 
    280271 
    281272 
     
    285276            } // end if 
    286277             
    287             // reset!!!! 
    288              
     278             
     279            // update for next message 
     280            // reset message !!!! 
    289281            in = ""; 
    290282