Changeset 789 for firmware/trunk/libraries/stepper/stepper.c
- Timestamp:
- 08/06/08 14:03:57 (5 months ago)
- Files:
-
- 1 modified
-
firmware/trunk/libraries/stepper/stepper.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
firmware/trunk/libraries/stepper/stepper.c
r777 r789 98 98 - bipolar or unipolar 99 99 - normal of half-stepping 100 100 101 \section Positioning 101 102 You can generally use the stepper motor in 2 modes - \b absolute positioning or \b relative positioning. 102 103 … … 106 107 107 108 For relative positioning, use Stepper_Step( ) to simply move a number of steps from the current position. 109 110 See the <a href="http://www.makingthings.com/documentation/how-to/stepper-motor">Stepper Motor how-to</a> 111 for more detailed info on hooking up a stepper motor to the Make Controller. 108 112 * \ingroup Libraries 109 113 * @{ … … 111 115 112 116 /** 113 Attempt to set the specified114 117 Sets whether the specified Stepper is active. 115 118 @param index An integer specifying which stepper (0 or 1). 116 119 @param state An integer specifying the active state - 1 (active) or 0 (inactive). 117 120 @return Zero on success. 121 122 \b Example 123 \code 124 // enable stepper 1 125 Stepper_SetActive(1, 1); 126 \endcode 118 127 */ 119 128 int Stepper_SetActive( int index, int state ) … … 152 161 @param index An integer specifying which stepper (0-1). 153 162 @return State - 1 (active) or 0 (inactive). 163 164 \b Example 165 \code 166 if( Stepper_GetActive(1) ) 167 { 168 // Stepper 1 is active 169 } 170 else 171 { 172 // Stepper 1 is inactive 173 } 174 \endcode 154 175 */ 155 176 int Stepper_GetActive( int index ) … … 166 187 /** 167 188 Set the position of the specified stepper motor. 189 Note that this will not ask the stepper to move. It will simply update 190 the position that the stepper thinks its at. To move the stepper, see 191 Stepper_SetPositionRequested() or Stepper_Step(). 168 192 @param index An integer specifying which stepper (0 or 1). 169 193 @param position An integer specifying the stepper position. 170 194 @return status (0 = OK). 195 196 \b Example 197 \code 198 // reset stepper 1 to call its current position 0 199 Stepper_SetPosition(1, 0); 200 \endcode 171 201 */ 172 202 int Stepper_SetPosition( int index, int position ) … … 192 222 /** 193 223 Set the destination position for a stepper motor. 224 This will start the stepper moving the given number of 225 steps at the current speed, as set by Stepper_SetSpeed(). 226 227 While it's moving, you can call Stepper_GetPosition() to read 228 its current position. 194 229 @param index An integer specifying which stepper (0 or 1). 195 230 @param positionRequested An integer specifying the desired stepper position. 196 231 @return status (0 = OK). 232 233 \b Example 234 \code 235 // start moving stepper 0 1500 steps 236 Stepper_SetPositionRequested(0, 1500); 237 \endcode 197 238 */ 198 239 int Stepper_SetPositionRequested( int index, int positionRequested ) … … 216 257 /** 217 258 Set the speed at which a stepper will move. 218 This is a number of ms per step, 219 rather than the more common steps per second. Arranging it this way makes 220 it easier to express as an integer. Fastest speed is 1ms / step (1000 steps 221 per second) and slowest is many seconds. 259 This is a number of ms per step, rather than the more common steps per second. 260 Arranging it this way makes it easier to express as an integer. 261 Fastest speed is 1ms / step (1000 steps per second) and slowest is many seconds. 222 262 @param index An integer specifying which stepper (0 or 1). 223 263 @param speed An integer specifying the stepper speed in ms per step 224 264 @return status (0 = OK). 265 266 \b Example 267 \code 268 // set the speed to 1ms / step (1000 steps per second) 269 Stepper_SetSpeed(0, 1); 270 \endcode 225 271 */ 226 272 int Stepper_SetSpeed( int index, int speed ) … … 250 296 @param index An integer specifying which stepper (0 or 1). 251 297 @return The speed (0 - 1023), or 0 on error. 298 299 \b Example 300 \code 301 int step0_speed = Stepper_GetSpeed(0); 302 // now step0_speed has the speed of stepper 0 303 \endcode 252 304 */ 253 305 int Stepper_GetSpeed( int index ) … … 264 316 /** 265 317 Read the current position of a stepper motor. 266 @param index An integer specifying which stepper (0 - 3).318 @param index An integer specifying which stepper (0 or 1). 267 319 @return The position, 0 on error. 320 321 \b Example 322 \code 323 int step0_pos = Stepper_GetPosition(0); 324 // now step0_pos has the current position of stepper 0 325 \endcode 268 326 */ 269 327 int Stepper_GetPosition( int index ) … … 280 338 /** 281 339 Read the destination position of a stepper motor. 340 This indicates where the stepper is ultimately headed. To see 341 where it actually is, see Stepper_GetPosition(). 282 342 @param index An integer specifying which stepper (0 or 1). 283 343 @return The position and 0 on error 344 345 \b Example 346 \code 347 int step1_destination = Stepper_GetPositionRequested(1); 348 // step1_destination has the requested position for stepper 1 349 \endcode 284 350 */ 285 351 int Stepper_GetPositionRequested( int index ) … … 300 366 @param steps An integer specifying the number of steps. Can be negative to go in reverse. 301 367 @return status (0 = OK). 368 369 \b Example 370 \code 371 // take 1200 steps forward from our current position 372 Stepper_Step(0, 1200); 373 \endcode 302 374 */ 303 375 int Stepper_Step( int index, int steps ) … … 319 391 320 392 /** 321 Not implemented - returns 0.322 @param index An integer specifying which stepper (0 or 1).323 */324 int Stepper_GetStep( int index )325 {326 if ( index < 0 || index >= STEPPER_COUNT )327 return CONTROLLER_ERROR_ILLEGAL_INDEX;328 329 return 0; // write-only330 }331 332 /**333 393 Set the duty - from 0 to 1023. The default is for 100% power (1023). 334 394 @param index An integer specifying which stepper (0 or 1). 335 395 @param duty An integer specifying the stepper duty (0 - 1023). 336 396 @return status (0 = OK). 397 398 \b Example 399 \code 400 // set stepper 0 to half power 401 Stepper_SetDuty(0, 512); 402 \endcode 337 403 */ 338 404 int Stepper_SetDuty( int index, int duty ) … … 358 424 Get the duty 359 425 Read the value previously set for the duty. 360 @param index An integer specifying which stepper (0 - 3).426 @param index An integer specifying which stepper (0 or 1). 361 427 @return The duty (0 - 1023), or 0 on error. 428 429 \b Example 430 \code 431 int step1_duty = Stepper_GetDuty(1); 432 // step1_duty has the current duty for stepper 1 433 \endcode 362 434 */ 363 435 int Stepper_GetDuty( int index ) … … 373 445 374 446 /** 375 Declare whether the stepper is bipolar or not. Default is bipolar. 447 Declare whether the stepper is bipolar or not. 448 Default is bipolar. 376 449 @param index An integer specifying which stepper (0 or 1). 377 450 @param bipolar An integer 1 for bipolar, 0 for unipolar 378 451 @return status (0 = OK). 452 453 \b Example 454 \code 455 // set stepper 1 to unipolar 456 Stepper_SetBipolar(1, 0); 457 \endcode 379 458 */ 380 459 int Stepper_SetBipolar( int index, int bipolar ) … … 395 474 Get the bipolar setting 396 475 Read the value previously set for bipolar. 397 @param index An integer specifying which stepper (0 - 3).476 @param index An integer specifying which stepper (0 or 1). 398 477 @return 1 for bipolar or 0 for unipolar. 478 479 \b Example 480 \code 481 if( Stepper_GetBipolar(1) ) 482 { 483 // stepper 1 is bipolar 484 } 485 else 486 { 487 // stepper 1 is unipolar 488 } 489 \endcode 399 490 */ 400 491 int Stepper_GetBipolar( int index ) … … 410 501 411 502 /** 412 Declare whether the stepper is in half stepping mode or not. Default is not - i.e. in full step mode. 503 Declare whether the stepper is in half stepping mode or not. 504 Default is not - i.e. in full step mode. 413 505 @param index An integer specifying which stepper (0 or 1). 414 506 @param halfStep An integer specifying 1 for half step, 0 for full step 415 507 @return status (0 = OK). 508 509 \b Example 510 \code 511 // set stepper 1 to half step mode 512 Stepper_SetHalfStep(1, 1); 513 \endcode 416 514 */ 417 515 int Stepper_SetHalfStep( int index, int halfStep ) … … 433 531 @param index An integer specifying which stepper (0 or 1). 434 532 @return the HalfStep setting. 533 534 \b Example 535 \code 536 if( Stepper_GetHalfStep(1) ) 537 { 538 // stepper 1 is in half step mode 539 } 540 else 541 { 542 // stepper 1 is in full step mode 543 } 544 \endcode 435 545 */ 436 546 int Stepper_GetHalfStep( int index ) … … 1151 1261 value = Stepper_GetBipolar( index ); 1152 1262 break; 1153 case 7: // step1154 value = Stepper_GetStep( index );1155 break;1156 1263 } 1157 1264 return value;
