Changeset 368
- Timestamp:
- 09/30/08 19:52:23 (5 years ago)
- Files:
-
- 1 modified
-
branches/atorf/NXC/MotorControl.nxc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/NXC/MotorControl.nxc
r356 r368 20 20 byte SyncPorts; 21 21 22 // tasks 22 23 task MoveA() { 23 24 24 Acquire(movingA); 25 25 RotateMotorEx(OUT_A, motorA.power, motorA.angle, motorA.turnratio, motorA.syncmode, motorA.endbrake); 26 26 Release(movingA); 27 28 27 }//MoveA 29 28 30 29 task MoveB() { 31 32 30 Acquire(movingB); 33 31 RotateMotorEx(OUT_B, motorB.power, motorB.angle, motorB.turnratio, motorB.syncmode, motorB.endbrake); 34 32 Release(movingB); 35 36 33 }//MoveB 37 34 38 35 task MoveC() { 39 40 36 Acquire(movingC); 41 37 RotateMotorEx(OUT_C, motorC.power, motorC.angle, motorC.turnratio, motorC.syncmode, motorC.endbrake); 42 38 Release(movingC); 43 44 39 }//MoveC 45 40 46 47 41 task MoveSync() { 48 49 if (SyncPorts == 3) { 42 if (SyncPorts == 3) { // OUT_AB 50 43 Acquire(movingA); 51 44 Acquire(movingB); … … 53 46 Release(movingA); 54 47 Release(movingB); 55 } else if (SyncPorts == 4) { 48 } else if (SyncPorts == 4) { // OUT_AC 56 49 Acquire(movingA); 57 50 Acquire(movingC); … … 59 52 Release(movingA); 60 53 Release(movingC); 61 } else if (SyncPorts == 5) { 54 } else if (SyncPorts == 5) { // OUT_BC 62 55 Acquire(movingB); 63 56 Acquire(movingC); … … 66 59 Release(movingC); 67 60 }//end if 68 69 70 71 }//MoveC 72 73 61 }//MoveSync 62 63 64 // ------------------------------------------------- 65 // functions 66 // TODO: function parameters 74 67 void ResetAllCounters(byte port, int pwr, long tacholimit, int turnratio, bool speedreg, bool sync) { 75 68 … … 90 83 }//end if 91 84 92 93 85 SetOutput(port, Power, pwr, TachoLimit, tacholimit, TurnRatio, turnratio, OutputMode, mode, RegMode, reg, RunState, state, UpdateFlags, flags); 94 95 96 86 } // end MotorCmd 97 98 87 99 88 … … 117 106 }//end if 118 107 119 120 108 SetOutput(port, Power, pwr, TachoLimit, tacholimit, TurnRatio, turnratio, OutputMode, mode, RegMode, reg, RunState, state, UpdateFlags, flags); 121 122 123 109 } // end MotorCmd 124 110 125 111 112 113 // ------------------------------------------------- 114 // main function 126 115 task main(){ 127 116 117 // parameter initialization 128 118 string in = ""; 129 119 int i = 0; … … 141 131 string tmp2 = ""; 142 132 133 143 134 while(true){ 144 135 … … 148 139 149 140 // read values 150 151 141 tmp = SubStr(in, 0, 1); // pos 0 152 142 port = StrToNum(tmp); … … 165 155 166 156 167 168 169 170 157 // interpretate values 158 159 // power 171 160 if (power == 201) { 172 161 if (port <= 2) { 173 162 ResetAllTachoCounts(port); 174 } else if (port == 6) { 163 } else if (port == 6) { // OUT_ABC 175 164 ResetAllTachoCounts(OUT_A); 176 165 ResetAllTachoCounts(OUT_B); … … 182 171 // process... 183 172 173 // power 184 174 if(power > 100) { 185 175 power = -(power - 100); 186 176 }//end if 187 177 178 // turnratio 188 179 if(turnratio > 100) { 189 180 turnratio = -(turnratio - 100); 190 181 }//end if 191 182 183 // sync / brake mode 192 184 synctext = "syncOFF"; 193 185 braketext = "endCOAST"; … … 212 204 213 205 214 // debug out 215 216 206 // debug out on NXT display 217 207 tmp = NumToStr(i); 218 208 msg = StrCat("MotorCmdNr=", tmp); … … 232 222 233 223 // finally, the command 234 235 if (port == 0) { 224 // start motors 225 if (port == 0) { // OUT_A 236 226 237 227 motorA.power = power; … … 243 233 start MoveA; 244 234 245 } else if (port == 1) { 235 } else if (port == 1) { // OUT_B 246 236 247 237 motorB.power = power; … … 253 243 start MoveB; 254 244 255 256 } else if (port == 2) { 245 } else if (port == 2) { // OUT_C 257 246 258 247 motorC.power = power; … … 263 252 264 253 start MoveC; 265 } else { 254 255 } else { // Otherwise (OUT_AB, OUT_AC, OUT_BC, OUT_ABC?) 266 256 267 257 SyncPorts = port; … … 278 268 279 269 //RotateMotorEx(port, power, angle, turnratio, syncmode, endbrake); 270 // problem command is waiting until finished. 280 271 281 272 … … 285 276 } // end if 286 277 287 // reset!!!! 288 278 279 // update for next message 280 // reset message !!!! 289 281 in = ""; 290 282
